@@ -5,6 +5,8 @@ import {MessageError} from '../../errors.js';
55import type { Reporter } from '../../reporters/index.js' ;
66import buildSubCommands from './_build-sub-commands.js' ;
77import { DEPENDENCY_TYPES } from '../../constants.js' ;
8+ import * as child from '../../util/child.js' ;
9+ import { NODE_BIN_PATH , YARN_BIN_PATH } from '../../constants' ;
810
911const invariant = require ( 'invariant' ) ;
1012const path = require ( 'path' ) ;
@@ -60,10 +62,41 @@ export async function info(config: Config, reporter: Reporter, flags: Object, ar
6062 reporter . log ( JSON . stringify ( publicData , null , 2 ) , { force : true } ) ;
6163}
6264
65+ export async function runScript ( config : Config , reporter : Reporter , flags : Object , args : Array < string > ) : Promise < void > {
66+ const { workspaceRootFolder } = config ;
67+
68+ if ( ! workspaceRootFolder ) {
69+ throw new MessageError ( reporter . lang ( 'workspaceRootNotFound' , config . cwd ) ) ;
70+ }
71+
72+ const manifest = await config . findManifest ( workspaceRootFolder , false ) ;
73+ invariant ( manifest && manifest . workspaces , 'We must find a manifest with a "workspaces" property' ) ;
74+
75+ const workspaces = await config . resolveWorkspaces ( workspaceRootFolder , manifest ) ;
76+
77+ try {
78+ const [ _ , ...rest ] = flags . originalArgs || [ ] ;
79+
80+ for ( const workspaceName of Object . keys ( workspaces ) ) {
81+ const { loc } = workspaces [ workspaceName ] ;
82+
83+ await child . spawn ( NODE_BIN_PATH , [ YARN_BIN_PATH , ...rest ] , {
84+ stdio : 'inherit' ,
85+ cwd : loc ,
86+ } ) ;
87+ }
88+ } catch ( err ) {
89+ throw err ;
90+ }
91+ }
92+
6393const { run , setFlags , examples } = buildSubCommands ( 'workspaces' , {
6494 async info ( config : Config , reporter : Reporter , flags : Object , args : Array < string > ) : Promise < void > {
6595 await info ( config , reporter , flags , args ) ;
6696 } ,
97+ async run ( config : Config , reporter : Reporter , flags : Object , args : Array < string > ) : Promise < void > {
98+ await runScript ( config , reporter , flags , args ) ;
99+ } ,
67100} ) ;
68101
69102export { run , setFlags , examples } ;
0 commit comments