Skip to content

Commit

Permalink
module: be lazy when creating CJS facades
Browse files Browse the repository at this point in the history
This should remove the penalty for loading CJS that is never imported.

PR-URL: #17153
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
bmeck authored and MylesBorins committed Dec 12, 2017
1 parent 4667c5e commit 06da8a7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,21 @@ Module.prototype.load = function(filename) {
if (ESMLoader) {
const url = getURLFromFilePath(filename);
const urlString = `${url}`;
const exports = this.exports;
if (ESMLoader.moduleMap.has(urlString) !== true) {
const ctx = createDynamicModule(['default'], url);
ctx.reflect.exports.default.set(this.exports);
ESMLoader.moduleMap.set(urlString,
new ModuleJob(ESMLoader, url, async () => ctx));
ESMLoader.moduleMap.set(
urlString,
new ModuleJob(ESMLoader, url, async () => {
const ctx = createDynamicModule(
['default'], url);
ctx.reflect.exports.default.set(exports);
return ctx;
})
);
} else {
const job = ESMLoader.moduleMap.get(urlString);
if (job.reflect)
job.reflect.exports.default.set(this.exports);
job.reflect.exports.default.set(exports);
}
}
};
Expand Down

0 comments on commit 06da8a7

Please sign in to comment.