Skip to content

Commit a65b1e1

Browse files
committed
feat: Improve path handling in getAbsPath function
This commit replaces the manual check for absolute paths with the built-in `path.isAbsolute` function for better reliability. It also ensures that all aliases end with a slash for consistent path resolution.
1 parent 689217f commit a65b1e1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mod.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ async function getAbsPath(
3939
const aliases = await loadAliases();
4040
const dirname = filename ? path.dirname(filename) : process.cwd();
4141

42-
if (file.startsWith("/")) {
42+
if (path.isAbsolute(file)) {
4343
return file;
4444
}
4545

4646
if (file.startsWith("./") || file.startsWith("../")) {
4747
return path.resolve(dirname, file);
4848
}
4949

50-
for (const [alias, aliasPath] of Object.entries(aliases)) {
50+
for (const [_alias, aliasPath] of Object.entries(aliases)) {
51+
const alias = _alias.endsWith("/") ? _alias : `${_alias}/`;
5152
if (file.startsWith(alias)) {
5253
const s = new MagicString(file);
5354
s.overwrite(0, alias.length, aliasPath);

0 commit comments

Comments
 (0)