@@ -154,36 +154,6 @@ The resolver has the following properties:
154154* No default extensions
155155* No folder mains
156156* Bare specifier package resolution lookup through node_modules
157- * Avoids the package fallback which breaks package isolation. This is the
158- problem that an import to ` x/ y .js ` will keep checking subsequent node_modules
159- even if a package "x" is found without a "y.js". This is done through package
160- name format detection.
161-
162- The ESM resolver differs from the CommonJS resolver in detecting a package name
163- based on it being either ` package ` or ` @scoped/ package ` . This allows the
164- resolver to know when a package has been matched, and then avoid a fallback for
165- missing modules.
166-
167- The main lookup is then provided by _CHECK_PACKAGE_MAIN_ which is still an
168- experimental approach under discussion.
169-
170- Currently, the main lookup will only check for _index.mjs_.
171-
172- ### Examples
173-
174- Relative and absolute resolution without directory or extension resolution
175- (URL resolution):
176-
177- * ESM_RESOLVE("./a.asdf", "file:///parent/path") -> "file:///parent/a.asdf"
178- * ESM_RESOLVE("/a", "file:///parent/path") -> "file:///a"
179- * ESM_RESOLVE("file:///a", "file:///parent/path") -> "file:///a"
180-
181- Package resolution:
182-
183- 1. ESM_RESOLVE("pkg/x", "file:///path/to/project") ->
184- "file:///path/to/nodemodules/pkg/x" (if it exists)
185- 1. ESM_RESOLVE("pkg/x", "file:///path/to/project") ->
186- Not Found otherwise, even if "file:///path/nodemodules/pkg/x" exists.
187157
188158### Resolver Algorithm
189159
@@ -207,50 +177,16 @@ _ESM_RESOLVE_:
207177
208178**PACKAGE_RESOLVE**(_packageSpecifier_, _parentURL_)
209179> 1. Assert: _packageSpecifier_ is a bare specifier.
210- > 1. Let _packageName_ be _undefined_.
211- > 1. Let _packagePath_ be _undefined_.
212- > 1. If _packageSpecifier_ does not start with _"@"_ then,
213- > 1. If _packageSpecifier_ is an empty string then,
214- > 1. Throw a _Invalid Package Name_ error.
215- > 1. Set _packageName_ to the substring of _packageSpecifier_ until the
216- > first _"/"_ separator or the end of the string.
217- > 1. If _packageSpecifier_ starts with _"@"_ then,
218- > 1. If _packageSpecifier_ does not contain a _"/"_ separator then,
219- > 1. Throw a _Invalid Package Name_ error.
220- > 1. Set _packageName_ to the substring of _packageSpecifier_
221- > until the second _"/"_ separator or the end of the string.
222- > 1. Let _packagePath_ be the substring of _packageSpecifier_ from the
223- > position at the length of _packageName_ plus one, if any.
224- > 1. Assert: _packageName_ is a valid package name or scoped package name.
225- > 1. Assert: _packagePath_ is either empty, or a path without a leading
226- > separator.
227- > 1. Note: Further package name validations can be added here.
228- > 1. If _packagePath_ is empty and _packageName_ is a Node.js builtin
229- > module then,
180+ > 1. If _packageSpecifier_ is a Node.js builtin module then,
230181> 1. Return _"node:${ packageName} "_.
231182> 1. Set _parentURL_ to the parent folder URL of _parentURL_.
232183> 1. While _parentURL_ contains a non-empty _pathname_,
233184> 1. Let _packageURL_ be the URL resolution of
234- > _"${ parentURL} /node_modules/${ packageName} "_.
235- > 1. If the folder at _packageURL_ does not exist then,
236- > 1. Note: This check can be optimized out where possible in
237- > implementation.
238- > 1. Set _parentURL_ to the parent URL path of _parentURL_.
239- > 1. Continue the next loop iteration.
240- > 1. If _packagePath_ is empty then,
241- > 1. Let _url_ be the result of **PACKAGE_MAIN_RESOLVE**(_packageURL_).
242- > 1. If _url_ is _undefined_ then,
243- > 1. Throw a _Module Not Found_ error.
244- > 1. Return _url_.
245- > 1. Otherwise,
246- > 1. Return the URL resolution of _packagePath_ in _packageURL_.
185+ > _"${ parentURL} /node_modules/${ packageSpecifier} "_.
186+ > 1. If the file at _packageURL_ exists then,
187+ > 1. Return _packageURL_.
247188> 1. Throw a _Module Not Found_ error.
248189
249- **PACKAGE_MAIN_RESOLVE**(_packageURL_)
250- > 1. Note: Main resolution to be implemented here.
251- > 1. Return _undefined_.
252-
253-
254190[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
255191[` module .createRequireFromPath ()` ]: modules.html#modules_module_createrequirefrompath_filename
256192[ESM Minimal Kernel]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
0 commit comments