feat(cli): generalize concurrency flag

This commit is contained in:
saberzero1
2026-04-11 15:51:50 +02:00
parent 7e01af6a4d
commit 64802f858b
3 changed files with 33 additions and 19 deletions

View File

@@ -135,6 +135,7 @@ yargs(hideBin(process.argv))
latest: argv.latest, latest: argv.latest,
clean: argv.clean, clean: argv.clean,
dryRun: argv.dryRun, dryRun: argv.dryRun,
concurrency: argv.concurrency,
}) })
}, },
) )
@@ -157,6 +158,7 @@ yargs(hideBin(process.argv))
await handlePluginAdd(argv.repos, { await handlePluginAdd(argv.repos, {
name: argv.name, name: argv.name,
subdir: argv.subdir, subdir: argv.subdir,
concurrency: argv.concurrency,
}) })
}, },
) )
@@ -212,11 +214,11 @@ yargs(hideBin(process.argv))
}, },
) )
// Hidden deprecated aliases // Hidden deprecated aliases
.command("restore", false, CommonArgv, async () => { .command("restore", false, CommonArgv, async (argv) => {
console.log( console.log(
"\x1b[33m⚠ 'plugin restore' is deprecated. Use 'plugin install --clean' instead.\x1b[0m", "\x1b[33m⚠ 'plugin restore' is deprecated. Use 'plugin install --clean' instead.\x1b[0m",
) )
await handlePluginInstallUnified({ clean: true }) await handlePluginInstallUnified({ clean: true, concurrency: argv.concurrency })
}) })
.command("update [names..]", false, CommonArgv, async (argv) => { .command("update [names..]", false, CommonArgv, async (argv) => {
console.log( console.log(
@@ -225,13 +227,18 @@ yargs(hideBin(process.argv))
await handlePluginInstallUnified({ await handlePluginInstallUnified({
names: argv.names?.length ? argv.names : undefined, names: argv.names?.length ? argv.names : undefined,
latest: true, latest: true,
concurrency: argv.concurrency,
}) })
}) })
.command("check", false, CommonArgv, async () => { .command("check", false, CommonArgv, async (argv) => {
console.log( console.log(
"\x1b[33m⚠ 'plugin check' is deprecated. Use 'plugin install --latest --dry-run' instead.\x1b[0m", "\x1b[33m⚠ 'plugin check' is deprecated. Use 'plugin install --latest --dry-run' instead.\x1b[0m",
) )
await handlePluginInstallUnified({ latest: true, dryRun: true }) await handlePluginInstallUnified({
latest: true,
dryRun: true,
concurrency: argv.concurrency,
})
}) })
.command( .command(
"resolve", "resolve",
@@ -251,6 +258,7 @@ yargs(hideBin(process.argv))
await handlePluginInstallUnified({ await handlePluginInstallUnified({
fromConfig: true, fromConfig: true,
dryRun: argv.dryRun, dryRun: argv.dryRun,
concurrency: argv.concurrency,
}) })
}, },
) )

View File

@@ -11,6 +11,11 @@ export const CommonArgv = {
default: false, default: false,
describe: "print out extra logging information", describe: "print out extra logging information",
}, },
concurrency: {
number: true,
alias: ["c"],
describe: "max parallel operations (default: number of CPU cores)",
},
} }
export const CreateArgv = { export const CreateArgv = {
@@ -112,8 +117,4 @@ export const BuildArgv = {
default: false, default: false,
describe: "show detailed bundle information", describe: "show detailed bundle information",
}, },
concurrency: {
number: true,
describe: "how many threads to use to parse notes",
},
} }

View File

