From f1cc41a059b71175196473d839ae276d7f101f70 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 15 Sep 2023 00:14:23 +0900 Subject: [PATCH] wip --- src/index.ts | 4 ++-- tests/fixtures/tsconfig/src/paths-slash-match.ts | 3 +++ tests/fixtures/tsconfig/tsconfig.json | 3 ++- tests/index.ts | 2 +- tests/specs/typescript/tsconfig.ts | 7 +++++++ 5 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/tsconfig/src/paths-slash-match.ts 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..1f8e3fd 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,7 +2,6 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader.js'; const nodeVersions = [ - '18', '20', ...( process.env.CI @@ -12,6 +11,7 @@ const nodeVersions = [ '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',