From c0efbe7c67a3edb2dd053fbce2f9debb1bdd180b Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 10 May 2021 18:03:20 +0200 Subject: [PATCH] fix(@angular/cli): allow config object to be of JSON. 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 0a0fc419070f31b8de2b88e8a1f709a64ed993b7) --- packages/angular/cli/commands/config-impl.ts | 2 +- .../e2e/tests/commands/config/config-set.ts | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/angular/cli/commands/config-impl.ts b/packages/angular/cli/commands/config-impl.ts index 717e67aae9a4..7e7b242ac926 100644 --- a/packages/angular/cli/commands/config-impl.ts +++ b/packages/angular/cli/commands/config-impl.ts @@ -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 { diff --git a/tests/legacy-cli/e2e/tests/commands/config/config-set.ts b/tests/legacy-cli/e2e/tests/commands/config/config-set.ts index e4c794c81d2c..26bf399763a6 100644 --- a/tests/legacy-cli/e2e/tests/commands/config/config-set.ts +++ b/tests/legacy-cli/e2e/tests/commands/config/config-set.ts @@ -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')); }