Best effort Module Resolution Algorithm implementation based on Node.js 25.2.1 #971
+792
−66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Best effort Module Resolution Algorithm implementation based on Node.js 25.2.1 as documented in https://nodejs.org/api/esm.html#resolution-and-loading-algorithm.
The following features are not implemented:
This patch breaks one unit test:
The previous behavoir with regard to using
importwith CommonJS modules was:import()can't import a commonjs module with.jsextension, in a package not marked with"type"="module"import()can import a commonjs module with.cjsextension.import()can import a commonjs module with.jsextension but not in a packageAs import/import() can be used to load JavaScript CommonJS modules stated in packages.html.
I believe it is fair to expect
import/import()to be able to import CommonJS modules.In this patch,
importcan import a commonjs module with acjsextension, or with ajsextension and in a package not marked with"type"="module".I couldn't get WebAssemblySimpleTestSuite working correctly (error: WebAssembly API enabled but "wasm" language cannot be accessed! Make sure the "wasm" l
anguage is found on the module path and one of the permitted languages when creating the Context). All other tests are running correctly.
Another thing to note:
In this patch, if
esmResolvereturns a result andesmFileFormatreturnsCommonJs, it will pass the resoluted path directly totryLoadingAsCommonjsModule. Instead of the originalspecifier.I don't know if this is the best way to do it, but at least we can import a CommonJs module exported in
exportsusingimportnow (ideally we should makerequirealso support it).This patch is based on #904