From 36d5e89c96f4b6b506e4ce5e3dda5b57911ddb00 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 22 Jun 2022 15:44:32 -0400 Subject: [PATCH 01/14] test: tsconfig paths dependency resolve current directory --- .../tsconfig/dependency-resolve-current-directory.ts | 1 + .../resolve-current-directory/lib/file.js | 1 + .../resolve-current-directory/lib/index.js | 1 + .../resolve-current-directory/package.json | 3 +++ tests/fixtures/tsconfig/src/index.ts | 1 + tests/specs/typescript/tsconfig.ts | 11 ++++++++++- 6 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/tsconfig/dependency-resolve-current-directory.ts create mode 100644 tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.js create mode 100644 tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js create mode 100644 tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json create mode 100644 tests/fixtures/tsconfig/src/index.ts diff --git a/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts b/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts new file mode 100644 index 0000000..5295f76 --- /dev/null +++ b/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts @@ -0,0 +1 @@ +import 'resolve-current-directory'; diff --git a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.js b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.js new file mode 100644 index 0000000..9ed9595 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.js @@ -0,0 +1 @@ +require('.'); diff --git a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js new file mode 100644 index 0000000..7f2bfb1 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js @@ -0,0 +1 @@ +console.log('resolved'); diff --git a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json new file mode 100644 index 0000000..05f97b4 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json @@ -0,0 +1,3 @@ +{ + "main": "lib/file.js" +} diff --git a/tests/fixtures/tsconfig/src/index.ts b/tests/fixtures/tsconfig/src/index.ts new file mode 100644 index 0000000..22c44c5 --- /dev/null +++ b/tests/fixtures/tsconfig/src/index.ts @@ -0,0 +1 @@ +console.log('Should not run'); \ No newline at end of file diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index 581edce..5c3acb1 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -10,7 +10,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toBe('div null hello world\nnull null goodbye world'); }); - describe('paths', ({ test }) => { + describe('paths', ({ test, describe }) => { test('resolves baseUrl', async () => { const nodeProcess = await node.load('./src/base-url.ts', { cwd: './tsconfig', @@ -38,6 +38,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); expect(nodeProcess.stdout).toBe('resolved'); }); + + describe('dependency', ({ test }) => { + test('resolve current directory', async () => { + const nodeProcess = await node.load('./dependency-resolve-current-directory', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); + }); }); }); }); From 969f3e7e3c02996e1f2c21102a1d5b4f26b7f919 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 22 Jun 2022 16:12:55 -0400 Subject: [PATCH 02/14] fix: upgrade get-tsconfig --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ff2181d..838f80d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "dependencies": { "@esbuild-kit/core-utils": "^2.0.0", - "get-tsconfig": "^4.0.0" + "get-tsconfig": "^4.0.5" }, "devDependencies": { "@pvtnbr/eslint-config": "^0.22.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fbae808..476fe90 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,7 +8,7 @@ specifiers: eslint: ^8.15.0 execa: ^6.1.0 get-node: ^12.1.0 - get-tsconfig: ^4.0.0 + get-tsconfig: ^4.0.5 manten: ^0.1.0 pkgroll: ^1.3.0 semver: ^7.3.7 @@ -17,7 +17,7 @@ specifiers: dependencies: '@esbuild-kit/core-utils': 2.0.0 - get-tsconfig: 4.0.0 + get-tsconfig: 4.0.5 devDependencies: '@pvtnbr/eslint-config': 0.22.0_4hx5bygx4rxgd7xwyndf6ymwce @@ -2018,8 +2018,8 @@ packages: get-intrinsic: 1.1.1 dev: true - /get-tsconfig/4.0.0: - resolution: {integrity: sha512-WvnskjM5QJbSjuZrJkG3CeIE/ywYjL9/UMYu5dpOa3iD6GjefbQq7J/nrZY4yo6QSYuYwmj7G7Xd9qzCjMMKUw==} + /get-tsconfig/4.0.5: + resolution: {integrity: sha512-UiOHySG2zoM0krlrfJOMQoY5UR1Z57/HjMUJdi7lJHCLKiES9zZsDXtU0BPo2GUI5EqJmNRnqU3FdMjDmf2XaA==} dev: false /glob-parent/5.1.2: From c6111d6f04447e7439c7734099af097a34596aab Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 22 Jun 2022 16:57:22 -0400 Subject: [PATCH 03/14] test: dependency shouldnt resolve by baseUrl --- .../tsconfig/dependency-resolve-current-directory.ts | 2 +- .../tsconfig/dependency-should-not-resolve-baseUrl.ts | 1 + .../node_modules/should-not-resolve-baseUrl/index.js | 1 + .../node_modules/resolve-target/index.js | 1 + .../node_modules/resolve-target/package.json | 1 + .../node_modules/should-not-resolve-baseUrl/package.json | 1 + tests/specs/typescript/tsconfig.ts | 7 +++++++ 7 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.js create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json diff --git a/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts b/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts index 5295f76..1c24c02 100644 --- a/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts +++ b/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts @@ -1 +1 @@ -import 'resolve-current-directory'; +require('resolve-current-directory'); diff --git a/tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts b/tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts new file mode 100644 index 0000000..9507bd1 --- /dev/null +++ b/tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts @@ -0,0 +1 @@ +require('should-not-resolve-baseUrl'); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.js b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.js new file mode 100644 index 0000000..4e1262c --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.js @@ -0,0 +1 @@ +console.log(require('resolve-target')); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js new file mode 100644 index 0000000..08c72ab --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js @@ -0,0 +1 @@ +module.exports = 'resolved'; \ No newline at end of file diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index 5c3acb1..0c1165d 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -46,6 +46,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); expect(nodeProcess.stdout).toBe('resolved'); }); + + test('should not resolve baseUrl', async () => { + const nodeProcess = await node.load('./dependency-should-not-resolve-baseUrl', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); }); }); }); From ba5a6cc9a8a1222132f0b1878b8d92cd5692b0ce Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 00:26:49 -0400 Subject: [PATCH 04/14] fix: dependency to not resolve to baseUrl --- src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.ts b/src/index.ts index 429e6fe..bf52bd4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -112,8 +112,12 @@ Module._resolveFilename = function (request, parent, isMain, options) { if ( tsconfigPathsMatcher + // bare specifier && !isPathPattern.test(request) + + // Dependency paths should not be resolved using tsconfig.json + && !parent.filename.includes('/node_modules/') ) { const possiblePaths = tsconfigPathsMatcher(request); for (const possiblePath of possiblePaths) { From 9f0349f13bed9771ba39402d74e22769f2a590a7 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 00:40:38 -0400 Subject: [PATCH 05/14] test: dependency to not resolve paths --- .../tsconfig/dependency-should-not-resolve-paths.ts | 1 + .../node_modules/should-not-resolve-paths/index.js | 1 + .../node_modules/p/nested-resolve-target.js | 1 + .../should-not-resolve-paths/node_modules/p/package.json | 1 + .../node_modules/should-not-resolve-paths/package.json | 1 + tests/specs/typescript/tsconfig.ts | 7 +++++++ 6 files changed, 12 insertions(+) create mode 100644 tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.js create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json create mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json diff --git a/tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts b/tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts new file mode 100644 index 0000000..a0a6a66 --- /dev/null +++ b/tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts @@ -0,0 +1 @@ +require('should-not-resolve-paths'); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.js b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.js new file mode 100644 index 0000000..0a617e4 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.js @@ -0,0 +1 @@ +console.log(require('p/nested-resolve-target')); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js new file mode 100644 index 0000000..08c72ab --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js @@ -0,0 +1 @@ +module.exports = 'resolved'; \ No newline at end of file diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index 0c1165d..cc83f48 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -53,6 +53,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); expect(nodeProcess.stdout).toBe('resolved'); }); + + test('should not resolve paths', async () => { + const nodeProcess = await node.load('./dependency-should-not-resolve-paths', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); }); }); }); From 5a5b0f9eeabe8ebba2186f77beb01f97a8a59063 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 00:45:28 -0400 Subject: [PATCH 06/14] fix: windows path --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index bf52bd4..e5beea2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import path from 'path'; import fs from 'fs'; import Module from 'module'; import { @@ -11,6 +12,7 @@ import { getTsconfig, createPathsMatcher } from 'get-tsconfig'; const isPathPattern = /^\.{0,2}\//; const isTsFilePatten = /\.[cm]?tsx?$/; +const nodeModulesPath = path.sep + 'node_modules' + path.sep; const tsconfig = getTsconfig(); const tsconfigRaw = tsconfig?.config; @@ -117,7 +119,7 @@ Module._resolveFilename = function (request, parent, isMain, options) { && !isPathPattern.test(request) // Dependency paths should not be resolved using tsconfig.json - && !parent.filename.includes('/node_modules/') + && !parent.filename.includes(nodeModulesPath) ) { const possiblePaths = tsconfigPathsMatcher(request); for (const possiblePath of possiblePaths) { From 20565df5b01e327ca0d1f860d7e2b02eaafd2ce1 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 00:45:46 -0400 Subject: [PATCH 07/14] style: lintfix --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e5beea2..b7c9081 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,7 @@ import { getTsconfig, createPathsMatcher } from 'get-tsconfig'; const isPathPattern = /^\.{0,2}\//; const isTsFilePatten = /\.[cm]?tsx?$/; -const nodeModulesPath = path.sep + 'node_modules' + path.sep; +const nodeModulesPath = `${path.sep}node_modules${path.sep}`; const tsconfig = getTsconfig(); const tsconfigRaw = tsconfig?.config; From 931bf9935df83cfa3ccafc3f097060fa42fad6d4 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 00:58:12 -0400 Subject: [PATCH 08/14] debug --- .github/workflows/test.yml | 2 +- src/index.ts | 8 ++- tests/index.ts | 12 ++--- tests/specs/typescript/index.ts | 10 ++-- tests/specs/typescript/tsconfig.ts | 84 +++++++++++++++--------------- 5 files changed, 61 insertions(+), 55 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 007bfbb..9d913bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [windows-latest] timeout-minutes: 10 steps: diff --git a/src/index.ts b/src/index.ts index b7c9081..dfc1938 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,8 +119,14 @@ Module._resolveFilename = function (request, parent, isMain, options) { && !isPathPattern.test(request) // Dependency paths should not be resolved using tsconfig.json - && !parent.filename.includes(nodeModulesPath) + // && !parent.filename.includes(nodeModulesPath) ) { + console.log({ + request, + parent: parent.filename, + nodeModulesPath, + isDependency: parent.filename.includes(nodeModulesPath), + }); const possiblePaths = tsconfigPathsMatcher(request); for (const possiblePath of possiblePaths) { try { diff --git a/tests/index.ts b/tests/index.ts index bf426d9..04d3575 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,7 +2,7 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader'; const nodeVersions = [ - '12.16.2', // Pre ESM import + // '12.16.2', // Pre ESM import '12.22.11', ...( process.env.CI @@ -20,11 +20,11 @@ const nodeVersions = [ const node = await createNode(nodeVersion, './tests/fixtures'); await describe(`Node ${node.version}`, ({ runTestSuite }) => { - runTestSuite( - // eslint-disable-next-line node/global-require,@typescript-eslint/no-var-requires - (require('./specs/javascript') as typeof import('./specs/javascript')).default, - node, - ); + // runTestSuite( + // // eslint-disable-next-line node/global-require,@typescript-eslint/no-var-requires + // (require('./specs/javascript') as typeof import('./specs/javascript')).default, + // node, + // ); runTestSuite( // eslint-disable-next-line node/global-require,@typescript-eslint/no-var-requires (require('./specs/typescript') as typeof import('./specs/typescript')).default, diff --git a/tests/specs/typescript/index.ts b/tests/specs/typescript/index.ts index e0cc531..875f1cc 100644 --- a/tests/specs/typescript/index.ts +++ b/tests/specs/typescript/index.ts @@ -9,11 +9,11 @@ import specTsconfig from './tsconfig'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('TypeScript', async ({ runTestSuite }) => { - runTestSuite(specTs, node); - runTestSuite(specTsx, node); - runTestSuite(specJsx, node); - runTestSuite(specMts, node); - runTestSuite(specCts, node); + // runTestSuite(specTs, node); + // runTestSuite(specTsx, node); + // runTestSuite(specJsx, node); + // runTestSuite(specMts, node); + // runTestSuite(specCts, node); runTestSuite(specTsconfig, node); }); }); diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index cc83f48..3e4d878 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -3,49 +3,49 @@ import type { NodeApis } from '../../utils/node-with-loader'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('tsconfig', ({ test, describe }) => { - test('jsxFactory & jsxFragmentFactory', async () => { - const nodeProcess = await node.load('./src/tsx.tsx', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('div null hello world\nnull null goodbye world'); - }); + // test('jsxFactory & jsxFragmentFactory', async () => { + // const nodeProcess = await node.load('./src/tsx.tsx', { + // cwd: './tsconfig', + // }); + // expect(nodeProcess.stdout).toBe('div null hello world\nnull null goodbye world'); + // }); describe('paths', ({ test, describe }) => { - test('resolves baseUrl', async () => { - const nodeProcess = await node.load('./src/base-url.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); + // test('resolves baseUrl', async () => { + // const nodeProcess = await node.load('./src/base-url.ts', { + // cwd: './tsconfig', + // }); + // expect(nodeProcess.stdout).toBe('resolved'); + // }); - test('resolves paths exact match', async () => { - const nodeProcess = await node.load('./src/paths-exact-match.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); + // test('resolves paths exact match', async () => { + // const nodeProcess = await node.load('./src/paths-exact-match.ts', { + // cwd: './tsconfig', + // }); + // expect(nodeProcess.stdout).toBe('resolved'); + // }); - test('resolves paths prefix', async () => { - const nodeProcess = await node.load('./src/paths-prefix-match.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); + // test('resolves paths prefix', async () => { + // const nodeProcess = await node.load('./src/paths-prefix-match.ts', { + // cwd: './tsconfig', + // }); + // expect(nodeProcess.stdout).toBe('resolved'); + // }); - test('resolves paths suffix', async () => { - const nodeProcess = await node.load('./src/paths-suffix-match.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); + // test('resolves paths suffix', async () => { + // const nodeProcess = await node.load('./src/paths-suffix-match.ts', { + // cwd: './tsconfig', + // }); + // expect(nodeProcess.stdout).toBe('resolved'); + // }); describe('dependency', ({ test }) => { - test('resolve current directory', async () => { - const nodeProcess = await node.load('./dependency-resolve-current-directory', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); + // test('resolve current directory', async () => { + // const nodeProcess = await node.load('./dependency-resolve-current-directory', { + // cwd: './tsconfig', + // }); + // expect(nodeProcess.stdout).toBe('resolved'); + // }); test('should not resolve baseUrl', async () => { const nodeProcess = await node.load('./dependency-should-not-resolve-baseUrl', { @@ -54,12 +54,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toBe('resolved'); }); - test('should not resolve paths', async () => { - const nodeProcess = await node.load('./dependency-should-not-resolve-paths', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); + // test('should not resolve paths', async () => { + // const nodeProcess = await node.load('./dependency-should-not-resolve-paths', { + // cwd: './tsconfig', + // }); + // expect(nodeProcess.stdout).toBe('resolved'); + // }); }); }); }); From 7c435ee5aeefbdcfea1986fd6a6841574df38012 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 01:02:33 -0400 Subject: [PATCH 09/14] debug --- tests/index.ts | 6 +++--- tests/specs/typescript/tsconfig.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/index.ts b/tests/index.ts index 04d3575..7ec655c 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -7,9 +7,9 @@ const nodeVersions = [ ...( process.env.CI ? [ - '14.19.1', - '16.14.2', - '17.8.0', + // '14.19.1', + // '16.14.2', + // '17.8.0', ] : [] ), diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index 3e4d878..984a1e3 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -51,6 +51,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.load('./dependency-should-not-resolve-baseUrl', { cwd: './tsconfig', }); + console.log(nodeProcess); expect(nodeProcess.stdout).toBe('resolved'); }); From 479a897e9ad932219e93471f6b2e23583930b6d6 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 01:06:15 -0400 Subject: [PATCH 10/14] debug --- src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index dfc1938..2b3d4f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -123,9 +123,15 @@ Module._resolveFilename = function (request, parent, isMain, options) { ) { console.log({ request, - parent: parent.filename, + parent, + isMain, + options, + }); + + console.log({ + parent: parent?.filename, nodeModulesPath, - isDependency: parent.filename.includes(nodeModulesPath), + isDependency: parent?.filename.includes(nodeModulesPath), }); const possiblePaths = tsconfigPathsMatcher(request); for (const possiblePath of possiblePaths) { From ef172473ba08cb135181f0de7b40c5c1fc34f1dc Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 01:14:20 -0400 Subject: [PATCH 11/14] debug --- src/index.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2b3d4f2..d6faefe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,20 +119,20 @@ Module._resolveFilename = function (request, parent, isMain, options) { && !isPathPattern.test(request) // Dependency paths should not be resolved using tsconfig.json - // && !parent.filename.includes(nodeModulesPath) + && !parent?.filename.includes(nodeModulesPath) ) { - console.log({ - request, - parent, - isMain, - options, - }); - - console.log({ - parent: parent?.filename, - nodeModulesPath, - isDependency: parent?.filename.includes(nodeModulesPath), - }); + // console.log({ + // request, + // parent, + // isMain, + // options, + // }); + + // console.log({ + // parent: parent?.filename, + // nodeModulesPath, + // isDependency: parent?.filename.includes(nodeModulesPath), + // }); const possiblePaths = tsconfigPathsMatcher(request); for (const possiblePath of possiblePaths) { try { From 95b17a5d3bea4a2fdbb9748fff7cb2f4466d0124 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 01:24:05 -0400 Subject: [PATCH 12/14] fix: windows --- src/index.ts | 12 ----- tests/index.ts | 18 +++---- tests/specs/typescript/index.ts | 10 ++-- tests/specs/typescript/tsconfig.ts | 85 +++++++++++++++--------------- 4 files changed, 56 insertions(+), 69 deletions(-) diff --git a/src/index.ts b/src/index.ts index d6faefe..9964f7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -121,18 +121,6 @@ Module._resolveFilename = function (request, parent, isMain, options) { // Dependency paths should not be resolved using tsconfig.json && !parent?.filename.includes(nodeModulesPath) ) { - // console.log({ - // request, - // parent, - // isMain, - // options, - // }); - - // console.log({ - // parent: parent?.filename, - // nodeModulesPath, - // isDependency: parent?.filename.includes(nodeModulesPath), - // }); const possiblePaths = tsconfigPathsMatcher(request); for (const possiblePath of possiblePaths) { try { diff --git a/tests/index.ts b/tests/index.ts index 7ec655c..bf426d9 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,14 +2,14 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader'; const nodeVersions = [ - // '12.16.2', // Pre ESM import + '12.16.2', // Pre ESM import '12.22.11', ...( process.env.CI ? [ - // '14.19.1', - // '16.14.2', - // '17.8.0', + '14.19.1', + '16.14.2', + '17.8.0', ] : [] ), @@ -20,11 +20,11 @@ const nodeVersions = [ const node = await createNode(nodeVersion, './tests/fixtures'); await describe(`Node ${node.version}`, ({ runTestSuite }) => { - // runTestSuite( - // // eslint-disable-next-line node/global-require,@typescript-eslint/no-var-requires - // (require('./specs/javascript') as typeof import('./specs/javascript')).default, - // node, - // ); + runTestSuite( + // eslint-disable-next-line node/global-require,@typescript-eslint/no-var-requires + (require('./specs/javascript') as typeof import('./specs/javascript')).default, + node, + ); runTestSuite( // eslint-disable-next-line node/global-require,@typescript-eslint/no-var-requires (require('./specs/typescript') as typeof import('./specs/typescript')).default, diff --git a/tests/specs/typescript/index.ts b/tests/specs/typescript/index.ts index 875f1cc..e0cc531 100644 --- a/tests/specs/typescript/index.ts +++ b/tests/specs/typescript/index.ts @@ -9,11 +9,11 @@ import specTsconfig from './tsconfig'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('TypeScript', async ({ runTestSuite }) => { - // runTestSuite(specTs, node); - // runTestSuite(specTsx, node); - // runTestSuite(specJsx, node); - // runTestSuite(specMts, node); - // runTestSuite(specCts, node); + runTestSuite(specTs, node); + runTestSuite(specTsx, node); + runTestSuite(specJsx, node); + runTestSuite(specMts, node); + runTestSuite(specCts, node); runTestSuite(specTsconfig, node); }); }); diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index 984a1e3..cc83f48 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -3,64 +3,63 @@ import type { NodeApis } from '../../utils/node-with-loader'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('tsconfig', ({ test, describe }) => { - // test('jsxFactory & jsxFragmentFactory', async () => { - // const nodeProcess = await node.load('./src/tsx.tsx', { - // cwd: './tsconfig', - // }); - // expect(nodeProcess.stdout).toBe('div null hello world\nnull null goodbye world'); - // }); + test('jsxFactory & jsxFragmentFactory', async () => { + const nodeProcess = await node.load('./src/tsx.tsx', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('div null hello world\nnull null goodbye world'); + }); describe('paths', ({ test, describe }) => { - // test('resolves baseUrl', async () => { - // const nodeProcess = await node.load('./src/base-url.ts', { - // cwd: './tsconfig', - // }); - // expect(nodeProcess.stdout).toBe('resolved'); - // }); + test('resolves baseUrl', async () => { + const nodeProcess = await node.load('./src/base-url.ts', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); - // test('resolves paths exact match', async () => { - // const nodeProcess = await node.load('./src/paths-exact-match.ts', { - // cwd: './tsconfig', - // }); - // expect(nodeProcess.stdout).toBe('resolved'); - // }); + test('resolves paths exact match', async () => { + const nodeProcess = await node.load('./src/paths-exact-match.ts', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); - // test('resolves paths prefix', async () => { - // const nodeProcess = await node.load('./src/paths-prefix-match.ts', { - // cwd: './tsconfig', - // }); - // expect(nodeProcess.stdout).toBe('resolved'); - // }); + test('resolves paths prefix', async () => { + const nodeProcess = await node.load('./src/paths-prefix-match.ts', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); - // test('resolves paths suffix', async () => { - // const nodeProcess = await node.load('./src/paths-suffix-match.ts', { - // cwd: './tsconfig', - // }); - // expect(nodeProcess.stdout).toBe('resolved'); - // }); + test('resolves paths suffix', async () => { + const nodeProcess = await node.load('./src/paths-suffix-match.ts', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); describe('dependency', ({ test }) => { - // test('resolve current directory', async () => { - // const nodeProcess = await node.load('./dependency-resolve-current-directory', { - // cwd: './tsconfig', - // }); - // expect(nodeProcess.stdout).toBe('resolved'); - // }); + test('resolve current directory', async () => { + const nodeProcess = await node.load('./dependency-resolve-current-directory', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); test('should not resolve baseUrl', async () => { const nodeProcess = await node.load('./dependency-should-not-resolve-baseUrl', { cwd: './tsconfig', }); - console.log(nodeProcess); expect(nodeProcess.stdout).toBe('resolved'); }); - // test('should not resolve paths', async () => { - // const nodeProcess = await node.load('./dependency-should-not-resolve-paths', { - // cwd: './tsconfig', - // }); - // expect(nodeProcess.stdout).toBe('resolved'); - // }); + test('should not resolve paths', async () => { + const nodeProcess = await node.load('./dependency-should-not-resolve-paths', { + cwd: './tsconfig', + }); + expect(nodeProcess.stdout).toBe('resolved'); + }); }); }); }); From c5008dfbefa106eed2a5db1429155acdaa317222 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 01:29:53 -0400 Subject: [PATCH 13/14] fix: windows --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d913bc..007bfbb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest] + os: [ubuntu-latest, windows-latest] timeout-minutes: 10 steps: From e31e259e4dfc1ebeaec7b95c00784bdb7d4deb0c Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 23 Jun 2022 03:51:07 -0400 Subject: [PATCH 14/14] test: fixture to return file name --- tests/fixtures/tsconfig/src/resolve-target.ts | 2 +- .../fixtures/tsconfig/src/utils/nested-resolve-target.ts | 2 +- tests/specs/typescript/tsconfig.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/fixtures/tsconfig/src/resolve-target.ts b/tests/fixtures/tsconfig/src/resolve-target.ts index 0c47d66..3e88556 100644 --- a/tests/fixtures/tsconfig/src/resolve-target.ts +++ b/tests/fixtures/tsconfig/src/resolve-target.ts @@ -1 +1 @@ -export default 'resolved'; +export default 'resolve-target'; diff --git a/tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts b/tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts index 0c47d66..65a22c6 100644 --- a/tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts +++ b/tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts @@ -1 +1 @@ -export default 'resolved'; +export default 'nested-resolve-target'; diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index cc83f48..4155798 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -15,28 +15,28 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.load('./src/base-url.ts', { cwd: './tsconfig', }); - expect(nodeProcess.stdout).toBe('resolved'); + expect(nodeProcess.stdout).toBe('resolve-target'); }); test('resolves paths exact match', async () => { const nodeProcess = await node.load('./src/paths-exact-match.ts', { cwd: './tsconfig', }); - expect(nodeProcess.stdout).toBe('resolved'); + expect(nodeProcess.stdout).toBe('resolve-target'); }); test('resolves paths prefix', async () => { const nodeProcess = await node.load('./src/paths-prefix-match.ts', { cwd: './tsconfig', }); - expect(nodeProcess.stdout).toBe('resolved'); + expect(nodeProcess.stdout).toBe('nested-resolve-target'); }); test('resolves paths suffix', async () => { const nodeProcess = await node.load('./src/paths-suffix-match.ts', { cwd: './tsconfig', }); - expect(nodeProcess.stdout).toBe('resolved'); + expect(nodeProcess.stdout).toBe('nested-resolve-target'); }); describe('dependency', ({ test }) => {