Skip to content

Commit c0efbe7

Browse files
alan-agius4filipesilva
authored andcommitted
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 0a0fc41)
1 parent 853fdff commit c0efbe7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

packages/angular/cli/commands/config-impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function normalizeValue(value: string | undefined | boolean | number): JsonValue
8080
return +valueString;
8181
}
8282

83-
return value ?? undefined;
83+
return parseJson(valueString) ?? value ?? undefined;
8484
}
8585

8686
export class ConfigCommand extends Command<ConfigCommandSchema> {

tests/legacy-cli/e2e/tests/commands/config/config-set.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ export default async function () {
1515
throw new Error(`Expected "yarn", received "${JSON.stringify(stdout2)}".`);
1616
}
1717

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

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

0 commit comments

Comments
 (0)