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

Commit 4dcdf73

Browse files
fix(tsconfig paths): support paths starting with slash (#41)
1 parent f21fe06 commit 4dcdf73

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'get-tsconfig';
1717
import type { TransformOptions } from 'esbuild';
1818

19-
const isPathPattern = /^\.{0,2}\//;
19+
const isRelativePathPattern = /^\.{1,2}\//;
2020
const isTsFilePatten = /\.[cm]?tsx?$/;
2121
const nodeModulesPath = `${path.sep}node_modules${path.sep}`;
2222

@@ -158,7 +158,7 @@ Module._resolveFilename = function (request, parent, isMain, options) {
158158
tsconfigPathsMatcher
159159

160160
// bare specifier
161-
&& !isPathPattern.test(request)
161+
&& !isRelativePathPattern.test(request)
162162

163163
// Dependency paths should not be resolved using tsconfig.json
164164
&& !parent?.filename?.includes(nodeModulesPath)
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/tsconfig/tsconfig.json

+2-1
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

+5-2
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.16.2', // Pre ESM import
1113
'12',
1214
'14',
1315
'16',
1416
'17',
17+
'18',
1518
]
1619
: []
1720
),

tests/specs/typescript/tsconfig.ts

+7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
143143
expect(nodeProcess.stdout).toBe('nested-resolve-target');
144144
});
145145

146+
test('resolves paths slash prefix', async () => {
147+
const nodeProcess = await node.load('./src/paths-slash-match.ts', {
148+
cwd: './tsconfig',
149+
});
150+
expect(nodeProcess.stdout).toBe('nested-resolve-target');
151+
});
152+
146153
test('resolves paths suffix', async () => {
147154
const nodeProcess = await node.load('./src/paths-suffix-match.ts', {
148155
cwd: './tsconfig',

0 commit comments

Comments
 (0)