mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-23 22:27:34 -05:00
459b6fa72b
* Refactor local-storage async refactor local storage search stream Remove async from local-storage, refactor search with streams refactor search with undici fetch finish search refactor stream multiple request to single stream refactor storage types remove async dependency #1225 add score and refactor metadata remove old search async fix missing stream local data clean up clean up refactor folder search format fix some test fix issue on publish filter preview update ci delete package folder refactor refactor get packages methods fix tests fix lock file add changeset fix test windows disable some test update package json versions * fix merge * fix e2e cli * restore e2e * Update process.ts * Update process.ts * add improvement * format * Update utils.ts * test * test * Update search.spec.ts * Update search.spec.ts * Update search.spec.ts * test * Update ci.yml * clean up * fix tests * Update tags.ts * Update index.spec.ts * document changeset * format
102 lines
2.6 KiB
TypeScript
102 lines
2.6 KiB
TypeScript
import { spawn } from 'child_process';
|
|
import { SpawnOptions } from 'child_process';
|
|
import readline from 'readline';
|
|
import buildDebug from 'debug';
|
|
|
|
const debug = buildDebug('verdaccio:e2e:process');
|
|
|
|
export type ExecOutput = {
|
|
stdout: string;
|
|
stderr: string;
|
|
};
|
|
|
|
export async function _exec(options: SpawnOptions, cmd, args): Promise<ExecOutput> {
|
|
debug('start _exec %o %o %o', options, cmd, args);
|
|
let stdout = '';
|
|
let stderr;
|
|
const env = options.env;
|
|
debug(`Running \`${cmd} ${args.join(' ')}`);
|
|
debug(`CWD: %o`, options.cwd);
|
|
debug(`ENV: ${JSON.stringify(env)}`);
|
|
const spawnOptions = {
|
|
cwd: options.cwd,
|
|
stdio: options.stdio || 'pipe',
|
|
...(env ? { env } : {}),
|
|
};
|
|
|
|
if (process.platform.startsWith('win')) {
|
|
args.unshift('/c', cmd);
|
|
cmd = 'cmd.exe';
|
|
spawnOptions['stdio'] = 'pipe';
|
|
}
|
|
|
|
const childProcess = spawn(cmd, args, spawnOptions);
|
|
const rl = readline.createInterface({ input: childProcess.stdout });
|
|
|
|
rl.on('line', function (line) {
|
|
stdout += line;
|
|
});
|
|
|
|
const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `);
|
|
return new Promise((resolve, reject) => {
|
|
childProcess.on('exit', (error) => {
|
|
if (!error) {
|
|
resolve({ stdout, stderr });
|
|
} else {
|
|
err.message += `${error}...\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`;
|
|
reject({ stdout, stderr: err });
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// export function execAndWaitForOutputToMatch(
|
|
// cmd: string,
|
|
// args: string[],
|
|
// match: RegExp,
|
|
// spawnOptions: SpawnOptions = {}
|
|
// ): any {
|
|
// return _exec({ waitForMatch: match, ...spawnOptions, silence: true }, cmd, args);
|
|
// }
|
|
|
|
export function pnpmGlobal(rootFolder, ...args) {
|
|
const pnpmCmd = require.resolve('pnpm');
|
|
debug('pnpmCommand %o', pnpmCmd);
|
|
debug('run pnpm on %o', rootFolder);
|
|
return _exec(
|
|
{
|
|
cwd: rootFolder,
|
|
},
|
|
process.execPath,
|
|
[pnpmCmd, ...args]
|
|
);
|
|
}
|
|
|
|
export function npm(...args): Promise<ExecOutput> {
|
|
return _exec({}, 'npm', args);
|
|
}
|
|
|
|
export function yarn(...args): Promise<ExecOutput> {
|
|
return _exec({}, 'yarn', args);
|
|
}
|
|
|
|
export function pnpm(...args): Promise<ExecOutput> {
|
|
return _exec({}, 'pnpm', args);
|
|
}
|
|
|
|
export function pnpmWithCwd(cwd, ...args): Promise<ExecOutput> {
|
|
return _exec({ cwd }, 'pnpm', args);
|
|
}
|
|
|
|
export function yarnWithCwd(cwd, ...args): Promise<ExecOutput> {
|
|
return _exec({ cwd }, 'yarn', args);
|
|
}
|
|
|
|
export function nodeCwd(cwd, ...args): Promise<ExecOutput> {
|
|
return _exec({ cwd }, 'yarn', args);
|
|
}
|
|
|
|
export function silentNpm(...args): Promise<ExecOutput> {
|
|
debug('run silent npm %o', args);
|
|
return _exec({ silent: true }, 'npm', args);
|
|
}
|