From f04aab21f9f6dc02316a9ff3a9cd43e90cd97828 Mon Sep 17 00:00:00 2001 From: rk_zhang <40221744+qmhc@users.noreply.github.com> Date: Tue, 23 Nov 2021 11:08:53 +0800 Subject: [PATCH] fix: aliases are not resolved when find ends with '/' flx #37 --- src/transform.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/transform.ts b/src/transform.ts index 2bd4d01..ae543d9 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -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 = @@ -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 ? ')' : ''}` ) }