@@ -158,8 +158,8 @@ The algorithm to load an ES module specifier is given through the
158158module specifier relative to a parentURL, in addition to the unique module
159159format for that resolved URL given by the **ESM_FORMAT** routine.
160160
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
163163CommonJS loader. Additional formats such as _"wasm"_ or _"addon"_ can be
164164extended in future updates.
165165
@@ -168,6 +168,12 @@ of these top-level routines.
168168
169169_isMain_ is **true** when resolving the Node.js application entry point.
170170
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+
171177**ESM_RESOLVE(_specifier_, _parentURL_, _isMain_)**
172178> 1. Let _resolvedURL_ be **undefined**.
173179> 1. If _specifier_ is a valid URL, then
@@ -234,7 +240,7 @@ PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
234240> _pjson.main_.
235241> 1. If the file at _resolvedMain_ exists, then
236242> 1. Return _resolvedMain_.
237- > 1. If _pjson.type_ is equal to _"esm "_, then
243+ > 1. If _pjson.type_ is equal to _"module "_, then
238244> 1. Throw a _Module Not Found_ error.
239245> 1. Let _legacyMainURL_ be the result applying the legacy
240246> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
@@ -245,18 +251,24 @@ PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
245251
246252**ESM_FORMAT(_url_, _isMain_)**
247253> 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"_.
248258> 1. Let _pjson_ be the result of **READ_PACKAGE_BOUNDARY**(_url_).
249259> 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"_.
252264> 1. If _url_ does not end in _".js"_ or _".mjs"_, then
253265> 1. Throw an _Unsupported File Extension_ error.
254- > 1. Return _"esm "_.
266+ > 1. Return _"module "_.
255267> 1. Otherwise,
256268> 1. If _url_ ends in _".mjs"_, then
257- > 1. Return _"esm "_.
269+ > 1. Return _"module "_.
258270> 1. Otherwise,
259- > 1. Return _"legacy "_.
271+ > 1. Return _"commonjs "_.
260272
261273READ_PACKAGE_BOUNDARY(_url_)
262274> 1. Let _boundaryURL_ be _url_.
0 commit comments