Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(typescript): resolve js to ts
  • Loading branch information
privatenumber committed May 25, 2022
commit f26f05bf8d89d36d43090b9404514b80564b2f6c
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"prepublishOnly": "npm test"
},
"dependencies": {
"@esbuild-kit/cjs-loader": "^2.0.0",
"@esbuild-kit/cjs-loader": "github:esbuild-kit/cjs-loader#built/resolve-ts-path",
"@esbuild-kit/core-utils": "^1.1.2",
"@esbuild-kit/esm-loader": "^2.1.1"
"@esbuild-kit/esm-loader": "github:esbuild-kit/esm-loader#built/resolve-ts-path"
},
"optionalDependencies": {
"fsevents": "~2.3.2"
Expand Down
42 changes: 26 additions & 16 deletions pnpm-lock.yaml

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

24 changes: 24 additions & 0 deletions tests/specs/typescript/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
});
});

describe('full path via .js', ({ test }) => {
const importPath = './lib/ts-ext-ts/index.js';

test('Load', async () => {
const nodeProcess = await node.load(importPath);
expect(nodeProcess.stderr).toMatch('Cannot find module');
});

test('Import', async () => {
const nodeProcess = await node.import(importPath, { typescript: true });

expect(nodeProcess.stdout).toBe(`${node.isCJS ? outputCjs : outputEsm}\n{"default":1234}`);
expect(nodeProcess.stderr).toBe('');
});

test('Require', async () => {
const nodeProcess = await node.require(importPath, { typescript: true });

// By "require()"ing an ESM file, it forces it to be compiled in a CJS context
expect(nodeProcess.stdout).toBe(`${outputCjs}\n{"default":1234}`);
expect(nodeProcess.stderr).toBe('');
});
});

describe('extensionless', ({ test }) => {
const importPath = './lib/ts-ext-ts/index';

Expand Down