Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit a25b925

Browse files
fix(tsconfig paths): support paths starting with slash (#75)
1 parent 9d77327 commit a25b925

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

src/loaders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async function tryDirectory(
125125
}
126126
}
127127

128-
const isPathPattern = /^\.{0,2}\//;
128+
const isRelativePathPattern = /^\.{1,2}\//;
129129

130130
const supportsNodePrefix = (
131131
compareNodeVersion([14, 13, 1]) >= 0
@@ -151,7 +151,7 @@ export const resolve: resolve = async function (
151151

152152
const isPath = (
153153
specifier.startsWith(fileProtocol)
154-
|| isPathPattern.test(specifier)
154+
|| isRelativePathPattern.test(specifier)
155155
);
156156

157157
if (
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import value from '/nested-resolve-target';
2+
3+
console.log(value);

tests/fixtures/package-module/tsconfig/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"paths": {
88
"paths-exact-match": ["resolve-target"],
99
"p/*": ["utils/*"],
10-
"*/s": ["utils/*"]
10+
"*/s": ["utils/*"],
11+
"/*": ["utils/*"]
1112
},
1213
},
1314
}

tests/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ import { describe } from 'manten';
22
import { createNode } from './utils/node-with-loader.js';
33

44
const nodeVersions = [
5-
'18',
65
'20',
76
...(
8-
process.env.CI
7+
(
8+
process.env.CI
9+
&& process.platform !== 'win32'
10+
)
911
? [
1012
'12.20.0', // CJS named export detection added
1113
'12',
1214
'14',
1315
'16',
1416
'17',
17+
'18',
1518
]
1619
: []
1720
),

tests/specs/typescript/tsconfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
113113
expect(nodeProcess.stdout).toBe('nested-resolve-target');
114114
});
115115

116+
test('resolves paths slash prefix', async () => {
117+
const nodeProcess = await node.load('./src/paths-slash-match.ts', {
118+
cwd: './tsconfig',
119+
});
120+
expect(nodeProcess.stdout).toBe('nested-resolve-target');
121+
});
122+
116123
test('resolves paths suffix', async () => {
117124
const nodeProcess = await node.load('./src/paths-suffix-match.ts', {
118125
cwd: './tsconfig',

0 commit comments

Comments
 (0)