Merge pull request #137 from AikidoSec/remove-yarn-version-check

This commit is contained in:
bitterpanda 2025-11-04 13:43:17 +01:00 committed by GitHub
commit fa0cc710ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 26 deletions

View file

@ -35,29 +35,7 @@ export async function runYarnCommand(args) {
async function fixYarnProxyEnvironmentVariables(env) { async function fixYarnProxyEnvironmentVariables(env) {
// Yarn ignores standard proxy environment variable HTTPS_PROXY // Yarn ignores standard proxy environment variable HTTPS_PROXY
// It does respect NODE_EXTRA_CA_CERTS for custom CA certificates though. // It does respect NODE_EXTRA_CA_CERTS for custom CA certificates though.
// Don't use YARN_HTTPS_CA_FILE_PATH though, as it causes to ignore all system CAs // Don't use YARN_HTTPS_CA_FILE_PATH or YARN_CA_FILE_PATH though, it causes yarn to ignore all system CAs
// Yarn v2/v3 and v4+ use different environment variables for proxy and CA certs
// When setting all variables, yarn returns an error about conflicting variables
// - v2/v3: "Usage Error: Unrecognized or legacy configuration settings found: httpsCaFilePath"
// - v4+: "Usage Error: Unrecognized or legacy configuration settings found: caFilePath"
const version = await yarnVersion();
const majorVersion = parseInt(version.split(".")[0]);
if (majorVersion >= 4) {
env.YARN_HTTPS_PROXY = env.HTTPS_PROXY; env.YARN_HTTPS_PROXY = env.HTTPS_PROXY;
} else if (majorVersion === 2 || majorVersion === 3) {
env.YARN_HTTPS_PROXY = env.HTTPS_PROXY;
}
}
async function yarnVersion() {
const result = await safeSpawn("yarn", ["--version"], {
stdio: "pipe",
});
if (result.status !== 0) {
throw new Error("Failed to get yarn version");
}
return result.stdout.trim();
} }

View file

@ -103,13 +103,13 @@ describe("runYarnCommand", () => {
); );
}); });
it("should not set Yarn-specific proxy vars for Yarn v1", async () => { it("should set YARN_HTTPS_PROXY for Yarn v1", async () => {
yarnVersion = "1.22.19"; yarnVersion = "1.22.19";
await runYarnCommand(["add", "lodash"]); await runYarnCommand(["add", "lodash"]);
assert.strictEqual( assert.strictEqual(
capturedEnv.YARN_HTTPS_PROXY, capturedEnv.YARN_HTTPS_PROXY,
undefined, "http://localhost:8080",
"YARN_HTTPS_PROXY should not be set for Yarn v1" "YARN_HTTPS_PROXY should not be set for Yarn v1"
); );
assert.strictEqual( assert.strictEqual(