@pnpm/fetch
Advanced tools
Comparing version 4.1.6 to 4.2.0
import { FetchFromRegistry } from '@pnpm/fetching-types'; | ||
import { AgentOptions } from '@pnpm/npm-registry-agent'; | ||
import { Response, RequestInfo, RequestInit } from './fetch'; | ||
export declare type FetchWithAgentOptions = RequestInit & { | ||
agentOptions: AgentOptions; | ||
}; | ||
export declare function fetchWithAgent(url: RequestInfo, opts: FetchWithAgentOptions): Promise<Response>; | ||
export { AgentOptions }; | ||
@@ -4,0 +9,0 @@ export default function (defaultOpts: { |
@@ -25,2 +25,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchWithAgent = void 0; | ||
const url_1 = require("url"); | ||
@@ -33,2 +34,16 @@ const npm_registry_agent_1 = __importDefault(require("@pnpm/npm-registry-agent")); | ||
const MAX_FOLLOWED_REDIRECTS = 20; | ||
function fetchWithAgent(url, opts) { | ||
var _a, _b; | ||
const agent = (0, npm_registry_agent_1.default)(url.toString(), { | ||
...opts.agentOptions, | ||
strictSsl: (_a = opts.agentOptions.strictSsl) !== null && _a !== void 0 ? _a : true, | ||
}); // eslint-disable-line | ||
const headers = (_b = opts.headers) !== null && _b !== void 0 ? _b : {}; | ||
headers['connection'] = agent ? 'keep-alive' : 'close'; | ||
return (0, fetch_1.default)(url, { | ||
...opts, | ||
agent, | ||
}); | ||
} | ||
exports.fetchWithAgent = fetchWithAgent; | ||
function default_1(defaultOpts) { | ||
@@ -49,12 +64,11 @@ return async (url, opts) => { | ||
while (true) { | ||
const agent = (0, npm_registry_agent_1.default)(urlObject.href, { | ||
const agentOptions = { | ||
...defaultOpts, | ||
...opts, | ||
strictSsl: (_a = defaultOpts.strictSsl) !== null && _a !== void 0 ? _a : true, | ||
}); // eslint-disable-line | ||
headers['connection'] = agent ? 'keep-alive' : 'close'; | ||
}; // eslint-disable-line | ||
// We should pass a URL object to node-fetch till this is not resolved: | ||
// https://github.com/bitinn/node-fetch/issues/245 | ||
const response = await (0, fetch_1.default)(urlObject, { | ||
agent, | ||
const response = await fetchWithAgent(urlObject, { | ||
agentOptions, | ||
// if verifying integrity, node-fetch must not decompress | ||
@@ -61,0 +75,0 @@ compress: (_b = opts === null || opts === void 0 ? void 0 : opts.compress) !== null && _b !== void 0 ? _b : false, |
import { FetchFromRegistry } from '@pnpm/fetching-types'; | ||
import fetch, { RetryTimeoutOptions } from './fetch'; | ||
import createFetchFromRegistry, { AgentOptions } from './fetchFromRegistry'; | ||
import createFetchFromRegistry, { fetchWithAgent, AgentOptions } from './fetchFromRegistry'; | ||
export default fetch; | ||
export { AgentOptions, createFetchFromRegistry, FetchFromRegistry, RetryTimeoutOptions, }; | ||
export { AgentOptions, createFetchFromRegistry, fetchWithAgent, FetchFromRegistry, RetryTimeoutOptions, }; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,7 +25,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createFetchFromRegistry = void 0; | ||
exports.fetchWithAgent = exports.createFetchFromRegistry = void 0; | ||
const fetch_1 = __importDefault(require("./fetch")); | ||
const fetchFromRegistry_1 = __importDefault(require("./fetchFromRegistry")); | ||
const fetchFromRegistry_1 = __importStar(require("./fetchFromRegistry")); | ||
exports.createFetchFromRegistry = fetchFromRegistry_1.default; | ||
Object.defineProperty(exports, "fetchWithAgent", { enumerable: true, get: function () { return fetchFromRegistry_1.fetchWithAgent; } }); | ||
exports.default = fetch_1.default; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnpm/fetch", | ||
"version": "4.1.6", | ||
"version": "4.2.0", | ||
"description": "node-fetch with retries", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18775
263