From 060f1d0412096dda19cb606076522658c2461bdd Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Tue, 7 Jan 2025 13:25:57 +0100 Subject: [PATCH 1/6] add missing jsdoc imports and defs --- lib/internal/modules/esm/loader.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index dd73b0d0e7dc99..308ad7325aba80 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -56,6 +56,7 @@ const onImport = tracingChannel('module.import'); /** * @typedef {import('./module_job.js').ModuleJobBase} ModuleJobBase * @typedef {import('url').URL} URL + * @typedef {import('internal/modules/esm/hooks.js').HooksProxy} HooksProxy */ /** @@ -109,6 +110,28 @@ let hooksProxy; * @typedef {ArrayBuffer|TypedArray|string} ModuleSource */ +/** + * @typedef {Object} LoadResult + * @property {ModuleFormat} format + * @property {ModuleSource} source + */ + +/** + * @typedef {Object} ResolveResult + * @property {string} format + * @property {URL['href']} url + */ + +/** + * @typedef {Object} Customizations + * @property {boolean} allowImportMetaResolve + * @property {(url: string, context: object) => Promise} load + * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => Promise} resolve + * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => ResolveResult} resolveSync + * @property {(specifier: string, parentURL: string) => any} register + * @property {() => void} forceLoadHooks + */ + /** * This class covers the base machinery of module loading. To add custom * behavior you can pass a customizations object and this object will be @@ -150,6 +173,7 @@ class ModuleLoader { * to this property and failure to do so will cause undefined * behavior when invoking `import.meta.resolve`. * @see {ModuleLoader.setCustomizations} + * @type {Customizations} */ #customizations; @@ -203,10 +227,11 @@ class ModuleLoader { * * Calling this function alters how modules are loaded and should be * invoked with care. - * @param {object} customizations + * @param {Customizations} customizations */ setCustomizations(customizations) { this.#customizations = customizations; + this.#customizations.load() if (customizations) { this.allowImportMetaResolve = customizations.allowImportMetaResolve; } else { @@ -679,7 +704,7 @@ class ModuleLoader { /** * Similar to {@link resolve}, but the results are always synchronously returned. If there are any * asynchronous resolve hooks from module.register(), it will block until the results are returned - * from the loader thread for this to be synchornous. + * from the loader thread for this to be synchronous. * This is here to support `import.meta.resolve()`, `require()` in imported CJS, and * `module.registerHooks()` hooks. * From 7a51ea61d66c15b64c30aaca963b6acc67263784 Mon Sep 17 00:00:00 2001 From: Carlos Espa <43477095+Ceres6@users.noreply.github.com> Date: Tue, 7 Jan 2025 13:29:58 +0100 Subject: [PATCH 2/6] Update lib/internal/modules/esm/loader.js --- lib/internal/modules/esm/loader.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 308ad7325aba80..6c9640a9c40956 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -231,7 +231,6 @@ class ModuleLoader { */ setCustomizations(customizations) { this.#customizations = customizations; - this.#customizations.load() if (customizations) { this.allowImportMetaResolve = customizations.allowImportMetaResolve; } else { From d5d895913695ab43168acd911c3e664e3f350029 Mon Sep 17 00:00:00 2001 From: Carlos Espa <43477095+Ceres6@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:03:12 +0100 Subject: [PATCH 3/6] Update lib/internal/modules/esm/loader.js Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> --- lib/internal/modules/esm/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 6c9640a9c40956..8a8ec5b1ab5063 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -56,7 +56,7 @@ const onImport = tracingChannel('module.import'); /** * @typedef {import('./module_job.js').ModuleJobBase} ModuleJobBase * @typedef {import('url').URL} URL - * @typedef {import('internal/modules/esm/hooks.js').HooksProxy} HooksProxy + * @typedef {import('./hooks.js').HooksProxy} HooksProxy */ /** From 9279948ef32cc7988ff61471a4077475b4891c2a Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Tue, 7 Jan 2025 14:12:39 +0100 Subject: [PATCH 4/6] fixup! add missing jsdoc imports and defs --- lib/internal/modules/esm/loader.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 8a8ec5b1ab5063..d6010a0a03cead 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -54,9 +54,9 @@ const { tracingChannel } = require('diagnostics_channel'); const onImport = tracingChannel('module.import'); /** + * @typedef {import('./hooks.js').HooksProxy} HooksProxy * @typedef {import('./module_job.js').ModuleJobBase} ModuleJobBase * @typedef {import('url').URL} URL - * @typedef {import('./hooks.js').HooksProxy} HooksProxy */ /** @@ -111,23 +111,17 @@ let hooksProxy; */ /** - * @typedef {Object} LoadResult - * @property {ModuleFormat} format - * @property {ModuleSource} source + * @typedef {import('internal/modules/customization_hooks.js').ModuleLoadResult} ModuleLoadResult + * @typedef {import('internal/modules/customization_hooks.js').ModuleResolveResult} ModuleResolveResult */ -/** - * @typedef {Object} ResolveResult - * @property {string} format - * @property {URL['href']} url - */ /** - * @typedef {Object} Customizations + * @typedef {object} Customizations * @property {boolean} allowImportMetaResolve - * @property {(url: string, context: object) => Promise} load - * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => Promise} resolve - * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => ResolveResult} resolveSync + * @property {(url: string, context: object) => Promise} load + * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => Promise} resolve + * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => ModuleResolveResult} resolveSync * @property {(specifier: string, parentURL: string) => any} register * @property {() => void} forceLoadHooks */ From aa26bee488410168b4d825e7f67b1eb1b1bde496 Mon Sep 17 00:00:00 2001 From: Carlos Espa <43477095+Ceres6@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:55:20 +0100 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> --- lib/internal/modules/esm/loader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index d6010a0a03cead..40189f60686fbc 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -167,7 +167,7 @@ class ModuleLoader { * to this property and failure to do so will cause undefined * behavior when invoking `import.meta.resolve`. * @see {ModuleLoader.setCustomizations} - * @type {Customizations} + * @type {CustomizedModuleLoader} */ #customizations; @@ -221,7 +221,7 @@ class ModuleLoader { * * Calling this function alters how modules are loaded and should be * invoked with care. - * @param {Customizations} customizations + * @param {CustomizedModuleLoader} customizations */ setCustomizations(customizations) { this.#customizations = customizations; From 5282fac3b6813851d0b53429a9aee2fa13342558 Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Fri, 10 Jan 2025 09:56:33 +0100 Subject: [PATCH 6/6] fixup! Apply suggestions from code review --- lib/internal/modules/esm/loader.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 40189f60686fbc..a3b437ade87c75 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -110,22 +110,6 @@ let hooksProxy; * @typedef {ArrayBuffer|TypedArray|string} ModuleSource */ -/** - * @typedef {import('internal/modules/customization_hooks.js').ModuleLoadResult} ModuleLoadResult - * @typedef {import('internal/modules/customization_hooks.js').ModuleResolveResult} ModuleResolveResult - */ - - -/** - * @typedef {object} Customizations - * @property {boolean} allowImportMetaResolve - * @property {(url: string, context: object) => Promise} load - * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => Promise} resolve - * @property {(originalSpecifier: string, parentURL: string, importAttributes: Record) => ModuleResolveResult} resolveSync - * @property {(specifier: string, parentURL: string) => any} register - * @property {() => void} forceLoadHooks - */ - /** * This class covers the base machinery of module loading. To add custom * behavior you can pass a customizations object and this object will be