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

Commit

Permalink
fix(tsconfig paths): support paths starting with slash (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Sep 14, 2023
1 parent 9d77327 commit a25b925
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function tryDirectory(
}
}

const isPathPattern = /^\.{0,2}\//;
const isRelativePathPattern = /^\.{1,2}\//;

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

const isPath = (
specifier.startsWith(fileProtocol)
|| isPathPattern.test(specifier)
|| isRelativePathPattern.test(specifier)
);

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import value from '/nested-resolve-target';

console.log(value);
3 changes: 2 additions & 1 deletion tests/fixtures/package-module/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"paths": {
"paths-exact-match": ["resolve-target"],
"p/*": ["utils/*"],
"*/s": ["utils/*"]
"*/s": ["utils/*"],
"/*": ["utils/*"]
},
},
}
7 changes: 5 additions & 2 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { describe } from 'manten';
import { createNode } from './utils/node-with-loader.js';

const nodeVersions = [
'18',
'20',
...(
process.env.CI
(
process.env.CI
&& process.platform !== 'win32'
)
? [
'12.20.0', // CJS named export detection added
'12',
'14',
'16',
'17',
'18',
]
: []
),
Expand Down
7 changes: 7 additions & 0 deletions tests/specs/typescript/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
expect(nodeProcess.stdout).toBe('nested-resolve-target');
});

test('resolves paths slash prefix', async () => {
const nodeProcess = await node.load('./src/paths-slash-match.ts', {
cwd: './tsconfig',
});
expect(nodeProcess.stdout).toBe('nested-resolve-target');
});

test('resolves paths suffix', async () => {
const nodeProcess = await node.load('./src/paths-suffix-match.ts', {
cwd: './tsconfig',
Expand Down

0 comments on commit a25b925

Please sign in to comment.