Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix squiggle-lang workers in hub #3456

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion packages/squiggle-lang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build": "pnpm run build:peggy && pnpm run build:ts && pnpm run build:worker",
"build:peggy": "peggy --cache --format es ./src/ast/peggyParser.peggy",
"build:ts": "tsc -b",
"build:worker": "esbuild src/runners/worker.ts --bundle --minify --platform=browser --outfile=dist/runners/esbuild-worker.cjs",
"build:worker": "esbuild src/runners/worker.ts --bundle --minify --platform=browser --format=esm --outfile=dist/runners/esbuild-worker.js",
"dev": "tsc -b -w",
"clean": "rm -rf dist && rm -f src/ast/peggyParser.js && rm *.tsbuildinfo",
"jest": "NODE_OPTIONS=--experimental-vm-modules jest",
Expand Down
15 changes: 4 additions & 11 deletions packages/squiggle-lang/src/runners/WebWorkerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@ export class WebWorkerRunner extends AnyWorkerRunner {
* If you need to touch this code, make sure to check carefully both the components (storybook) and the hub editor.
* This configuration and the esbuild configuration in `package.json` are extremely fragile.
*
* In particular:
* 1. ESM is problematic:`{ type: "module" }` (with `.mjs` or `.js`)will seemingly work, but cause lots of Turbopack CLI errors; Turbopack fails to analyze `(url, { type: "module" })` parameters correctly, as of Next.js 15.0.3.
* 2. `.js` extension will collide with the default `"type": "module"` in `package.json`, which will lead to Next.js warnings.
*
* So, instead, we bundle the worker to the basic IIFE; see `package.json` for details.
*
* This might cause issues in the future, if we decide to depend on some library that's ESM-only; I'm not sure how good esbuild is for bundling ESM dependencies.
*
* But, for now, it seems like it's working.
* Details here: https://github.com/quantified-uncertainty/squiggle/pull/3456
*/
const url = new URL("./esbuild-worker.cjs", import.meta.url);
this.worker = new Worker(url);
this.worker = new Worker(new URL("./esbuild-worker.js", import.meta.url), {
type: "module",
});
}

async getWorker(): Promise<Worker> {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

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

Loading