@@ -127,53 +127,50 @@ export const resolve: resolve = async (
127
127
|| isRelativePathPattern . test ( specifier )
128
128
) ;
129
129
130
- // bare specifier
131
- if ( ! isPath ) {
132
- // TS path alias
133
- if (
134
- tsconfigPathsMatcher
135
- && ! context . parentURL ?. includes ( '/node_modules/' )
136
- ) {
137
- const possiblePaths = tsconfigPathsMatcher ( specifier ) ;
138
- for ( const possiblePath of possiblePaths ) {
139
- try {
140
- return await resolve (
141
- pathToFileURL ( possiblePath ) . toString ( ) ,
142
- context ,
143
- nextResolve ,
144
- ) ;
145
- } catch { }
130
+ if ( isPath ) {
131
+ // Inherit namespace from parent
132
+ let requestNamespace = getNamespace ( specifier ) ;
133
+ if ( context . parentURL ) {
134
+ const parentNamespace = getNamespace ( context . parentURL ) ;
135
+ if ( parentNamespace && ! requestNamespace ) {
136
+ requestNamespace = parentNamespace ;
137
+ specifier += `${ specifier . includes ( '?' ) ? '&' : '?' } ${ namespaceQuery } ${ parentNamespace } ` ;
146
138
}
147
139
}
148
140
149
- // npm package -- use default resolution
150
- return nextResolve ( specifier , context ) ;
151
- }
152
-
153
- // Inherit namespace from parent
154
- let requestNamespace = getNamespace ( specifier ) ;
155
- if ( context . parentURL ) {
156
- const parentNamespace = getNamespace ( context . parentURL ) ;
157
- if ( parentNamespace && ! requestNamespace ) {
158
- requestNamespace = parentNamespace ;
159
- specifier += `${ specifier . includes ( '?' ) ? '&' : '?' } ${ namespaceQuery } ${ parentNamespace } ` ;
141
+ if ( data . namespace && data . namespace !== requestNamespace ) {
142
+ return nextResolve ( specifier , context ) ;
160
143
}
161
- }
162
-
163
- if ( data . namespace && data . namespace !== requestNamespace ) {
164
- return nextResolve ( specifier , context ) ;
165
- }
166
144
167
- // If directory, can be index.js, index.ts, etc.
168
- if ( isDirectoryPattern . test ( specifier ) ) {
169
- return await tryDirectory ( specifier , context , nextResolve ) ;
145
+ // If directory, can be index.js, index.ts, etc.
146
+ if ( isDirectoryPattern . test ( specifier ) ) {
147
+ return await tryDirectory ( specifier , context , nextResolve ) ;
148
+ }
149
+ } else if ( // Bare specifier
150
+ // TS path alias
151
+ tsconfigPathsMatcher
152
+ && ! context . parentURL ?. includes ( '/node_modules/' )
153
+ ) {
154
+ const possiblePaths = tsconfigPathsMatcher ( specifier ) ;
155
+ for ( const possiblePath of possiblePaths ) {
156
+ try {
157
+ return await resolve (
158
+ pathToFileURL ( possiblePath ) . toString ( ) ,
159
+ context ,
160
+ nextResolve ,
161
+ ) ;
162
+ } catch { }
163
+ }
170
164
}
171
165
172
166
// Typescript gives .ts, .cts, or .mts priority over actual .js, .cjs, or .mjs extensions
173
167
//
174
168
// If `allowJs` is set in `tsconfig.json`, then we'll apply the same resolution logic
175
169
// to files without a TypeScript extension.
176
- if ( tsExtensionsPattern . test ( context . parentURL ! ) || allowJs ) {
170
+ if (
171
+ tsExtensionsPattern . test ( context . parentURL ! )
172
+ || allowJs
173
+ ) {
177
174
const tsPaths = resolveTsPath ( specifier ) ;
178
175
if ( tsPaths ) {
179
176
for ( const tsPath of tsPaths ) {
0 commit comments