diff --git a/packages/core/package.json b/packages/core/package.json index 9516f46..54a78c5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -10,6 +10,7 @@ ".": "./lib/index.js", "./cli": "./lib/cli.js", "./utils": "./lib/utils.js", + "./exec": "./lib/plugins/exec.js", "./list": "./lib/plugins/list.js", "./prepare": "./lib/plugins/prepare.js", "./publish": "./lib/plugins/publish.js", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2a0e6d4..0d21b35 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -40,6 +40,7 @@ export interface PackageJson extends Partial private?: boolean version: string workspaces?: string[] + scripts?: Dict yakumo?: PackageConfig peerDependenciesMeta?: Dict<{ optional?: boolean }> } @@ -90,6 +91,7 @@ const builtin = [ 'list', 'prepare', 'publish', + 'run', 'test', 'upgrade', 'version', diff --git a/packages/core/src/plugins/run.ts b/packages/core/src/plugins/run.ts new file mode 100644 index 0000000..26809b2 --- /dev/null +++ b/packages/core/src/plugins/run.ts @@ -0,0 +1,21 @@ +import { Context, manager, spawnAsync } from '../index.js' + +export const inject = ['yakumo'] + +export function apply(ctx: Context) { + ctx.register('run', async () => { + const { argv, cwd } = ctx.yakumo + const index = argv._.indexOf('--') + if (index === -1 || index === argv._.length - 1) { + throw new Error('Missing command') + } + const [, command, ...rest] = argv._.splice(index) + const paths = ctx.yakumo.locate(argv._, { + filter: (meta) => !!meta.scripts?.[command], + }) + for (const path of paths) { + const agent = manager?.name || 'npm' + await spawnAsync([agent, 'run', command, ...rest], { cwd: cwd + path }) + } + }) +}