This commit is contained in:
Sander Declerck 2025-11-14 10:29:09 +01:00
parent 290a630526
commit 157725a25a
No known key found for this signature in database
2 changed files with 5 additions and 46 deletions

View file

@ -1,7 +1,9 @@
import { getMinimumPackageAgeHours } from "../../../config/settings.js";
import { ui } from "../../../environment/userInteraction.js";
let hasSuppressedVersions = false;
const state = {
hasSuppressedVersions: false,
};
/**
* @param {NodeJS.Dict<string | string[]>} headers
@ -109,7 +111,7 @@ export function modifyNpmInfoResponse(body, headers) {
* @param {string} version
*/
function deleteVersionFromJson(json, version) {
hasSuppressedVersions = true;
state.hasSuppressedVersions = true;
ui.writeVerbose(
`Safe-chain: ${version} is newer than ${getMinimumPackageAgeHours()} hours and was removed (minimumPackageAgeInHours setting).`
@ -168,7 +170,7 @@ function getMostRecentTag(tagList) {
* @returns {boolean}
*/
export function getHasSuppressedVersions() {
return hasSuppressedVersions;
return state.hasSuppressedVersions;
}
/**

View file

@ -1,43 +0,0 @@
/**
* @typedef {Object} ResponseInterceptorBuilder
* @property {() => ResponseInterceptor} build
* @property {(modificationFunc: (body: Buffer) => Buffer) => void} modifyBody
*
* @typedef {Object} ResponseInterceptor
* @property {(buffer: Buffer) => Buffer} modifyBody
*/
/**
* @returns {ResponseInterceptorBuilder}
*/
export function createResponseInterceptorBuilder() {
/** @type {Array<(body: Buffer) => Buffer>} */
let modifyBodyFuncs = [];
return {
modifyBody: (func) => modifyBodyFuncs.push(func),
build: () => createResponseInterceptor(modifyBodyFuncs),
};
}
/**
* @returns {ResponseInterceptor}
* @param {Array<(body: Buffer) => Buffer>} modifyBodyFuncs
*/
function createResponseInterceptor(modifyBodyFuncs) {
/**
* @param {Buffer} body
* @returns {Buffer}
*/
function modifyBody(body) {
let modifiedBody = body;
for (var func of modifyBodyFuncs) {
modifiedBody = func(body);
}
return modifiedBody;
}
return { modifyBody };
}