feat!: make the client's own code runtime-independent - #1052
Open
vdusek wants to merge 14 commits into
Open
Conversation
Contributor
|
See more at https://github.com/apify/apify-client-js/actions/runs/34464275426#summary-102829050276 |
# Conflicts: # docs/04_upgrading/upgrading_v3.md
# Conflicts: # docs/04_upgrading/upgrading_v3.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 insrc/runtime/web.ts. The#runtimeentry inimportspicks between them: thenodecondition resolves to the Node.js module, everything else to the Web API one, so a bundler targeting a browser or an edge runtime never seesnode:zlib,node:os,node:utilorproxy-agent. Node.js, Bun and Deno keep today's behavior.Base64 encoding, byte counting, log chunk joining and response decoding go through
TextEncoder,TextDecoderandbtoa, so theisNode()sniff and theBROWSER_BUILDandVERSIONglobals are gone. rsbuild also needsaliasStrategy: 'prefer-alias', so thetsconfig.jsonpathsentry stops beating the#runtimealias. The bundle is 324 kB, down from 335 kB.Issues
apify-clientruntime-independent #753.@apify/logand@apify/utilitiesstill importnode:events,node:streamandnode:crypto, so bundling the ES module build for a non-Node.js target needs polyfills forevents,process,streamandbuffer; tracked in Make shared packages runtime-independent apify-shared-js#537.Testing
test/runtime.test.tscovers both implementations and bundlesdistwith esbuild to assert that browser, Cloudflare Workers, neutral and Node.js targets each resolve#runtimeto the right file, and that the Web API build imports nonode:module.Breaking changes
TextDecoderdecodes response bodies instead ofBuffer, so acontent-typecharset can be handled differently:iso-8859-1and similar decode to a string,hexandbase64come back as raw bytes,asciiis read aswindows-1252, and a leading UTF-8 BOM is stripped.Uint8ArrayandArrayBufferbodies, which gain acontent-encodingheader.browsercondition gets the Web API implementation even on Node.js. Jest'sjsdomenvironment does, so a suite running under it loses log streaming, thestreamrecord option, proxy support and compression unlesstestEnvironmentOptions.customExportConditionsis set to['node'].The v3 upgrading guide covers all of these.
✍️ Drafted by Claude Code