66 ObjectPrototypeHasOwnProperty,
77 PromisePrototypeThen,
88 PromiseResolve,
9+ StringPrototypeSlice,
910} = primordials ;
10- const { extname, basename } = require ( 'path' ) ;
11+ const { basename , extname, relative } = require ( 'path' ) ;
1112const { getOptionValue } = require ( 'internal/options' ) ;
1213const { fetchModule } = require ( 'internal/modules/esm/fetch_module' ) ;
1314const {
@@ -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- */
3936function getDataProtocolModuleFormat ( parsed ) {
4037 const { 1 : mime } = RegExpPrototypeExec (
4138 / ^ ( [ ^ / ] + \/ [ ^ ; , ] + ) (?: [ ^ , ] * ?) ( ; b a s e 6 4 ) ? , / ,
@@ -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- */
5445function 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- */
8976function 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- */
10587function 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- */
11794function defaultGetFormat ( url , context ) {
11895 const parsed = new URL ( url ) ;
11996 return ObjectPrototypeHasOwnProperty ( protocolHandlers , parsed . protocol ) ?
0 commit comments