Skip to content

Commit

Permalink
fix(@angular/cli): remove deprecation warning of no prefixed schema…
Browse files Browse the repository at this point in the history
… options

Prefixing options with `no` in schema definitions appears to be used more widely than initially thought.

The `noOption` can also be provided in the `angular.json` which makes this property definition less ambiguous, since boolean options don't get prefixed with `no` in the JSON config. Therefore, in order to reduce the community changes we remove the deprecation warning for such options and change the interim solution to permanent one.

None-the-less, it's still recommended that options are defined without the `no` prefix.

(cherry picked from commit 6693459)
  • Loading branch information
alan-agius4 authored and dgp1130 committed Jul 11, 2022
1 parent d396eba commit 10f2449
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
13 changes: 3 additions & 10 deletions packages/angular/cli/src/command-builder/command-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,12 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
...(this.context.args.options.help ? { default: defaultVal } : {}),
};

// TODO(alanagius4): remove in a major version.
// the below is an interim workaround to handle options which have been defined in the schema with `no` prefix.
let dashedName = strings.dasherize(name);

// Handle options which have been defined in the schema with `no` prefix.
if (type === 'boolean' && dashedName.startsWith('no-')) {
dashedName = dashedName.slice(3);
booleanOptionsWithNoPrefix.add(dashedName);

// eslint-disable-next-line no-console
console.warn(
`Warning: '${name}' option has been declared with a 'no' prefix in the schema.` +
'Please file an issue with the author of this package.',
);
}

if (positional === undefined) {
Expand All @@ -258,8 +252,7 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
}
}

// TODO(alanagius4): remove in a major version.
// the below is an interim workaround to handle options which have been defined in the schema with `no` prefix.
// Handle options which have been defined in the schema with `no` prefix.
if (booleanOptionsWithNoPrefix.size) {
localYargs.middleware((options: Arguments) => {
for (const key of booleanOptionsWithNoPrefix) {
Expand Down
6 changes: 0 additions & 6 deletions tests/legacy-cli/e2e/tests/misc/negated-boolean-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ export default async function () {
['generate', './schematic-boolean-option-negated:test', '--watch'],
/noWatch: false/,
);

await execAndWaitForOutputToMatch(
'ng',
['generate', './schematic-boolean-option-negated:test'],
/'noWatch' option has been declared with a 'no' prefix in the schema/,
);
}

0 comments on commit 10f2449

Please sign in to comment.