Skip to content

Commit 3a2115e

Browse files
committed
Patch tuf-js to use internal agent
1 parent 3d18c9a commit 3a2115e

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
diff --git a/dist/fetcher.js b/dist/fetcher.js
2-
index f966ce1bb0cdc6c785ce1263f1faea15d3fe764c..3b50fa0c24fd5f6e9e29cf398a3d3bf13836fabd 100644
2+
index f966ce1bb0cdc6c785ce1263f1faea15d3fe764c..111588c64ba0cc049cabeb471d39f0fdc78bbb7e 100644
33
--- a/dist/fetcher.js
44
+++ b/dist/fetcher.js
55
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
66
exports.DefaultFetcher = exports.BaseFetcher = void 0;
77
const debug_1 = __importDefault(require("debug"));
88
const fs_1 = __importDefault(require("fs"));
99
-const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
10-
+const stream = require("node:stream");
10+
+const stream = require("node:stream")
1111
const util_1 = __importDefault(require("util"));
1212
const error_1 = require("./error");
1313
const tmpfile_1 = require("./utils/tmpfile");
14-
@@ -61,14 +61,13 @@ class DefaultFetcher extends BaseFetcher {
14+
@@ -61,14 +61,12 @@ class DefaultFetcher extends BaseFetcher {
1515
}
1616
async fetch(url) {
1717
log('GET %s', url);
1818
- const response = await (0, make_fetch_happen_1.default)(url, {
1919
- timeout: this.timeout,
2020
- retry: this.retry,
21-
+ const response = await globalThis.fetch(url, {
22-
+ signal: this.timeout && AbortSignal.timeout(this.timeout)
23-
});
21+
- });
22+
+ const response = await globalThis.tufJsFetch(url);
23+
+
2424
if (!response.ok || !response?.body) {
2525
throw new error_1.DownloadHTTPError('Failed to download', response.status);
2626
}

sources/httpUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export async function fetchUrlStream(input: string | URL, init?: RequestInit) {
9292

9393
let ProxyAgent: typeof import('undici').ProxyAgent;
9494

95-
async function getProxyAgent(input: string | URL) {
95+
export async function getProxyAgent(input: string | URL) {
9696
const {getProxyForUrl} = await import(`proxy-from-env`);
9797

9898
// @ts-expect-error - The internal implementation is compatible with a WHATWG URL instance

sources/npmRegistryUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ async function fetchSigstoreTufKeys(): Promise<Array<KeyInfo> | null> {
4848
// See https://github.com/npm/cli/blob/3a80a7b7d168c23b5e297cba7b47ba5b9875934d/lib/utils/verify-signatures.js#L174
4949
let keysRaw: string;
5050
try {
51+
// @ts-expect-error inject custom fetch into monkey-patched `tuf-js` module.
52+
globalThis.tufJsFetch = async (input: string) => {
53+
const agent = await httpUtils.getProxyAgent(input);
54+
return await globalThis.fetch(input, {
55+
dispatcher: agent,
56+
});
57+
58+
}
5159
const sigstoreTufClient = await sigstoreTuf.initTUF({
5260
cachePath: path.join(folderUtils.getCorepackHomeFolder(), `_tuf`),
5361
});

yarn.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@ __metadata:
16211621
supports-color: "npm:^10.0.0"
16221622
tar: "npm:^7.4.0"
16231623
tsx: "npm:^4.16.2"
1624+
tuf-js: "patch:tuf-js@npm%3A3.0.1#~/.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch"
16241625
typescript: "npm:^5.7.3"
16251626
undici: "npm:^6.19.2"
16261627
v8-compile-cache: "npm:^2.3.0"
@@ -4703,12 +4704,12 @@ __metadata:
47034704

47044705
"tuf-js@patch:tuf-js@npm%3A3.0.1#~/.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch":
47054706
version: 3.0.1
4706-
resolution: "tuf-js@patch:tuf-js@npm%3A3.0.1#~/.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch::version=3.0.1&hash=05f694"
4707+
resolution: "tuf-js@patch:tuf-js@npm%3A3.0.1#~/.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch::version=3.0.1&hash=26fdc2"
47074708
dependencies:
47084709
"@tufjs/models": "npm:3.0.1"
47094710
debug: "npm:^4.3.6"
47104711
make-fetch-happen: "npm:^14.0.1"
4711-
checksum: 10c0/8f50e885865555112d5ffc5fe7803c9270a611462300b53fd0b528914eb6b9f849b7a4782c07f356f4f0aeb6b752cbb3f7e1c5f2b068bfb574fca3990d1675d5
4712+
checksum: 10c0/e301844e9cfaf7dff085358285ed15ea21d7bb871ea3b6a2c6647c3558069fe62473b1dec1cb30e015955647bf1f36c547fb63c827f2563bbc7be4749281e78c
47124713
languageName: node
47134714
linkType: hard
47144715

0 commit comments

Comments
 (0)