From ea173640f289fd0f75e52842264cd6eaf57786c3 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 30 Oct 2018 14:24:18 -0400 Subject: [PATCH 1/2] Bump CoffeeScript to version 2.3.2 and enable lazy compilation. The introduction of lazy compilation should help with #10298. --- .../.npm/package/npm-shrinkwrap.json | 6 +++--- packages/non-core/coffeescript-compiler/package.js | 4 ++-- .../compile-coffeescript/npm-shrinkwrap.json | 6 +++--- .../non-core/coffeescript/compile-coffeescript.js | 14 ++++++++++++++ packages/non-core/coffeescript/package.js | 4 ++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/non-core/coffeescript-compiler/.npm/package/npm-shrinkwrap.json b/packages/non-core/coffeescript-compiler/.npm/package/npm-shrinkwrap.json index 87857d7090..1d8d07771c 100644 --- a/packages/non-core/coffeescript-compiler/.npm/package/npm-shrinkwrap.json +++ b/packages/non-core/coffeescript-compiler/.npm/package/npm-shrinkwrap.json @@ -2,9 +2,9 @@ "lockfileVersion": 1, "dependencies": { "coffeescript": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.3.1.tgz", - "integrity": "sha512-DNJmSPMyiz+OjWYyuDXNBcFutDjP2TS2owsZ8YvT65hA8c5IdHWIBqdA3Yf/XHoK23d/f1HqLjQbEJJZJoeV1w==" + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.3.2.tgz", + "integrity": "sha512-YObiFDoukx7qPBi/K0kUKyntEZDfBQiqs/DbrR1xzASKOBjGT7auD85/DiPeRr9k++lRj7l3uA9TNMLfyfcD/Q==" }, "source-map": { "version": "0.5.7", diff --git a/packages/non-core/coffeescript-compiler/package.js b/packages/non-core/coffeescript-compiler/package.js index f05cb8e6f1..0850dd130b 100644 --- a/packages/non-core/coffeescript-compiler/package.js +++ b/packages/non-core/coffeescript-compiler/package.js @@ -13,11 +13,11 @@ Package.describe({ summary: 'Compiler for CoffeeScript code, supporting the coffeescript package', // This version of NPM `coffeescript` module, with _1, _2 etc. // If you change this, make sure to also update ../coffeescript/package.js to match. - version: '2.3.1_2' + version: '2.3.2_1' }); Npm.depends({ - 'coffeescript': '2.3.1', + 'coffeescript': '2.3.2', 'source-map': '0.5.7' }); diff --git a/packages/non-core/coffeescript/.npm/plugin/compile-coffeescript/npm-shrinkwrap.json b/packages/non-core/coffeescript/.npm/plugin/compile-coffeescript/npm-shrinkwrap.json index 1f1254a557..a59317fc81 100644 --- a/packages/non-core/coffeescript/.npm/plugin/compile-coffeescript/npm-shrinkwrap.json +++ b/packages/non-core/coffeescript/.npm/plugin/compile-coffeescript/npm-shrinkwrap.json @@ -2,9 +2,9 @@ "lockfileVersion": 1, "dependencies": { "@babel/runtime": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.0.0.tgz", - "integrity": "sha512-7hGhzlcmg01CvH1EHdSPVXYX1aJ8KCEyz6I9xYIi/asDtzBPMyMhVibhM/K6g/5qnKBwjZtp10bNZIEFTRW1MA==" + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.1.2.tgz", + "integrity": "sha512-Y3SCjmhSupzFB6wcv1KmmFucH6gDVnI30WjOcicV10ju0cZjak3Jcs67YLIXBrmZYw1xCrVeJPbycFwrqNyxpg==" }, "regenerator-runtime": { "version": "0.12.1", diff --git a/packages/non-core/coffeescript/compile-coffeescript.js b/packages/non-core/coffeescript/compile-coffeescript.js index 7f91bb552d..3792d61d71 100644 --- a/packages/non-core/coffeescript/compile-coffeescript.js +++ b/packages/non-core/coffeescript/compile-coffeescript.js @@ -28,6 +28,20 @@ class CachedCoffeeScriptCompiler extends CachingCompiler { return super.setDiskCacheDirectory(cacheDir); } + compileOneFileLater(inputFile, getResult) { + inputFile.addJavaScript({ + path: this.coffeeScriptCompiler.outputFilePath(inputFile), + sourcePath: inputFile.getPathInPackage(), + bare: inputFile.getFileOptions().bare + }, async () => { + const result = await getResult(); + return result && { + data: result.source, + sourceMap: result.sourceMap, + }; + }); + } + compileOneFile(inputFile) { return this.coffeeScriptCompiler.compileOneFile(inputFile); } diff --git a/packages/non-core/coffeescript/package.js b/packages/non-core/coffeescript/package.js index c873977ee7..d549a3c25b 100644 --- a/packages/non-core/coffeescript/package.js +++ b/packages/non-core/coffeescript/package.js @@ -6,7 +6,7 @@ Package.describe({ // so bumping the version of this package will be how they get newer versions // of `coffeescript-compiler`. If you change this, make sure to also update // ../coffeescript-compiler/package.js to match. - version: '2.3.1_2' + version: '2.3.2_1' }); Package.registerBuildPlugin({ @@ -22,7 +22,7 @@ Package.registerBuildPlugin({ // rather than delegating to the one installed in the application's // node_modules directory, so the coffeescript package can work in // Meteor 1.7.1 apps as well as 1.7.0.x and earlier. - '@babel/runtime': '7.0.0' + '@babel/runtime': '7.1.2' } }); From c96278700de8fd6ffb9e0b1d374c3518f3ab10c8 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 31 Oct 2018 10:40:16 -0400 Subject: [PATCH 2/2] Fix compiler plugins self-tests by waiting for lazy compilation to finish. --- packages/caching-compiler/caching-compiler.js | 34 +++++++++++++------ .../multi-file-caching-compiler.js | 22 ++++++------ tools/isobuild/bundler.js | 13 +++++++ tools/project-context.js | 7 +++- tools/tests/compiler-plugins.js | 14 ++++++++ 5 files changed, 69 insertions(+), 21 deletions(-) diff --git a/packages/caching-compiler/caching-compiler.js b/packages/caching-compiler/caching-compiler.js index ab1cea5cae..e29e1362e5 100644 --- a/packages/caching-compiler/caching-compiler.js +++ b/packages/caching-compiler/caching-compiler.js @@ -25,6 +25,10 @@ CachingCompilerBase = class CachingCompilerBase { // For testing. this._callCount = 0; + + // Callbacks that will be called after the linker is done processing + // files, after all lazy compilation has finished. + this._afterLinkCallbacks = []; } // Your subclass must override this method to define the key used to identify @@ -113,6 +117,14 @@ CachingCompilerBase = class CachingCompilerBase { }, 0); } + // Called by the compiler plugins system after all linking and lazy + // compilation has finished. + afterLink() { + this._afterLinkCallbacks.splice(0).forEach(callback => { + callback(); + }); + } + // Borrowed from another MIT-licensed project that benjamn wrote: // https://github.com/reactjs/commoner/blob/235d54a12c/lib/util.js#L136-L168 _deepHash(val) { @@ -327,17 +339,19 @@ CachingCompiler = class CachingCompiler extends CachingCompilerBase { }); if (this._cacheDebugEnabled) { - cacheMisses.sort(); + this._afterLinkCallbacks.push(() => { + cacheMisses.sort(); - this._cacheDebug( - `Ran (#${ - ++this._callCount - }) on: ${ - JSON.stringify(cacheMisses) - } ${ - JSON.stringify(Object.keys(arches).sort()) - }` - ); + this._cacheDebug( + `Ran (#${ + ++this._callCount + }) on: ${ + JSON.stringify(cacheMisses) + } ${ + JSON.stringify(Object.keys(arches).sort()) + }` + ); + }); } } diff --git a/packages/caching-compiler/multi-file-caching-compiler.js b/packages/caching-compiler/multi-file-caching-compiler.js index 4add6b81a3..dcd75ac2e7 100644 --- a/packages/caching-compiler/multi-file-caching-compiler.js +++ b/packages/caching-compiler/multi-file-caching-compiler.js @@ -172,17 +172,19 @@ extends CachingCompilerBase { }); if (this._cacheDebugEnabled) { - cacheMisses.sort(); + this._afterLinkCallbacks.push(() => { + cacheMisses.sort(); - this._cacheDebug( - `Ran (#${ - ++this._callCount - }) on: ${ - JSON.stringify(cacheMisses) - } ${ - JSON.stringify(Object.keys(arches).sort()) - }` - ); + this._cacheDebug( + `Ran (#${ + ++this._callCount + }) on: ${ + JSON.stringify(cacheMisses) + } ${ + JSON.stringify(Object.keys(arches).sort()) + }` + ); + }); } } diff --git a/tools/isobuild/bundler.js b/tools/isobuild/bundler.js index a473bd5c9d..b6eb36b360 100644 --- a/tools/isobuild/bundler.js +++ b/tools/isobuild/bundler.js @@ -1286,6 +1286,19 @@ class Target { ), "utf8") ); }); + + // Call any plugin.afterLink callbacks defined by compiler plugins, + // now that all compilation (including lazy compilation) is finished. + sourceBatches.forEach(batch => { + batch.resourceSlots.forEach(slot => { + const plugin = + slot.sourceProcessor && + slot.sourceProcessor.userPlugin; + if (plugin && typeof plugin.afterLink === "function") { + plugin.afterLink(); + } + }); + }); } // Minify the JS in this target diff --git a/tools/project-context.js b/tools/project-context.js index c3a1195055..7806436baf 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -28,6 +28,10 @@ import { import Resolver from "./isobuild/resolver.js"; +const CAN_DELAY_LEGACY_BUILD = ! JSON.parse( + process.env.METEOR_DISALLOW_DELAYED_LEGACY_BUILD || "false" +); + // The ProjectContext represents all the context associated with an app: // metadata files in the `.meteor` directory, the choice of package versions // used by it, etc. Any time you want to work with an app, create a @@ -1310,7 +1314,8 @@ _.extend(exports.PlatformList.prototype, { }, canDelayBuildingArch(arch) { - return arch === "web.browser.legacy"; + return CAN_DELAY_LEGACY_BUILD && + arch === "web.browser.legacy"; } }); diff --git a/tools/tests/compiler-plugins.js b/tools/tests/compiler-plugins.js index 2222cd0fab..8e8abb8381 100644 --- a/tools/tests/compiler-plugins.js +++ b/tools/tests/compiler-plugins.js @@ -30,6 +30,11 @@ selftest.define("compiler plugin caching - coffee", () => { // Ask them to print out when they build a file (instead of using it from the // cache) as well as when they load cache from disk. s.set('METEOR_COFFEESCRIPT_CACHE_DEBUG', 't'); + + // Enforcing the order of builds is just too tricky if we let the legacy + // build race with the os.* build. + s.set("METEOR_DISALLOW_DELAYED_LEGACY_BUILD", "true"); + var run = startRun(s); let nextRunOrdinal = 1; @@ -69,6 +74,7 @@ selftest.define("compiler plugin caching - coffee", () => { // App prints this: run.match("Coffeescript X is 2 Y is 1 FromPackage is 4"); + run.match("App running at"); s.write("f2.coffee", "share.Y = 'Y is 3'\n"); @@ -79,6 +85,7 @@ selftest.define("compiler plugin caching - coffee", () => { // Program prints this: run.match("Coffeescript X is 2 Y is 3 FromPackage is 4"); + run.match("Meteor server restarted"); // Force a rebuild of the local package without actually changing the // coffeescript file in it. This should not require us to coffee.compile @@ -90,6 +97,7 @@ selftest.define("compiler plugin caching - coffee", () => { matchRun([], osArch); run.match("Coffeescript X is 2 Y is 3 FromPackage is 4"); + run.match("Meteor server restarted"); // But writing to the actual source file in the local package should // recompile. @@ -100,6 +108,7 @@ selftest.define("compiler plugin caching - coffee", () => { matchRun(["/packages/local-pack/p.coffee"], osArch); run.match("Coffeescript X is 2 Y is 3 FromPackage is 5"); + run.match("Meteor server restarted"); // We never should have loaded cache from disk, since we only made // each compiler once and there were no cache files at this point. @@ -140,6 +149,11 @@ selftest.define("compiler plugin caching - coffee", () => { // Ask them to print out when they build a file (instead of using it from // the cache) as well as when they load cache from disk. s.set(`METEOR_${ packageName.toUpperCase() }_CACHE_DEBUG`, "t"); + + // Enforcing the order of builds is just too tricky if we let the legacy + // build race with the "Client modified - refreshing" messages. + s.set("METEOR_DISALLOW_DELAYED_LEGACY_BUILD", "true"); + var run = startRun(s); const cacheMatch = selftest.markStack((message, arch) => {