@@ -1042,7 +1042,8 @@ a URL should be interpreted. This can be one of the following:
10421042` ` ` js
10431043/**
10441044 * @param {string} url
1045- * @param {object} context (currently empty)
1045+ * @param {object} context
1046+ * @param {string} context.parentURL
10461047 * @param {function} defaultGetFormat
10471048 * @returns {object} response
10481049 * @returns {string} response.format
@@ -1366,13 +1367,15 @@ updates.
13661367In the following algorithms, all subroutine errors are propagated as errors
13671368of these top-level routines unless stated otherwise.
13681369
1370+ _isMain_ is **true** when resolving the Node.js application entry point.
1371+
13691372_defaultEnv_ is the conditional environment name priority array,
13701373` [" node" , " import" ]` .
13711374
13721375<details>
13731376<summary>Resolver algorithm specification</summary>
13741377
1375- **ESM_RESOLVE**(_specifier_, _parentURL_)
1378+ **ESM_RESOLVE**(_specifier_, _parentURL_, _isMain_ )
13761379
13771380> 1. Let _resolvedURL_ be **undefined**.
13781381> 1. If _specifier_ is a valid URL, then
@@ -1393,7 +1396,7 @@ _defaultEnv_ is the conditional environment name priority array,
13931396> 1. If the file at _resolvedURL_ does not exist, then
13941397> 1. Throw a _Module Not Found_ error.
13951398> 1. Set _resolvedURL_ to the real path of _resolvedURL_.
1396- > 1. Let _format_ be the result of **ESM_FORMAT**(_resolvedURL_).
1399+ > 1. Let _format_ be the result of **ESM_FORMAT**(_resolvedURL_, _isMain_ ).
13971400> 1. Load _resolvedURL_ as module format, _format_.
13981401
13991402**PACKAGE_RESOLVE**(_packageSpecifier_, _parentURL_)
@@ -1546,20 +1549,20 @@ _defaultEnv_ is the conditional environment name priority array,
15461549> 1. Return _resolved_.
15471550> 1. Throw a _Module Not Found_ error.
15481551
1549- **ESM_FORMAT**(_url_)
1552+ **ESM_FORMAT**(_url_, _isMain_ )
15501553
1551- > 1. Assert: _url_ corresponds to an existing file pathname .
1554+ > 1. Assert: _url_ corresponds to an existing file.
15521555> 1. Let _pjson_ be the result of **READ_PACKAGE_SCOPE**(_url_).
15531556> 1. If _url_ ends in _".mjs"_, then
15541557> 1. Return _"module"_.
15551558> 1. If _url_ ends in _".cjs"_, then
15561559> 1. Return _"commonjs"_.
15571560> 1. If _pjson?.type_ exists and is _"module"_, then
1558- > 1. If _url_ ends in _".js"_ or lacks a file extension , then
1561+ > 1. If _isMain_ is **true** or _url_ ends in _".js"_, then
15591562> 1. Return _"module"_.
15601563> 1. Throw an _Unsupported File Extension_ error.
15611564> 1. Otherwise,
1562- > 1. If _url_ lacks a file extension , then
1565+ > 1. If _isMain_ is **true** , then
15631566> 1. Return _"commonjs"_.
15641567> 1. Throw an _Unsupported File Extension_ error.
15651568
0 commit comments