Skip to content

Commit

Permalink
fix: skip relative resolving for absolute paths
Browse files Browse the repository at this point in the history
fix #445
  • Loading branch information
yyx990803 committed Jun 24, 2020
1 parent 298c78d commit e0a0258
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
39 changes: 22 additions & 17 deletions src/node/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,33 @@ export function createResolver(
},

resolveRelativeRequest(importer: string, importee: string) {
let resolved = path.posix.resolve(path.posix.dirname(importer), importee)

for (const alias in literalDirAlias) {
if (importer.startsWith(alias)) {
if (!resolved.startsWith(alias)) {
// resolved path is outside of alias directory, we need to use
// its full path instead
const importerFilePath = resolver.requestToFile(importer)
const importeeFilePath = path.resolve(
path.dirname(importerFilePath),
importee
)
resolved = resolver.fileToRequest(importeeFilePath)
const queryMatch = importee.match(queryRE)
let resolved = importee

if (importee.startsWith('.')) {
resolved = path.posix.resolve(path.posix.dirname(importer), importee)
for (const alias in literalDirAlias) {
if (importer.startsWith(alias)) {
if (!resolved.startsWith(alias)) {
// resolved path is outside of alias directory, we need to use
// its full path instead
const importerFilePath = resolver.requestToFile(importer)
const importeeFilePath = path.resolve(
path.dirname(importerFilePath),
importee
)
resolved = resolver.fileToRequest(importeeFilePath)
}
break
}
break
}
}

const queryMatch = importee.match(queryRE)
return {
// path resolve strips ending / which should be preserved
pathname: cleanUrl(resolved) + (importee.endsWith('/') ? '/' : ''),
pathname:
cleanUrl(resolved) +
// path resolve strips ending / which should be preserved
(importee.endsWith('/') && !resolved.endsWith('/') ? '/' : ''),
query: queryMatch ? queryMatch[0] : ''
}
}
Expand Down
1 change: 0 additions & 1 deletion src/node/server/serverPluginModuleRewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,5 @@ export const resolveImport = (
id += `${id.includes(`?`) ? `&` : `?`}t=${latestVersionsMap.get(cleanId)}`
}
}

return id
}

0 comments on commit e0a0258

Please sign in to comment.