Skip to content

feat: experimental srvx/scriptc adapter - #363

Draft
pi0x wants to merge 3 commits into
mainfrom
feat/scriptc-adapter
Draft

pi0x wants to merge 3 commits into
mainfrom
feat/scriptc-adapter

Conversation

@pi0x

@pi0x pi0x commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Implements the proposal in #362. Experimental.

Adds srvx/scriptc, a small node:http driver for scriptc, which compiles TypeScript to native executables. It uses scriptc's built-in Request/Response/URL directly. The srvx/node adapter can't compile under scriptc (see #362), so this is a separate adapter.

Changes

  • src/adapters/scriptc.ts: the new adapter.
    • Reuses wrapFetch (middleware), errorPlugin, plugins, resolvePortAndHost and printListening. Nothing from _node/ or _url.ts.
    • FastURL is the native URL. FastResponse is a factory that returns a native Response, because scriptc can't new the native Response through another binding (constructor is not a constructor). It forwards json/redirect/error, and instanceof FastResponse is false.
    • Requests: streamed request bodies with backpressure, and a body the handler never reads is drained. request.signal aborts on client disconnect. Absolute-form request targets are supported, and a bad Host header gets a 400.
    • Responses: multiple set-cookie headers, custom statusText, streamed bodies, HEAD and null-body statuses. Handler errors give a 500 or the error handler's response.
    • server.waitUntil() is written inline, because createWaitUntil() doesn't compile under scriptc. close() waits for pending tasks.
  • package.json: adds a ./scriptc export and a "scriptc" condition in ".", before "node". scriptc currently resolves only import/node/default (npm.ts#L14), so the condition takes effect only if scriptc adds one. Until then, users import srvx/scriptc explicitly.
  • src/types.ts: adds "scriptc" to Server.runtime.
  • build.config.mjs: adds the adapter to the build entries.
  • Docs: new docs/1.guide/12.scriptc.md, and srvx/scriptc added to the explicit-imports list in the bundler guide.
  • test/scriptc.test.ts: 24 tests run the adapter under Node. An 8-test native suite, enabled by setting SCRIPTC=<path to scriptc>, compiles a sample app with scriptc and checks it over HTTP. It needs pnpm build first.

Limitations (documented)

  • No request.ip/waitUntil/runtime/context. scriptc can't add properties to a built-in Request: assignment, Object.defineProperty, extends Request and declare global augmentation all fail. Code that relies on them, such as h3, won't work yet.
  • HTTP/1.1 only. tls, protocol and node are ignored, as are gracefulShutdown, trustProxy, maxRequestBodySize and reusePort.
  • No backpressure on response writes, because scriptc's ServerResponse has no drain event.
  • Not wired to the srvx CLI loader.

Verification

  • scriptc 0.4.10 on Linux x64 compiles a sample app with 0 errors into a 3.0 MB binary. scriptc coverage reports 99% of statements compile statically, with no deferred sites in the adapter.
  • Tested against the native binary: text, JSON, a byte-identical 1 MB POST echo, two set-cookie headers, custom status text, streaming, HEAD and 204. Also middleware and plugins, the error handler, clean 500s, request.signal on disconnect, bad Host → 400, and exiting cleanly after close().
  • pnpm lint and pnpm typecheck are clean. The full vitest run has 1853 passing and 52 skipped. With SCRIPTC set, the scriptc suite passes 32/32, native included. The native FastResponse test fails if the old FastResponse = Response is put back.
  • Quick load test (oha -c 64, on a shared machine): about 45k req/s for a minimal app, versus about 20k req/s for srvx/node on Node 24 (see Proposal: experimental srvx/scriptc adapter (native executables) #362).

Notes for review

  • Apps compile srvx from its published JS, so scriptc warns that the adapter uses untyped values (SC6101), and middleware/plugins arrays become checked-dynamic values (SC6104). In a quick run, two async middlewares dropped throughput to about 18k req/s.

  • Compiling src/adapters/scriptc.ts itself (rather than dist) currently fails with 2 errors in shared code: src/_utils.ts:100 (readFileSync on unknown) and src/types.ts:201 (node:net has no ListenOptions in scriptc's types). That only matters if the "scriptc" condition is ever pointed at source.

  • h3 compatibility findings, including whether bundling with the scriptc condition helps: Proposal: experimental srvx/scriptc adapter (native executables) #362 (comment)

🤖 Generated with AI assistant

@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
srvx Ready Ready Preview Nov 11, 2026 3:48pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/adapters/scriptc.ts 92.30% 11 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/srvx@363

commit: 535be50

This branch was successfully deployed

1 active deployment
Preview — 535be502 Deployed Nov 11, 2026 by vercel[bot]
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