Repository navigation
chore(npm): replace axios with native node:http/node:https - #2350
rafaeelaudibert wants to merge 7 commits into
Conversation
Part of the e18e (https://e18e.dev) ecosystem cleanup effort. Remove axios, axios-proxy-builder, console.table, and rimraf from the npm installer template dependencies, replacing them with Node.js built-in modules. This reduces production dependencies from 42 packages to 1 (detect-libc). See: https://e18e.dev/docs/replacements/fetch.html - Replace axios HTTP client with node:https/node:http built-in modules - Implement redirect following (up to 5 hops) inline - Implement HTTP CONNECT proxy tunneling for HTTPS through HTTP proxies, with support for proxy authentication and NO_PROXY - Replace rimraf.sync() with fs.rmSync() (available since Node 14.14) - Remove dead console.table import (cTable was never referenced) - Regenerate npm-shrinkwrap.json (537 lines → 49 lines) - Update test snapshots
2e40960 to
a649eab
Compare
|
CC @mistydemeo since you seem to be the most active maintainer here :) |
|
Thanks for the confirmation @tnkuehne! @mistydemeo would love a review here! |
|
Good work! I was just about to open a PR for the same 😄 rimraf was 5MB of transitive deps removed alone (glob was the main offender) This PR closes #2224 |
|
This PR reduces installed size by 56%, 11M -> 4.8M |
|
Nice, even better! 4.8M is cool 😎 |
|
Sorry for the delay getting to this; will review soon. |
mistydemeo
left a comment
There was a problem hiding this comment.
Thanks again! Got a couple of minor comments, and will get @Gankra to take a look too. I'll also do some testing before we merge anything.
Do you mind bumping the minimum node in the package.json too? From what you're describing looks like the new minimum is 18.
- Bump engines.node to >=18 (the new minimum after dropping axios) - Preserve axios behavior of allowing password-only proxy auth - Drop stray space in `constructor (` for prettier consistency Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Reverts the rename to `pkg` introduced when removing axios — the original name was `package`, which works fine in this CommonJS file. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@mistydemeo changes have been addressed! I've also merged with master to make diff cleaner |
|
@rafaeelaudibert @mistydemeo why does the minimum Node version needs to be bumped after dropping axios? All the Node modules used in the replacement do work with this old version AFAIK, don’t they? (don’t get me wrong, 18 is very reasonable and even too old itself, but dropping support for versions despite no technical limitations seems weird) |
|
@WarningImHack3r The fetch API this PR uses was introduced in Node 18. |
I reviewed the code a good half dozen times since it’s been created, and I don’t see any usage of Unless some precise APIs introduced recently have been used, this PR looks good with Node 14 support (or even less) |
This PR will require at least
|
This is for |
Yep, I read the link from the PR description but missed that the API described there wasn't actually the one used in this PR 😅 |
|
@mistydemeo @WarningImHack3r I apologize, that's my fault! I changed approach in the middle of it, but then forgot to actually think about it when implementing the node changes. I'll revert it back to the previous node version, this should make this easier to merge. I'll be able to get to this next week. |
|
Ok, so I just went ahead and did a manual checkup of every addition and their Node support so we're as fair as possible with the actual needs. Here are the results (once again, I don't care about old Node specifically at all, I even think we should drop everything non-supported, but it's one less breaking change for this PR to get approved and it doesn't close doors for no reason for the 3 people still using old Node):
So, as far as my research goes, we can either support |
The node: prefix in require() was added in Node 14.18.0. Drop it so the npm installer floor stays compatible with older Node 14 patches. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
fs.rmSync was the last API on this template requiring Node >= 14.14.0. Replace it with a small drop-in polyfill so the npm installer once again works on the same floor it had before the axios removal (>= 14). The polyfill is annotated to be removed once the floor is bumped to >= 14.14. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This snapshot still reflected the pre-PR axios-based installer because the original axios-removal commit couldn't regenerate it locally (omnibor-cli is required to run this test and wasn't installed). Bring it in line with the rest of the npm snapshots. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| // Drop-in replacement for fs.rmSync, which was only added in Node 14.14.0. | ||
| // Once our minimum supported Node version is >= 14.14.0, this can be removed | ||
| // and callers can switch back to fs.rmSync directly. | ||
| function rmSync(target, options) { | ||
| const { recursive = false, force = false } = options || {}; | ||
| let stat; | ||
| try { | ||
| stat = lstatSync(target); | ||
| } catch (e) { | ||
| if (force && e.code === "ENOENT") return; | ||
| throw e; | ||
| } | ||
| if (stat.isDirectory()) { | ||
| if (!recursive) { | ||
| const err = new Error(`EISDIR: illegal operation on a directory, ${target}`); | ||
| err.code = "EISDIR"; | ||
| throw err; | ||
| } | ||
| for (const entry of readdirSync(target)) { | ||
| rmSync(join(target, entry), { recursive: true, force }); | ||
| } | ||
| rmdirSync(target); | ||
| } else { | ||
| unlinkSync(target); | ||
| } | ||
| } |
There was a problem hiding this comment.
@WarningImHack3r @mistydemeo this is my attempt to keep this at >= 14 since I believe moving to >= 14.14.0 might be a breaking change.
Let me know how you feel around this, I can see this being a problem, in which case we can just bump to >= 14.14.0 instead.
|
@WarningImHack3r @mistydemeo I've pushed some changes that mean we can go back to supporting Node Of course, this means we have to ship some inline code that is native to Node in more modern versions, but I feel like this is a reasonable change to keep the backwards compatibility. I would suggest the maintainers to consider releasing a new breaking version soon bumping to a newer Node version, there's a lot that can be changed in this repo to make it more modern while only supporting supported Node versions. |
|
I'm mildly inclined to just bump the node version we require since the one you want is like, from 2020? But since you already did the legwork it seems fine. Confirmed the proxy variables you checked are used right, and that we're not dropping anything. I can't speak super well to the precise node APIs but if it works, it works. |
|
Kudos to the single misformatted file ruining the CI and preventing merging |
|
I'll merge a squashed version with the appropriate style changes. |
|
Closed by #2400 :) tysm! |
AWS Inspector is flagging 32 high and critical CVEs in one of our images, and they all come from the `npm-shrinkwrap.json` that ships in `@aether-agent/cli`: | Package | Version | CVEs | | --- | --- | --- | | axios | 1.13.5 | 21 (4 critical) | | brace-expansion | 5.0.2 | 7 | | minimatch | 10.2.0 | 3 | | form-data | 4.0.5 | 1 | cargo-dist generates that shrinkwrap for its npm installer. npm installs it exactly as written, so patchwave can't override those versions. Dependabot doesn't track the cargo-dist version either, which is how we're still on 0.31.0. 0.32.0 swapped axios and rimraf for Node's built-in `http` and `https` modules (axodotdev/cargo-dist#2350). I built the npm package locally with 0.34.0 and `detect-libc` is the only dependency left in the shrinkwrap. I went with 0.34.0 over 0.33.1 because it also moves our Apple Silicon build off `macos-14`, which GitHub is retiring. It only came out today, though, and we normally wait 7 days on Dependabot bumps. Feedback welcome.
The only reason why @PostHog depends on axios is because of
cargo-dist. We don't want that anymore, so... here's a contribution!Part of the e18e (https://e18e.dev) ecosystem cleanup effort. Remove axios, axios-proxy-builder, console.table, and rimraf from the npm installer template dependencies, replacing them with Node.js built-in modules. This reduces production dependencies from 42 packages to 1 (detect-libc).
See: https://e18e.dev/docs/replacements/fetch.html
http/httpsbuilt-in modulesrmSyncfunction - can usefs.rmSync()once we bump to v14.14+