Skip to content

Commit 4b42943

Browse files
committed
fix(@angular/cli): allow global config command outside project
Fixes angular#12296
1 parent 1b268b2 commit 4b42943

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@angular-devkit/core';
1919
import { writeFileSync } from 'fs';
2020
import { Command } from '../models/command';
21-
import { Arguments } from '../models/interface';
21+
import { Arguments, CommandScope } from '../models/interface';
2222
import {
2323
getWorkspace,
2424
getWorkspaceRaw,
@@ -178,6 +178,10 @@ export class ConfigCommand extends Command<ConfigCommandSchema> {
178178
public async run(options: ConfigCommandSchema & Arguments) {
179179
const level = options.global ? 'global' : 'local';
180180

181+
if (!options.global) {
182+
this.validateScope(CommandScope.InProject);
183+
}
184+
181185
let config =
182186
(getWorkspace(level) as {} as { _workspace: experimental.workspace.WorkspaceSchema });
183187

packages/angular/cli/commands/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"$longDescription": "",
66

77
"$aliases": [],
8-
"$scope": "in",
8+
"$scope": "all",
99
"$type": "native",
1010
"$impl": "./config-impl#ConfigCommand",
1111

packages/angular/cli/models/command.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>
114114
}
115115
}
116116

117-
async validateScope(): Promise<void> {
118-
switch (this.description.scope) {
117+
async validateScope(scope?: CommandScope): Promise<void> {
118+
switch (scope === undefined ? this.description.scope : scope) {
119119
case CommandScope.OutProject:
120120
if (this.workspace.configFile) {
121121
this.logger.fatal(tags.oneLine`

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

+40-25
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,44 @@ import { ng } from '../../../utils/process';
55
import { expectToFail } from '../../../utils/utils';
66

77

8-
export default function() {
9-
return Promise.resolve()
10-
.then(() => expectToFail(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle')))
11-
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'false'))
12-
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'))
13-
.then(({ stdout }) => {
14-
if (!stdout.match(/false\n?/)) {
15-
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
16-
}
17-
})
18-
// This test requires schema querying capabilities
19-
// .then(() => expectToFail(() => {
20-
// return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN');
21-
// }))
22-
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'true'))
23-
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'))
24-
.then(({ stdout }) => {
25-
if (!stdout.match(/true\n?/)) {
26-
throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`);
27-
}
28-
})
29-
.then(() => expectToFail(() => ng('config', '--global', 'cli.warnings.notreal', 'true')))
30-
.then(() => ng('config', '--global', 'cli.warnings.versionMismatch', 'false'))
31-
.then(() => expectFileToExist(path.join(homedir(), '.angular-config.json')))
32-
.then(() => deleteFile(path.join(homedir(), '.angular-config.json')));
8+
export default async function() {
9+
await expectToFail(() => ng(
10+
'config',
11+
'--global',
12+
'schematics.@schematics/angular.component.inlineStyle',
13+
));
14+
15+
await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'false');
16+
let output = await ng(
17+
'config',
18+
'--global',
19+
'schematics.@schematics/angular.component.inlineStyle',
20+
);
21+
if (!output.stdout.match(/false\n?/)) {
22+
throw new Error(`Expected "false", received "${JSON.stringify(output.stdout)}".`);
23+
}
24+
25+
// This test requires schema querying capabilities
26+
// .then(() => expectToFail(() => {
27+
// return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN');
28+
// }))
29+
30+
const cwd = process.cwd();
31+
process.chdir('/');
32+
try {
33+
await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'true');
34+
} finally {
35+
process.chdir(cwd);
36+
}
37+
38+
output = await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle');
39+
if (!output.stdout.match(/true\n?/)) {
40+
throw new Error(`Expected "true", received "${JSON.stringify(output.stdout)}".`);
41+
}
42+
43+
await expectToFail(() => ng('config', '--global', 'cli.warnings.notreal', 'true'));
44+
45+
await ng('config', '--global', 'cli.warnings.versionMismatch', 'false');
46+
await expectFileToExist(path.join(homedir(), '.angular-config.json'));
47+
await deleteFile(path.join(homedir(), '.angular-config.json'));
3348
}

0 commit comments

Comments
 (0)