Skip to content

Commit 02c38d1

Browse files
committed
feat: Improve alias path resolution in getAbsPath
This commit refactors the getAbsPath function to improve the resolution of alias paths. It removes unnecessary variables and adds a condition to handle cases where the file is exactly equal to the alias. It also ensures that the aliasPath is always appended with a slash.
1 parent 97ae724 commit 02c38d1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

mod.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ async function getAbsPath(
4949
return path.resolve(dirname, file);
5050
}
5151

52-
for (const [_alias, _aliasPath] of Object.entries(aliases)) {
52+
for (const [alias, aliasPath] of Object.entries(aliases)) {
5353
const addSlash = (str: string) => (str.endsWith("/") ? str : `${str}/`);
54-
const alias = addSlash(_alias);
55-
const aliasPath = addSlash(_aliasPath);
56-
if (file.startsWith(alias)) {
54+
if (file.startsWith(addSlash(alias)) || file === alias) {
5755
const s = new MagicString(file);
58-
s.overwrite(0, alias.length, aliasPath);
56+
s.overwrite(0, alias.length, addSlash(aliasPath));
5957
return path.resolve(s.toString());
6058
}
6159
}

0 commit comments

Comments
 (0)