Merge pull request #8972 from meteor/run-bare-files-before-eager-modules

Run all "bare" package files before requiring eager entry point modules.
This commit is contained in:
Ben Newman
2017-08-07 14:54:24 -04:00
committed by GitHub
2 changed files with 24 additions and 10 deletions

View File

@@ -24,6 +24,12 @@
[Issue #5121](https://github.com/meteor/meteor/issues/5121)
[PR #8917](https://github.com/meteor/meteor/pull/8917)
* Files contained by `client/compatibility/` directories or added with
`api.addFiles(files, ..., { bare: true })` are now evaluated before
importing modules with `require`, which may be a breaking change if you
depend on the interleaving of `bare` files with eager module evaluation.
[PR #8972](https://github.com/meteor/meteor/pull/8972)
## v1.5.1, 2017-07-12
* Node has been upgraded to version 4.8.4.

View File

@@ -233,8 +233,8 @@ _.extend(Module.prototype, {
_.each(this.files, file => {
if (file.bare) {
// Bare files will be added in between the synchronous require
// calls in _chunkifyEagerRequires.
// Bare files will be added before the synchronous require calls
// in _chunkifyEagerRequires.
return;
}
@@ -384,10 +384,9 @@ _.extend(Module.prototype, {
},
// Adds require calls to the chunks array for all modules that should be
// eagerly evaluated, and also includes bare files in the appropriate
// order with respect to the require calls. Returns the name of the
// variable that holds the main exports object, if api.mainModule was
// used to define a main module.
// eagerly evaluated, and also includes any bare files before the
// require calls. Returns the name of the variable that holds the main
// exports object, if api.mainModule was used to define a main module.
_chunkifyEagerRequires(chunks, moduleCount, sourceWidth) {
assert.ok(_.isArray(chunks));
assert.ok(_.isNumber(moduleCount));
@@ -396,8 +395,11 @@ _.extend(Module.prototype, {
let exportsName;
// Now that we have installed everything in this package or
// application, immediately require the non-lazy modules and
// evaluate the bare files.
// application, first evaluate the bare files, then require the
// non-lazy (eager) modules.
const eagerModuleFiles = [];
_.each(this.files, file => {
if (file.bare) {
chunks.push("\n", file.getPrelinkedOutput({
@@ -405,6 +407,12 @@ _.extend(Module.prototype, {
noLineNumbers: this.noLineNumbers
}));
} else if (moduleCount > 0 && ! file.lazy) {
eagerModuleFiles.push(file);
}
});
if (eagerModuleFiles.length > 0) {
_.each(eagerModuleFiles, file => {
if (file.mainModule) {
exportsName = "exports";
}
@@ -415,8 +423,8 @@ _.extend(Module.prototype, {
JSON.stringify("./" + file.installPath),
");"
);
}
});
});
}
return exportsName;
}