Skip to content

Commit 8b33d6d

Browse files
committed
fixup: reviews and make suggestion copy paste friendly
1 parent 0cfecce commit 8b33d6d

File tree

4 files changed

+7
-38
lines changed

4 files changed

+7
-38
lines changed

lib/internal/modules/esm/formats.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ if (experimentalWasmModules) {
3131
extensionFormatMap['.wasm'] = legacyExtensionFormatMap['.wasm'] = 'wasm';
3232
}
3333

34-
/**
35-
* @param {string} mime
36-
* @returns {string | null}
37-
*/
3834
function mimeToFormat(mime) {
3935
if (
4036
RegExpPrototypeTest(

lib/internal/modules/esm/get_format.js

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const {
66
ObjectPrototypeHasOwnProperty,
77
PromisePrototypeThen,
88
PromiseResolve,
9+
StringPrototypeSlice,
910
} = primordials;
10-
const { extname, basename } = require('path');
11+
const { basename, extname, relative } = require('path');
1112
const { getOptionValue } = require('internal/options');
1213
const { fetchModule } = require('internal/modules/esm/fetch_module');
1314
const {
@@ -32,10 +33,6 @@ const protocolHandlers = ObjectAssign(ObjectCreate(null), {
3233
'node:'() { return 'builtin'; },
3334
});
3435

35-
/**
36-
* @param {URL} parsed
37-
* @returns {string | null}
38-
*/
3936
function getDataProtocolModuleFormat(parsed) {
4037
const { 1: mime } = RegExpPrototypeExec(
4138
/^([^/]+\/[^;,]+)(?:[^,]*?)(;base64)?,/,
@@ -45,12 +42,6 @@ function getDataProtocolModuleFormat(parsed) {
4542
return mimeToFormat(mime);
4643
}
4744

48-
/**
49-
* @param {URL} url
50-
* @param {{parentURL: string}} context
51-
* @param {boolean} ignoreErrors
52-
* @returns {string}
53-
*/
5445
function getFileProtocolModuleFormat(url, context, ignoreErrors) {
5546
const filepath = fileURLToPath(url);
5647
const ext = extname(filepath);
@@ -68,24 +59,20 @@ function getFileProtocolModuleFormat(url, context, ignoreErrors) {
6859
if (getPackageType(url) === 'module' && ext === '') {
6960
const config = getPackageScopeConfig(url);
7061
const fileBasename = basename(filepath);
71-
suggestion = 'Extension-less files are disabled inside of ' +
62+
const relativePath = StringPrototypeSlice(relative(config.pjsonPath, filepath), 1);
63+
suggestion = 'Extension-less files are unsupported inside of ' +
7264
'"type":"module" package.json contexts. The package.json file ' +
7365
`${config.pjsonPath} caused this "type":"module" context. Try ` +
7466
`changing ${filepath} to have a file extension. Note the "bin" ` +
7567
'field of package.json can point to a file with an extension, for example ' +
76-
`{"type":"module","bin":{"${fileBasename}":"${fileBasename}.js"}}`;
68+
`{"type":"module","bin":{"${fileBasename}":"${relativePath}.js"}}`;
7769
}
7870
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath, suggestion);
7971
}
8072

8173
return getLegacyExtensionFormat(ext) ?? null;
8274
}
8375

84-
/**
85-
* @param {URL} url
86-
* @param {{parentURL: string}} context
87-
* @returns {Promise<string> | undefined} only works when enabled
88-
*/
8976
function getHttpProtocolModuleFormat(url, context) {
9077
if (experimentalNetworkImports) {
9178
return PromisePrototypeThen(
@@ -97,23 +84,13 @@ function getHttpProtocolModuleFormat(url, context) {
9784
}
9885
}
9986

100-
/**
101-
* @param {URL | URL['href']} url
102-
* @param {{parentURL: string}} context
103-
* @returns {Promise<string> | string | undefined} only works when enabled
104-
*/
10587
function defaultGetFormatWithoutErrors(url, context) {
10688
const parsed = new URL(url);
10789
if (!ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol))
10890
return null;
10991
return protocolHandlers[parsed.protocol](parsed, context, true);
11092
}
11193

112-
/**
113-
* @param {URL | URL['href']} url
114-
* @param {{parentURL: string}} context
115-
* @returns {Promise<string> | string | undefined} only works when enabled
116-
*/
11794
function defaultGetFormat(url, context) {
11895
const parsed = new URL(url);
11996
return ObjectPrototypeHasOwnProperty(protocolHandlers, parsed.protocol) ?

lib/internal/modules/esm/resolve.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ const DEFAULT_CONDITIONS_SET = new SafeSet(DEFAULT_CONDITIONS);
7979
* @typedef {string | string[] | Record<string, unknown>} Exports
8080
* @typedef {'module' | 'commonjs'} PackageType
8181
* @typedef {{
82-
* pjsonPath: string,
8382
* exports?: ExportConfig;
8483
* name?: string;
8584
* main?: string;
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import '../common/index.mjs';
22
import assert from 'assert';
33
import ok from '../fixtures/es-modules/test-esm-ok.mjs';
4-
import * as okShebangNs from './test-esm-shebang.mjs';
5-
// encode the '.'
6-
import * as okShebangPercentNs from './test-esm-shebang%2emjs';
4+
import okShebang from './test-esm-shebang.mjs';
75

86
assert(ok);
9-
assert(okShebangNs.default);
10-
assert.strict.equal(okShebangNs, okShebangPercentNs);
7+
assert(okShebang);

0 commit comments

Comments
 (0)