diff --git a/src/index.ts b/src/index.ts index 5ce9fc8..5c68efb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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}`; @@ -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) diff --git a/tests/fixtures/tsconfig/src/paths-slash-match.ts b/tests/fixtures/tsconfig/src/paths-slash-match.ts new file mode 100644 index 0000000..c906c5a --- /dev/null +++ b/tests/fixtures/tsconfig/src/paths-slash-match.ts @@ -0,0 +1,3 @@ +import value from '/nested-resolve-target'; + +console.log(value); diff --git a/tests/fixtures/tsconfig/tsconfig.json b/tests/fixtures/tsconfig/tsconfig.json index 9d0c412..ea35d97 100644 --- a/tests/fixtures/tsconfig/tsconfig.json +++ b/tests/fixtures/tsconfig/tsconfig.json @@ -7,7 +7,8 @@ "paths": { "paths-exact-match": ["resolve-target"], "p/*": ["utils/*"], - "*/s": ["utils/*"] + "*/s": ["utils/*"], + "/*": ["utils/*"] }, }, } diff --git a/tests/index.ts b/tests/index.ts index 8776334..844c272 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -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.16.2', // Pre ESM import '12', '14', '16', '17', + '18', ] : [] ), diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index bf434ce..6b71f9a 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -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',