@@ -158,8 +158,8 @@ The algorithm to load an ES module specifier is given through the
158
158
module specifier relative to a parentURL, in addition to the unique module
159
159
format for that resolved URL given by the **ESM_FORMAT** routine.
160
160
161
- The _"esm "_ format is returned for an ECMAScript Module, while the
162
- _"legacy "_ format is used to indicate loading through the legacy
161
+ The _"module "_ format is returned for an ECMAScript Module, while the
162
+ _"commonjs "_ format is used to indicate loading through the legacy
163
163
CommonJS loader. Additional formats such as _"wasm"_ or _"addon"_ can be
164
164
extended in future updates.
165
165
@@ -168,6 +168,12 @@ of these top-level routines.
168
168
169
169
_isMain_ is **true** when resolving the Node.js application entry point.
170
170
171
+ If the top-level ` -- type` is _"commonjs"_, then the ESM resolver is skipped
172
+ entirely for the CommonJS loader.
173
+
174
+ If the top-level ` -- type` is _"module"_, then the ESM resolver is used
175
+ as described here, with the conditional ` -- type` check in **ESM_FORMAT**.
176
+
171
177
**ESM_RESOLVE(_specifier_, _parentURL_, _isMain_)**
172
178
> 1. Let _resolvedURL_ be **undefined**.
173
179
> 1. If _specifier_ is a valid URL, then
@@ -234,7 +240,7 @@ PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
234
240
> _pjson.main_.
235
241
> 1. If the file at _resolvedMain_ exists, then
236
242
> 1. Return _resolvedMain_.
237
- > 1. If _pjson.type_ is equal to _"esm "_, then
243
+ > 1. If _pjson.type_ is equal to _"module "_, then
238
244
> 1. Throw a _Module Not Found_ error.
239
245
> 1. Let _legacyMainURL_ be the result applying the legacy
240
246
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
@@ -245,18 +251,24 @@ PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
245
251
246
252
**ESM_FORMAT(_url_, _isMain_)**
247
253
> 1. Assert: _url_ corresponds to an existing file.
254
+ > 1. If _isMain_ is **true** and the ` -- type` flag is _"module"_, then
255
+ > 1. If _url_ ends with _".cjs"_, then
256
+ > 1. Throw an _Invalid File Extension_ error.
257
+ > 1. Return _"module"_.
248
258
> 1. Let _pjson_ be the result of **READ_PACKAGE_BOUNDARY**(_url_).
249
259
> 1. If _pjson_ is **null** and _isMain_ is **true**, then
250
- > 1. Return _"legacy"_.
251
- > 1. If _pjson.type_ exists and is _"esm"_, then
260
+ > 1. Return _"commonjs"_.
261
+ > 1. If _pjson.type_ exists and is _"module"_, then
262
+ > 1. If _url_ ends in _".cjs"_, then
263
+ > 1. Return _"commonjs"_.
252
264
> 1. If _url_ does not end in _".js"_ or _".mjs"_, then
253
265
> 1. Throw an _Unsupported File Extension_ error.
254
- > 1. Return _"esm "_.
266
+ > 1. Return _"module "_.
255
267
> 1. Otherwise,
256
268
> 1. If _url_ ends in _".mjs"_, then
257
- > 1. Return _"esm "_.
269
+ > 1. Return _"module "_.
258
270
> 1. Otherwise,
259
- > 1. Return _"legacy "_.
271
+ > 1. Return _"commonjs "_.
260
272
261
273
READ_PACKAGE_BOUNDARY(_url_)
262
274
> 1. Let _boundaryURL_ be _url_.
0 commit comments