chore: update dependencies and refactor command execution
This commit is contained in:
6240
pnpm-lock.yaml
generated
6240
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -130,7 +130,7 @@ catalog:
|
|||||||
eslint-plugin-unused-imports: ^4.4.1
|
eslint-plugin-unused-imports: ^4.4.1
|
||||||
eslint-plugin-vue: ^10.9.2
|
eslint-plugin-vue: ^10.9.2
|
||||||
eslint-plugin-yml: ^3.6.0
|
eslint-plugin-yml: ^3.6.0
|
||||||
execa: ^9.6.1
|
execa: ^10.0.0
|
||||||
find-up: ^8.0.0
|
find-up: ^8.0.0
|
||||||
get-port: ^7.2.0
|
get-port: ^7.2.0
|
||||||
globals: ^17.7.0
|
globals: ^17.7.0
|
||||||
@@ -148,10 +148,10 @@ catalog:
|
|||||||
nitropack: ^2.13.4
|
nitropack: ^2.13.4
|
||||||
nprogress: ^0.2.0
|
nprogress: ^0.2.0
|
||||||
ora: ^9.4.1
|
ora: ^9.4.1
|
||||||
oxfmt: ^0.58.0
|
oxfmt: ^0.59.0
|
||||||
oxlint: ^1.74.0
|
oxlint: ^1.74.0
|
||||||
oxlint-tsgolint: ^0.24.0
|
oxlint-tsgolint: ^0.25.0
|
||||||
pinia: ^3.0.4
|
pinia: ^4.0.2
|
||||||
pinia-plugin-persistedstate: ^4.7.1
|
pinia-plugin-persistedstate: ^4.7.1
|
||||||
pkg-types: ^2.3.1
|
pkg-types: ^2.3.1
|
||||||
playwright: ^1.61.1
|
playwright: ^1.61.1
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { execaCommand, getPackages } from '@vben/node-utils';
|
import { execa, getPackages } from '@vben/node-utils';
|
||||||
|
|
||||||
import { cancel, isCancel, select } from '@clack/prompts';
|
import { cancel, isCancel, select } from '@clack/prompts';
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ export async function run(options: RunOptions) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
execaCommand(`pnpm --filter=${selectPkg} run ${command}`, {
|
execa('pnpm', [`--filter=${selectPkg}`, 'run', command], {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { CAC } from 'cac';
|
|||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
import { availableParallelism, freemem } from 'node:os';
|
import { availableParallelism, freemem } from 'node:os';
|
||||||
|
|
||||||
import { execaCommand } from '@vben/node-utils';
|
import { execa } from '@vben/node-utils';
|
||||||
|
|
||||||
interface LintCommandOptions {
|
interface LintCommandOptions {
|
||||||
/**
|
/**
|
||||||
@@ -29,16 +29,35 @@ const CPU_CORE_THRESHOLD = 4;
|
|||||||
*/
|
*/
|
||||||
const FREE_MEMORY_THRESHOLD = 8 * 1024 ** 3;
|
const FREE_MEMORY_THRESHOLD = 8 * 1024 ** 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一条命令:可执行文件名 + 参数数组。
|
||||||
|
*
|
||||||
|
* execa v10 移除了 execaCommand,execa(file, args?, options?) 的第一个参数是
|
||||||
|
* 「可执行文件名」而非整条命令行;且默认不走 shell。因此统一用 [file, args] 数组形式,
|
||||||
|
* 参数逐个传入、无需 shell 转义,跨平台行为一致(避免把整条字符串误当文件名)。
|
||||||
|
*/
|
||||||
|
type Command = [file: string, args: string[]];
|
||||||
|
|
||||||
|
/** 执行单条命令。 */
|
||||||
|
function runCommand([file, args]: Command) {
|
||||||
|
return execa(file, args, { stdio: 'inherit' });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 将命令还原为可读字符串,用于失败信息展示。 */
|
||||||
|
function formatCommand([file, args]: Command) {
|
||||||
|
return [file, ...args].join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 串行执行所有命令:一次只运行一个进程。
|
* 串行执行所有命令:一次只运行一个进程。
|
||||||
* 保证一次能看到所有工具的报错(配置低的机器更友好)。
|
* 保证一次能看到所有工具的报错(配置低的机器更友好)。
|
||||||
*/
|
*/
|
||||||
async function runSerial(commands: string[]) {
|
async function runSerial(commands: Command[]) {
|
||||||
const failed: string[] = [];
|
const failed: Command[] = [];
|
||||||
|
|
||||||
for (const command of commands) {
|
for (const command of commands) {
|
||||||
try {
|
try {
|
||||||
await execaCommand(command, { stdio: 'inherit' });
|
await runCommand(command);
|
||||||
} catch {
|
} catch {
|
||||||
failed.push(command);
|
failed.push(command);
|
||||||
}
|
}
|
||||||
@@ -46,7 +65,9 @@ async function runSerial(commands: string[]) {
|
|||||||
|
|
||||||
if (failed.length > 0) {
|
if (failed.length > 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Lint failed:\n${failed.map((command) => ` - ${command}`).join('\n')}`,
|
`Lint failed:\n${failed
|
||||||
|
.map((command) => ` - ${formatCommand(command)}`)
|
||||||
|
.join('\n')}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,10 +76,8 @@ async function runSerial(commands: string[]) {
|
|||||||
* 并行执行所有命令:同时启动全部进程。
|
* 并行执行所有命令:同时启动全部进程。
|
||||||
* 任一进程失败时,强制结束其余仍在运行的进程,避免产生遗漏进程。
|
* 任一进程失败时,强制结束其余仍在运行的进程,避免产生遗漏进程。
|
||||||
*/
|
*/
|
||||||
async function runParallel(commands: string[]) {
|
async function runParallel(commands: Command[]) {
|
||||||
const subprocesses = commands.map((command) =>
|
const subprocesses = commands.map((command) => runCommand(command));
|
||||||
execaCommand(command, { stdio: 'inherit' }),
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(subprocesses);
|
await Promise.all(subprocesses);
|
||||||
@@ -89,29 +108,24 @@ async function runLint({ format, threads }: LintCommandOptions) {
|
|||||||
// 用户通过 --threads 显式指定时优先使用其值。
|
// 用户通过 --threads 显式指定时优先使用其值。
|
||||||
const defaultThreads =
|
const defaultThreads =
|
||||||
cpuCores > CPU_CORE_THRESHOLD && freemem() > FREE_MEMORY_THRESHOLD ? 4 : 2;
|
cpuCores > CPU_CORE_THRESHOLD && freemem() > FREE_MEMORY_THRESHOLD ? 4 : 2;
|
||||||
const threadsArg = ` --threads=${threads || defaultThreads}`;
|
const threadsArg = `--threads=${threads || defaultThreads}`;
|
||||||
|
|
||||||
if (format) {
|
if (format) {
|
||||||
await execaCommand(`stylelint "**/*.{vue,css,less,scss}" --cache --fix`, {
|
await runCommand([
|
||||||
stdio: 'inherit',
|
'stylelint',
|
||||||
});
|
['**/*.{vue,css,less,scss}', '--cache', '--fix'],
|
||||||
await execaCommand(`oxfmt${threadsArg}`, {
|
]);
|
||||||
stdio: 'inherit',
|
await runCommand(['oxfmt', [threadsArg]]);
|
||||||
});
|
await runCommand(['oxlint', ['--fix', '--type-aware', threadsArg]]);
|
||||||
await execaCommand(`oxlint --fix --type-aware${threadsArg}`, {
|
await runCommand(['eslint', ['.', '--cache', '--fix']]);
|
||||||
stdio: 'inherit',
|
|
||||||
});
|
|
||||||
await execaCommand(`eslint . --cache --fix`, {
|
|
||||||
stdio: 'inherit',
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const commands = [
|
const commands: Command[] = [
|
||||||
`oxfmt --check${threadsArg}`,
|
['oxfmt', ['--check', threadsArg]],
|
||||||
`oxlint --type-aware${threadsArg}`,
|
['oxlint', ['--type-aware', threadsArg]],
|
||||||
`eslint . --cache`,
|
['eslint', ['.', '--cache']],
|
||||||
`stylelint "**/*.{vue,css,less,scss}" --cache`,
|
['stylelint', ['**/*.{vue,css,less,scss}', '--cache']],
|
||||||
];
|
];
|
||||||
|
|
||||||
// 低配机器(CPU 核心数较少)串行执行,避免多进程并发导致瞬时占用飙升;
|
// 低配机器(CPU 核心数较少)串行执行,避免多进程并发导致瞬时占用飙升;
|
||||||
|
|||||||
Reference in New Issue
Block a user