Skip to content

Commit 91bfb34

Browse files
committed
fix cr
1 parent cfdc81f commit 91bfb34

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

server/utils/import-resolver.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
256260
function 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)

0 commit comments

Comments
 (0)