@@ -6,6 +6,8 @@ use crate::{ResolveError, ResolveOptions, Resolver, TsconfigOptions, TsconfigRef
6
6
fn auto ( ) {
7
7
let f = super :: fixture_root ( ) . join ( "tsconfig/cases/project_references" ) ;
8
8
9
+ // The following resolver's `config_file` has defined it's own paths alias which has higher priority
10
+ // some cases will work without references
9
11
let resolver = Resolver :: new ( ResolveOptions {
10
12
tsconfig : Some ( TsconfigOptions {
11
13
config_file : f. join ( "app" ) ,
@@ -14,14 +16,23 @@ fn auto() {
14
16
..ResolveOptions :: default ( )
15
17
} ) ;
16
18
19
+ // The following resolver's `config_file` has no `paths` alias with `references` enabled
20
+ let no_paths_resolver = Resolver :: new ( ResolveOptions {
21
+ tsconfig : Some ( TsconfigOptions {
22
+ config_file : f. join ( "app/tsconfig.nopaths.json" ) ,
23
+ references : TsconfigReferences :: Auto ,
24
+ } ) ,
25
+ ..ResolveOptions :: default ( )
26
+ } ) ;
27
+
17
28
#[ rustfmt:: skip]
18
29
let pass = [
19
30
// Test normal paths alias
20
31
( f. join ( "app" ) , "@/index.ts" , f. join ( "app/aliased/index.ts" ) ) ,
21
32
( f. join ( "app" ) , "@/../index.ts" , f. join ( "app/index.ts" ) ) ,
22
33
// Test project reference
23
- ( f. join ( "project_a" ) , "@/index.ts" , f. join ( "project_a /aliased/index.ts" ) ) ,
24
- ( f. join ( "project_b/src" ) , "@/index.ts" , f. join ( "project_b/src /aliased/index.ts" ) ) ,
34
+ ( f. join ( "project_a" ) , "@/index.ts" , f. join ( "app /aliased/index.ts" ) ) ,
35
+ ( f. join ( "project_b/src" ) , "@/index.ts" , f. join ( "app /aliased/index.ts" ) ) ,
25
36
// Does not have paths alias
26
37
( f. join ( "project_a" ) , "./index.ts" , f. join ( "project_a/index.ts" ) ) ,
27
38
( f. join ( "project_c" ) , "./index.ts" , f. join ( "project_c/index.ts" ) ) ,
@@ -36,12 +47,37 @@ fn auto() {
36
47
let resolved_path = resolver. resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
37
48
assert_eq ! ( resolved_path, Ok ( expected) , "{request} {path:?}" ) ;
38
49
}
50
+
51
+ #[ rustfmt:: skip]
52
+ let pass = [
53
+ // Test normal paths alias
54
+ ( f. join ( "app" ) , "@/index.ts" , Err ( ResolveError :: NotFound ( "@/index.ts" . into ( ) ) ) ) ,
55
+ ( f. join ( "app" ) , "@/../index.ts" , Ok ( f. join ( "app/index.ts" ) ) ) ,
56
+ // Test project reference
57
+ ( f. join ( "project_a" ) , "@/index.ts" , Ok ( f. join ( "project_a/aliased/index.ts" ) ) ) ,
58
+ ( f. join ( "project_b/src" ) , "@/index.ts" , Ok ( f. join ( "project_b/src/aliased/index.ts" ) ) ) ,
59
+ // Does not have paths alias
60
+ ( f. join ( "project_a" ) , "./index.ts" , Ok ( f. join ( "project_a/index.ts" ) ) ) ,
61
+ ( f. join ( "project_c" ) , "./index.ts" , Ok ( f. join ( "project_c/index.ts" ) ) ) ,
62
+ // Template variable
63
+ {
64
+ let dir = f. parent ( ) . unwrap ( ) . join ( "paths_template_variable" ) ;
65
+ ( dir. clone ( ) , "foo" , Ok ( dir. join ( "foo.js" ) ) )
66
+ }
67
+ ] ;
68
+
69
+ for ( path, request, expected) in pass {
70
+ let resolved_path = no_paths_resolver. resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
71
+ assert_eq ! ( resolved_path, expected, "{request} {path:?}" ) ;
72
+ }
39
73
}
40
74
41
75
#[ test]
42
76
fn disabled ( ) {
43
77
let f = super :: fixture_root ( ) . join ( "tsconfig/cases/project_references" ) ;
44
78
79
+ // The following resolver's `config_file` has defined it's own paths alias which has higher priority
80
+ // some cases will work without references
45
81
let resolver = Resolver :: new ( ResolveOptions {
46
82
tsconfig : Some ( TsconfigOptions {
47
83
config_file : f. join ( "app" ) ,
@@ -50,12 +86,39 @@ fn disabled() {
50
86
..ResolveOptions :: default ( )
51
87
} ) ;
52
88
89
+ // The following resolver's `config_file` has no `paths` alias with `references` enabled
90
+ let no_paths_resolver = Resolver :: new ( ResolveOptions {
91
+ tsconfig : Some ( TsconfigOptions {
92
+ config_file : f. join ( "app/tsconfig.nopaths.json" ) ,
93
+ references : TsconfigReferences :: Disabled ,
94
+ } ) ,
95
+ ..ResolveOptions :: default ( )
96
+ } ) ;
97
+
53
98
#[ rustfmt:: skip]
54
99
let pass = [
55
100
// Test normal paths alias
56
101
( f. join ( "app" ) , "@/index.ts" , Ok ( f. join ( "app/aliased/index.ts" ) ) ) ,
57
102
( f. join ( "app" ) , "@/../index.ts" , Ok ( f. join ( "app/index.ts" ) ) ) ,
58
103
// Test project reference
104
+ ( f. join ( "project_a" ) , "@/index.ts" , Ok ( f. join ( "app/aliased/index.ts" ) ) ) ,
105
+ ( f. join ( "project_b/src" ) , "@/index.ts" , Ok ( f. join ( "app/aliased/index.ts" ) ) ) ,
106
+ // Does not have paths alias
107
+ ( f. join ( "project_a" ) , "./index.ts" , Ok ( f. join ( "project_a/index.ts" ) ) ) ,
108
+ ( f. join ( "project_c" ) , "./index.ts" , Ok ( f. join ( "project_c/index.ts" ) ) ) ,
109
+ ] ;
110
+
111
+ for ( path, request, expected) in pass {
112
+ let resolved_path = resolver. resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
113
+ assert_eq ! ( resolved_path, expected, "{request} {path:?}" ) ;
114
+ }
115
+
116
+ #[ rustfmt:: skip]
117
+ let pass = [
118
+ // Test normal paths alias
119
+ ( f. join ( "app" ) , "@/index.ts" , Err ( ResolveError :: NotFound ( "@/index.ts" . into ( ) ) ) ) ,
120
+ ( f. join ( "app" ) , "#/../index.ts" , Ok ( f. join ( "app/index.ts" ) ) ) , // This works because "#/../index.ts" is resolved as "./index.ts"
121
+ // Test project reference
59
122
( f. join ( "project_a" ) , "@/index.ts" , Err ( ResolveError :: NotFound ( "@/index.ts" . into ( ) ) ) ) ,
60
123
( f. join ( "project_b/src" ) , "@/index.ts" , Err ( ResolveError :: NotFound ( "@/index.ts" . into ( ) ) ) ) ,
61
124
// Does not have paths alias
@@ -64,7 +127,7 @@ fn disabled() {
64
127
] ;
65
128
66
129
for ( path, request, expected) in pass {
67
- let resolved_path = resolver . resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
130
+ let resolved_path = no_paths_resolver . resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
68
131
assert_eq ! ( resolved_path, expected, "{request} {path:?}" ) ;
69
132
}
70
133
}
@@ -73,6 +136,8 @@ fn disabled() {
73
136
fn manual ( ) {
74
137
let f = super :: fixture_root ( ) . join ( "tsconfig/cases/project_references" ) ;
75
138
139
+ // The following resolver's `config_file` has defined it's own paths alias which has higher priority
140
+ // some cases will work without references
76
141
let resolver = Resolver :: new ( ResolveOptions {
77
142
tsconfig : Some ( TsconfigOptions {
78
143
config_file : f. join ( "app" ) ,
@@ -81,12 +146,39 @@ fn manual() {
81
146
..ResolveOptions :: default ( )
82
147
} ) ;
83
148
149
+ // The following resolver's `config_file` has no `paths` alias with `references` enabled
150
+ let no_paths_resolver = Resolver
10000
:: new ( ResolveOptions {
151
+ tsconfig : Some ( TsconfigOptions {
152
+ config_file : f. join ( "app/tsconfig.nopaths.json" ) ,
153
+ references : TsconfigReferences :: Paths ( vec ! [ "../project_a/conf.json" . into( ) ] ) ,
154
+ } ) ,
155
+ ..ResolveOptions :: default ( )
156
+ } ) ;
157
+
84
158
#[ rustfmt:: skip]
85
159
let pass = [
86
160
// Test normal paths alias
87
161
( f. join ( "app" ) , "@/index.ts" , Ok ( f. join ( "app/aliased/index.ts" ) ) ) ,
88
162
( f. join ( "app" ) , "@/../index.ts" , Ok ( f. join ( "app/index.ts" ) ) ) ,
89
163
// Test project reference
164
+ ( f. join ( "project_a" ) , "@/index.ts" , Ok ( f. join ( "app/aliased/index.ts" ) ) ) ,
165
+ ( f. join ( "project_b/src" ) , "@/index.ts" , Ok ( f. join ( "app/aliased/index.ts" ) ) ) ,
166
+ // Does not have paths alias
167
+ ( f. join ( "project_a" ) , "./index.ts" , Ok ( f. join ( "project_a/index.ts" ) ) ) ,
168
+ ( f. join ( "project_c" ) , "./index.ts" , Ok ( f. join ( "project_c/index.ts" ) ) ) ,
169
+ ] ;
170
+
171
+ for ( path, request, expected) in pass {
172
+ let resolved_path = resolver. resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
173
+ assert_eq ! ( resolved_path, expected, "{request} {path:?}" ) ;
174
+ }
175
+
176
+ #[ rustfmt:: skip]
177
+ let pass = [
178
+ // Test normal paths alias
179
+ ( f. join ( "app" ) , "@/index.ts" , Err ( ResolveError :: NotFound ( "@/index.ts" . into ( ) ) ) ) ,
180
+ ( f. join ( "app" ) , "@/../index.ts" , Ok ( f. join ( "app/index.ts" ) ) ) ,
181
+ // Test project reference
90
182
( f. join ( "project_a" ) , "@/index.ts" , Ok ( f. join ( "project_a/aliased/index.ts" ) ) ) ,
91
183
( f. join ( "project_b/src" ) , "@/index.ts" , Err ( ResolveError :: NotFound ( "@/index.ts" . into ( ) ) ) ) ,
92
184
// Does not have paths alias
@@ -95,7 +187,7 @@ fn manual() {
95
187
] ;
96
188
97
189
for ( path, request, expected) in pass {
98
- let resolved_path = resolver . resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
190
+ let resolved_path = no_paths_resolver . resolve ( & path, request) . map ( |f| f. full_path ( ) ) ;
99
191
<
DB5E
/td> assert_eq ! ( resolved_path, expected, "{request} {path:?}" ) ;
100
192
}
101
193
}
0 commit comments