1010 */
1111
1212import Resolver from '../index' ;
13- import { createResolutionContext } from './utils' ;
14- import { createPackageAccessors } from './utils' ;
13+ import {
14+ createPackageAccessors ,
15+ createResolutionContext ,
16+ posixToSystemPath as p ,
17+ } from './utils' ;
1518
1619// Implementation of PACKAGE_IMPORTS_RESOLVE described in https://nodejs.org/api/esm.html
1720describe ( 'subpath imports resolution support' , ( ) => {
1821 const baseContext = {
1922 ...createResolutionContext ( {
20- '/root/src/main.js' : '' ,
21- '/root/node_modules/test-pkg/package.json' : '' ,
22- '/root/node_modules/test-pkg/index.js' : '' ,
23- '/root/node_modules/test-pkg/index-main.js' : '' ,
24- '/root/node_modules/test-pkg/symlink.js' : {
25- realPath : '/root/node_modules/test-pkg/symlink-target.js' ,
23+ [ p ( '/root/src/main.js' ) ] : '' ,
24+ [ p ( '/root/node_modules/test-pkg/package.json' ) ] : '' ,
25+ [ p ( '/root/node_modules/test-pkg/index.js' ) ] : '' ,
26+ [ p ( '/root/node_modules/test-pkg/index-main.js' ) ] : '' ,
27+ // $FlowFixMe[incompatible-type] Flow wants a string for some reason
28+ [ p ( '/root/node_modules/test-pkg/symlink.js' ) ] : {
29+ realPath : p ( '/root/node_modules/test-pkg/symlink-target.js' ) ,
2630 } ,
2731 } ) ,
28- originModulePath : '/root/src/main.js' ,
32+ originModulePath : p ( '/root/src/main.js' ) ,
2933 } ;
3034
3135 test ( '"imports" subpath that maps directly to a file' , ( ) => {
3236 const context = {
3337 ...baseContext ,
3438 ...createPackageAccessors ( {
35- '/root/node_modules/test-pkg/package.json' : {
39+ [ p ( '/root/node_modules/test-pkg/package.json' ) ] : {
3640 main : 'index-main.js' ,
3741 imports : {
3842 '#foo' : './index.js' ,
3943 } ,
4044 } ,
4145 } ) ,
42- originModulePath : '/root/node_modules/test-pkg/lib/foo.js' ,
46+ originModulePath : p ( '/root/node_modules/test-pkg/lib/foo.js' ) ,
4347 } ;
4448
4549 expect ( Resolver . resolve ( context , '#foo' , null ) ) . toEqual ( {
4650 type : 'sourceFile' ,
47- filePath : '/root/node_modules/test-pkg/index.js' ,
51+ filePath : p ( '/root/node_modules/test-pkg/index.js' ) ,
4852 } ) ;
4953 } ) ;
5054} ) ;
5155
5256describe ( 'import subpath patterns resolution support' , ( ) => {
5357 const baseContext = {
5458 ...createResolutionContext ( {
55- '/root/src/main.js' : '' ,
56- '/root/node_modules/test-pkg/package.json' : JSON . stringify ( {
59+ [ p ( '/root/src/main.js' ) ] : '' ,
60+ [ p ( '/root/node_modules/test-pkg/package.json' ) ] : JSON . stringify ( {
5761 name : 'test-pkg' ,
5862 main : 'index.js' ,
5963 imports : {
6064 '#features/*' : './src/features/*.js' ,
6165 } ,
6266 } ) ,
63- '/root/node_modules/test-pkg/src/index.js' : '' ,
64- '/root/node_modules/test-pkg/src/features/foo.js' : '' ,
65- '/root/node_modules/test-pkg/src/features/foo.js.js' : '' ,
66- '/root/node_modules/test-pkg/src/features/bar/Bar.js' : '' ,
67- '/root/node_modules/test-pkg/src/features/baz.native.js' : '' ,
67+ [ p ( '/root/node_modules/test-pkg/src/index.js' ) ] : '' ,
68+ [ p ( '/root/node_modules/test-pkg/src/features/foo.js' ) ] : '' ,
69+ [ p ( '/root/node_modules/test-pkg/src/features/foo.js.js' ) ] : '' ,
70+ [ p ( '/root/node_modules/test-pkg/src/features/bar/Bar.js' ) ] : '' ,
71+ [ p ( '/root/node_modules/test-pkg/src/features/baz.native.js' ) ] : '' ,
6872 } ) ,
69- originModulePath : '/root/node_modules/test-pkg/src/index.js' ,
73+ originModulePath : p ( '/root/node_modules/test-pkg/src/index.js' ) ,
7074 } ;
7175
7276 test ( 'resolving subpath patterns in "imports" matching import specifier' , ( ) => {
7377 expect ( Resolver . resolve ( baseContext , '#features/foo' , null ) ) . toEqual ( {
7478 type : 'sourceFile' ,
75- filePath : '/root/node_modules/test-pkg/src/features/foo.js' ,
79+ filePath : p ( '/root/node_modules/test-pkg/src/features/foo.js' ) ,
7680 } ) ;
7781
7882 expect ( Resolver . resolve ( baseContext , '#features/foo.js' , null ) ) . toEqual ( {
7983 type : 'sourceFile' ,
80- filePath : '/root/node_modules/test-pkg/src/features/foo.js.js' ,
84+ filePath : p ( '/root/node_modules/test-pkg/src/features/foo.js.js' ) ,
8185 } ) ;
8286 } ) ;
8387} ) ;
8488
8589describe ( 'import subpath conditional imports resolution' , ( ) => {
8690 const baseContext = {
8791 ...createResolutionContext ( {
88- '/root/src/main.js' : '' ,
89- '/root/node_modules/test-pkg/package.json' : JSON . stringify ( {
92+ [ p ( '/root/src/main.js' ) ] : '' ,
93+ [ p ( '/root/node_modules/test-pkg/package.json' ) ] : JSON . stringify ( {
9094 name : 'test-pkg' ,
9195 main : 'index.js' ,
9296 imports : {
@@ -104,18 +108,18 @@ describe('import subpath conditional imports resolution', () => {
104108 } ,
105109 } ,
106110 } ) ,
107- '/root/node_modules/test-pkg/index.js' : '' ,
108- '/root/node_modules/test-pkg/lib/foo.js' : '' ,
109- '/root/node_modules/test-pkg/lib/foo-require.cjs' : '' ,
110- '/root/node_modules/test-pkg/lib/foo-module.mjs' : '' ,
111- '/root/node_modules/test-pkg/lib/foo-dev.js' : '' ,
112- '/root/node_modules/test-pkg/lib/foo-browser.js' : '' ,
113- '/root/node_modules/test-pkg/lib/foo-react-native.cjs' : '' ,
114- '/root/node_modules/test-pkg/lib/foo-react-native.mjs' : '' ,
115- '/root/node_modules/test-pkg/lib/foo-react-native.js' : '' ,
116- '/root/node_modules/test-pkg/lib/foo.web.js' : '' ,
111+ [ p ( '/root/node_modules/test-pkg/index.js' ) ] : '' ,
112+ [ p ( '/root/node_modules/test-pkg/lib/foo.js' ) ] : '' ,
113+ [ p ( '/root/node_modules/test-pkg/lib/foo-require.cjs' ) ] : '' ,
114+ [ p ( '/root/node_modules/test-pkg/lib/foo-module.mjs' ) ] : '' ,
115+ [ p ( '/root/node_modules/test-pkg/lib/foo-dev.js' ) ] : '' ,
116+ [ p ( '/root/node_modules/test-pkg/lib/foo-browser.js' ) ] : '' ,
117+ [ p ( '/root/node_modules/test-pkg/lib/foo-react-native.cjs' ) ] : '' ,
118+ [ p ( '/root/node_modules/test-pkg/lib/foo-react-native.mjs' ) ] : '' ,
119+ [ p ( '/root/node_modules/test-pkg/lib/foo-react-native.js' ) ] : '' ,
120+ [ p ( '/root/node_modules/test-pkg/lib/foo.web.js' ) ] : '' ,
117121 } ) ,
118- originModulePath : '/root/node_modules/test-pkg/src/index.js' ,
122+ originModulePath : p ( '/root/node_modules/test-pkg/src/index.js' ) ,
119123 } ;
120124
121125 test ( 'resolving imports subpath with conditions' , ( ) => {
@@ -128,14 +132,14 @@ describe('import subpath conditional imports resolution', () => {
128132 Resolver . resolve ( { ...context , isESMImport : false } , '#foo' , null ) ,
129133 ) . toEqual ( {
130134 type : 'sourceFile' ,
131- filePath : '/root/node_modules/test-pkg/lib/foo-react-native.cjs' ,
135+ filePath : p ( '/root/node_modules/test-pkg/lib/foo-react-native.cjs' ) ,
132136 } ) ;
133137
134138 expect (
135139 Resolver . resolve ( { ...context , isESMImport : true } , '#foo' , null ) ,
136140 ) . toEqual ( {
137141 type : 'sourceFile' ,
138- filePath : '/root/node_modules/test-pkg/lib/foo-react-native.mjs' ,
142+ filePath : p ( '/root/node_modules/test-pkg/lib/foo-react-native.mjs' ) ,
139143 } ) ;
140144 } ) ;
141145} ) ;
0 commit comments