diff --git a/packages/angular/cli/commands/config-impl.ts b/packages/angular/cli/commands/config-impl.ts index 37b1156219c2..b6ad2d52e0d5 100644 --- a/packages/angular/cli/commands/config-impl.ts +++ b/packages/angular/cli/commands/config-impl.ts @@ -18,7 +18,7 @@ import { } from '@angular-devkit/core'; import { writeFileSync } from 'fs'; import { Command } from '../models/command'; -import { Arguments } from '../models/interface'; +import { Arguments, CommandScope } from '../models/interface'; import { getWorkspace, getWorkspaceRaw, @@ -178,6 +178,10 @@ export class ConfigCommand extends Command { public async run(options: ConfigCommandSchema & Arguments) { const level = options.global ? 'global' : 'local'; + if (!options.global) { + await this.validateScope(CommandScope.InProject); + } + let config = (getWorkspace(level) as {} as { _workspace: experimental.workspace.WorkspaceSchema }); diff --git a/packages/angular/cli/commands/config.json b/packages/angular/cli/commands/config.json index db5a1b665a0e..899d563a2be4 100644 --- a/packages/angular/cli/commands/config.json +++ b/packages/angular/cli/commands/config.json @@ -5,7 +5,7 @@ "$longDescription": "", "$aliases": [], - "$scope": "in", + "$scope": "all", "$type": "native", "$impl": "./config-impl#ConfigCommand", diff --git a/packages/angular/cli/models/command.ts b/packages/angular/cli/models/command.ts index 793c57ed2528..da2079c149ea 100644 --- a/packages/angular/cli/models/command.ts +++ b/packages/angular/cli/models/command.ts @@ -114,8 +114,8 @@ export abstract class Command } } - async validateScope(): Promise { - switch (this.description.scope) { + async validateScope(scope?: CommandScope): Promise { + switch (scope === undefined ? this.description.scope : scope) { case CommandScope.OutProject: if (this.workspace.configFile) { this.logger.fatal(tags.oneLine` diff --git a/tests/legacy-cli/e2e/tests/commands/config/config-global.ts b/tests/legacy-cli/e2e/tests/commands/config/config-global.ts index 0df85d890619..8327836fc500 100644 --- a/tests/legacy-cli/e2e/tests/commands/config/config-global.ts +++ b/tests/legacy-cli/e2e/tests/commands/config/config-global.ts @@ -5,29 +5,44 @@ import { ng } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; -export default function() { - return Promise.resolve() - .then(() => expectToFail(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'))) - .then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'false')) - .then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle')) - .then(({ stdout }) => { - if (!stdout.match(/false\n?/)) { - throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`); - } - }) - // This test requires schema querying capabilities - // .then(() => expectToFail(() => { - // return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN'); - // })) - .then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'true')) - .then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle')) - .then(({ stdout }) => { - if (!stdout.match(/true\n?/)) { - throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`); - } - }) - .then(() => expectToFail(() => ng('config', '--global', 'cli.warnings.notreal', 'true'))) - .then(() => ng('config', '--global', 'cli.warnings.versionMismatch', 'false')) - .then(() => expectFileToExist(path.join(homedir(), '.angular-config.json'))) - .then(() => deleteFile(path.join(homedir(), '.angular-config.json'))); +export default async function() { + await expectToFail(() => ng( + 'config', + '--global', + 'schematics.@schematics/angular.component.inlineStyle', + )); + + await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'false'); + let output = await ng( + 'config', + '--global', + 'schematics.@schematics/angular.component.inlineStyle', + ); + if (!output.stdout.match(/false\n?/)) { + throw new Error(`Expected "false", received "${JSON.stringify(output.stdout)}".`); + } + + // This test requires schema querying capabilities + // .then(() => expectToFail(() => { + // return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN'); + // })) + + const cwd = process.cwd(); + process.chdir('/'); + try { + await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'true'); + } finally { + process.chdir(cwd); + } + + output = await ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'); + if (!output.stdout.match(/true\n?/)) { + throw new Error(`Expected "true", received "${JSON.stringify(output.stdout)}".`); + } + + await expectToFail(() => ng('config', '--global', 'cli.warnings.notreal', 'true')); + + await ng('config', '--global', 'cli.warnings.versionMismatch', 'false'); + await expectFileToExist(path.join(homedir(), '.angular-config.json')); + await deleteFile(path.join(homedir(), '.angular-config.json')); }