mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
module: be lazy when creating CJS facades
This should remove the penalty for loading CJS that is never imported. PR-URL: https://github.com/nodejs/node/pull/17153 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
4667c5e720
commit
06da8a7f16
1 file changed
+11
-5
+11
-5
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user