Skip to content

Commit

Permalink
fix(@angular/cli): allow config object to be of JSON.
Browse files Browse the repository at this point in the history
With this change we allow unset a config value to be a JSON.

Example, `ng config -g schematics {}` will remove the entire `schematics` section from the configuration.

(cherry picked from commit 0a0fc41)
  • Loading branch information
alan-agius4 authored and filipesilva committed May 10, 2021
1 parent 853fdff commit c0efbe7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/angular/cli/commands/config-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function normalizeValue(value: string | undefined | boolean | number): JsonValue
return +valueString;
}

return value ?? undefined;
return parseJson(valueString) ?? value ?? undefined;
}

export class ConfigCommand extends Command<ConfigCommandSchema> {
Expand Down
15 changes: 7 additions & 8 deletions tests/legacy-cli/e2e/tests/commands/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ export default async function () {
throw new Error(`Expected "yarn", received "${JSON.stringify(stdout2)}".`);
}

await ng('config', 'schematics.@schematics/angular:component.style', 'css');
const { stdout: stdout3 } = await ng('config', '@schematics/angular:component.style');
if (!stdout2.includes('css')) {
throw new Error(`Expected "css", received "${JSON.stringify(stdout3)}".`);
await ng('config', 'schematics', '{"@schematics/angular:component":{"style": "scss"}}');
const { stdout: stdout3 } = await ng('config', 'schematics.@schematics/angular:component.style');
if (!stdout3.includes('scss')) {
throw new Error(`Expected "scss", received "${JSON.stringify(stdout3)}".`);
}

const { stderr } = await ng('config', 'schematics', 'undefined');
if (!stderr.includes('Value cannot be found.')) {
throw new Error(`Expected "Value cannot be found", received "${JSON.stringify(stderr)}".`);
}
await ng('config', 'schematics');
await ng('config', 'schematics', 'undefined');
await expectToFail(() => ng('config', 'schematics'));
}

0 comments on commit c0efbe7

Please sign in to comment.