@@ -152,6 +152,7 @@ The resolver has the following properties:
152
152
* Support for builtin module loading
153
153
* Relative and absolute URL resolution
154
154
* No default extensions
155
+ * No folder mains
155
156
* Bare specifier package resolution lookup through node_modules
156
157
* Avoids the package fallback which breaks package isolation. This is the
157
158
problem that an import to ` x/ y .js ` will keep checking subsequent node_modules
@@ -184,49 +185,33 @@ Package resolution:
184
185
1. ESMRESOLVE("pkg/x", "file:///path/to/project") ->
185
186
Not Found otherwise, even if "file:///path/nodemodules/pkg/x" exists.
186
187
187
- Main resolution:
188
-
189
- 1. ESMRESOLVE("pkg", "file:///path/to/project") ->
190
- "file:///path/to/project/nodemodules/pkg/index.mjs" (if it exists)
191
- 1. ESMRESOLVE("pkg", "file:///path/to/project") -> Not Found otherwise,
192
- even if "file:///path/to/nodemodules/pkg/index.mjs" exists.
193
- 1. ESMRESOLVE("file:///path/to/project") ->
194
- "file:///path/to/project/index.mjs" (if it exists)
195
- 1. ESMRESOLVE("file:///path/to/project") ->
196
- Not Found, if "file:///path/to/project/index.mjs" does not exist.
197
-
198
188
### Resolver Algorithm
199
189
200
190
The algorithm to resolve an ES module specifier is provided through
201
191
_ESM_RESOLVE_:
202
192
203
193
**ESM_RESOLVE**(_specifier_, _parentURL_)
194
+ > 1. Let _resolvedURL_ be _undefined_.
204
195
> 1. If _specifier_ is a valid URL then,
205
- > 1. Let _resolvedURL_ be the result of parsing and reserializing
196
+ > 1. Set _resolvedURL_ to the result of parsing and reserializing
206
197
> _specifier_ as a URL.
207
- > 1. Return the result of **PATH_RESOLVE**(_resolvedURL_).
208
- > 1. If _specifier_ starts with _"/"_, _"./"_ or _"../"_ then,
209
- > 1. Let _resolvedURL_ be the URL resolution of _specifier_ to _parentURL_.
210
- > 1. Return the result of **PATH_RESOLVE**(_resolvedURL_).
211
- > 1. Note: _specifier_ is now a bare specifier.
212
- > 1. Return the result of **PACKAGE_RESOLVE**(_specifier_, _parentURL_).
213
-
214
- **PATH_RESOLVE**(_resolvedURL_)
215
- > 1. If the file at _resolvedURL_ exists then,
216
- > 1. Return _resolvedURL_.
217
- > 1. Let _packageMainURL_ be the result of
218
- > **PACKAGE_MAIN_RESOLVE**(_resolvedURL_).
219
- > 1. If _packageMainURL_ is not _undefined_ then,
220
- > 1. Return _packageMainURL_.
221
- > 1. Throw a _Module Not Found_ error.
198
+ > 1. Otherwise, if _specifier_ starts with _"/"_, _"./"_ or _"../"_ then,
199
+ > 1. Set _resolvedURL_ to the URL resolution of _specifier_ to _parentURL_.
200
+ > 1. Otherwise,
201
+ > 1. Note: _specifier_ is now a bare specifier.
202
+ > 1. Set _resolvedURL_ the result of
203
+ > **PACKAGE_RESOLVE**(_specifier_, _parentURL_).
204
+ > 1. If the file at _resolvedURL_ does not exist then,
205
+ > 1. Throw a _Module Not Found_ error.
206
+ > 1. Return _resolvedURL_.
222
207
223
208
**PACKAGE_RESOLVE**(_packageSpecifier_, _parentURL_)
224
209
> 1. Assert: _packageSpecifier_ is a bare specifier.
225
- > 1. If _packageSpecifier_ is an empty string then,
226
- > 1. Throw a _Module Not Found_ error.
227
210
> 1. Let _packageName_ be _undefined_.
228
211
> 1. Let _packagePath_ be _undefined_.
229
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.
230
215
> 1. Set _packageName_ to the substring of _packageSpecifier_ until the
231
216
> first _"/"_ separator or the end of the string.
232
217
> 1. If _packageSpecifier_ starts with _"@"_ then,
@@ -239,7 +224,7 @@ _ESM_RESOLVE_:
239
224
> 1. Assert: _packageName_ is a valid package name or scoped package name.
240
225
> 1. Assert: _packagePath_ is either empty, or a path without a leading
241
226
> separator.
242
- > 1. Note: Further package name encoding validations can be added here.
227
+ > 1. Note: Further package name validations can be added here.
243
228
> 1. If _packagePath_ is empty and _packageName_ is a Node.js builtin
244
229
> module then,
245
230
> 1. Return _"node:${ packageName} "_.
@@ -254,23 +239,15 @@ _ESM_RESOLVE_:
254
239
> 1. Continue the next loop iteration.
255
240
> 1. If _packagePath_ is empty then,
256
241
> 1. Let _url_ be the result of **PACKAGE_MAIN_RESOLVE**(_packageURL_).
257
- > 1. If _url_ is not _undefined_ then,
258
- > 1. Return _url_.
242
+ > 1. If _url_ is _undefined_ then,
243
+ > 1. Throw a _Module Not Found_ error.
244
+ > 1. Return _url_.
259
245
> 1. Otherwise,
260
- > 1. Let _url_ be equal to the URL resolution of _packagePath_ in
261
- > _packageURL_.
262
- > 1. If the file at _url_ exists then,
263
- > 1. Return _url_.
264
- > 1. Otherwise, if _url_ is a directory then,
265
- > 1. Let _url_ be the result of **PACKAGE_MAIN_RESOLVE**(_url_).
266
- > 1. If _url_ is not _undefined_ then,
267
- > 1. Return _url_.
268
- > 1. Throw a _Module Not Found_ error.
246
+ > 1. Return the URL resolution of _packagePath_ in _packageURL_.
269
247
> 1. Throw a _Module Not Found_ error.
270
248
271
249
**PACKAGE_MAIN_RESOLVE**(_packageURL_)
272
- > 1. If the file at _"${ packageURL} /index.mjs"_ exists then,
273
- > 1. Return _"${ packageURL} /index.mjs"_.
250
+ > 1. Note: Main resolution to be implemented here.
274
251
> 1. Return _undefined_.
275
252
276
253
0 commit comments