1- import { getPackagesSync , type Package } from '@manypkg/get-packages' ;
1+ import { getPackagesSync } from '@manypkg/get-packages' ;
22import { spawn } from 'child_process' ;
33import graphlib , { Graph } from 'graphlib' ;
4- import path from 'path' ;
5-
4+ import { join } from 'path' ;
65import {
76 MODERN_MODULE_READY_MESSAGE ,
87 PACKAGE_JSON ,
@@ -11,11 +10,12 @@ import {
1110 TSUP_READY_MESSAGE ,
1211} from './constant.js' ;
1312import { debugLog , Logger } from './logger.js' ;
13+ import type { PackageWithScripts } from './types.js' ;
1414import { readPackageJson } from './utils.js' ;
1515
1616interface GraphNode {
1717 name : string ;
18- packageJson : Package [ 'packageJson' ] ;
18+ packageJson : PackageWithScripts [ 'packageJson' ] ;
1919 path : string ;
2020}
2121
@@ -37,12 +37,12 @@ export class WorkspaceDevRunner {
3737 private options : WorkspaceDevRunnerOptions ;
3838 private cwd : string ;
3939 private workspaceFileDir : string ;
40- private packages : Package [ ] = [ ] ;
40+ private packages : PackageWithScripts [ ] = [ ] ;
4141 private graph : Graph ;
4242 private visited : Record < string , boolean > ;
4343 private visiting : Record < string , boolean > ;
4444 private matched : Record < string , boolean > ;
45- private metaData ! : Package [ 'packageJson' ] ;
45+ private metaData ! : PackageWithScripts [ 'packageJson' ] ;
4646
4747 constructor ( options : WorkspaceDevRunnerOptions ) {
4848 this . options = {
@@ -59,7 +59,7 @@ export class WorkspaceDevRunner {
5959 }
6060
6161 async init ( ) : Promise < void > {
62- this . metaData = await readPackageJson ( path . join ( this . cwd , PACKAGE_JSON ) ) ;
62+ this . metaData = await readPackageJson ( join ( this . cwd , PACKAGE_JSON ) ) ;
6363 this . buildDependencyGraph ( ) ;
6464 debugLog (
6565 'Dependency graph:\n' +
@@ -77,7 +77,7 @@ export class WorkspaceDevRunner {
7777 ) ! ;
7878 this . packages = packages ;
7979
80- const initNode = ( pkg : Package ) => {
80+ const initNode = ( pkg : PackageWithScripts ) => {
8181 const { packageJson, dir } = pkg ;
8282 const { name, dependencies, devDependencies, peerDependencies } =
8383 packageJson ;
@@ -173,12 +173,15 @@ export class WorkspaceDevRunner {
173173
174174 visitNodes ( node : string ) : Promise < void > {
175175 return new Promise ( ( resolve ) => {
176- const { name, path } = this . getNode ( node ) ;
176+ const { name, path, packageJson } = this . getNode ( node ) ;
177177 const logger = new Logger ( {
178178 name,
179179 } ) ;
180+
180181 const config = this . options ?. projects ?. [ name ] ;
181- if ( config ?. skip ) {
182+ const command = config ?. command ? config . command : 'dev' ;
183+ const scripts = packageJson . scripts || { } ;
184+ if ( config ?. skip || ! scripts [ command ] ) {
182185 this . visited [ node ] = true ;
183186 this . visiting [ node ] = false ;
184187 debugLog ( `Skip visit node: ${ node } ` ) ;
@@ -187,18 +190,14 @@ export class WorkspaceDevRunner {
187190 }
188191 this . visiting [ node ] = true ;
189192
190- const child = spawn (
191- 'npm' ,
192- [ 'run' , config ?. command ? config . command : 'dev' ] ,
193- {
194- cwd : path ,
195- env : {
196- ...process . env ,
197- FORCE_COLOR : '3' ,
198- } ,
199- shell : true ,
193+ const child = spawn ( 'npm' , [ 'run' , command ] , {
194+ cwd : path ,
195+ env : {
196+ ...process . env ,
197+ FORCE_COLOR : '3' ,
200198 } ,
201- ) ;
199+ shell : true ,
200+ } ) ;
202201
203202 child . stdout . on ( 'data' , async ( data ) => {
204203 const stdout = data . toString ( ) ;
0 commit comments