@@ -257,12 +257,15 @@ export async function handlePluginInstallUnified({
latest = false, latest = false,
clean = false, clean = false,
dryRun = false, dryRun = false,
concurrency: concurrencyOption,
} = {}) { } = {}) {
if (clean && latest) { if (clean && latest) {
console.log(styleText("red", "✗ --clean and --latest cannot be used together")) console.log(styleText("red", "✗ --clean and --latest cannot be used together"))
return return
} }
const resolvedConcurrency = Math.max(1, concurrencyOption ?? os.cpus().length)
const pluginsJson = readPluginsJson() const pluginsJson = readPluginsJson()
let lockfile = readLockfile() let lockfile = readLockfile()
@@ -539,7 +542,7 @@ export async function handlePluginInstallUnified({
// Clone remote plugins in parallel // Clone remote plugins in parallel
if (remoteEntries.length > 0) { if (remoteEntries.length > 0) {
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
await runParallel( await runParallel(
remoteEntries, remoteEntries,
concurrency, concurrency,
@@ -595,7 +598,7 @@ export async function handlePluginInstallUnified({
if (installed.length > 0) { if (installed.length > 0) {
console.log() console.log()
console.log(styleText("cyan", "→ Building plugins...")) console.log(styleText("cyan", "→ Building plugins..."))
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
const results = await runParallel(installed, concurrency, async ({ name, pluginDir }) => { const results = await runParallel(installed, concurrency, async ({ name, pluginDir }) => {
const ok = await buildPluginAsync(pluginDir, name) const ok = await buildPluginAsync(pluginDir, name)
if (ok) console.log(styleText("green", `${name} built`)) if (ok) console.log(styleText("green", `${name} built`))
@@ -722,7 +725,7 @@ export async function handlePluginInstallUnified({
// Clone remote plugins in parallel // Clone remote plugins in parallel
if (remotePlugins.length > 0) { if (remotePlugins.length > 0) {
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
await runParallel(remotePlugins, concurrency, async ({ name, entry, pluginDir }) => { await runParallel(remotePlugins, concurrency, async ({ name, entry, pluginDir }) => {
try { try {
if (entry.subdir) { if (entry.subdir) {
@@ -763,7 +766,7 @@ export async function handlePluginInstallUnified({
if (restoredPlugins.length > 0) { if (restoredPlugins.length > 0) {
console.log() console.log()
console.log(styleText("cyan", "→ Building restored plugins...")) console.log(styleText("cyan", "→ Building restored plugins..."))
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
const results = await runParallel( const results = await runParallel(
restoredPlugins, restoredPlugins,
concurrency, concurrency,
@@ -824,7 +827,7 @@ export async function handlePluginInstallUnified({
// Phase 2: Fetch/update plugins in parallel // Phase 2: Fetch/update plugins in parallel
if (validPlugins.length > 0) { if (validPlugins.length > 0) {
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
await runParallel(validPlugins, concurrency, async ({ name, pluginDir, entry }) => { await runParallel(validPlugins, concurrency, async ({ name, pluginDir, entry }) => {
try { try {
console.log(styleText("cyan", `→ Updating ${name}...`)) console.log(styleText("cyan", `→ Updating ${name}...`))
@@ -884,7 +887,7 @@ export async function handlePluginInstallUnified({
if (updatedPlugins.length > 0) { if (updatedPlugins.length > 0) {
console.log() console.log()
console.log(styleText("cyan", "→ Rebuilding updated plugins...")) console.log(styleText("cyan", "→ Rebuilding updated plugins..."))
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
await runParallel(updatedPlugins, concurrency, async ({ name, pluginDir }) => { await runParallel(updatedPlugins, concurrency, async ({ name, pluginDir }) => {
const ok = await buildPluginAsync(pluginDir, name) const ok = await buildPluginAsync(pluginDir, name)
if (ok) console.log(styleText("green", `${name} rebuilt`)) if (ok) console.log(styleText("green", `${name} rebuilt`))
@@ -986,7 +989,7 @@ export async function handlePluginInstallUnified({
// Run git fetch/clone operations in parallel // Run git fetch/clone operations in parallel
if (gitEntries.length > 0) { if (gitEntries.length > 0) {
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
await runParallel(gitEntries, concurrency, async ({ name, entry, pluginDir, action }) => { await runParallel(gitEntries, concurrency, async ({ name, entry, pluginDir, action }) => {
try { try {
if (action === "update") { if (action === "update") {
@@ -1031,7 +1034,7 @@ export async function handlePluginInstallUnified({
if (pluginsToBuild.length > 0) { if (pluginsToBuild.length > 0) {
console.log() console.log()
console.log(styleText("cyan", "→ Building plugins...")) console.log(styleText("cyan", "→ Building plugins..."))
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
const results = await runParallel(pluginsToBuild, concurrency, async ({ name, pluginDir }) => { const results = await runParallel(pluginsToBuild, concurrency, async ({ name, pluginDir }) => {
const ok = await buildPluginAsync(pluginDir, name) const ok = await buildPluginAsync(pluginDir, name)
if (ok) console.log(styleText("green", `${name} built`)) if (ok) console.log(styleText("green", `${name} built`))
@@ -1061,7 +1064,7 @@ export async function handlePluginInstall() {
export async function handlePluginAdd( export async function handlePluginAdd(
sources, sources,
{ name: nameOverride, subdir: subdirOverride } = {}, { name: nameOverride, subdir: subdirOverride, concurrency: concurrencyOption } = {},
) { ) {
if (nameOverride && sources.length > 1) { if (nameOverride && sources.length > 1) {
console.log(styleText("red", "✗ --name/--as can only be used when adding a single plugin")) console.log(styleText("red", "✗ --name/--as can only be used when adding a single plugin"))
@@ -1072,6 +1075,8 @@ export async function handlePluginAdd(
return return
} }
const resolvedConcurrency = Math.max(1, concurrencyOption ?? os.cpus().length)
let lockfile = readLockfile() let lockfile = readLockfile()
if (!lockfile) { if (!lockfile) {
lockfile = { version: "1.0.0", plugins: {} } lockfile = { version: "1.0.0", plugins: {} }
@@ -1136,7 +1141,7 @@ export async function handlePluginAdd(
// Clone remote plugins in parallel // Clone remote plugins in parallel
if (remoteSources.length > 0) { if (remoteSources.length > 0) {
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
await runParallel( await runParallel(
remoteSources, remoteSources,
concurrency, concurrency,
@@ -1187,7 +1192,7 @@ export async function handlePluginAdd(
if (addedPlugins.length > 0) { if (addedPlugins.length > 0) {
console.log() console.log()
console.log(styleText("cyan", "→ Building plugins...")) console.log(styleText("cyan", "→ Building plugins..."))
const concurrency = Math.max(1, os.cpus().length) const concurrency = resolvedConcurrency
await runParallel(addedPlugins, concurrency, async ({ name, pluginDir }) => { await runParallel(addedPlugins, concurrency, async ({ name, pluginDir }) => {
const ok = await buildPluginAsync(pluginDir, name) const ok = await buildPluginAsync(pluginDir, name)
if (ok) console.log(styleText("green", `${name} built`)) if (ok) console.log(styleText("green", `${name} built`))