feat(core): add batch flag to run (#19575)
Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
This commit is contained in:
parent
09ff419040
commit
c83102a2c4
@ -79,6 +79,12 @@ Type: `string`
|
|||||||
|
|
||||||
Base of the current branch (usually main)
|
Base of the current branch (usually main)
|
||||||
|
|
||||||
|
### batch
|
||||||
|
|
||||||
|
Type: `boolean`
|
||||||
|
|
||||||
|
Default: `false`
|
||||||
|
|
||||||
### configuration
|
### configuration
|
||||||
|
|
||||||
Type: `string`
|
Type: `string`
|
||||||
|
|||||||
@ -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.
|
[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
|
### configuration
|
||||||
|
|
||||||
Type: `string`
|
Type: `string`
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
|
- [batch](../../devkit/documents/DefaultTasksRunnerOptions#batch): boolean
|
||||||
- [cacheDirectory](../../devkit/documents/DefaultTasksRunnerOptions#cachedirectory): string
|
- [cacheDirectory](../../devkit/documents/DefaultTasksRunnerOptions#cachedirectory): string
|
||||||
- [cacheableOperations](../../devkit/documents/DefaultTasksRunnerOptions#cacheableoperations): string[]
|
- [cacheableOperations](../../devkit/documents/DefaultTasksRunnerOptions#cacheableoperations): string[]
|
||||||
- [cacheableTargets](../../devkit/documents/DefaultTasksRunnerOptions#cacheabletargets): string[]
|
- [cacheableTargets](../../devkit/documents/DefaultTasksRunnerOptions#cacheabletargets): string[]
|
||||||
@ -16,6 +17,12 @@
|
|||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
|
### batch
|
||||||
|
|
||||||
|
• `Optional` **batch**: `boolean`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### cacheDirectory
|
### cacheDirectory
|
||||||
|
|
||||||
• `Optional` **cacheDirectory**: `string`
|
• `Optional` **cacheDirectory**: `string`
|
||||||
|
|||||||
@ -79,6 +79,12 @@ Type: `string`
|
|||||||
|
|
||||||
Base of the current branch (usually main)
|
Base of the current branch (usually main)
|
||||||
|
|
||||||
|
### batch
|
||||||
|
|
||||||
|
Type: `boolean`
|
||||||
|
|
||||||
|
Default: `false`
|
||||||
|
|
||||||
### configuration
|
### configuration
|
||||||
|
|
||||||
Type: `string`
|
Type: `string`
|
||||||
|
|||||||
@ -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.
|
[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
|
### configuration
|
||||||
|
|
||||||
Type: `string`
|
Type: `string`
|
||||||
|
|||||||
@ -152,7 +152,7 @@ describe('js:tsc executor', () => {
|
|||||||
|
|
||||||
// check batch build
|
// check batch build
|
||||||
rmDist();
|
rmDist();
|
||||||
const batchBuildOutput = runCLI(`build ${parentLib} --skip-nx-cache`, {
|
let batchBuildOutput = runCLI(`build ${parentLib} --skip-nx-cache`, {
|
||||||
env: { NX_BATCH_MODE: 'true' },
|
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`
|
`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(
|
checkFilesExist(
|
||||||
// parent
|
// parent
|
||||||
`dist/libs/${parentLib}/package.json`,
|
`dist/libs/${parentLib}/package.json`,
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { boolean, CommandModule, middleware } from 'yargs';
|
|||||||
import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
|
import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
|
||||||
import {
|
import {
|
||||||
withAffectedOptions,
|
withAffectedOptions,
|
||||||
|
withBatch,
|
||||||
withConfiguration,
|
withConfiguration,
|
||||||
withDepGraphOptions,
|
withDepGraphOptions,
|
||||||
withOutputStyleOption,
|
withOutputStyleOption,
|
||||||
@ -17,7 +18,9 @@ export const yargsAffectedCommand: CommandModule = {
|
|||||||
linkToNxDevAndExamples(
|
linkToNxDevAndExamples(
|
||||||
withAffectedOptions(
|
withAffectedOptions(
|
||||||
withRunOptions(
|
withRunOptions(
|
||||||
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
|
withOutputStyleOption(
|
||||||
|
withTargetAndConfigurationOption(withBatch(yargs))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.option('all', {
|
.option('all', {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import {
|
|||||||
withOutputStyleOption,
|
withOutputStyleOption,
|
||||||
withTargetAndConfigurationOption,
|
withTargetAndConfigurationOption,
|
||||||
withOverrides,
|
withOverrides,
|
||||||
|
withBatch,
|
||||||
} from '../yargs-utils/shared-options';
|
} from '../yargs-utils/shared-options';
|
||||||
|
|
||||||
export const yargsRunManyCommand: CommandModule = {
|
export const yargsRunManyCommand: CommandModule = {
|
||||||
@ -13,7 +14,9 @@ export const yargsRunManyCommand: CommandModule = {
|
|||||||
builder: (yargs) =>
|
builder: (yargs) =>
|
||||||
linkToNxDevAndExamples(
|
linkToNxDevAndExamples(
|
||||||
withRunManyOptions(
|
withRunManyOptions(
|
||||||
withOutputStyleOption(withTargetAndConfigurationOption(yargs))
|
withOutputStyleOption(
|
||||||
|
withTargetAndConfigurationOption(withBatch(yargs))
|
||||||
|
)
|
||||||
),
|
),
|
||||||
'run-many'
|
'run-many'
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { CommandModule } from 'yargs';
|
import { CommandModule } from 'yargs';
|
||||||
import {
|
import {
|
||||||
|
withBatch,
|
||||||
withOverrides,
|
withOverrides,
|
||||||
withRunOneOptions,
|
withRunOneOptions,
|
||||||
} from '../yargs-utils/shared-options';
|
} from '../yargs-utils/shared-options';
|
||||||
@ -13,7 +14,7 @@ export const yargsRunCommand: CommandModule = {
|
|||||||
(e.g., nx serve myapp --configuration=production)
|
(e.g., nx serve myapp --configuration=production)
|
||||||
|
|
||||||
You can skip the use of Nx cache by using the --skip-nx-cache option.`,
|
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) =>
|
handler: async (args) =>
|
||||||
(await import('./run-one')).runOne(process.cwd(), withOverrides(args)),
|
(await import('./run-one')).runOne(process.cwd(), withOverrides(args)),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export interface RunOptions {
|
|||||||
skipNxCache: boolean;
|
skipNxCache: boolean;
|
||||||
cloud: boolean;
|
cloud: boolean;
|
||||||
dte: boolean;
|
dte: boolean;
|
||||||
|
batch: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
|
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', {
|
.options('dte', {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
hidden: true,
|
hidden: true,
|
||||||
}) as Argv<Omit<RunOptions, 'projects' | 'exclude'>> as any;
|
}) as Argv<Omit<RunOptions, 'exclude' | 'batch'>> as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withTargetAndConfigurationOption(
|
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) {
|
export function withAffectedOptions(yargs: Argv) {
|
||||||
return withExcludeOption(yargs)
|
return withExcludeOption(yargs)
|
||||||
.parserConfiguration({
|
.parserConfiguration({
|
||||||
|
|||||||
@ -24,6 +24,7 @@ export interface DefaultTasksRunnerOptions {
|
|||||||
lifeCycle: LifeCycle;
|
lifeCycle: LifeCycle;
|
||||||
captureStderr?: boolean;
|
captureStderr?: boolean;
|
||||||
skipNxCache?: boolean;
|
skipNxCache?: boolean;
|
||||||
|
batch?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultTasksRunner: TasksRunner<
|
export const defaultTasksRunner: TasksRunner<
|
||||||
|
|||||||
@ -194,7 +194,11 @@ export async function runCommand(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setEnvVarsBasedOnArgs(nxArgs: NxArgs, loadDotEnvFiles: boolean) {
|
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_STREAM_OUTPUT = 'true';
|
||||||
process.env.NX_PREFIX_OUTPUT = 'true';
|
process.env.NX_PREFIX_OUTPUT = 'true';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,7 +71,7 @@ export class TasksSchedule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async scheduleTasks() {
|
private async scheduleTasks() {
|
||||||
if (process.env.NX_BATCH_MODE === 'true') {
|
if (this.options.batch || process.env.NX_BATCH_MODE === 'true') {
|
||||||
await this.scheduleBatches();
|
await this.scheduleBatches();
|
||||||
}
|
}
|
||||||
for (let root of this.notScheduledTaskGraph.roots) {
|
for (let root of this.notScheduledTaskGraph.roots) {
|
||||||
|
|||||||
@ -35,6 +35,7 @@ export interface NxArgs {
|
|||||||
nxBail?: boolean;
|
nxBail?: boolean;
|
||||||
nxIgnoreCycles?: boolean;
|
nxIgnoreCycles?: boolean;
|
||||||
type?: string;
|
type?: string;
|
||||||
|
batch?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createOverrides(__overrides_unparsed__: string[] = []) {
|
export function createOverrides(__overrides_unparsed__: string[] = []) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user