Skip to content

feat!: make the client's own code runtime-independent - #1052

Open
vdusek wants to merge 14 commits into
v3from
feat/runtime-independent
Open

feat!: make the client's own code runtime-independent#1052
vdusek wants to merge 14 commits into
v3from
feat/runtime-independent

Conversation

@vdusek

@vdusek vdusek commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Description

The client's own code imports no Node.js built-in. The Node-only parts, keep-alive HTTP agents with proxy support and request body compression, live in src/runtime/node.ts, with a Web API twin in src/runtime/web.ts. The #runtime entry in imports picks between them: the node condition resolves to the Node.js module, everything else to the Web API one, so a bundler targeting a browser or an edge runtime never sees node:zlib, node:os, node:util or proxy-agent. Node.js, Bun and Deno keep today's behavior.

Base64 encoding, byte counting, log chunk joining and response decoding go through TextEncoder, TextDecoder and btoa, so the isNode() sniff and the BROWSER_BUILD and VERSION globals are gone. rsbuild also needs aliasStrategy: 'prefer-alias', so the tsconfig.json paths entry stops beating the #runtime alias. The bundle is 324 kB, down from 335 kB.

Issues

Testing

  • test/runtime.test.ts covers both implementations and bundles dist with esbuild to assert that browser, Cloudflare Workers, neutral and Node.js targets each resolve #runtime to the right file, and that the Web API build imports no node: module.

Breaking changes

  • TextDecoder decodes response bodies instead of Buffer, so a content-type charset can be handled differently: iso-8859-1 and similar decode to a string, hex and base64 come back as raw bytes, ascii is read as windows-1252, and a leading UTF-8 BOM is stripped.
  • Request compression now accepts Uint8Array and ArrayBuffer bodies, which gain a content-encoding header.
  • Anything asking for the browser condition gets the Web API implementation even on Node.js. Jest's jsdom environment does, so a suite running under it loses log streaming, the stream record option, proxy support and compression unless testEnvironmentOptions.customExportConditions is set to ['node'].

The v3 upgrading guide covers all of these.

✍️ Drafted by Claude Code

@vdusek vdusek added the t-tooling Issues with this label are in the ownership of the tooling team. label Sep 9, 2026
@vdusek vdusek self-assigned this Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ There are broken links in the documentation.

See more at https://github.com/apify/apify-client-js/actions/runs/34464275426#summary-102829050276

@vdusek
vdusek requested a review from B4nan September 10, 2026 10:08
@vdusek
vdusek marked this pull request as ready for review September 10, 2026 10:08
@vdusek
vdusek requested a review from szaganek as a code owner September 10, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants