Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 11 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 18 additions & 13 deletions src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/specs/typescript/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
21 changes: 21 additions & 0 deletions tests/specs/typescript/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
34 changes: 34 additions & 0 deletions tests/specs/typescript/tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down