Files
vercel/packages/cli/test/helpers/exec.ts
Jeff See 596b68ce56 Add eslint rule for no-console within the cli package (#11452)
This PR adds a rule to disallow the use of console.log/console.error/etc
from within the CLI package. The aim is to centralize our use of stdio
within the CLI so that everything moves through our client's output
module. It also disables the rule for all of the current console usage,
with the hopes that we will clean things up soon™

Also want to note that the rule only applies to usage from within the
CLI, so dependencies that the CLI pulls in (both external and even
within this monorepo) are unaffected.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2024-04-18 10:54:05 -07:00

60 lines
1.3 KiB
TypeScript

import execa from 'execa';
import getGlobalDir from './get-global-dir';
const defaultOptions = {
reject: false,
};
let globalArgs: string[] = [];
function getGlobalArgs() {
if (process.env.CI) {
return [];
}
if (globalArgs.length === 0) {
globalArgs = ['-Q', getGlobalDir()];
// eslint-disable-next-line no-console
console.log(
'No CI detected, adding defaultArgs to avoid polluting user settings',
globalArgs
);
}
return globalArgs;
}
/**
* Execute Vercel CLI subcommands.
*/
export function execCli(
file: string,
args: string[] = [],
options?: execa.Options<string>
): execa.ExecaChildProcess<string> {
// eslint-disable-next-line no-console
console.log(`$ vercel ${args.join(' ')}`);
const globalArgs = getGlobalArgs();
const combinedOptions: execa.Options<string> = {
...defaultOptions,
...options,
};
// @ts-ignore - allow overwriting readonly property "env"
combinedOptions.env = combinedOptions.env ?? {};
combinedOptions.env['NO_COLOR'] = combinedOptions.env['NO_COLOR'] ?? '1';
return execa(file, [...args, ...globalArgs], combinedOptions);
}
/**
* Execute an abitrary command.
*/
export function exec(cwd: string, command: string, args: string[] = []) {
return execa(command, args, {
cwd,
...defaultOptions,
});
}