File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -253,18 +253,27 @@ function normalizeInternalImportTarget(target: InternalImportTarget): string | n
253253 return null
254254}
255255
256+ function normalizeAliasPrefix ( value : string ) : string {
257+ return value . replace ( / ^ ( [ # ~ @ ] ) \/ / , '$1' )
258+ }
259+
256260function guessInternalImportTarget (
257261 imports : InternalImportsMap ,
258262 specifier : string ,
259263 files : FileSet ,
260264 currentFile : string ,
261265) : string | null {
262266 for ( const [ key , value ] of Object . entries ( imports ) ) {
263- if ( specifier . startsWith ( key ) ) {
267+ const normalizedSpecifier = normalizeAliasPrefix ( specifier )
268+ const normalizedKey = normalizeAliasPrefix ( key )
269+ if (
270+ normalizedSpecifier === normalizedKey ||
271+ normalizedSpecifier . startsWith ( `${ normalizedKey } /` )
272+ ) {
264273 const basePath = resolveAliasToDir ( key , normalizeInternalImportTarget ( value ) )
265274 if ( ! basePath ) continue
266275
267- const suffix = specifier . substring ( key . length ) . trim ( ) . replace ( / ^ \/ / , '' )
276+ const suffix = normalizedSpecifier . slice ( normalizedKey . length ) . replace ( / ^ \/ / , '' )
268277 const pathWithoutExt = suffix ? `${ basePath } /${ suffix } ` : basePath
269278
270279 const toCheckPath = ( p : string ) => files . has ( normalizePath ( p ) ) || files . has ( p )
You can’t perform that action at this time.
0 commit comments