| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 85d152f commit 24a0212
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1154,15 +1154,13 @@ updates. | |||
| 1154 | 1154 | In the following algorithms, all subroutine errors are propagated as errors | |
| 1155 | 1155 | of these top-level routines unless stated otherwise. | |
| 1156 | 1156 | ||
| 1157 | - _isMain_ is **true** when resolving the Node.js application entry point. | ||
| 1158 | - | ||
| 1159 | 1157 | _defaultEnv_ is the conditional environment name priority array, | |
| 1160 | 1158 | `["node", "import"]`. | |
| 1161 | 1159 | ||
| 1162 | 1160 | <details> | |
| 1163 | 1161 | <summary>Resolver algorithm specification</summary> | |
| 1164 | 1162 | ||
| 1165 | - **ESM_RESOLVE**(_specifier_, _parentURL_, _isMain_) | ||
| 1163 | + **ESM_RESOLVE**(_specifier_, _parentURL_) | ||
| 1166 | 1164 | ||
| 1167 | 1165 | > 1. Let _resolvedURL_ be **undefined**. | |
| 1168 | 1166 | > 1. If _specifier_ is a valid URL, then | |
@@ -1183,7 +1181,7 @@ _defaultEnv_ is the conditional environment name priority array, | |||
| 1183 | 1181 | > 1. If the file at _resolvedURL_ does not exist, then | |
| 1184 | 1182 | > 1. Throw a _Module Not Found_ error. | |
| 1185 | 1183 | > 1. Set _resolvedURL_ to the real path of _resolvedURL_. | |
| 1186 | - > 1. Let _format_ be the result of **ESM_FORMAT**(_resolvedURL_, _isMain_). | ||
| 1184 | + > 1. Let _format_ be the result of **ESM_FORMAT**(_resolvedURL_). | ||
| 1187 | 1185 | > 1. Load _resolvedURL_ as module format, _format_. | |
| 1188 | 1186 | ||
| 1189 | 1187 | **PACKAGE_RESOLVE**(_packageSpecifier_, _parentURL_) | |
@@ -1334,20 +1332,20 @@ _defaultEnv_ is the conditional environment name priority array, | |||
| 1334 | 1332 | > 1. Return _resolved_. | |
| 1335 | 1333 | > 1. Throw a _Module Not Found_ error. | |
| 1336 | 1334 | ||
| 1337 | - **ESM_FORMAT**(_url_, _isMain_) | ||
| 1335 | + **ESM_FORMAT**(_url_) | ||
| 1338 | 1336 | ||
| 1339 | - > 1. Assert: _url_ corresponds to an existing file. | ||
| 1337 | + > 1. Assert: _url_ corresponds to an existing file pathname. | ||
| 1340 | 1338 | > 1. Let _pjson_ be the result of **READ_PACKAGE_SCOPE**(_url_). | |
| 1341 | 1339 | > 1. If _url_ ends in _".mjs"_, then | |
| 1342 | 1340 | > 1. Return _"module"_. | |
| 1343 | 1341 | > 1. If _url_ ends in _".cjs"_, then | |
| 1344 | 1342 | > 1. Return _"commonjs"_. | |
| 1345 | 1343 | > 1. If _pjson?.type_ exists and is _"module"_, then | |
| 1346 | - > 1. If _isMain_ is **true** or _url_ ends in _".js"_, then | ||
| 1344 | + > 1. If _url_ ends in _".js"_ or lacks a file extension, then | ||
| 1347 | 1345 | > 1. Return _"module"_. | |
| 1348 | 1346 | > 1. Throw an _Unsupported File Extension_ error. | |
| 1349 | 1347 | > 1. Otherwise, | |
| 1350 | - > 1. If _isMain_ is **true**, then | ||
| 1348 | + > 1. If _url_ lacks a file extension, then | ||
| 1351 | 1349 | > 1. Return _"commonjs"_. | |
| 1352 | 1350 | > 1. Throw an _Unsupported File Extension_ error. | |
| 1353 | 1351 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,9 +106,12 @@ function resolve(specifier, parentURL) { | |||
| 106 | 106 | } | |
| 107 | 107 | ||
| 108 | 108 | const ext = extname(url.pathname); | |
| 109 | - let format = extensionFormatMap[ext]; | ||
| 110 | - if (ext === '.js' || (!format && isMain)) | ||
| 109 | + let format; | ||
| 110 | + if (ext === '.js' || ext === '') { | ||
| 111 | 111 | format = getPackageType(url.href) === TYPE_MODULE ? 'module' : 'commonjs'; | |
| 112 | + } else { | ||
| 113 | + format = extensionFormatMap[ext]; | ||
| 114 | + } | ||
| 112 | 115 | if (!format) { | |
| 113 | 116 | if (experimentalSpeciferResolution === 'node') { | |
| 114 | 117 | process.emitWarning( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,81 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const fixtures = require('../common/fixtures'); | ||
| 5 | + const { spawn } = require('child_process'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + | ||
| 8 | + { | ||
| 9 | + const entry = fixtures.path( | ||
| 10 | + '/es-modules/package-type-module/extension.unknown' | ||
| 11 | + ); | ||
| 12 | + const child = spawn(process.execPath, [entry]); | ||
| 13 | + let stdout = ''; | ||
| 14 | + let stderr = ''; | ||
| 15 | + child.stderr.setEncoding('utf8'); | ||
| 16 | + child.stdout.setEncoding('utf8'); | ||
| 17 | + child.stdout.on('data', (data) => { | ||
| 18 | + stdout += data; | ||
| 19 | + }); | ||
| 20 | + child.stderr.on('data', (data) => { | ||
| 21 | + stderr += data; | ||
| 22 | + }); | ||
| 23 | + child.on('close', common.mustCall((code, signal) => { | ||
| 24 | + assert.strictEqual(code, 1); | ||
| 25 | + assert.strictEqual(signal, null); | ||
| 26 | + assert.strictEqual(stdout, ''); | ||
| 27 | + assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1); | ||
| 28 | + })); | ||
| 29 | + } | ||
| 30 | + { | ||
| 31 | + const entry = fixtures.path( | ||
| 32 | + '/es-modules/package-type-module/imports-unknownext.mjs' | ||
| 33 | + ); | ||
| 34 | + const child = spawn(process.execPath, [entry]); | ||
| 35 | + let stdout = ''; | ||
| 36 | + let stderr = ''; | ||
| 37 | + child.stderr.setEncoding('utf8'); | ||
| 38 | + child.stdout.setEncoding('utf8'); | ||
| 39 | + child.stdout.on('data', (data) => { | ||
| 40 | + stdout += data; | ||
| 41 | + }); | ||
| 42 | + child.stderr.on('data', (data) => { | ||
| 43 | + stderr += data; | ||
| 44 | + }); | ||
| 45 | + child.on('close', common.mustCall((code, signal) => { | ||
| 46 | + assert.strictEqual(code, 1); | ||
| 47 | + assert.strictEqual(signal, null); | ||
| 48 | + assert.strictEqual(stdout, ''); | ||
| 49 | + assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1); | ||
| 50 | + })); | ||
| 51 | + } | ||
| 52 | + { | ||
| 53 | + const entry = fixtures.path('/es-modules/package-type-module/noext-esm'); | ||
| 54 | + const child = spawn(process.execPath, [entry]); | ||
| 55 | + let stdout = ''; | ||
| 56 | + child.stdout.setEncoding('utf8'); | ||
| 57 | + child.stdout.on('data', (data) => { | ||
| 58 | + stdout += data; | ||
| 59 | + }); | ||
| 60 | + child.on('close', common.mustCall((code, signal) => { | ||
| 61 | + assert.strictEqual(code, 0); | ||
| 62 | + assert.strictEqual(signal, null); | ||
| 63 | + assert.strictEqual(stdout, 'executed\n'); | ||
| 64 | + })); | ||
| 65 | + } | ||
| 66 | + { | ||
| 67 | + const entry = fixtures.path( | ||
| 68 | + '/es-modules/package-type-module/imports-noext.mjs' | ||
| 69 | + ); | ||
| 70 | + const child = spawn(process.execPath, [entry]); | ||
| 71 | + let stdout = ''; | ||
| 72 | + child.stdout.setEncoding('utf8'); | ||
| 73 | + child.stdout.on('data', (data) => { | ||
| 74 | + stdout += data; | ||
| 75 | + }); | ||
| 76 | + child.on('close', common.mustCall((code, signal) => { | ||
| 77 | + assert.strictEqual(code, 0); | ||
| 78 | + assert.strictEqual(signal, null); | ||
| 79 | + assert.strictEqual(stdout, 'executed\n'); | ||
| 80 | + })); | ||
| 81 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + throw new Error('NO, NEVER'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + import './noext-esm'; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + import './extension.unknown'; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments