-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): confirm ng add action before installation
BREAKING CHANGE: The `ng add` command will now ask the user to confirm the package and version prior to installing and executing an uninstalled package. This new behavior allows a user to abort the action if the version selected is not appropriate or if a typo occurred on the command line and an incorrect package would be installed. A `--skip-confirmation` option has been added to skip the prompt and directly install and execute the package. This option is useful in CI and non-TTY scenarios such as automated scripts.
- Loading branch information
1 parent
3c2f583
commit 985dc1a
Showing
15 changed files
with
80 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import * as inquirer from 'inquirer'; | ||
import { isTTY } from './tty'; | ||
|
||
export async function askConfirmation( | ||
message: string, | ||
defaultResponse: boolean, | ||
noTTYResponse?: boolean, | ||
): Promise<boolean> { | ||
if (!isTTY()) { | ||
return noTTYResponse ?? defaultResponse; | ||
} | ||
|
||
const question: inquirer.Question = { | ||
type: 'confirm', | ||
name: 'confirmation', | ||
prefix: '', | ||
message, | ||
default: defaultResponse, | ||
}; | ||
|
||
const answers = await inquirer.prompt([question]); | ||
|
||
return answers['confirmation']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,25 +10,25 @@ export default async function () { | |
|
||
const tag = await isPrereleaseCli() ? '@next' : ''; | ||
|
||
await ng('add', `@angular/localize${tag}`); | ||
await ng('add', `@angular/localize${tag}`, '--skip-confirmation'); | ||
await expectFileToMatch('package.json', /@angular\/localize/); | ||
|
||
const output1 = await ng('add', '@angular/localize'); | ||
const output1 = await ng('add', '@angular/localize', '--skip-confirmation'); | ||
if (!output1.stdout.includes('Skipping installation: Package already installed')) { | ||
throw new Error('Installation was not skipped'); | ||
} | ||
|
||
const output2 = await ng('add', '@angular/localize@latest'); | ||
const output2 = await ng('add', '@angular/localize@latest', '--skip-confirmation'); | ||
if (output2.stdout.includes('Skipping installation: Package already installed')) { | ||
throw new Error('Installation should not have been skipped'); | ||
} | ||
|
||
const output3 = await ng('add', '@angular/[email protected]'); | ||
const output3 = await ng('add', '@angular/[email protected]', '--skip-confirmation'); | ||
if (output3.stdout.includes('Skipping installation: Package already installed')) { | ||
throw new Error('Installation should not have been skipped'); | ||
} | ||
|
||
const output4 = await ng('add', '@angular/localize@10'); | ||
const output4 = await ng('add', '@angular/localize@10', '--skip-confirmation'); | ||
if (!output4.stdout.includes('Skipping installation: Package already installed')) { | ||
throw new Error('Installation was not skipped'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters