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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Sep 14, 2023
1 parent f21fe06 commit f1cc41a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'get-tsconfig';
import type { TransformOptions } from 'esbuild';

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

Expand Down Expand Up @@ -158,7 +158,7 @@ Module._resolveFilename = function (request, parent, isMain, options) {
tsconfigPathsMatcher

// bare specifier
&& !isPathPattern.test(request)
&& !isRelativePathPattern.test(request)

// Dependency paths should not be resolved using tsconfig.json
&& !parent?.filename?.includes(nodeModulesPath)
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/tsconfig/src/paths-slash-match.ts
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/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/*"]
},
},
}
2 changes: 1 addition & 1 deletion tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe } from 'manten';
import { createNode } from './utils/node-with-loader.js';

const nodeVersions = [
'18',
'20',
...(
process.env.CI
Expand All @@ -12,6 +11,7 @@ const nodeVersions = [
'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 @@ -143,6 +143,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 f1cc41a

Please sign in to comment.