1
1
import { join , dirname } from "path" ;
2
- import { removeExtension } from "../../src/filesystem" ;
3
2
4
3
export interface OneTest {
5
4
readonly name : string ;
@@ -60,7 +59,7 @@ export const tests: ReadonlyArray<OneTest> = [
60
59
existingFiles : [ join ( "/root" , "location" , "mylib.myext" ) ] ,
61
60
requestedModule : "lib/mylib" ,
62
61
extensions : [ ".js" , ".myext" ] ,
63
- expectedPath : removeExtension ( join ( "/root" , "location" , "mylib.myext" ) ) ,
62
+ expectedPath : join ( "/root" , "location" , "mylib.myext" ) ,
64
63
} ,
65
64
{
66
65
name : "should resolve request with extension specified" ,
@@ -78,7 +77,7 @@ export const tests: ReadonlyArray<OneTest> = [
78
77
} ,
79
78
existingFiles : [ join ( "/root" , "location" , "foo.ts" ) ] ,
80
79
requestedModule : "lib/foo" ,
81
- expectedPath : removeExtension ( join ( "/root" , "location" , "foo.ts" ) ) ,
80
+ expectedPath : join ( "/root" , "location" , "foo.ts" ) ,
82
81
} ,
83
82
{
84
83
name : "should resolve to parent folder when filename is in subfolder" ,
@@ -95,9 +94,7 @@ export const tests: ReadonlyArray<OneTest> = [
95
94
existingFiles : [ join ( "/root" , "location" , "mylib" , "kalle.ts" ) ] ,
96
95
packageJson : { main : "./kalle.ts" } ,
97
96
requestedModule : "lib/mylib" ,
98
- expectedPath : removeExtension (
99
- join ( "/root" , "location" , "mylib" , "kalle.ts" )
100
- ) ,
97
+ expectedPath : join ( "/root" , "location" , "mylib" , "kalle.ts" ) ,
101
98
} ,
102
99
{
103
100
name : "should resolve from main field in package.json (js)" ,
@@ -107,9 +104,7 @@ export const tests: ReadonlyArray<OneTest> = [
107
104
packageJson : { main : "./kalle.js" } ,
108
105
requestedModule : "lib/mylib.js" ,
109
106
extensions : [ ".ts" , ".js" ] ,
110
- expectedPath : removeExtension (
111
- join ( "/root" , "location" , "mylib.js" , "kalle.js" )
112
- ) ,
107
+ expectedPath : join ( "/root" , "location" , "mylib.js" , "kalle.js" ) ,
113
108
} ,
114
109
{
115
110
name :
@@ -120,9 +115,7 @@ export const tests: ReadonlyArray<OneTest> = [
120
115
packageJson : { main : "./kalle.js" } ,
121
116
extensions : [ ".ts" , ".js" ] ,
122
117
requestedModule : "lib/mylibjs" ,
123
- expectedPath : removeExtension (
124
- join ( "/root" , "location" , "mylibjs" , "kalle.js" )
125
- ) ,
118
+ expectedPath : join ( "/root" , "location" , "mylibjs" , "kalle.js" ) ,
126
119
} ,
127
120
{
128
121
name : "should resolve from list of fields by priority in package.json" ,
@@ -136,9 +129,7 @@ export const tests: ReadonlyArray<OneTest> = [
136
129
] ,
137
130
extensions : [ ".ts" , ".js" ] ,
138
131
requestedModule : "lib/mylibjs" ,
139
- expectedPath : removeExtension (
140
- join ( "/root" , "location" , "mylibjs" , "browser.js" )
141
- ) ,
132
+ expectedPath : join ( "/root" , "location" , "mylibjs" , "browser.js" ) ,
142
133
} ,
143
134
{
144
135
name : "should ignore field mappings to missing files in package.json" ,
@@ -152,9 +143,7 @@ export const tests: ReadonlyArray<OneTest> = [
152
143
browser : "./nope.js" ,
153
144
} ,
154
145
extensions : [ ".ts" , ".js" ] ,
155
- expectedPath : removeExtension (
156
- join ( "/root" , "location" , "mylibjs" , "kalle.js" )
157
- ) ,
146
+ expectedPath : join ( "/root" , "location" , "mylibjs" , "kalle.js" ) ,
158
147
} ,
159
148
{
160
149
name : "should ignore advanced field mappings in package.json" ,
@@ -170,9 +159,7 @@ export const tests: ReadonlyArray<OneTest> = [
170
159
browser : { mylibjs : "./browser.js" , "./kalle.js" : "./browser.js" } ,
171
160
} ,
172
161
extensions : [ ".ts" , ".js" ] ,
173
- expectedPath : removeExtension (
174
- join ( "/root" , "location" , "mylibjs" , "kalle.js" )
175
- ) ,
162
+ expectedPath : join ( "/root" , "location" , "mylibjs" , "kalle.js" ) ,
176
163
} ,
177
164
{
178
165
name : "should resolve to with the help of baseUrl when not explicitly set" ,
@@ -209,4 +196,15 @@ export const tests: ReadonlyArray<OneTest> = [
209
196
requestedModule : "lib/mylib" ,
210
197
expectedPath : undefined ,
211
198
} ,
199
+ {
200
+ name : "should resolve main file with cjs file extension" ,
201
+ absoluteBaseUrl : "/root/" ,
202
+ paths : { } ,
203
+ existingFiles : [ join ( "/root" , "mylib" , "index.cjs" ) ] ,
204
+ packageJson : {
205
+ main : "./index.cjs" ,
206
+ } ,
207
+ requestedModule : "mylib" ,
208
+ expectedPath : join ( "/root" , "mylib" , "index.cjs" ) ,
209
+ } ,
212
210
] ;
0 commit comments