Merge pull request #10312 from meteor/lazy-coffeescript-compilation

Bump CoffeeScript to version 2.3.2 and enable lazy compilation.
This commit is contained in:
Ben Newman
2018-10-31 11:10:02 -04:00
committed by GitHub
10 changed files with 93 additions and 31 deletions

View File

@@ -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())
}`
);
});
}
}

View File

@@ -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())
}`
);
});
}
}

View File

@@ -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",

View File

@@ -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'
});

View File

@@ -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",

View File

@@ -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);
}

View File

@@ -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'
}
});

View File

@@ -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

View File

@@ -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";
}
});

View File

@@ -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) => {