Skip to content

Commit ea02a9c

Browse files
committed
refactor(tools): use .ts import extensions (#1274)
Switch tools package imports from .js to .ts extensions, update entry point from bin.js to index.ts, and enable allowImportingTsExtensions in tsconfig. Also fix potential null reference on wasiBindingError in the NAPI binding loader. #1252 (comment)
1 parent 0d24eb9 commit ea02a9c

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _clean_dist:
1818

1919
init: _clean_dist
2020
cargo binstall watchexec-cli cargo-insta typos-cli cargo-shear dprint taplo-cli -y
21-
node packages/tools/src/bin.js sync-remote
21+
node packages/tools/src/index.ts sync-remote
2222
pnpm install
2323
pnpm -C docs install
2424

packages/cli/binding/index.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,13 +725,17 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
725725
wasiBindingError = err;
726726
}
727727
}
728-
if (!nativeBinding) {
728+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
729729
try {
730730
wasiBinding = require('@voidzero-dev/vite-plus-wasm32-wasi');
731731
nativeBinding = wasiBinding;
732732
} catch (err) {
733733
if (process.env.NAPI_RS_FORCE_WASI) {
734-
wasiBindingError.cause = err;
734+
if (!wasiBindingError) {
735+
wasiBindingError = err;
736+
} else {
737+
wasiBindingError.cause = err;
738+
}
735739
loadErrors.push(err);
736740
}
737741
}

packages/tools/src/__tests__/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from 'node:path';
55

66
import { describe, expect, test } from '@voidzero-dev/vite-plus-test';
77

8-
import { isPassThroughEnv, replaceUnstableOutput } from '../utils.js';
8+
import { isPassThroughEnv, replaceUnstableOutput } from '../utils.ts';
99

1010
describe('replaceUnstableOutput()', () => {
1111
test('strip ANSI escape sequences', () => {

packages/tools/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ const subcommand = process.argv[2];
22

33
switch (subcommand) {
44
case 'snap-test':
5-
const { snapTest } = await import('./snap-test.js');
5+
const { snapTest } = await import('./snap-test.ts');
66
await snapTest();
77
break;
88
case 'replace-file-content':
9-
const { replaceFileContent } = await import('./replace-file-content.js');
9+
const { replaceFileContent } = await import('./replace-file-content.ts');
1010
replaceFileContent();
1111
break;
1212
case 'sync-remote':
13-
const { syncRemote } = await import('./sync-remote-deps.js');
13+
const { syncRemote } = await import('./sync-remote-deps.ts');
1414
await syncRemote();
1515
break;
1616
case 'json-sort':
17-
const { jsonSort } = await import('./json-sort.js');
17+
const { jsonSort } = await import('./json-sort.ts');
1818
jsonSort();
1919
break;
2020
case 'merge-peer-deps':
21-
const { mergePeerDeps } = await import('./merge-peer-deps.js');
21+
const { mergePeerDeps } = await import('./merge-peer-deps.ts');
2222
mergePeerDeps();
2323
break;
2424
case 'install-global-cli':
25-
const { installGlobalCli } = await import('./install-global-cli.js');
25+
const { installGlobalCli } = await import('./install-global-cli.ts');
2626
installGlobalCli();
2727
break;
2828
case 'brand-vite':
29-
const { brandVite } = await import('./brand-vite.js');
29+
const { brandVite } = await import('./brand-vite.ts');
3030
brandVite();
3131
break;
3232
default:

packages/tools/src/sync-remote-deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ export async function syncRemote() {
773773
log('✓ package.json exports updated successfully!');
774774

775775
// Apply Vite+ branding patches to vite source
776-
const { brandVite } = await import('./brand-vite.js');
776+
const { brandVite } = await import('./brand-vite.ts');
777777
brandVite(rootDir);
778778

779779
log('✓ Done!');

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"allowImportingTsExtensions": true,
34
"declaration": true,
45
"esModuleInterop": true,
56
"module": "nodenext",

0 commit comments

Comments
 (0)