From 3c040348fe9c49687a796fbeea3fe7a9bc1251ed Mon Sep 17 00:00:00 2001 From: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> Date: Wed, 22 Jun 2022 09:13:36 +0200 Subject: [PATCH] Revert "esm: convert `resolve` hook to synchronous" This reverts commit 90b634a5a5bd1b4131b297fedc366777f174a091. PR-URL: https://github.com/nodejs/node/pull/43526 Reviewed-By: Geoffrey Booth Reviewed-By: Guy Bedford Reviewed-By: Antoine du Hamel Reviewed-By: Mohammed Keyvanzadeh --- doc/api/esm.md | 29 ++---- .../modules/esm/initialize_import_meta.js | 26 +++-- lib/internal/modules/esm/loader.js | 95 ++++++------------- lib/internal/modules/esm/resolve.js | 6 +- .../test-esm-import-meta-resolve.mjs | 70 ++++++-------- test/es-module/test-esm-loader-chaining.mjs | 26 ----- test/es-module/test-esm-loader-search.js | 4 +- test/es-module/test-esm-resolve-type.js | 16 ++-- .../builtin-named-exports-loader.mjs | 4 +- .../es-module-loaders/hook-resolve-type.mjs | 4 +- .../loader-invalid-format.mjs | 2 +- .../es-module-loaders/loader-invalid-url.mjs | 4 +- .../es-module-loaders/loader-resolve-42.mjs | 2 +- .../loader-resolve-async-fn.mjs | 3 - .../loader-resolve-bad-next-context.mjs | 2 +- .../loader-resolve-bad-next-specifier.mjs | 2 +- .../es-module-loaders/loader-resolve-foo.mjs | 2 +- .../loader-resolve-incomplete.mjs | 2 +- .../loader-resolve-multiple-next-calls.mjs | 6 +- .../loader-resolve-next-modified.mjs | 4 +- ...oader-resolve-passing-modified-context.mjs | 2 +- .../loader-resolve-passthru.mjs | 2 +- ...der-resolve-receiving-modified-context.mjs | 2 +- .../loader-resolve-shortcircuit.mjs | 2 +- .../es-module-loaders/loader-shared-dep.mjs | 4 +- .../loader-with-custom-condition.mjs | 4 +- .../es-module-loaders/loader-with-dep.mjs | 4 +- .../missing-dynamic-instantiate-hook.mjs | 4 +- .../es-module-loaders/mock-loader.mjs | 4 +- .../not-found-assert-loader.mjs | 6 +- 30 files changed, 127 insertions(+), 216 deletions(-) delete mode 100644 test/fixtures/es-module-loaders/loader-resolve-async-fn.mjs diff --git a/doc/api/esm.md b/doc/api/esm.md index c5ef7eb863f6b7..9f80dcb094e607 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -324,9 +324,6 @@ added: - v13.9.0 - v12.16.2 changes: - - version: REPLACEME - pr-url: https://github.com/nodejs/node/pull/43363 - description: Convert from asynchronous to synchronous. - version: - v16.2.0 - v14.18.0 @@ -342,19 +339,15 @@ command flag enabled. * `specifier` {string} The module specifier to resolve relative to `parent`. * `parent` {string|URL} The absolute parent module URL to resolve from. If none is specified, the value of `import.meta.url` is used as the default. -* Returns: {string} +* Returns: {Promise} Provides a module-relative resolution function scoped to each module, returning -the URL string. In alignment with browser behavior, this now returns -synchronously. - -> **Caveat** This can result in synchronous file-system operations, which -> can impact performance similarly to `require.resolve`. +the URL string. ```js -const dependencyAsset = import.meta.resolve('component-lib/asset.css'); +const dependencyAsset = await import.meta.resolve('component-lib/asset.css'); ``` `import.meta.resolve` also accepts a second argument which is the parent module @@ -363,11 +356,11 @@ from which to resolve from: ```js -import.meta.resolve('./dep', import.meta.url); +await import.meta.resolve('./dep', import.meta.url); ``` -This function is synchronous because the ES module resolver in Node.js is -synchronous. +This function is asynchronous because the ES module resolver in Node.js is +allowed to be asynchronous. ## Interoperability with CommonJS @@ -738,9 +731,6 @@ prevent unintentional breaks in the chain.