Windows Cmd and Powershell don't support autocompletion, but it can be done with utilities like Windows Subsystem for Linux and Git Bash, which should "just work" due to emulating a Linux environment. This clarifies the error message most users will see to call out the state of the world with regard to autocompletion on Windows platforms.
`ng update` is most likely called when upgrading a project to the next version and users should be more concerned about their project than their personal terminal setup.
`ng completion` is unconditionally setting up autocompletion, while `ng completion script` is getting the shell script for autocompletion setup. As a result, both of these don't benefit from a prompt and should be safe to skip it.
After the user rejects the autocompletion prompt or accepts and is successfully configured, the state is saved into the Angular CLI's global configuration. Before displaying the autocompletion prompt, this state is checked and the prompt is skipped if it was already shown. If the user accepts the prompt but the setup process fails, then the CLI will prompt again on the next execution, this gives users an opportunity to fix whatever issue they are encountering and try again.
Refs #23003.
When the CLI is executed with any command, it will check if `ng completion script` is already included in the user's `~/.bashrc` file (or similar) and if not, ask the user if they would like it to be configured for them. The CLI checks any existing `~/.bashrc`, `~/.zshrc`, `~/.bash_profile`, `~/.zsh_profile`, and `~/.profile` files for `ng completion script`, and if that string is found for the current shell's configuration files, this prompt is skipped. If the user refuses the prompt, no action is taken and the CLI continues on the command the user originally requested.
Refs #23003.
`ng completion` is changed to set up Angular CLI autocompletion for the current user by appending `source <(ng completion script)` to their `~/.bashrc`, `~/.bash_profile`, `~/.zshrc`, `~/.zsh_profile`, or `~/.profile`.
The previous `ng completion` functionality (printing Yargs autocompletion shell script) is moved to `ng completion script` because most users won't need to worry about this, so we're prioritizing `ng completion` as the part most users will actually type.
I couldn't find a good way of testing an error when writing to the `~/.bashrc` file. Since the CLI checks if it has access to the file first, that would usually fail in any circumstance when the file can't be written to. Things could change in between (user modifies file permissions or disk runs out of storage), but there's no easy hook to simulate this change in the e2e test.
Refs #23003.
To enable bash and zsh real-time type-ahead autocompletion, copy and paste the generated script by the `ng completion` command to your `.bashrc`, `.bash_profile`, `.zshrc` or `.zsh_profile`.
Closes#11043
This changes removes most of the usage of `getWorkspaceRaw` in the Angular CLI. This is needed to eventually drop the direct dependency on `jsonc-parser`.
With this change we add a Yargs middleware that normalizes non Array options when the argument has been provided multiple times.
By default, when an option is non array and it is provided multiple times in the command line, yargs
will not override it's value but instead it will be changed to an array unless `duplicate-arguments-array` is disabled.
But this option also have an effect on real array options which isn't desired.
See: https://github.com/yargs/yargs-parser/pull/163#issuecomment-516566614Closes#22956
Infrastructure has been added to the schematics runtime within the `@angular/cli`
package to allow schematics executed via the Angular CLI to have access upcoming
built-in modules. These built-in modules will be imported/required using the
`schematics:` scheme similar to the Node.js `node:` scheme available for Node.js
built-in modules. No built-in modules exist yet but will be added in the future.
Schematics must be executed via the Angular CLI Schematics runtime's custom VM context
to use the upcoming built-in modules. All first-party Angular schematics have been
executed in this manner for several major versions. Third-party schematics can now
opt-in to the behavior by enabling the `encapsulation` option within a schematic collection
JSON file.
With this change we add prompts to `ng deploy` and `ng e2e` to facilitate adding packages that offer these capabalities.
We also add back `ng lint` prompt to add ESLint which was removed by mistake during the commands refactoring.
This option is never set and doesn't provide any value, since typically when one wants to debug, you add a `debugger` statement where needed or use the `break on exception` option in the debugger.
Apart from better code quality, this helps reduce the time of CLI bootstrapping time, as retrieving the package manager name is a rather expensive operator due to the number of process spawns.
The package manager name isn't always needed until we run a command and therefore in some cases we can see an improvement of around `~600ms`. Ex: `ng b --help`. From ` 1.34s` to `0.76s`.
This will be important when we eventually introduce auto complete as users will get faster loopback.
With this change we remove the postinstall hook that was used to prompt users to confirm if they'd like to share anonymous usage with the Angular team.
This post install hook was used to set the global configuration, which was mainly used for commands that run outside of a workspace such as `ng new`, `ng version` and ng `config`. We now prompt once the users runs the above mentioned commands instead of the post install.
With this change we clean up the package-metadata retrieval logic and types by using public `@types/` packages.
Also, we lazily require `pacote` since this has a large set to dependencies which slows down module resolution.
With this change we replace the custom dimension 8 `AOT Enabled`, with `Angular CLI Major Version`. The motivation behind replacing this dimension is that the there is already an `aot` dimension with id 13 which serves for the same purpose.
More information to why we need a new dimension for the Angular CLI major version can be found #22130Closes#22130
`inquirer` has a number of depedencies which slow down module resolution when importing (~138ms) by lazy loading this module we remove this overhead when prompts are not needed.
The `schematicCollections` can be placed under the `cli` option in the global `.angular.json` configuration, at the root or at project level in `angular.json` .
```jsonc
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"schematicCollections": ["@schematics/angular", "@angular/material"]
}
// ...
}
```
**Rationale**
When this option is not configured and a user would like to run a schematic which is not part of `@schematics/angular`,
the collection name needs to be provided to `ng generate` command in the form of `[collection-name:schematic-name]`. This make the `ng generate` command too verbose for repeated usages.
This is where `schematicCollections` comes handle. When adding `@angular/material` to the list of `schematicCollections`, the generate command will try to locate the schematic in the specified collections.
```
ng generate navigation
```
is equivalent to:
```
ng generate @angular/material:navigation
```
**Conflicting schematic names**
When multiple collections have a schematic with the same name. Both `ng generate` and `ng new` will run the first schematic matched based on the ordering (as specified) of `schematicCollections`.
DEPRECATED:
The `defaultCollection` workspace option has been deprecated in favor of `schematicCollections`.
Before
```json
"defaultCollection": "@angular/material"
```
After
```json
"schematicCollections": ["@angular/material"]
```
Closes#12157
With this change we deprecate the angular.json `defaultProject` option.
DEPRECATED:
The `defaultProject` workspace option has been deprecated. The project to use will be determined from the current working directory.
Closes#20661
With this change we create a new command `ng cache` that can be used control and check the disk cache settings.
This command has 4 subcommands
- `ng cache enable` which can be used to enable the cache.
- `ng cache disable` which can be used to disable the cache.
- `ng cache clean` which can be used to delete the cache from disk.
- `ng cache info` which will print statistics and information about the cache.