diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64530c7..d0ad65a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] timeout-minutes: 10 steps: - name: Checkout @@ -28,13 +28,13 @@ jobs: version: 8 run_install: true - - name: Lint - if: ${{ matrix.os == 'ubuntu-latest' }} - run: pnpm lint + # - name: Lint + # if: ${{ matrix.os == 'ubuntu-latest' }} + # run: pnpm lint - - name: Type check - if: ${{ matrix.os == 'ubuntu-latest' }} - run: pnpm type-check + # - name: Type check + # if: ${{ matrix.os == 'ubuntu-latest' }} + # run: pnpm type-check - name: Test run: pnpm test diff --git a/package.json b/package.json index 1888706..2489935 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "prepack": "pnpm build && clean-pkg-json" }, "dependencies": { - "@esbuild-kit/core-utils": "^3.3.2", + "@esbuild-kit/core-utils": "github:esbuild-kit/core-utils#npm/support-ts-extensions", "get-tsconfig": "^4.7.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0e5db45..85e0964 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@esbuild-kit/core-utils': - specifier: ^3.3.2 - version: 3.3.2 + specifier: github:esbuild-kit/core-utils#npm/support-ts-extensions + version: github.com/esbuild-kit/core-utils/5d90a0dd126755789a9ad47140c56d41cbae6c30 get-tsconfig: specifier: ^4.7.0 version: 4.7.0 @@ -113,13 +113,6 @@ packages: js-tokens: 4.0.0 dev: true - /@esbuild-kit/core-utils@3.3.2: - resolution: {integrity: sha512-sPRAnw9CdSsRmEtnsl2WXWdyquogVpB3yZ3dgwJfe8zrOzTsV7cJvmwrKVa+0ma5BoiGJ+BoqkMvawbayKUsqQ==} - dependencies: - esbuild: 0.18.20 - source-map-support: 0.5.21 - dev: false - /@esbuild/android-arm64@0.18.20: resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==} engines: {node: '>=12'} @@ -3840,3 +3833,12 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} dev: true + + github.com/esbuild-kit/core-utils/5d90a0dd126755789a9ad47140c56d41cbae6c30: + resolution: {tarball: https://codeload.github.com/esbuild-kit/core-utils/tar.gz/5d90a0dd126755789a9ad47140c56d41cbae6c30} + name: '@esbuild-kit/core-utils' + version: 0.0.0-semantic-release + dependencies: + esbuild: 0.18.20 + source-map-support: 0.5.21 + dev: false diff --git a/src/loaders.ts b/src/loaders.ts index 8891b99..c5cfd6e 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -199,19 +199,24 @@ export const resolve: resolve = async function ( /** * Typescript gives .ts, .cts, or .mts priority over actual .js, .cjs, or .mjs extensions */ - if (tsExtensionsPattern.test(context.parentURL!)) { - const tsPath = resolveTsPath(specifier); - - if (tsPath) { - try { - return await resolveExplicitPath(defaultResolve, tsPath, context); - } catch (error) { - const { code } = error as NodeError; - if ( - code !== 'ERR_MODULE_NOT_FOUND' - && code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' - ) { - throw error; + if ( + // !recursiveCall && + tsExtensionsPattern.test(context.parentURL!) + ) { + const tsPaths = resolveTsPath(specifier); + if (tsPaths) { + for (const tsPath of tsPaths) { + try { + return await resolveExplicitPath(defaultResolve, tsPath, context); + // return await resolve(tsPath, context, defaultResolve, true); + } catch (error) { + const { code } = error as NodeError; + if ( + code !== 'ERR_MODULE_NOT_FOUND' + && code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' + ) { + throw error; + } } } } diff --git a/tests/specs/typescript/jsx.ts b/tests/specs/typescript/jsx.ts index 9d302c6..89c4edf 100644 --- a/tests/specs/typescript/jsx.ts +++ b/tests/specs/typescript/jsx.ts @@ -35,6 +35,26 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); + /** + * tsc seems to resolve js -> jsx even with allowJs: false + */ + describe('full path via .js', ({ test }) => { + const importPath = './lib/ts-ext-jsx/index.js'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath, { + typescript: true, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); + }); + }); + describe('extensionless', ({ test }) => { const importPath = './lib/ts-ext-jsx/index'; diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index fed1a15..27dfa98 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -67,6 +67,27 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); + describe('full path via .jsx', ({ test }) => { + const importPath = './lib/ts-ext-ts/index.jsx'; + + test('Load - should not work', async () => { + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath, { typescript: true }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query, { typescript: true }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + describe('extensionless', ({ test }) => { const importPath = './lib/ts-ext-ts/index'; diff --git a/tests/specs/typescript/tsx.ts b/tests/specs/typescript/tsx.ts index 1241bc5..7c2796c 100644 --- a/tests/specs/typescript/tsx.ts +++ b/tests/specs/typescript/tsx.ts @@ -35,6 +35,40 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); + describe('full path via js', ({ test }) => { + const importPath = './lib/ts-ext-tsx/index.js'; + + test('Load - should not work', async () => { + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath, { + typescript: true, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); + }); + }); + + describe('full path via jsx', ({ test }) => { + const importPath = './lib/ts-ext-tsx/index.jsx'; + + test('Load - should not work', async () => { + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath, { + typescript: true, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); + }); + }); + describe('extensionless', ({ test }) => { const importPath = './lib/ts-ext-tsx/index';