Skip to content

Commit 853fdff

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular/cli): allow unsetting config when value is undefined
With this change we allow unset a config value when the provided value is `undefined`. Example, `ng config -g schematics undefined` will remove the entire `schematics` section from the configuration. (cherry picked from commit 4af963e)
1 parent 2cb1242 commit 853fdff

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const validCliPaths = new Map<
2121
['cli.warnings.versionMismatch', undefined],
2222
['cli.defaultCollection', undefined],
2323
['cli.packageManager', undefined],
24+
2425
['cli.analytics', undefined],
2526
['cli.analyticsSharing.tracking', undefined],
2627
['cli.analyticsSharing.uuid', (v) => (v ? `${v}` : uuidV4())],
@@ -64,15 +65,22 @@ function parseJsonPath(path: string): (string | number)[] {
6465

6566
function normalizeValue(value: string | undefined | boolean | number): JsonValue | undefined {
6667
const valueString = `${value}`.trim();
67-
if (valueString === 'true') {
68-
return true;
69-
} else if (valueString === 'false') {
70-
return false;
71-
} else if (isFinite(+valueString)) {
68+
switch (valueString) {
69+
case 'true':
70+
return true;
71+
case 'false':
72+
return false;
73+
case 'null':
74+
return null;
75+
case 'undefined':
76+
return undefined;
77+
}
78+
79+
if (isFinite(+valueString)) {
7280
return +valueString;
7381
}
7482

75-
return value || undefined;
83+
return value ?? undefined;
7684
}
7785

7886
export class ConfigCommand extends Command<ConfigCommandSchema> {
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import { ng } from '../../../utils/process';
22
import { expectToFail } from '../../../utils/utils';
33

4-
export default function() {
5-
return Promise.resolve()
6-
.then(() => expectToFail(() => ng('config', 'cli.warnings.zzzz')))
7-
.then(() => ng('config', 'cli.warnings.versionMismatch' , 'false'))
8-
.then(() => ng('config', 'cli.warnings.versionMismatch'))
9-
.then(({ stdout }) => {
10-
if (!stdout.match(/false/)) {
11-
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
12-
}
13-
})
14-
.then(() => ng('config', 'cli.packageManager' , 'yarn'))
15-
.then(() => ng('config', 'cli.packageManager'))
16-
.then(({ stdout }) => {
17-
if (!stdout.match(/yarn/)) {
18-
throw new Error(`Expected "yarn", received "${JSON.stringify(stdout)}".`);
19-
}
20-
});
4+
export default async function () {
5+
await expectToFail(() => ng('config', 'cli.warnings.zzzz'));
6+
await ng('config', 'cli.warnings.versionMismatch', 'false');
7+
const { stdout } = await ng('config', 'cli.warnings.versionMismatch');
8+
if (!stdout.includes('false')) {
9+
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
10+
}
11+
12+
await ng('config', 'cli.packageManager', 'yarn');
13+
const { stdout: stdout2 } = await ng('config', 'cli.packageManager');
14+
if (!stdout2.includes('yarn')) {
15+
throw new Error(`Expected "yarn", received "${JSON.stringify(stdout2)}".`);
16+
}
17+
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)}".`);
22+
}
23+
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+
}
2128
}

0 commit comments

Comments
 (0)