Skip to content

Commit

Permalink
Revert "feat(core): properly passthrough flags unparsed to executors (#…
Browse files Browse the repository at this point in the history
…12890)"

This reverts commit 145dda7.
  • Loading branch information
FrozenPandaz committed Nov 2, 2022
1 parent 2d84f25 commit 23c103f
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 146 deletions.
6 changes: 0 additions & 6 deletions docs/generated/cli/print-affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ Default: `false`

Rerun the tasks even when the results are available in the cache

### target

Type: `string`

Task to run for affected projects

### type

Type: `string`
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"name": "print-affected",
"id": "print-affected",
"file": "generated/cli/print-affected",
"content": "---\ntitle: 'print-affected - CLI command'\ndescription: 'Prints information about the projects and targets affected by changes'\n---\n\n# print-affected\n\nPrints information about the projects and targets affected by changes\n\n## Usage\n\n```terminal\nnx print-affected\n```\n\nInstall `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.\n\n### Examples\n\nPrint information about affected projects and the project graph:\n\n```terminal\n nx print-affected\n```\n\nPrint information about the projects affected by the changes between main and HEAD (e.g,. PR):\n\n```terminal\n nx print-affected --base=main --head=HEAD\n```\n\nPrints information about the affected projects and a list of tasks to test them:\n\n```terminal\n nx print-affected --target=test\n```\n\nPrints the projects property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=projects\n```\n\nPrints the tasks.target.project property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=tasks.target.project\n```\n\n## Options\n\n### all\n\nType: `boolean`\n\nAll projects\n\n### base\n\nType: `string`\n\nBase of the current branch (usually main)\n\n### configuration\n\nType: `string`\n\nThis is the configuration to use when performing tasks on projects\n\n### exclude\n\nType: `array`\n\nDefault: `[]`\n\nExclude certain projects from being processed\n\n### files\n\nType: `array`\n\nChange the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas\n\n### head\n\nType: `string`\n\nLatest commit of the current branch (usually HEAD)\n\n### help\n\nType: `boolean`\n\nShow help\n\n### nx-bail\n\nType: `boolean`\n\nDefault: `false`\n\nStop command execution after the first failed task\n\n### nx-ignore-cycles\n\nType: `boolean`\n\nDefault: `false`\n\nIgnore cycles in the task graph\n\n### runner\n\nType: `string`\n\nThis is the name of the tasks runner configured in nx.json\n\n### select\n\nType: `string`\n\nSelect the subset of the returned json document (e.g., --select=projects)\n\n### skip-nx-cache\n\nType: `boolean`\n\nDefault: `false`\n\nRerun the tasks even when the results are available in the cache\n\n### target\n\nType: `string`\n\nTask to run for affected projects\n\n### type\n\nType: `string`\n\nChoices: [app, lib]\n\nSelect the type of projects to be returned (e.g., --type=app)\n\n### uncommitted\n\nType: `boolean`\n\nUncommitted changes\n\n### untracked\n\nType: `boolean`\n\nUntracked changes\n\n### verbose\n\nType: `boolean`\n\nDefault: `false`\n\nPrints additional information about the commands (e.g., stack traces)\n\n### version\n\nType: `boolean`\n\nShow version number\n"
"content": "---\ntitle: 'print-affected - CLI command'\ndescription: 'Prints information about the projects and targets affected by changes'\n---\n\n# print-affected\n\nPrints information about the projects and targets affected by changes\n\n## Usage\n\n```terminal\nnx print-affected\n```\n\nInstall `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`.\n\n### Examples\n\nPrint information about affected projects and the project graph:\n\n```terminal\n nx print-affected\n```\n\nPrint information about the projects affected by the changes between main and HEAD (e.g,. PR):\n\n```terminal\n nx print-affected --base=main --head=HEAD\n```\n\nPrints information about the affected projects and a list of tasks to test them:\n\n```terminal\n nx print-affected --target=test\n```\n\nPrints the projects property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=projects\n```\n\nPrints the tasks.target.project property from the print-affected output:\n\n```terminal\n nx print-affected --target=build --select=tasks.target.project\n```\n\n## Options\n\n### all\n\nType: `boolean`\n\nAll projects\n\n### base\n\nType: `string`\n\nBase of the current branch (usually main)\n\n### configuration\n\nType: `string`\n\nThis is the configuration to use when performing tasks on projects\n\n### exclude\n\nType: `array`\n\nDefault: `[]`\n\nExclude certain projects from being processed\n\n### files\n\nType: `array`\n\nChange the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas\n\n### head\n\nType: `string`\n\nLatest commit of the current branch (usually HEAD)\n\n### help\n\nType: `boolean`\n\nShow help\n\n### nx-bail\n\nType: `boolean`\n\nDefault: `false`\n\nStop command execution after the first failed task\n\n### nx-ignore-cycles\n\nType: `boolean`\n\nDefault: `false`\n\nIgnore cycles in the task graph\n\n### runner\n\nType: `string`\n\nThis is the name of the tasks runner configured in nx.json\n\n### select\n\nType: `string`\n\nSelect the subset of the returned json document (e.g., --select=projects)\n\n### skip-nx-cache\n\nType: `boolean`\n\nDefault: `false`\n\nRerun the tasks even when the results are available in the cache\n\n### type\n\nType: `string`\n\nChoices: [app, lib]\n\nSelect the type of projects to be returned (e.g., --type=app)\n\n### uncommitted\n\nType: `boolean`\n\nUncommitted changes\n\n### untracked\n\nType: `boolean`\n\nUntracked changes\n\n### verbose\n\nType: `boolean`\n\nDefault: `false`\n\nPrints additional information about the commands (e.g., stack traces)\n\n### version\n\nType: `boolean`\n\nShow version number\n"
},
{
"name": "format:check",
Expand Down
12 changes: 6 additions & 6 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
// check building project
let output = runCLI(`build ${project} --outputHashing none`);
expect(output).toContain(
`> nx run ${project}:build:production --outputHashing none`
`> nx run ${project}:build:production --outputHashing=none`
);
expect(output).toContain(
`Successfully ran target build for project ${project}`
Expand All @@ -590,7 +590,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {

output = runCLI(`build ${project} --outputHashing none`);
expect(output).toContain(
`> nx run ${project}:build:production --outputHashing none [local cache]`
`> nx run ${project}:build:production --outputHashing=none [local cache]`
);
expect(output).toContain(
`Successfully ran target build for project ${project}`
Expand All @@ -599,7 +599,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
// check building app1
output = runCLI(`build ${app1} --outputHashing none`);
expect(output).toContain(
`> nx run ${app1}:build:production --outputHashing none`
`> nx run ${app1}:build:production --outputHashing=none`
);
expect(output).toContain(
`Successfully ran target build for project ${app1}`
Expand All @@ -608,7 +608,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {

output = runCLI(`build ${app1} --outputHashing none`);
expect(output).toContain(
`> nx run ${app1}:build:production --outputHashing none [local cache]`
`> nx run ${app1}:build:production --outputHashing=none [local cache]`
);
expect(output).toContain(
`Successfully ran target build for project ${app1}`
Expand Down Expand Up @@ -638,7 +638,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
// check building an app
let output = runCLI(`build ${project} --outputHashing none`);
expect(output).toContain(
`> nx run ${project}:build:production --outputHashing none`
`> nx run ${project}:build:production --outputHashing=none`
);
expect(output).toContain(
`Successfully ran target build for project ${project}`
Expand All @@ -647,7 +647,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {

output = runCLI(`build ${project} --outputHashing none`);
expect(output).toContain(
`> nx run ${project}:build:production --outputHashing none [local cache]`
`> nx run ${project}:build:production --outputHashing=none [local cache]`
);
expect(output).toContain(
`Successfully ran target build for project ${project}`
Expand Down
31 changes: 0 additions & 31 deletions e2e/nx-run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,6 @@ describe('Nx Running Tests', () => {
afterAll(() => cleanupProject());

describe('running targets', () => {
describe('(forwarding params)', () => {
let proj = uniq('proj');
beforeAll(() => {
runCLI(`generate @nrwl/workspace:lib ${proj}`);
updateProjectConfig(proj, (c) => {
c.targets['echo'] = {
executor: 'nx:run-commands',
options: {
command: 'echo ECHO:',
},
};
return c;
});
});

it.each([
'--watch false',
'--watch=false',
'--arr=a,b,c',
'--arr=a --arr=b --arr=c',
'a',
'--a.b=1',
'--a.b 1',
'-- a b c --a --a.b=1',
'--ignored -- a b c --a --a.b=1',
])('should forward %s properly', (args) => {
const output = runCLI(`echo ${proj} ${args}`);
expect(output).toContain(`ECHO: ${args.replace(/^.*-- /, '')}`);
});
});

it('should execute long running tasks', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nrwl/web:app ${myapp}`);
Expand Down
73 changes: 23 additions & 50 deletions packages/nx/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ export const commandsObject = yargs
'Prints information about the projects and targets affected by changes',
builder: (yargs) =>
linkToNxDevAndExamples(
withAffectedOptions(
withTargetOption(withPrintAffectedOptions(yargs), false)
),
withAffectedOptions(withPrintAffectedOptions(yargs)),
'print-affected'
),
handler: async (args) => {
Expand Down Expand Up @@ -408,9 +406,9 @@ function withPlainOption(yargs: yargs.Argv): yargs.Argv {
function withAffectedOptions(yargs: yargs.Argv): yargs.Argv {
return yargs
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
'populate--': true,
'camel-case-expansion': false,
// allow parsing --env.SOME_ARG for cypress cli env args
'dot-notation': true,
})
.option('files', {
describe:
Expand Down Expand Up @@ -475,12 +473,6 @@ function withAffectedOptions(yargs: yargs.Argv): yargs.Argv {
'This is the configuration to use when performing tasks on projects',
type: 'string',
})
.option('prod', {
describe: 'Use the production configuration',
type: 'boolean',
default: false,
hidden: true,
})
.option('verbose', {
type: 'boolean',
describe:
Expand All @@ -502,32 +494,15 @@ function withAffectedOptions(yargs: yargs.Argv): yargs.Argv {
untracked: ['uncommitted', 'files', 'base', 'head', 'all'],
uncommitted: ['files', 'untracked', 'base', 'head', 'all'],
all: ['files', 'untracked', 'uncommitted', 'base', 'head'],
})
.check((nxArgs) => {
if (
!nxArgs.files &&
!nxArgs.uncommitted &&
!nxArgs.untracked &&
!nxArgs.base &&
!nxArgs.head &&
!nxArgs.all &&
nxArgs._ &&
nxArgs._.length >= 3
) {
throw new Error(
`Nx no longer supports using positional arguments for base and head. Please use --base and --head instead.`
);
}
return true;
});
}

function withRunManyOptions(yargs: yargs.Argv): yargs.Argv {
return yargs
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
'populate--': true,
'camel-case-expansion': false,
// allow parsing --env.SOME_ARG for cypress cli env args
'dot-notation': true,
})
.option('projects', {
describe: 'Projects to run (comma delimited)',
Expand All @@ -538,12 +513,6 @@ function withRunManyOptions(yargs: yargs.Argv): yargs.Argv {
type: 'boolean',
default: true,
})
.option('prod', {
describe: 'Use the production configuration',
type: 'boolean',
default: false,
hidden: true,
})
.options('runner', {
describe: 'Override the tasks runner in `nx.json`',
type: 'string',
Expand Down Expand Up @@ -627,12 +596,16 @@ function withDepGraphOptions(yargs: yargs.Argv): yargs.Argv {
}

function withOverrides(args: any): any {
args.__overrides_unparsed__ = (args['--'] ?? args._.slice(1)).map((v) =>
v.toString()
);
delete args['--'];
delete args._;
return args;
const split = process.argv.indexOf('--');
if (split > -1) {
const overrides = process.argv.slice(split + 1);
delete args._;
return { ...args, __overrides__: overrides };
} else {
args['__positional_overrides__'] = args._.slice(1);
delete args._;
return args;
}
}

function withParallelOption(yargs: yargs.Argv): yargs.Argv {
Expand All @@ -650,12 +623,12 @@ function withOutputStyleOption(yargs: yargs.Argv): yargs.Argv {
});
}

function withTargetOption(yargs: yargs.Argv, demandOption = true): yargs.Argv {
function withTargetOption(yargs: yargs.Argv): yargs.Argv {
return yargs.option('target', {
describe: 'Task to run for affected projects',
type: 'string',
requiresArg: true,
demandOption,
demandOption: true,
global: false,
});
}
Expand Down Expand Up @@ -714,11 +687,11 @@ function withRunOneOptions(yargs: yargs.Argv) {
const executorShouldShowHelp = !(
process.argv[2] === 'run' && process.argv[3] === '--help'
);
const res = withOutputStyleOption(yargs)
const res = yargs
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
'populate--': true,
'camel-case-expansion': false,
// allow parsing --env.SOME_ARG for cypress cli env args
'dot-notation': true,
})
.option('prod', {
describe: 'Use the production configuration',
Expand Down

0 comments on commit 23c103f

Please sign in to comment.