2024-07-02 11:48:01 +02:00
/ * * *
* Running lerna with since and scope is not working as expected .
2024-07-02 12:02:00 +02:00
* For example , running the command ` yarn test --scope=@budibase/worker --since=master ` , with changes only on ` @budibase/backend-core ` will not work as expected , as it does not analyse the dependencies properly . The actual ` @budibase/worker ` task will not be triggered .
2024-07-02 11:48:01 +02:00
*
2024-07-02 12:02:00 +02:00
* This script is using ` lerna ls ` to detect all the affected projects from a given commit , and if the scoped package is affected , the actual command will be executed .
2024-07-02 11:48:01 +02:00
*
* The current version of the script only supports a single project in the scope .
* /
2024-07-02 11:38:21 +02:00
const { execSync } = require ( "child_process" )
2024-07-02 11:48:01 +02:00
const argv = require ( "yargs" ) . demandOption ( [ "task" , "since" , "scope" ] ) . argv
2024-07-02 11:38:21 +02:00
2024-07-02 11:48:01 +02:00
const { task , since , scope } = argv
2024-07-02 11:38:21 +02:00
const affectedPackages = execSync (
2024-07-02 12:28:25 +02:00
` yarn --silent nx show projects --affected -t ${ task } --base= ${ since } --json ` ,
2024-07-02 11:38:21 +02:00
{
encoding : "utf-8" ,
}
)
const packages = JSON . parse ( affectedPackages )
2024-07-02 12:28:25 +02:00
const isAffected = packages . includes ( scope )
2024-07-02 11:38:21 +02:00
if ( isAffected ) {
2024-07-02 11:48:01 +02:00
console . log ( ` ${ scope } is affected. Running task " ${ task } " ` )
execSync ( ` yarn ${ task } --scope= ${ scope } ` , {
2024-07-02 11:38:21 +02:00
stdio : "inherit" ,
} )
} else {
2024-07-02 11:48:01 +02:00
console . log ( ` ${ scope } is not affected. Skipping task " ${ task } " ` )
2024-07-02 11:38:21 +02:00
}