feat(core): add batch flag to run (#19575)

Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
This commit is contained in:
Emily Xiong 2023-10-13 13:09:01 -04:00 committed by GitHub
parent 09ff419040
commit c83102a2c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 65 additions and 7 deletions

View File

@ -79,6 +79,12 @@ Type: `string`
Base of the current branch (usually main)
### batch
Type: `boolean`
Default: `false`
### configuration
Type: `string`

View File

@ -81,6 +81,12 @@ Default: `true`
[deprecated] `run-many` runs all targets on all projects in the workspace if no projects are provided. This option is no longer required.
### batch
Type: `boolean`
Default: `false`
### configuration
Type: `string`

View File

@ -4,6 +4,7 @@
### Properties
- [batch](../../devkit/documents/DefaultTasksRunnerOptions#batch): boolean
- [cacheDirectory](../../devkit/documents/DefaultTasksRunnerOptions#cachedirectory): string
- [cacheableOperations](../../devkit/documents/DefaultTasksRunnerOptions#cacheableoperations): string[]
- [cacheableTargets](../../devkit/documents/DefaultTasksRunnerOptions#cacheabletargets): string[]
@ -16,6 +17,12 @@
## Properties
### batch
`Optional` **batch**: `boolean`
---
### cacheDirectory
`Optional` **cacheDirectory**: `string`

View File

@ -79,6 +79,12 @@ Type: `string`
Base of the current branch (usually main)
### batch
Type: `boolean`
Default: `false`
### configuration
Type: `string`

View File

@ -81,6 +81,12 @@ Default: `true`
[deprecated] `run-many` runs all targets on all projects in the workspace if no projects are provided. This option is no longer required.
### batch
Type: `boolean`
Default: `false`
### configuration
Type: `string`

View File

@ -152,7 +152,7 @@ describe('js:tsc executor', () => {
// check batch build
rmDist();
const batchBuildOutput = runCLI(`build ${parentLib} --skip-nx-cache`, {
let batchBuildOutput = runCLI(`build ${parentLib} --skip-nx-cache`, {
env: { NX_BATCH_MODE: 'true' },
});
@ -173,6 +173,9 @@ describe('js:tsc executor', () => {
`Successfully ran target build for project ${parentLib} and 1 task it depends on`
);
batchBuildOutput = runCLI(`build ${parentLib} --skip-nx-cache --batch`);
expect(batchBuildOutput).toContain(`Running 2 tasks with @nx/js:tsc`);
checkFilesExist(
// parent
`dist/libs/${parentLib}/package.json`,

View File

@ -2,6 +2,7 @@ import { boolean, CommandModule, middleware } from 'yargs';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import {
withAffectedOptions,
withBatch,
withConfiguration,
withDepGraphOptions,
withOutputStyleOption,
@ -17,7 +18,9 @@ export const yargsAffectedCommand: CommandModule = {
linkToNxDevAndExamples(
withAffectedOptions(
withRunOptions(
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
withOutputStyleOption(
withTargetAndConfigurationOption(withBatch(yargs))
)
)
)
.option('all', {

View File

@ -5,6 +5,7 @@ import {
withOutputStyleOption,
withTargetAndConfigurationOption,
withOverrides,
withBatch,
} from '../yargs-utils/shared-options';
export const yargsRunManyCommand: CommandModule = {
@ -13,7 +14,9 @@ export const yargsRunManyCommand: CommandModule = {
builder: (yargs) =>
linkToNxDevAndExamples(
withRunManyOptions(
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
withOutputStyleOption(
withTargetAndConfigurationOption(withBatch(yargs))
)
),
'run-many'
),

View File

@ -1,5 +1,6 @@
import { CommandModule } from 'yargs';
import {
withBatch,
withOverrides,
withRunOneOptions,
} from '../yargs-utils/shared-options';
@ -13,7 +14,7 @@ export const yargsRunCommand: CommandModule = {
(e.g., nx serve myapp --configuration=production)
You can skip the use of Nx cache by using the --skip-nx-cache option.`,
builder: (yargs) => withRunOneOptions(yargs),
builder: (yargs) => withRunOneOptions(withBatch(yargs)),
handler: async (args) =>
(await import('./run-one')).runOne(process.cwd(), withOverrides(args)),
};

View File

@ -25,6 +25,7 @@ export interface RunOptions {
skipNxCache: boolean;
cloud: boolean;
dte: boolean;
batch: boolean;
}
export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
@ -89,7 +90,7 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
.options('dte', {
type: 'boolean',
hidden: true,
}) as Argv<Omit<RunOptions, 'projects' | 'exclude'>> as any;
}) as Argv<Omit<RunOptions, 'exclude' | 'batch'>> as any;
}
export function withTargetAndConfigurationOption(
@ -116,6 +117,16 @@ export function withConfiguration(yargs: Argv) {
});
}
export function withBatch(yargs: Argv) {
return yargs.options('batch', {
type: 'boolean',
coerce: (v) => {
return v || process.env.BATCH_MODE === 'true';
},
default: false,
}) as any;
}
export function withAffectedOptions(yargs: Argv) {
return withExcludeOption(yargs)
.parserConfiguration({

View File

@ -24,6 +24,7 @@ export interface DefaultTasksRunnerOptions {
lifeCycle: LifeCycle;
captureStderr?: boolean;
skipNxCache?: boolean;
batch?: boolean;
}
export const defaultTasksRunner: TasksRunner<

View File

@ -194,7 +194,11 @@ export async function runCommand(
}
function setEnvVarsBasedOnArgs(nxArgs: NxArgs, loadDotEnvFiles: boolean) {
if (nxArgs.outputStyle == 'stream' || process.env.NX_BATCH_MODE === 'true') {
if (
nxArgs.outputStyle == 'stream' ||
process.env.NX_BATCH_MODE === 'true' ||
nxArgs.batch
) {
process.env.NX_STREAM_OUTPUT = 'true';
process.env.NX_PREFIX_OUTPUT = 'true';
}

View File

@ -71,7 +71,7 @@ export class TasksSchedule {
}
private async scheduleTasks() {
if (process.env.NX_BATCH_MODE === 'true') {
if (this.options.batch || process.env.NX_BATCH_MODE === 'true') {
await this.scheduleBatches();
}
for (let root of this.notScheduledTaskGraph.roots) {

View File

@ -35,6 +35,7 @@ export interface NxArgs {
nxBail?: boolean;
nxIgnoreCycles?: boolean;
type?: string;
batch?: boolean;
}
export function createOverrides(__overrides_unparsed__: string[] = []) {