Skip to content

Commit

Permalink
fix: posixify path when resolving path aliases (#71)
Browse files Browse the repository at this point in the history
Previously path resolving failed because it resulted in stuff like `import foo from '.\x` which is invalid, resulting in `any` types
  • Loading branch information
dummdidumm authored Dec 12, 2023
1 parent 4df5793 commit 7ee1ddb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export async function createBundle(options) {
}

if (replacement) {
let relative = path.relative(path.dirname(file), replacement);
let relative = path.relative(path.dirname(file), replacement).replaceAll('\\', '/');
if (relative[0] !== '.') relative = `./${relative}`;

code.overwrite(node.pos, node.end, `${match[1]}${relative}${match[1]}`);
Expand Down
2 changes: 2 additions & 0 deletions test/samples/path-config/input/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { foo_nested } from './nested/file.js';

/**
* @param {import('#lib').Input} input
* @returns {import('#lib').Output}
Expand Down
7 changes: 7 additions & 0 deletions test/samples/path-config/input/nested/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @param {import('#lib').Input} input
* @returns {import('#lib').Output}
*/
export function foo_nested(input) {
return input * 2;
}
1 change: 1 addition & 0 deletions test/samples/path-config/output 5.0 - 5.1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module 'path-config' {
};
type Input = number;
type Output = number;
export function foo_nested(input: Input): Output;
}

//# sourceMappingURL=index.d.ts.map
9 changes: 6 additions & 3 deletions test/samples/path-config/output 5.0 - 5.1/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
"overload",
"foo2",
"Input",
"Output"
"Output",
"foo_nested"
],
"sources": [
"../input/index.js",
"../input/lib.d.ts"
"../input/lib.d.ts",
"../input/nested/file.js"
],
"sourcesContent": [
null,
null,
null
],
"mappings": ";iBAIgBA,GAAGA;iBASfC,QAAQA;iBAARA,QAAQA;;iBAgBIC,IAAIA;;;;MC7BRC,KAAKA;MACLC,MAAMA"
"mappings": ";iBAMgBA,GAAGA;iBASfC,QAAQA;iBAARA,QAAQA;;iBAgBIC,IAAIA;;;;MC/BRC,KAAKA;MACLC,MAAMA;iBCGFC,UAAUA"
}
1 change: 1 addition & 0 deletions test/samples/path-config/output/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare module 'path-config' {
};
type Input = number;
type Output = number;
export function foo_nested(input: Input): Output;
}

//# sourceMappingURL=index.d.ts.map
9 changes: 6 additions & 3 deletions test/samples/path-config/output/index.d.ts.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
"overload",
"foo2",
"Input",
"Output"
"Output",
"foo_nested"
],
"sources": [
"../input/index.js",
"../input/lib.d.ts"
"../input/lib.d.ts",
"../input/nested/file.js"
],
"sourcesContent": [
null,
null,
null
],
"mappings": ";iBAIgBA,GAAGA;;iBASfC,QAAQA;;iBAARA,QAAQA;;iBAgBIC,IAAIA;;;;MC7BRC,KAAKA;MACLC,MAAMA"
"mappings": ";iBAMgBA,GAAGA;;iBASfC,QAAQA;;iBAARA,QAAQA;;iBAgBIC,IAAIA;;;;MC/BRC,KAAKA;MACLC,MAAMA;iBCGFC,UAAUA"
}

0 comments on commit 7ee1ddb

Please sign in to comment.