Skip to content

Replace @tootallnate/quickjs-emscripten with quickjs-wasi#394

Merged
TooTallNate merged 3 commits intomainfrom
quickjs-wasi
Mar 6, 2026
Merged

Replace @tootallnate/quickjs-emscripten with quickjs-wasi#394
TooTallNate merged 3 commits intomainfrom
quickjs-wasi

Conversation

@TooTallNate
Copy link
Owner

Summary

Replaces @tootallnate/quickjs-emscripten with quickjs-wasi across all three PAC-related packages. quickjs-wasi is a lighter-weight QuickJS WASM runtime built on quickjs-ng with WASI reactor mode, supporting VM state snapshotting/restore.

Changes

  • degenerator: compile() now takes a QuickJS instance directly (no more qjs.newContext() — the instance IS the context). resolvePromise() returns {value}|{error} instead of VmCallResult. Promise bridging calls executePendingJobs() after resolve/reject.
  • pac-resolver: createPacResolver() takes QuickJS instead of QuickJSWASMModule. Switched to workspace:* dependency on degenerator.
  • pac-proxy-agent: QuickJS.create() replaces getQuickJS(). quickjs-wasi is a runtime dependency. Switched to workspace:* dependency on pac-resolver.
  • Tests: Updated error message assertion for quickjs-ng which formats identifier errors slightly differently.

Test Results

All tests pass:

  • degenerator: 18/18
  • pac-resolver: 63/63
  • pac-proxy-agent: 14/14

Copilot AI review requested due to automatic review settings March 6, 2026 22:44
@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2026

🦋 Changeset detected

Latest commit: e053c6e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
degenerator Minor
pac-resolver Minor
pac-proxy-agent Minor
proxy-agent Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
proxy-agents Ready Ready Preview Mar 6, 2026 11:26pm

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the PAC-related packages off @tootallnate/quickjs-emscripten and onto quickjs-wasi, updating the VM construction/usage and aligning tests with quickjs-ng error formatting.

Changes:

  • Swapped QuickJS implementation to quickjs-wasi and updated call sites to use QuickJS.create() and the new promise/job APIs.
  • Updated degenerator.compile() to accept a QuickJS instance directly and adapted promise resolution/error handling.
  • Updated internal workspace dependencies (pac-proxy-agentpac-resolver, pac-resolverdegenerator) and refreshed tests/error assertions.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pnpm-lock.yaml Replaces quickjs-emscripten entries with quickjs-wasi and updates workspace links.
packages/pac-resolver/test/test.ts Uses QuickJS.create() and updates identifier error assertion.
packages/pac-resolver/src/index.ts Updates createPacResolver() to accept QuickJS from quickjs-wasi.
packages/pac-resolver/package.json Switches degenerator to workspace:* and adds quickjs-wasi for development/tests.
packages/pac-proxy-agent/src/index.ts Uses QuickJS.create() when loading PAC resolver.
packages/pac-proxy-agent/package.json Moves to workspace:* pac-resolver and adds quickjs-wasi dependency.
packages/degenerator/test/test.ts Uses QuickJS.create(), disposes VM in teardown, updates identifier error assertion.
packages/degenerator/src/compile.ts Reworks compile flow to use quickjs-wasi VM API and updated promise bridging.
packages/degenerator/package.json Adds quickjs-wasi for development/tests.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

packages/pac-proxy-agent/src/index.ts:149

  • loadResolver() creates a new QuickJS instance unconditionally, but if the PAC file hash matches and you reuse this.resolver, the newly created qjs is never disposed. This will leak WASM/VM memory over time. Consider computing the hash first (before creating the VM), or explicitly disposing the unused qjs before returning.
			// (Re)load the contents of the PAC file URI
			const [qjs, code] = await Promise.all([
				QuickJS.create(),
				this.loadPacFile(),
			]);

			// Create a sha1 hash of the JS code
			const hash = crypto.createHash('sha1').update(code).digest('hex');

			if (this.resolver && this.resolverHash === hash) {
				debug(
					'Same sha1 hash for code - contents have not changed, reusing previous proxy resolver'
				);
				return this.resolver;
			}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@TooTallNate TooTallNate changed the title Replace @tootallnate/quickjs-emscripten with quickjs-wasi Replace @tootallnate/quickjs-emscripten with quickjs-wasi Mar 6, 2026
Migrate degenerator, pac-resolver, and pac-proxy-agent from
@tootallnate/quickjs-emscripten to quickjs-wasi, a lighter-weight
QuickJS WASM runtime built on quickjs-ng with WASI reactor mode.

Key changes:
- degenerator: compile() now takes a QuickJS instance directly instead
  of QuickJSWASMModule (no more qjs.newContext() — the QuickJS instance
  IS the context). Host callbacks receive _this as first arg.
  resolvePromise() returns {value}|{error} instead of VmCallResult.
  Promise bridging calls executePendingJobs() after resolve/reject.
- pac-resolver: createPacResolver() takes QuickJS instead of
  QuickJSWASMModule. Updated workspace dependency on degenerator.
- pac-proxy-agent: QuickJS.create() replaces getQuickJS(). quickjs-wasi
  is now a runtime dependency (replaces @tootallnate/quickjs-emscripten).
  Updated workspace dependency on pac-resolver.
- Tests: Updated error message assertion for quickjs-ng which formats
  'process is not defined' without quotes around the identifier.
…PAC reload

- degenerator: add quickjs-wasi as peerDependency (type appears in public API)
- pac-resolver: add quickjs-wasi as peerDependency (type appears in public API)
- pac-proxy-agent: store QuickJS instance, dispose previous VM when PAC is
  reloaded with new content, dispose unused VM when hash matches
@TooTallNate TooTallNate merged commit b1509d8 into main Mar 6, 2026
9 checks passed
@TooTallNate TooTallNate deleted the quickjs-wasi branch March 6, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants