Skip to content

Commit

Permalink
fix(typescript): resolve js to ts (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored May 25, 2022
1 parent 062ff2a commit 85f5219
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
6 changes: 3 additions & 3 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/core-utils": "^1.1.2",
"@esbuild-kit/esm-loader": "^2.1.1"
"@esbuild-kit/cjs-loader": "^2.0.1",
"@esbuild-kit/core-utils": "^1.2.0",
"@esbuild-kit/esm-loader": "^2.1.2"
},
"optionalDependencies": {
"fsevents": "~2.3.2"
Expand Down
28 changes: 14 additions & 14 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

0 comments on commit 85f5219

Please sign in to comment.