@@ -10,13 +10,13 @@ describe("getDependencyResolver(root, path, input)", () => {
10
10
const root = "test/input/build/simple-public" ;
11
11
const specifier = "/npm/[email protected] /dist/d3-array.js" ;
12
12
const resolver = await getDependencyResolver ( root , "/_npm/[email protected] /_esm.js" , `import '${ specifier } ';\n` ) ; // prettier-ignore
13
- assert . strictEqual ( resolver ( specifier ) , "../[email protected] /dist/d3-array.js" ) ;
13
+ assert . strictEqual ( resolver ( specifier ) , "../[email protected] /dist/d3-array.js._esm.js " ) ;
14
14
} ) ;
15
15
it ( "finds /npm/ import resolutions and re-resolves their versions" , async ( ) => {
16
16
const root = "test/input/build/simple-public" ;
17
17
const specifier = "/npm/[email protected] /dist/d3-array.js" ;
18
18
const resolver = await getDependencyResolver ( root , "/_npm/[email protected] /_esm.js" , `import.meta.resolve('${ specifier } ');\n` ) ; // prettier-ignore
19
- assert . strictEqual ( resolver ( specifier ) , "../[email protected] /dist/d3-array.js" ) ;
19
+ assert . strictEqual ( resolver ( specifier ) , "../[email protected] /dist/d3-array.js._esm.js " ) ;
20
20
} ) ;
21
21
} ) ;
22
22
@@ -49,21 +49,24 @@ describe("parseNpmSpecifier(specifier)", () => {
49
49
describe ( "resolveNpmImport(root, specifier)" , ( ) => {
50
50
mockJsDelivr ( ) ;
51
51
const root = "test/input/build/simple" ;
52
- it ( "implicitly adds / _esm.js for specifiers without an extension" , async ( ) => {
52
+ it ( "implicitly adds . _esm.js for specifiers without an extension" , async ( ) => {
53
53
assert . strictEqual ( await resolveNpmImport ( root , "d3-array" ) , "/_npm/[email protected] /_esm.js" ) ;
54
54
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/src" ) , "/_npm/[email protected] /src._esm.js" ) ;
55
55
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/foo+bar" ) , "/_npm/[email protected] /foo+bar._esm.js" ) ;
56
56
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/foo+esm" ) , "/_npm/[email protected] /foo+esm._esm.js" ) ;
57
57
} ) ;
58
+ it ( "implicitly adds ._esm.js for specifiers with a JavaScript extension" , async ( ) => {
59
+ assert . strictEqual ( await resolveNpmImport ( root , "d3-array/src/index.js" ) , "/_npm/[email protected] /src/index.js._esm.js" ) ; // prettier-ignore
60
+ } ) ;
58
61
it ( "replaces /+esm with /_esm.js or ._esm.js" , async ( ) => {
59
62
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/+esm" ) , "/_npm/[email protected] /_esm.js" ) ;
60
63
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/src/+esm" ) , "/_npm/[email protected] /src._esm.js" ) ;
61
64
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/src/index.js/+esm" ) , "/_npm/[email protected] /src/index.js._esm.js" ) ; // prettier-ignore
62
65
} ) ;
63
- it ( "does not add / _esm.js if given a path with a file extension" , async ( ) => {
64
- assert . strictEqual ( await resolveNpmImport ( root , "d3-array/src/index.js " ) , "/_npm/[email protected] /src/index.js " ) ;
66
+ it ( "does not add . _esm.js for specifiers with a non-JavaScript extension" , async ( ) => {
67
+ assert . strictEqual ( await resolveNpmImport ( root , "d3-array/src/index.css " ) , "/_npm/[email protected] /src/index.css " ) ;
65
68
} ) ;
66
- it ( "does not add /_esm.js if given a path with a trailing slash" , async ( ) => {
69
+ it ( "does not add /_esm.js for specifiers with a trailing slash" , async ( ) => {
67
70
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/" ) , "/_npm/[email protected] /" ) ;
68
71
assert . strictEqual ( await resolveNpmImport ( root , "d3-array/src/" ) , "/_npm/[email protected] /src/" ) ;
69
72
} ) ;
0 commit comments