Skip to content

chore(cli)!: replace node-fetch with undici#306

Merged
so0k merged 2 commits into
open-constructs:mainfrom
X-Guardian:chore/replace-node-fetch-with-undici
Jul 10, 2026
Merged

chore(cli)!: replace node-fetch with undici#306
so0k merged 2 commits into
open-constructs:mainfrom
X-Guardian:chore/replace-node-fetch-with-undici

Conversation

@X-Guardian

@X-Guardian X-Guardian commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

@cdktn/cli-core depended on the legacy node-fetch package and its proxy helper https-proxy-agent. This PR replaces that with the undici package — a modern, actively maintained fetch implementation with first-class proxy and mocking support — and removes node-fetch, @types/node-fetch, and https-proxy-agent.

Changes

  • Fetch → undici. All three files now import { fetch } from "undici" instead of node-fetch. We use undici's exported fetch rather than the global fetch deliberately: it keeps the whole HTTP stack — code and test mocks — on a single undici instance. globalThis.fetch uses Node's internal undici, which is a different instance from the undici npm package, so mocking has to target the same one the code uses.

  • Proxy → undici ProxyAgent via the dispatcher option. node-fetch's agent option (a Node http.Agent from https-proxy-agent) is replaced by an undici ProxyAgent built from the same http_proxy / HTTP_PROXY env vars and passed as the request dispatcher.

  • Proxy support extended to package-manager.ts. Previously only registry-api.ts and prebuilt-providers.ts honoured a proxy; package-manager.ts (the PyPI / NuGet / Maven Central / GitHub / npm availability probes) never did. It now uses the same dispatcher, so all registry traffic respects a corporate proxy consistently.

  • undici@8.6.0 dependency + Node floor. undici is added to @cdktn/cli-core. undici 8 requires Node ≥ 22.19.0, so both published packages (@cdktn/cli-core and cdktn-cli) declare "engines": { "node": ">=22.19.0" } — surfacing a clear install-time warning on older Node instead of an opaque runtime failure.

  • Tests → undici MockAgent. prebuilt-providers.test.ts and package-manager.test.ts exercise undici's fetch, so their nock scopes are replaced with an undici MockAgent wired via setGlobalDispatcher.

Checklist

  • I have updated the PR title to match CDKTN's style guide
  • I have run the linter on my code locally
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if applicable
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works if applicable
  • New and existing unit tests pass locally with my changes

@X-Guardian X-Guardian marked this pull request as ready for review July 6, 2026 15:08
@X-Guardian X-Guardian requested a review from a team as a code owner July 6, 2026 15:08
@jsteinich jsteinich changed the title chore(cli): replace node-fetch with undici chore(cli)!: replace node-fetch with undici Jul 7, 2026

@so0k so0k left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, noticed this is flagged as breaking change (due to Node version bump?)

@X-Guardian

Copy link
Copy Markdown
Contributor Author

Shouldn't be a breaking change. The engines.node property only creates a warning on install.

@X-Guardian X-Guardian changed the title chore(cli)!: replace node-fetch with undici chore(cli): replace node-fetch with undici Jul 8, 2026
@jsteinich

Copy link
Copy Markdown
Contributor

Shouldn't be a breaking change. The engines.node property only creates a warning on install.

I had marked as a breaking change due to the part in the PR description: undici 8 requires Node ≥ 22.19.0. If that's accurate, then this does seem like a breaking change as we haven't officially dropped support for Node 20 yet.

I don't really see that as a problem as I expect the next release to come with a major version bump regardless.

@X-Guardian X-Guardian changed the title chore(cli): replace node-fetch with undici chore(cli)!: replace node-fetch with undici Jul 8, 2026
@X-Guardian

Copy link
Copy Markdown
Contributor Author

OK Jon, I've restored the breaking change marker in the PR title.

@so0k

so0k commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

LGTM, added docs PR - see preview environment - merging now

Docs: open-constructs/cdk-terrain-docs#28 — bumps the Node.js prerequisite to 22.19+ in the install and deploy-applications tutorials.
Preview: https://cdkterrain-docs-node-22-19-prereqs.mintlify.app

@X-Guardian X-Guardian force-pushed the chore/replace-node-fetch-with-undici branch from 1ae4192 to a4b3db7 Compare July 10, 2026 09:59
@sakul-learning

Copy link
Copy Markdown
Contributor

Non-blocking follow-up: undici v8.7.0 is now available and retains the same Node.js >=22.19.0 requirement as the v8.6.0 version introduced here. After this transport migration merges, a small dependency-only update to v8.7.0 would be straightforward.

@so0k so0k merged commit 1317141 into open-constructs:main Jul 10, 2026
258 checks passed
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.

4 participants