@@ -1042,7 +1042,8 @@ a URL should be interpreted. This can be one of the following:
1042
1042
` ` ` js
1043
1043
/**
1044
1044
* @param {string} url
1045
- * @param {object} context (currently empty)
1045
+ * @param {object} context
1046
+ * @param {string} context.parentURL
1046
1047
* @param {function} defaultGetFormat
1047
1048
* @returns {object} response
1048
1049
* @returns {string} response.format
@@ -1366,13 +1367,15 @@ updates.
1366
1367
In the following algorithms, all subroutine errors are propagated as errors
1367
1368
of these top-level routines unless stated otherwise.
1368
1369
1370
+ _isMain_ is **true** when resolving the Node.js application entry point.
1371
+
1369
1372
_defaultEnv_ is the conditional environment name priority array,
1370
1373
` [" node" , " import" ]` .
1371
1374
1372
1375
<details>
1373
1376
<summary>Resolver algorithm specification</summary>
1374
1377
1375
- **ESM_RESOLVE**(_specifier_, _parentURL_)
1378
+ **ESM_RESOLVE**(_specifier_, _parentURL_, _isMain_ )
1376
1379
1377
1380
> 1. Let _resolvedURL_ be **undefined**.
1378
1381
> 1. If _specifier_ is a valid URL, then
@@ -1393,7 +1396,7 @@ _defaultEnv_ is the conditional environment name priority array,
1393
1396
> 1. If the file at _resolvedURL_ does not exist, then
1394
1397
> 1. Throw a _Module Not Found_ error.
1395
1398
> 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_ ).
1397
1400
> 1. Load _resolvedURL_ as module format, _format_.
1398
1401
1399
1402
**PACKAGE_RESOLVE**(_packageSpecifier_, _parentURL_)
@@ -1546,20 +1549,20 @@ _defaultEnv_ is the conditional environment name priority array,
1546
1549
> 1. Return _resolved_.
1547
1550
> 1. Throw a _Module Not Found_ error.
1548
1551
1549
- **ESM_FORMAT**(_url_)
1552
+ **ESM_FORMAT**(_url_, _isMain_ )
1550
1553
1551
- > 1. Assert: _url_ corresponds to an existing file pathname .
1554
+ > 1. Assert: _url_ corresponds to an existing file.
1552
1555
> 1. Let _pjson_ be the result of **READ_PACKAGE_SCOPE**(_url_).
1553
1556
> 1. If _url_ ends in _".mjs"_, then
1554
1557
> 1. Return _"module"_.
1555
1558
> 1. If _url_ ends in _".cjs"_, then
1556
1559
> 1. Return _"commonjs"_.
1557
1560
> 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
1559
1562
> 1. Return _"module"_.
1560
1563
> 1. Throw an _Unsupported File Extension_ error.
1561
1564
> 1. Otherwise,
1562
- > 1. If _url_ lacks a file extension , then
1565
+ > 1. If _isMain_ is **true** , then
1563
1566
> 1. Return _"commonjs"_.
1564
1567
> 1. Throw an _Unsupported File Extension_ error.
1565
1568
0 commit comments