Repository navigation
fix: accept both proxyAgent shapes and correct proxy docs - #233
seantomburke wants to merge 1 commit into
Conversation
The README and type definitions documented passing a bare hpagent
instance as `proxyAgent`, but got v13 expects an object keyed by
protocol. Passing a bare agent made got throw
`Unexpected agent option: _events` before any request was sent, so the
documented proxy example could never work.
Normalize `proxyAgent` in the constructor: an `{ http, https }` object
passes through untouched, and a bare agent is wrapped under the key
matching its protocol. Protocol detection inspects the instance rather
than using `instanceof`, since hpagent is only a devDependency and
importing it would break installs that don't use a proxy.
Existing usage keeps working either way, so this is not a breaking
change. Updates the README example and options table, the JSDoc, and
the TypeScript definitions, and adds tests for both shapes.
Fixes #186
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughSitemapper now supports protocol-keyed proxy agent objects and normalizes bare HTTP or HTTPS hpagent instances before passing them to ChangesProxy agent support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Sitemapper
participant normalizeProxyAgent
participant hpagent
participant got
Sitemapper->>normalizeProxyAgent: pass proxyAgent option
normalizeProxyAgent->>hpagent: inspect bare agent protocol
normalizeProxyAgent-->>Sitemapper: return keyed agent object
Sitemapper->>got: provide normalized request agent
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@sitemapper.d.ts`:
- Around line 53-57: Update the proxyAgent type in sitemapper.d.ts to use false
| http2-wrapper.Agent.AgentLike instead of unknown for http2. In
src/assets/sitemapper.js and README.md, update the matching JSDoc/documentation
to describe the supported shape as { http, https? [, http2] }, preserving the
existing http and https entries.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c9334739-2864-4fc0-8203-0f0e470f7a2f
📒 Files selected for processing (5)
README.mdsitemapper.d.tssrc/assets/sitemapper.jssrc/tests/coverage.test.tssrc/tests/type-check.ts
| | { | ||
| http?: HttpProxyAgent; | ||
| https?: HttpsProxyAgent; | ||
| http2?: unknown; | ||
| }; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
For got v13, what TypeScript type is accepted for the agent.http2option, and does it use thehttp2-wrapper Agent type?
💡 Result:
In Got v13, the agent.http2 option accepts a value of type unknown | false within the TypeScript Agents type definition [1][2]. While the type is defined as unknown in the source code [1][2], the official documentation explicitly requires that the HTTP/2 agent must be an instance of http2wrapper.Agent [3][4]. It is not compatible with the standard Node.js http.Agent [5][6]. Got uses the http2-wrapper library to provide HTTP/2 support, and consequently, the agent.http2 property is specifically intended to hold an http2wrapper.Agent instance [3][1][7].
Citations:
- 1: https://github.com/sindresorhus/got/blob/main/source/core/options.ts
- 2: https://github.com/sindresorhus/got/blob/bc9e48ae689ceb132a192652f5ff6aeedbb4f56c/source/core/options.ts
- 3: https://github.com/sindresorhus/got/blob/HEAD/documentation/2-options.md
- 4: https://github.com/sindresorhus/got/blob/fd7536078148461ad9cc72f2d57f89c98ca8f63e/documentation/2-options.md
- 5: https://github.com/szmarczak/http2-wrapper/
- 6: https://www.npmjs.com/package/http2-wrapper
- 7: https://github.com/sindresorhus/got/blob/38bbb04ea24f01eed6f01e394bc3e9405df8cfc5/source/core/index.ts
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Tracked files matching sitemapper/package/readme:"
git ls-files | rg '(^|/)(sitemapper\.d\.ts|package\.json|README\.md)$|src/assets/sitemapper\.js$' || true
echo
echo "sitemapper.d.ts around proxyAgent:"
sed -n '40,70p' sitemapper.d.ts 2>/dev/null || true
echo
echo "src/assets/sitemapper.js around normalize function and usages:"
rg -n "normalize.*proxyAgent|proxyAgent|http2|httpProxy|httpsProxy|agent:" src/assets/sitemapper.js 2>/dev/null || true
echo
echo "README proxy doc:"
sed -n '200,225p' README.md 2>/dev/null || true
echo
echo "package got/http2-wrapper versions:"
node - <<'JS'
const fs = require('fs');
for (const file of ['package.json']) {
if (!fs.existsSync(file)) continue;
const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
console.log(file, JSON.stringify({dependencies: pkg.dependencies, devDependencies: pkg.devDependencies}, null, 2));
}
JSRepository: seantomburke/sitemapper
Length of output: 4117
Specify the http2 proxy-agent contract.
proxyAgent.http2?: unknown lets invalid keys/values pass through to Got. Use false | http2-wrapper.Agent.AgentLike (or an equivalent typed definition) and update the matching JSDoc/README text to cover { http, https? [, http2] }.
📍 Affects 3 files
sitemapper.d.ts#L53-L57(this comment)src/assets/sitemapper.js#L56-L66README.md#L214-L216
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@sitemapper.d.ts` around lines 53 - 57, Update the proxyAgent type in
sitemapper.d.ts to use false | http2-wrapper.Agent.AgentLike instead of unknown
for http2. In src/assets/sitemapper.js and README.md, update the matching
JSDoc/documentation to describe the supported shape as { http, https? [, http2]
}, preserving the existing http and https entries.
Source: Coding guidelines
|
Note Unit test generation is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
🤖 Coding Agent task started for unit test generation. |
Fixes #186
The problem
The README, JSDoc, and TypeScript definitions all documented passing a bare
hpagentinstance:But
gotv13 expects itsagentoption to be an object keyed by protocol ({ http, https, http2 }). Its setter iterates the value's keys and rejects anything unrecognized, so a bare agent throws on the enumerable properties it inherits fromEventEmitter:This happens before any request is sent — the documented proxy example could never have worked. Verified against
gotv13:The fix
The issue thread suggested docs-only, on the grounds that changing the interface would be breaking. Both are addressed here, and the code change is not breaking: the only shape that would "break" is the bare agent, which is currently 100% non-functional, so no working caller exists to break.
normalizeProxyAgent()in the constructor:{ http, https }/http2objects pass through untouched{}, as beforeProtocol detection inspects the instance (
defaultPort/protocol) rather than usinginstanceof.hpagentis only a devDependency, so importing it at runtime would break installs for the majority of users who don't use a proxy.Docs
README example and options table, JSDoc, and
sitemapper.d.tsnow showgot's{ http, https }form as the documented shape, with the bare agent still accepted and typed.Testing
type-check.tsexercises both the wrapped and bare formsgot, and that no-proxy fetching is unaffected (36 sites)🤖 Generated with Claude Code
Made with Orca 🐋
Summary by CodeRabbit
New Features
Documentation