GeezerVison is showing github.com — module: fix segment deprecation for imports field · nodejs/node@15f1051
File treeExpand file treeCollapse file tree Open diff view settings fixtures/es-modules/pkgimports
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/resolve.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,15 +98,15 @@ function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) { | 98 | 98 |
| 99 | 99 | const doubleSlashRegEx = /[/\\][/\\]/; | 100 | 100 |
| 101 | | -function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, base) { | | 101 | +function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, internal, base, isTarget) { | 102 | 102 | const pjsonPath = fileURLToPath(pjsonUrl); | 103 | | - const double = RegExpPrototypeExec(doubleSlashRegEx, target) !== null; | | 103 | + const double = RegExpPrototypeExec(doubleSlashRegEx, isTarget ? target : request) !== null; | 104 | 104 | process.emitWarning( | 105 | 105 | `Use of deprecated ${double ? 'double slash' : | 106 | 106 | 'leading or trailing slash matching'} resolving "${target}" for module ` + | 107 | 107 | `request "${request}" ${request !== match ? `matched to "${match}" ` : '' | 108 | | - }in the "exports" field module resolution of the package at ${pjsonPath}${ | 109 | | - base ? ` imported from ${fileURLToPath(base)}` : ''}.`, | | 108 | + }in the "${internal ? 'imports' : 'exports'}" field module resolution of the package at ${ | | 109 | + pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ''}.`, | 110 | 110 | 'DeprecationWarning', | 111 | 111 | 'DEP0166' | 112 | 112 | ); | @@ -372,7 +372,7 @@ function resolvePackageTargetString( | 372 | 372 | const resolvedTarget = pattern ? | 373 | 373 | RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) : | 374 | 374 | target; | 375 | | - emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJSONUrl, base); | | 375 | + emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJSONUrl, internal, base, true); | 376 | 376 | } | 377 | 377 | } else { | 378 | 378 | throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base); | @@ -395,7 +395,7 @@ function resolvePackageTargetString( | 395 | 395 | const resolvedTarget = pattern ? | 396 | 396 | RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) : | 397 | 397 | target; | 398 | | - emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJSONUrl, base); | | 398 | + emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJSONUrl, internal, base, false); | 399 | 399 | } | 400 | 400 | } else { | 401 | 401 | throwInvalidSubpath(request, match, packageJSONUrl, internal, base); | |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --pending-deprecation | | 2 | +import { mustCall } from '../common/index.mjs'; | | 3 | +import assert from 'assert'; | | 4 | + | | 5 | +let curWarning = 0; | | 6 | +const expectedWarnings = [ | | 7 | + 'Use of deprecated double slash', | | 8 | + 'Use of deprecated double slash', | | 9 | + './sub//null', | | 10 | + './sub/////null', | | 11 | + './sub//internal/test', | | 12 | + './sub//internal//test', | | 13 | + '#subpath/////internal', | | 14 | + '#subpath//asdf.asdf', | | 15 | + '#subpath/as//df.asdf', | | 16 | + './sub//null', | | 17 | + './sub/////null', | | 18 | + './sub//internal/test', | | 19 | + './sub//internal//test', | | 20 | + '#subpath/////internal', | | 21 | +]; | | 22 | + | | 23 | +process.addListener('warning', mustCall((warning) => { | | 24 | + assert(warning.stack.includes(expectedWarnings[curWarning++]), warning.stack); | | 25 | +}, expectedWarnings.length)); | | 26 | + | | 27 | +await import('./test-esm-imports.mjs'); |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-imports.mjs +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,6 +22,10 @@ const { requireImport, importImport } = importer; | 22 | 22 | ['#external/subpath/asdf.js', { default: 'asdf' }], | 23 | 23 | // Trailing pattern imports | 24 | 24 | ['#subpath/asdf.asdf', { default: 'test' }], | | 25 | + // Leading slash | | 26 | + ['#subpath//asdf.asdf', { default: 'test' }], | | 27 | + // Double slash | | 28 | + ['#subpath/as//df.asdf', { default: 'test' }], | 25 | 29 | ]); | 26 | 30 |
| 27 | 31 | for (const [validSpecifier, expected] of internalImports) { | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/es-modules/pkgimports/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "imports": { | 3 | | - "#test": "./test.js", | 4 | 3 | "#branch": { | 5 | 4 | "import": "./importbranch.js", | 6 | 5 | "require": "./requirebranch.js" | | 26 | 25 | }, | 27 | 26 | "#subpath/nullshadow/*": [null], | 28 | 27 | "#": "./test.js", | | 28 | + "#*est": "./*est.js", | 29 | 29 | "#/initialslash": "./test.js", | 30 | 30 | "#notfound": "./notfound.js", | 31 | 31 | "#encodedslash": "./..%2F/x.js", | |
|