Migrate hpagent to https-proxy-agent
org.openrewrite.node.migrate.hpagent.migrate-hpagent-to-https-proxy-agentArtifact@openrewrite/recipes-nodejsReplaces the unmaintained hpagent package with https-proxy-agent. Both of hpagent's agent classes tunnel through the proxy with CONNECT, which is what https-proxy-agent does, upgrading the tunnel to TLS only for an https: target — so HttpProxyAgent and HttpsProxyAgent both become https-proxy-agent's HttpsProxyAgent. The proxy URL moves from the proxy option to the constructor's first argument, proxyRequestOptions members move up into the options object, and the dependency is swapped in each package.json that declares it.
Two things do not carry over, and both are reported in the HpagentManualMigrationSteps data table rather than rewritten. A TLS option set at the top level of hpagent's HttpsProxyAgent (ca, rejectUnauthorized, cert, ...) configured the handshake with the **destination**, because that class extends https.Agent; https-proxy-agent spends its constructor options on the connection to the **proxy** and takes the destination's TLS options from each request, so such an option has to move to the request or the client library. Agent options that aren't written as an object literal can't be split into the new two-argument form either.
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.migrate-hpagent-to-https-proxy-agentIf the recipe isn’t available locally, install it with:
mod config recipes npm install @openrewrite/recipes-nodejsOptions
| Name | Type | Description |
|---|---|---|
version | String | The version range to declare for https-proxy-agent. The default keeps hpagent's Node 14 floor; https-proxy-agent 9 and later require Node 20.e.g. ^7.0.6 |
migrateSpreadOptions | String | Also migrate options that spread another object, as in {...shared, proxy: url}. Off by default, since the spread may carry a proxyRequestOptions or a destination TLS option that has to move rather than be passed through. |
Definition
This recipe runs the following recipes in order.
- Replace
hpagentwithhttps-proxy-agentorg.openrewrite.node.migrate.hpagent.replace-hpagent - Find hpagent usages that need manual migration
org.openrewrite.node.migrate.hpagent.find-hpagent-manual-migrations - Swap the
hpagentdependency forhttps-proxy-agentorg.openrewrite.node.migrate.hpagent.swap-hpagent-dependency