Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ todo/
.docs-test-tmp/
src/commands/python3/worker.js
src/commands/js-exec/worker.js
src/commands/js-exec/js-exec-worker.js
fuzz-*.log
.claude/settings.local.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"scripts": {
"build": "rm -rf dist && tsc && pnpm build:lib && pnpm build:lib:cjs && pnpm build:browser && pnpm build:cli && pnpm build:shell && pnpm build:worker && pnpm build:clean && cp dist/index.d.ts dist/index.d.cts && sed '1,/^-->/d' AGENTS.npm.md > dist/AGENTS.md",
"build:clean": "find dist -name '*.test.js' -delete && find dist -name '*.test.d.ts' -delete",
"build:worker": "esbuild src/commands/python3/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/python3/worker.js --external:../../../vendor/cpython-emscripten/* && cp src/commands/python3/worker.js dist/commands/python3/worker.js && mkdir -p dist/bin/chunks && cp src/commands/python3/worker.js dist/bin/chunks/worker.js && mkdir -p dist/bundle/chunks && cp src/commands/python3/worker.js dist/bundle/chunks/worker.js && esbuild src/commands/js-exec/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/js-exec/worker.js --external:quickjs-emscripten && cp src/commands/js-exec/worker.js dist/commands/js-exec/worker.js && cp src/commands/js-exec/worker.js dist/bin/chunks/js-exec-worker.js && cp src/commands/js-exec/worker.js dist/bundle/chunks/js-exec-worker.js",
"build:worker": "esbuild src/commands/python3/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/python3/worker.js --external:../../../vendor/cpython-emscripten/* && cp src/commands/python3/worker.js dist/commands/python3/worker.js && mkdir -p dist/bin/chunks && cp src/commands/python3/worker.js dist/bin/chunks/worker.js && mkdir -p dist/bundle/chunks && cp src/commands/python3/worker.js dist/bundle/chunks/worker.js && esbuild src/commands/js-exec/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/js-exec/js-exec-worker.js --external:quickjs-emscripten && cp src/commands/js-exec/js-exec-worker.js dist/commands/js-exec/js-exec-worker.js && cp src/commands/js-exec/js-exec-worker.js dist/bin/chunks/js-exec-worker.js && cp src/commands/js-exec/js-exec-worker.js dist/bundle/chunks/js-exec-worker.js",
"build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
"build:lib:cjs": "esbuild dist/index.js --bundle --platform=node --format=cjs --minify --outfile=dist/bundle/index.cjs --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
"build:browser": "esbuild dist/browser.js --bundle --platform=browser --format=esm --minify --outfile=dist/bundle/browser.js --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:node:zlib --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --define:__BROWSER__=true --alias:node:dns=./src/shims/browser-unsupported.js",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/js-exec/js-exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ type QueuedExecution = {
const executionQueue: QueuedExecution[] = [];
let currentExecution: QueuedExecution | null = null;

const workerPath = fileURLToPath(new URL("./worker.js", import.meta.url));
const workerPath = fileURLToPath(new URL("./js-exec-worker.js", import.meta.url));

function processNextExecution(): void {
// Skip canceled entries (timed out before execution started)
Expand Down
15 changes: 14 additions & 1 deletion src/commands/js-exec/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@
* Run: npx esbuild src/commands/js-exec/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/js-exec/worker.js --external:quickjs-emscripten
*/

import { stripTypeScriptTypes } from "node:module";
import { parentPort } from "node:worker_threads";

// Dynamic require with fallback: stripTypeScriptTypes is a Node.js 23.2+ API
// that is not available in all runtimes (e.g., Bun). When unavailable, TypeScript
// type stripping is disabled but plain JavaScript execution works normally.
// Uses require() instead of await import() because Bun Worker threads load .js
// files in a context where top-level await is not supported.
let stripTypeScriptTypes: (code: string) => string;
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const nodeModule = require("node:module");
stripTypeScriptTypes = nodeModule.stripTypeScriptTypes ?? ((code: string) => code);
} catch {
stripTypeScriptTypes = (code: string) => code;
}
import {
getQuickJS,
type QuickJSContext,
Expand Down