Skip to content

Commit

Permalink
fix: aliases are not resolved when find ends with '/'
Browse files Browse the repository at this point in the history
flx #37
  • Loading branch information
qmhc committed Nov 23, 2021
1 parent 7de7ccb commit f04aab2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/transform.ts
Expand Up @@ -64,7 +64,10 @@ function isAliasMatch(alias: Alias, importee: string) {
if (importee.length < alias.find.length) return false
if (importee === alias.find) return true

return importee.indexOf(alias.find) === 0 && importee.substring(alias.find.length)[0] === '/'
return (
importee.indexOf(alias.find) === 0 &&
(alias.find.endsWith('/') || importee.substring(alias.find.length)[0] === '/')
)
}

const globalImportRE =
Expand Down Expand Up @@ -98,7 +101,8 @@ export function transformAliasImport(filePath: string, content: string, aliases:
isDynamic ? simpleDynamicImportRE : simpleStaticImportRE,
`$1'${matchResult[1].replace(
matchedAlias.find,
truthPath.startsWith('.') ? truthPath : `./${truthPath}`
(truthPath.startsWith('.') ? truthPath : `./${truthPath}`) +
(typeof matchedAlias.find === 'string' && matchedAlias.find.endsWith('/') ? '/' : '')
)}'${isDynamic ? ')' : ''}`
)
}
Expand Down

0 comments on commit f04aab2

Please sign in to comment.