Repository navigation
Bundle userland punycode in the native Node build - #252
Open
pablotransifex wants to merge 1 commit into
Open
pablotransifex wants to merge 1 commit into
pablotransifex wants to merge 1 commit into
Conversation
node-fetch@2 (via cross-fetch) pulls in tr46, which requires Node's deprecated punycode core module. Loading it prints DEP0040 on Node 21 to 22.12, and on any Node version when an app bundles the package into its own server build. Bundle the punycode npm package instead, the same library with the same API; the rest of the build is unchanged. Fixes #235
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.
Fixes #235.
Problem
@transifex/nativeusescross-fetch, which on Node usesnode-fetch@2. That pulls inwhatwg-url@5andtr46, andtr46callsrequire("punycode"), Node's deprecated core module. The Node build bundles this chain and keepspunycodeexternal, sodist/node.native.jsloads the core module and Node prints:Users see this:
node_modules;Fix
The Node build now bundles the userland
punycodepackage instead of loading the core module. It is the same library that Node's core module was made from, with the same API. Webpack decides which modules are Node built-ins from the request name, before any alias or replacement runs. So the config now declares Node built-ins as externals itself, the same waytarget: 'node'does, minuspunycode.punycodeis a devDependency because it is bundled.Nothing else changes.
node-fetchandcross-fetchare still used, so code that mocks requests withnockkeeps working. I first tried loadingcross-fetchfromnode_modulesinstead of bundling it, but Node 21 to 22.12 still warn in that case. Switching to Node's built-infetchwould breaknock13 for anyone mocking Transifex requests, so I left that for a major version.Verification
Build output compared with a build of
master:browser.native.jsandnode.native.d.tsare byte-identical, so React Native and browser users are unaffected.node.native.js, the source maps show one change:external "punycode"is replaced by the bundledpunycode.es6.js(+2.4 KB). Every other module and external is the same.package.jsonare unchanged apart fromdevDependencies.Smoke tests against the packed tarball, installed fresh in a separate project, on Node 16, 18, 20, 21, 22.0.0, 22.8.0, 22.12.0, 22 (latest), 23 and 24, for both
masterand this branch. All checks pass on every version for both builds:pushSourcewith job polling;HTTP 403: forbidden;fetchTimeoutaborting a request that never answers;nockinterception;cdsHost(bücher…) resolving to its punycode form;DEP0040 on Node 21 and 22.0–22.12: printed by
master, not by this branch.masternockconsumer, Node 22.8.0Other checks:
node.native.js).node-fetchuses Node's ownURLwhen it exists, so thewhatwg-url/punycodecode is loaded but not called at runtime on supported Node versions. Even so, the userlandtoASCII/toUnicodegive the same output as Node's core module on a set of internationalized domain names.