Replace hpagent with https-proxy-agent
org.openrewrite.node.migrate.hpagent.replace-hpagentArtifact@openrewrite/recipes-nodejsReplaces hpagent's HttpProxyAgent and HttpsProxyAgent with https-proxy-agent's HttpsProxyAgent, whose constructor takes the proxy URL as its first argument rather than as a proxy option: new HttpsProxyAgent({proxy: url, keepAlive: true}) becomes new HttpsProxyAgent(url, {keepAlive: true}). Both hpagent classes tunnel with CONNECT, and https-proxy-agent upgrades the tunnel to TLS only for an https: target, so one class serves both. proxyRequestOptions members move up into the options object, where https-proxy-agent applies them to the connection to the proxy. Calls whose options aren't an object literal, or that set a TLS option for the destination handshake (ca, rejectUnauthorized, cert, ...), are left alone: https-proxy-agent would apply those to the proxy hop instead. FindHpagentManualMigrations reports every usage left behind.
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.node.migrate.hpagent.replace-hpagentIf the recipe isn’t available locally, install it with:
mod config recipes npm install @openrewrite/recipes-nodejsOptions
| Name | Type | Description |
|---|---|---|
migrateSpreadOptions | String | Also migrate options that spread another object, as in {...shared, proxy: url}, passing the spread through to the new options object. Left off by default: the spread may itself carry a proxyRequestOptions, which has to be flattened, or a TLS option for the destination handshake, which https-proxy-agent would apply to the proxy connection instead. Enable it once the spread objects in the codebase are known to hold plain agent options. A spread that resolves to a literal of plain agent options in the same file is migrated either way, since there it can be checked rather than assumed. |