mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 20:20:49 +00:00
Merge branch 'main' into feature/pypi
This commit is contained in:
commit
d789491561
26 changed files with 186 additions and 118 deletions
|
|
@ -39,7 +39,6 @@ async function runBunCommand(command, args) {
|
|||
try {
|
||||
const result = await safeSpawn(command, args, {
|
||||
stdio: "inherit",
|
||||
// @ts-expect-error values of process.env can be string | undefined
|
||||
env: mergeSafeChainProxyEnvironmentVariables(process.env),
|
||||
});
|
||||
return { status: result.status };
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ export async function runNpm(args) {
|
|||
try {
|
||||
const result = await safeSpawn("npm", args, {
|
||||
stdio: "inherit",
|
||||
// @ts-expect-error values of process.env can be string | undefined
|
||||
env: mergeSafeChainProxyEnvironmentVariables(process.env),
|
||||
});
|
||||
return { status: result.status };
|
||||
|
|
@ -24,37 +23,3 @@ export async function runNpm(args) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string[]} args
|
||||
* @returns {Promise<{status: number, output?: string}>}
|
||||
*/
|
||||
export async function dryRunNpmCommandAndOutput(args) {
|
||||
try {
|
||||
const result = await safeSpawn(
|
||||
"npm",
|
||||
[...args, "--ignore-scripts", "--dry-run"],
|
||||
{
|
||||
stdio: "pipe",
|
||||
// @ts-expect-error values of process.env can be string | undefined
|
||||
env: mergeSafeChainProxyEnvironmentVariables(process.env),
|
||||
}
|
||||
);
|
||||
return {
|
||||
status: result.status,
|
||||
output: result.status === 0 ? result.stdout : result.stderr,
|
||||
};
|
||||
} catch (/** @type any */ error) {
|
||||
if (error.status) {
|
||||
const output =
|
||||
error.stdout?.toString() ??
|
||||
error.stderr?.toString() ??
|
||||
error.message ??
|
||||
"";
|
||||
return { status: error.status, output };
|
||||
} else {
|
||||
ui.writeError("Error executing command:", error.message);
|
||||
return { status: 1 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ export async function runNpx(args) {
|
|||
try {
|
||||
const result = await safeSpawn("npx", args, {
|
||||
stdio: "inherit",
|
||||
// @ts-expect-error values of process.env can be string | undefined
|
||||
env: mergeSafeChainProxyEnvironmentVariables(process.env),
|
||||
});
|
||||
return { status: result.status };
|
||||
|
|
|
|||
|
|
@ -13,13 +13,11 @@ export async function runPnpmCommand(args, toolName = "pnpm") {
|
|||
if (toolName === "pnpm") {
|
||||
result = await safeSpawn("pnpm", args, {
|
||||
stdio: "inherit",
|
||||
// @ts-expect-error values of process.env can be string | undefined
|
||||
env: mergeSafeChainProxyEnvironmentVariables(process.env),
|
||||
});
|
||||
} else if (toolName === "pnpx") {
|
||||
result = await safeSpawn("pnpx", args, {
|
||||
stdio: "inherit",
|
||||
// @ts-expect-error values of process.env can be string | undefined
|
||||
env: mergeSafeChainProxyEnvironmentVariables(process.env),
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import { mergeSafeChainProxyEnvironmentVariables } from "../../registryProxy/reg
|
|||
*/
|
||||
export async function runYarnCommand(args) {
|
||||
try {
|
||||
// @ts-expect-error values of process.env can be string | undefined
|
||||
const env = mergeSafeChainProxyEnvironmentVariables(process.env);
|
||||
await fixYarnProxyEnvironmentVariables(env);
|
||||
|
||||
|
|
@ -36,29 +35,7 @@ export async function runYarnCommand(args) {
|
|||
async function fixYarnProxyEnvironmentVariables(env) {
|
||||
// Yarn ignores standard proxy environment variable HTTPS_PROXY
|
||||
// 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;
|
||||
} 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();
|
||||
env.YARN_HTTPS_PROXY = env.HTTPS_PROXY;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
await runYarnCommand(["add", "lodash"]);
|
||||
|
||||
assert.strictEqual(
|
||||
capturedEnv.YARN_HTTPS_PROXY,
|
||||
undefined,
|
||||
"http://localhost:8080",
|
||||
"YARN_HTTPS_PROXY should not be set for Yarn v1"
|
||||
);
|
||||
assert.strictEqual(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue