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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 90 deletions

View File

@ -60,7 +60,6 @@
"consola": "^3.0.2", "consola": "^3.0.2",
"esbuild": "^0.18.11", "esbuild": "^0.18.11",
"eslint": "^8.46.0", "eslint": "^8.46.0",
"execa": "^6.1.0",
"enquirer": "2.3.6", "enquirer": "2.3.6",
"fast-glob": "^3.2.11", "fast-glob": "^3.2.11",
"fs-extra": "^11.1.0", "fs-extra": "^11.1.0",

View File

@ -1,5 +1,5 @@
import fse from 'fs-extra'; import fse from 'fs-extra';
import { execa } from 'execa'; import { execSync } from 'child_process';
import { join, relative } from 'node:path'; import { join, relative } from 'node:path';
import { clean } from './clean.js'; import { clean } from './clean.js';
import { CSS_LANG } from '../common/css.js'; import { CSS_LANG } from '../common/css.js';
@ -104,9 +104,8 @@ async function buildTypeDeclarations() {
const tsConfig = join(process.cwd(), 'tsconfig.declaration.json'); const tsConfig = join(process.cwd(), 'tsconfig.declaration.json');
if (existsSync(tsConfig)) { if (existsSync(tsConfig)) {
await execa('tsc', ['-p', tsConfig], { execSync(`tsc -p ${tsConfig}`, {
stdout: 'inherit', stdio: 'inherit',
stderr: 'inherit',
}); });
} }
} }

View File

@ -1,4 +1,4 @@
import { execa } from 'execa'; import { exec } from 'child_process';
import { consola, createSpinner } from '../common/logger.js'; import { consola, createSpinner } from '../common/logger.js';
import { SCRIPT_EXTS } from '../common/constant.js'; import { SCRIPT_EXTS } from '../common/constant.js';
@ -8,40 +8,33 @@ type RunCommandMessages = {
failed: string; failed: string;
}; };
function runCommand( function runCommand(cmd: string, messages: RunCommandMessages) {
cmd: string,
options: string[],
messages: RunCommandMessages,
) {
const spinner = createSpinner(messages.start).start(); const spinner = createSpinner(messages.start).start();
return new Promise((resolve) => { return new Promise((resolve) => {
execa(cmd, options, { const options = {
preferLocal: true, env: Object.assign({}, process.env, { FORCE_COLOR: 'true' }),
env: { FORCE_COLOR: 'true' }, };
})
.then(() => { 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 }); spinner.success({ text: messages.succeed });
resolve(true); resolve(true);
}) }
.catch((err: any) => { });
spinner.error({ text: messages.failed });
consola.error(err.stderr || err.stdout);
resolve(false);
});
}); });
} }
function eslint() { function eslint() {
return runCommand( return runCommand(`eslint ./src --fix --ext ${SCRIPT_EXTS.join(',')}`, {
'eslint', start: 'Running eslint...',
['./src', '--fix', '--ext', SCRIPT_EXTS.join(',')], succeed: 'ESLint Passed.',
{ failed: 'ESLint failed!',
start: 'Running eslint...', });
succeed: 'ESLint Passed.',
failed: 'ESLint failed!',
},
);
} }
export async function lint() { export async function lint() {

View File

@ -1,4 +1,3 @@
import { execa } from 'execa';
import { consola } from './logger.js'; import { consola } from './logger.js';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { getVantConfig } from './constant.js'; import { getVantConfig } from './constant.js';
@ -34,7 +33,7 @@ export async function installDependencies() {
try { try {
const manager = getPackageManager(); const manager = getPackageManager();
await execa(manager, ['install', '--prod=false'], { execSync(`${manager} install --prod=false`, {
stdio: 'inherit', stdio: 'inherit',
}); });

57
pnpm-lock.yaml generated
View File

@ -157,9 +157,6 @@ importers:
eslint: eslint:
specifier: ^8.46.0 specifier: ^8.46.0
version: 8.47.0 version: 8.47.0
execa:
specifier: ^6.1.0
version: 6.1.0
fast-glob: fast-glob:
specifier: ^3.2.11 specifier: ^3.2.11
version: 3.3.1 version: 3.3.1
@ -2516,21 +2513,6 @@ packages:
strip-final-newline: 2.0.0 strip-final-newline: 2.0.0
dev: false dev: false
/execa@6.1.0:
resolution: {integrity: sha512-QVWlX2e50heYJcCPG0iWtf8r0xjEYfz/OYLGDYH+IyjWezzPNxz63qNFOu0l4YftGWuizFVZHHs8PrLU5p2IDA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
cross-spawn: 7.0.3
get-stream: 6.0.1
human-signals: 3.0.1
is-stream: 3.0.0
merge-stream: 2.0.0
npm-run-path: 5.1.0
onetime: 6.0.0
signal-exit: 3.0.7
strip-final-newline: 3.0.0
dev: false
/exit@0.1.2: /exit@0.1.2:
resolution: {integrity: sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==} resolution: {integrity: sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==}
engines: {node: '>= 0.8.0'} engines: {node: '>= 0.8.0'}
@ -2832,11 +2814,6 @@ packages:
engines: {node: '>=10.17.0'} engines: {node: '>=10.17.0'}
dev: false dev: false
/human-signals@3.0.1:
resolution: {integrity: sha512-rQLskxnM/5OCldHo+wNXbpVgDn5A17CUoKX+7Sokwaknlq7CdSnphy0W39GU8dw59XiCXmFXDg4fRuckQRKewQ==}
engines: {node: '>=12.20.0'}
dev: false
/husky@8.0.3: /husky@8.0.3:
resolution: {integrity: sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==} resolution: {integrity: sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==}
engines: {node: '>=14'} engines: {node: '>=14'}
@ -2940,11 +2917,6 @@ packages:
engines: {node: '>=8'} engines: {node: '>=8'}
dev: false dev: false
/is-stream@3.0.0:
resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: false
/is-what@3.14.1: /is-what@3.14.1:
resolution: {integrity: sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==} resolution: {integrity: sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==}
dev: false dev: false
@ -3731,11 +3703,6 @@ packages:
engines: {node: '>=6'} engines: {node: '>=6'}
dev: false dev: false
/mimic-fn@4.0.0:
resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==}
engines: {node: '>=12'}
dev: false
/minimatch@3.1.2: /minimatch@3.1.2:
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
dependencies: dependencies:
@ -3853,13 +3820,6 @@ packages:
path-key: 3.1.1 path-key: 3.1.1
dev: false dev: false
/npm-run-path@5.1.0:
resolution: {integrity: sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
path-key: 4.0.0
dev: false
/nth-check@2.1.1: /nth-check@2.1.1:
resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==} resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==}
dependencies: dependencies:
@ -3882,13 +3842,6 @@ packages:
mimic-fn: 2.1.0 mimic-fn: 2.1.0
dev: false dev: false
/onetime@6.0.0:
resolution: {integrity: sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==}
engines: {node: '>=12'}
dependencies:
mimic-fn: 4.0.0
dev: false
/optionator@0.9.3: /optionator@0.9.3:
resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==} resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==}
engines: {node: '>= 0.8.0'} engines: {node: '>= 0.8.0'}
@ -3970,11 +3923,6 @@ packages:
resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
engines: {node: '>=8'} engines: {node: '>=8'}
/path-key@4.0.0:
resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==}
engines: {node: '>=12'}
dev: false
/path-parse@1.0.7: /path-parse@1.0.7:
resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==}
dev: false dev: false
@ -4341,11 +4289,6 @@ packages:
engines: {node: '>=6'} engines: {node: '>=6'}
dev: false dev: false
/strip-final-newline@3.0.0:
resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==}
engines: {node: '>=12'}
dev: false
/strip-json-comments@3.1.1: /strip-json-comments@3.1.1:
resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==}
engines: {node: '>=8'} engines: {node: '>=8'}