Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Misc Options:
--if Run main command only if this condition runs successfully
--ifDependency Run main command only if packages dependencies passed the condition (not
available in parallel mode) [boolean]
--if-private Run main command only if the package is private [boolean]
--if-public Run main command only if the package is public [boolean]

Other Options:
--help Show help [boolean]
Expand Down Expand Up @@ -90,3 +92,7 @@ Examples
`yarn wsrun --stages --if build-needed build` - for each package it will first try `yarn wsrun build-needed` and only if the exit code is zero (success) it will run `yarn wsrun build`

`yarn wsrun --stages --if build-needed --if-dependency build` - it will run `build` for each package in stages, if either the package's own condition command was success, or any of the dependencies had a successful condition.

#### Publishing public packages

`yarn wsrun --stages --if-public publish`
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ let yargsParser = yargs
'exclude-missing',
'report',
'if',
'ifDependency'
'ifDependency',
'if-private',
'if-public'
],
'Misc Options:'
)
Expand All @@ -87,6 +89,14 @@ let yargsParser = yargs
'Run main command only if packages dependencies passed the condition (not available in parallel mode)',
boolean: true
},
'if-private': {
describe: 'Run main command only if the package is private',
boolean: true
},
'if-public': {
describe: 'Run main command only if the package is public',
boolean: true
},
'fast-exit': {
boolean: true,
describe: 'If at least one script exits with code > 0, abort'
Expand Down Expand Up @@ -211,6 +221,8 @@ let runner = new RunGraph(
excludeMissing,
showReport,
if: argv.if || null,
ifPrivate: argv.ifPrivate || false,
ifPublic: argv.ifPublic || false,
ifDependency: argv.ifDependency || false,
workspacePath: process.cwd(),
concurrency
Expand Down
15 changes: 10 additions & 5 deletions src/run-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface GraphOptions {
excludeMissing: boolean
showReport: boolean
if: string
ifPublic: boolean
ifPrivate: boolean
ifDependency: boolean
concurrency: number | null
}
Expand Down Expand Up @@ -168,11 +170,14 @@ export class RunGraph {

let ifCondtition = Bromise.resolve(true)

if (
this.opts.if &&
(!this.opts.ifDependency || !depsStatuses.find(ds => ds === ProcResolution.Normal))
) {
ifCondtition = this.runCondition(this.opts.if, pkg)
if (!this.opts.ifDependency || !depsStatuses.find(ds => ds === ProcResolution.Normal)) {
if (this.opts.if) {
ifCondtition = this.runCondition(this.opts.if, pkg)
} else if (this.opts.ifPrivate && p) {
ifCondtition = Bromise.resolve(p.private || false)
} else if (this.opts.ifPublic && p) {
ifCondtition = Bromise.resolve(!p.private)
}
}

let child = ifCondtition.then(shouldExecute => {
Expand Down
1 change: 1 addition & 0 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Dict<T> = { [key: string]: T }

export interface PkgJson {
name: string
private?: boolean
dependencies?: Dict<string>
devDependencies?: Dict<string>
scripts?: { [name: string]: string }
Expand Down
62 changes: 55 additions & 7 deletions tests/basic.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import 'jest'
import { withScaffold, echo, wsrun } from './test.util'

let pkgList = (errorp3: boolean = false, condition?: string) => [
echo.makePkg({ name: 'p1', dependencies: { p2: '*' } }, condition),
echo.makePkg({ name: 'p2', dependencies: { p3: '*', p4: '*' } }, condition),
let pkgList = (
errorp3: boolean = false,
condition?: string,
privatePackages: { [key: string]: boolean } = {}
) => [
echo.makePkg(
{ name: 'p1', private: privatePackages['p1'], dependencies: { p2: '*' } },
condition
),
echo.makePkg(
{ name: 'p2', private: privatePackages['p2'], dependencies: { p3: '*', p4: '*' } },
condition
),
errorp3
? echo.makePkgErr({ name: 'p3', dependencies: { p4: '*', p5: '*' } })
: echo.makePkg({ name: 'p3', dependencies: { p4: '*', p5: '*' } }, condition),
echo.makePkg({ name: 'p4', dependencies: { p5: '*' } }, condition),
echo.makePkg({ name: 'p5', dependencies: {} }, condition)
? echo.makePkgErr({
name: 'p3',
private: privatePackages['p3'],
dependencies: { p4: '*', p5: '*' }
})
: echo.makePkg(
{ name: 'p3', private: privatePackages['p3'], dependencies: { p4: '*', p5: '*' } },
condition
),
echo.makePkg(
{ name: 'p4', private: privatePackages['p4'], dependencies: { p5: '*' } },
condition
),
echo.makePkg({ name: 'p5', private: privatePackages['p5'], dependencies: {} }, condition)
]

describe('basic', () => {
Expand Down Expand Up @@ -90,6 +110,34 @@ describe('basic', () => {
)
})

it('should support if-private execution', async () => {
await withScaffold(
{
packages: pkgList(false, undefined, { p4: true })
},
async () => {
let tst = await wsrun('--stages -r --if-private -- doecho')
expect(tst.error).toBeFalsy()
let output = await echo.getOutput()
expect(output).toEqual(['p4', ''].join('\n'))
}
)
})

it('should support if-public execution', async () => {
await withScaffold(
{
packages: pkgList(false, undefined, { p1: true, p2: true, p3: true, p5: true })
},
async () => {
let tst = await wsrun('--stages -r --if-public -- doecho')
expect(tst.error).toBeFalsy()
let output = await echo.getOutput()
expect(output).toEqual(['p4', ''].join('\n'))
}
)
})

it('should support dependant conditional execution', async () => {
await withScaffold(
{
Expand Down
1 change: 1 addition & 0 deletions tests/test.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let mkdirpAsync = promisify(mkdirp)

export type PackageJson = {
name?: string
private?: boolean
path?: string
dependencies?: { [name: string]: string }
devDependencies?: { [name: string]: string }
Expand Down