Skip to content

Commit 80a2e1c

Browse files
committed
cr
1 parent 8c29a0e commit 80a2e1c

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

server/utils/import-resolver.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,16 @@ export function resolveAliasToDir(aliasSpec: string, filePath?: string | null):
116116

117117
// Support #app, #/app, ~app, ~/app, @app, @/app
118118
const alias = aliasSpec.replace(/^[#~@]\/?/, '')
119-
const segments = filePath.split('/')
119+
const normalizedFilePath = filePath.replace(/\/+$/, '')
120+
if (!normalizedFilePath) {
121+
return null
122+
}
123+
124+
if (alias === '') {
125+
return normalizedFilePath
126+
}
120127

128+
const segments = normalizedFilePath.split('/')
121129
let lastMatchIndex = -1
122130
for (let i = 0; i < segments.length; i++) {
123131
if (segments[i] === alias) {
@@ -349,11 +357,31 @@ export function resolveInternalImport(
349357
}
350358

351359
const path = normalizePath(target)
352-
if (!path || path.startsWith('..') || !files.has(path)) {
360+
if (!path || path.startsWith('..')) {
353361
return null
354362
}
355363

356-
return { path }
364+
if (files.has(path)) {
365+
return { path }
366+
}
367+
368+
for (const extensions of getExtensionPriority(currentFile)) {
369+
for (const ext of extensions) {
370+
const candidate = `${path}${ext}`
371+
if (files.has(candidate)) {
372+
return { path: candidate }
373+
}
374+
}
375+
}
376+
377+
for (const indexFile of getIndexExtensions(currentFile)) {
378+
const candidate = `${path}/${indexFile}`
379+
if (files.has(candidate)) {
380+
return { path: candidate }
381+
}
382+
}
383+
384+
return null
357385
}
358386

359387
/**

0 commit comments

Comments
 (0)