| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cad5c2b commit 298fdbe
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1160,15 +1160,13 @@ updates. | |||
| 1160 | 1160 | In the following algorithms, all subroutine errors are propagated as errors | |
| 1161 | 1161 | of these top-level routines unless stated otherwise. | |
| 1162 | 1162 | ||
| 1163 | - _isMain_ is **true** when resolving the Node.js application entry point. | ||
| 1164 | - | ||
| 1165 | 1163 | _defaultEnv_ is the conditional environment name priority array, | |
| 1166 | 1164 | `["node", "import"]`. | |
| 1167 | 1165 | ||
| 1168 | 1166 | <details> | |
| 1169 | 1167 | <summary>Resolver algorithm specification</summary> | |
| 1170 | 1168 | ||
| 1171 | - **ESM_RESOLVE**(_specifier_, _parentURL_, _isMain_) | ||
| 1169 | + **ESM_RESOLVE**(_specifier_, _parentURL_) | ||
| 1172 | 1170 | ||
| 1173 | 1171 | > 1. Let _resolvedURL_ be **undefined**. | |
| 1174 | 1172 | > 1. If _specifier_ is a valid URL, then | |
@@ -1189,7 +1187,7 @@ _defaultEnv_ is the conditional environment name priority array, | |||
| 1189 | 1187 | > 1. If the file at _resolvedURL_ does not exist, then | |
| 1190 | 1188 | > 1. Throw a _Module Not Found_ error. | |
| 1191 | 1189 | > 1. Set _resolvedURL_ to the real path of _resolvedURL_. | |
| 1192 | - > 1. Let _format_ be the result of **ESM_FORMAT**(_resolvedURL_, _isMain_). | ||
| 1190 | + > 1. Let _format_ be the result of **ESM_FORMAT**(_resolvedURL_). | ||
| 1193 | 1191 | > 1. Load _resolvedURL_ as module format, _format_. | |
| 1194 | 1192 | ||
| 1195 | 1193 | **PACKAGE_RESOLVE**(_packageSpecifier_, _parentURL_) | |
@@ -1340,20 +1338,20 @@ _defaultEnv_ is the conditional environment name priority array, | |||
| 1340 | 1338 | > 1. Return _resolved_. | |
| 1341 | 1339 | > 1. Throw a _Module Not Found_ error. | |
| 1342 | 1340 | ||
| 1343 | - **ESM_FORMAT**(_url_, _isMain_) | ||
| 1341 | + **ESM_FORMAT**(_url_) | ||
| 1344 | 1342 | ||
| 1345 | - > 1. Assert: _url_ corresponds to an existing file. | ||
| 1343 | + > 1. Assert: _url_ corresponds to an existing file pathname. | ||
| 1346 | 1344 | > 1. Let _pjson_ be the result of **READ_PACKAGE_SCOPE**(_url_). | |
| 1347 | 1345 | > 1. If _url_ ends in _".mjs"_, then | |
| 1348 | 1346 | > 1. Return _"module"_. | |
| 1349 | 1347 | > 1. If _url_ ends in _".cjs"_, then | |
| 1350 | 1348 | > 1. Return _"commonjs"_. | |
| 1351 | 1349 | > 1. If _pjson?.type_ exists and is _"module"_, then | |
| 1352 | - > 1. If _isMain_ is **true** or _url_ ends in _".js"_, then | ||
| 1350 | + > 1. If _url_ ends in _".js"_ or lacks a file extension, then | ||
| 1353 | 1351 | > 1. Return _"module"_. | |
| 1354 | 1352 | > 1. Throw an _Unsupported File Extension_ error. | |
| 1355 | 1353 | > 1. Otherwise, | |
| 1356 | - > 1. If _isMain_ is **true**, then | ||
| 1354 | + > 1. If _url_ lacks a file extension, then | ||
| 1357 | 1355 | > 1. Return _"commonjs"_. | |
| 1358 | 1356 | > 1. Throw an _Unsupported File Extension_ error. | |
| 1359 | 1357 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,9 +104,12 @@ function resolve(specifier, parentURL) { | |||
| 104 | 104 | } | |
| 105 | 105 | ||
| 106 | 106 | const ext = extname(url.pathname); | |
| 107 | - let format = extensionFormatMap[ext]; | ||
| 108 | - if (ext === '.js' || (!format && isMain)) | ||
| 107 | + let format; | ||
| 108 | + if (ext === '.js' || ext === '') { | ||
| 109 | 109 | format = getPackageType(url.href) === TYPE_MODULE ? 'module' : 'commonjs'; | |
| 110 | + } else { | ||
| 111 | + format = extensionFormatMap[ext]; | ||
| 112 | + } | ||
| 110 | 113 | if (!format) { | |
| 111 | 114 | if (experimentalSpeciferResolution === 'node') { | |
| 112 | 115 | 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, ['--experimental-modules', 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, ['--experimental-modules', 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, ['--experimental-modules', 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, ['--experimental-modules', 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