From eb18d59faa1986d912a59bd57a4ecc03ba4b3572 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 8 Apr 2016 00:06:39 -0400 Subject: [PATCH] Make all files in imports and node_modules directories lazy. The most notable change here is that we now treat files in app imports directories as lazy even before we know whether the app is using modules. This could be a breaking change for some 1.3 apps that do not use modules but have imports directories containing eager .js files. That (very minor) level of backwards incompatibility seems acceptable in the context of upgrading to Meteor ~1.3, however. --- tools/isobuild/package-source.js | 63 ++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/tools/isobuild/package-source.js b/tools/isobuild/package-source.js index f8b6ba1e45..42bcba3b3a 100644 --- a/tools/isobuild/package-source.js +++ b/tools/isobuild/package-source.js @@ -1329,40 +1329,49 @@ _.extend(PackageSource.prototype, { const fileOptions = {}; const dirs = files.pathDirname(relPath).split(files.pathSep); - // If the file is restricted to the opposite architecture, make sure - // it is not evaluated eagerly. - if (arch === "os") { - if (dirs.indexOf("client") >= 0) { - fileOptions.lazy = true; - } - } else if (dirs.indexOf("server") >= 0) { - fileOptions.lazy = true; - } - - if (dirs.indexOf("node_modules") >= 0) { - fileOptions.lazy = true; - fileOptions.transpile = false; - } - - // If running in test mode (`meteor test`), all - // files other than test files should be loaded lazily + // If running in test mode (`meteor test`), all files other than test + // files should be loaded lazily. if (global.testCommandMetadata && global.testCommandMetadata.isTest) { if (!isTestFilePath(relPath)) { fileOptions.lazy = true; } } - // Special case: in app code on the client, JavaScript files in a - // `client/compatibility` directory don't get wrapped in a closure. - if (isApp && // Skip this check for packages. - archinfo.matches(arch, "web") && - relPath.endsWith(".js")) { - for (var i = 1; i < dirs.length; ++i) { - if (dirs[i - 1] === "client" && - dirs[i] === "compatibility") { - fileOptions.bare = true; - break; + for (var i = 0; i < dirs.length; ++i) { + let dir = dirs[i]; + + if (dir === "node_modules") { + fileOptions.lazy = true; + fileOptions.transpile = false; + + // Return immediately so that we don't apply special meanings to + // client or server directories inside node_modules directories. + return fileOptions; + } + + if (isApp && dir === "imports") { + fileOptions.lazy = true; + } + + // If the file is restricted to the opposite architecture, make sure + // it is not evaluated eagerly. + if (archinfo.matches(arch, "os")) { + if (dir === "client") { + fileOptions.lazy = true; } + } else if (dir === "server") { + fileOptions.lazy = true; + } + + // Special case: in app code on the client, JavaScript files in a + // `client/compatibility` directory don't get wrapped in a closure. + if (i > 0 && + dirs[i - 1] === "client" && + dir === "compatibility" && + isApp && // Skip this check for packages. + archinfo.matches(arch, "web") && + relPath.endsWith(".js")) { + fileOptions.bare = true; } }