refactor(cli): remove execa dependency (#12205)

This commit is contained in:
neverland
2023-08-19 15:14:40 +08:00
committed by GitHub
parent 47950a1353
commit 5dc2f4dcd2
5 changed files with 23 additions and 90 deletions
+3 -4
View File
@@ -1,5 +1,5 @@
import fse from 'fs-extra';
import { execa } from 'execa';
import { execSync } from 'child_process';
import { join, relative } from 'node:path';
import { clean } from './clean.js';
import { CSS_LANG } from '../common/css.js';
@@ -104,9 +104,8 @@ async function buildTypeDeclarations() {
const tsConfig = join(process.cwd(), 'tsconfig.declaration.json');
if (existsSync(tsConfig)) {
await execa('tsc', ['-p', tsConfig], {
stdout: 'inherit',
stderr: 'inherit',
execSync(`tsc -p ${tsConfig}`, {
stdio: 'inherit',
});
}
}
+19 -26
View File
@@ -1,4 +1,4 @@
import { execa } from 'execa';
import { exec } from 'child_process';
import { consola, createSpinner } from '../common/logger.js';
import { SCRIPT_EXTS } from '../common/constant.js';
@@ -8,40 +8,33 @@ type RunCommandMessages = {
failed: string;
};
function runCommand(
cmd: string,
options: string[],
messages: RunCommandMessages,
) {
function runCommand(cmd: string, messages: RunCommandMessages) {
const spinner = createSpinner(messages.start).start();
return new Promise((resolve) => {
execa(cmd, options, {
preferLocal: true,
env: { FORCE_COLOR: 'true' },
})
.then(() => {
const options = {
env: Object.assign({}, process.env, { FORCE_COLOR: 'true' }),
};
exec(cmd, options, (error, stdout, stderr) => {
if (error) {
consola.error(stderr || stdout);
spinner.error({ text: messages.failed });
resolve(false);
} else {
spinner.success({ text: messages.succeed });
resolve(true);
})
.catch((err: any) => {
spinner.error({ text: messages.failed });
consola.error(err.stderr || err.stdout);
resolve(false);
});
}
});
});
}
function eslint() {
return runCommand(
'eslint',
['./src', '--fix', '--ext', SCRIPT_EXTS.join(',')],
{
start: 'Running eslint...',
succeed: 'ESLint Passed.',
failed: 'ESLint failed!',
},
);
return runCommand(`eslint ./src --fix --ext ${SCRIPT_EXTS.join(',')}`, {
start: 'Running eslint...',
succeed: 'ESLint Passed.',
failed: 'ESLint failed!',
});
}
export async function lint() {