Skip to content

Commit b698f02

Browse files
committed
fix: fixes a resolve path loop
1 parent c1e244d commit b698f02

File tree

15 files changed

+111
-18
lines changed

15 files changed

+111
-18
lines changed

examples/index.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,19 @@ describe('examples', () => {
2727
]
2828
`);
2929
});
30+
31+
test('with-custom-resolve-path-fn', () => {
32+
const standard = jest.requireActual(
33+
'@babel-plugin-tsconfig-paths-module-resolver/with-custom-resolve-path-fn',
34+
).default;
35+
36+
expect(standard).toMatchInlineSnapshot(`
37+
Array [
38+
"from src/bar/a",
39+
"from src/foo/b",
40+
"from umbrella/baz/c",
41+
"from special",
42+
]
43+
`);
44+
});
3045
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { createResolvePath } = require('../..');
2+
3+
const resolvePath = createResolvePath();
4+
5+
function customResolvePath(...args) {
6+
const [sourceFile] = args;
7+
8+
if (sourceFile === 'needs-a-custom-resolver') return './special';
9+
return resolvePath(...args);
10+
}
11+
12+
module.exports = {
13+
presets: [
14+
'@babel/preset-typescript',
15+
['@babel/preset-env', { targets: { node: true } }],
16+
],
17+
plugins: [
18+
[
19+
require.resolve('../..'),
20+
{
21+
resolvePath: customResolvePath,
22+
},
23+
],
24+
],
25+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@babel-plugin-tsconfig-paths-module-resolver/with-custom-resolve-path-fn",
3+
"private": true,
4+
"version": "1.0.0",
5+
"main": "./dist/index.js",
6+
"scripts": {
7+
"build": "babel -x .ts ./src --out-dir ./dist"
8+
},
9+
"license": "MIT"
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'from src/bar/a';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'from src/foo/b';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import a from '@/bar/a';
2+
import b from '@/foo/b';
3+
import c from '@/baz/c';
4+
// @ts-expect-error
5+
import d from 'needs-a-custom-resolver';
6+
7+
export default [a, b, c, d];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'from special';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'from umbrella/baz/c';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"esModuleInterop": true,
5+
"moduleResolution": "node",
6+
"baseUrl": "./src",
7+
"paths": {
8+
"@/*": ["umbrella/*", "*"]
9+
}
10+
},
11+
"include": ["./src/**/*.ts"],
12+
"exclude": ["**/node_modules"]
13+
}

external.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ declare module 'babel-plugin-module-resolver' {
205205
* [0]: https://docs.npmjs.com/misc/config#loglevel
206206
*/
207207
logLevel?: string;
208+
/**
209+
* @internal
210+
*/
211+
_originalResolvePath?: ResolvePath;
208212
}
209213

210214
export const resolvePath: ResolvePath;

0 commit comments

Comments
 (0)