BREAKING CHANGE: The 'path' option in schematics schema no longer has a special meaning. Use 'workingDirectory' smart default provider should be used instead.
Prefixing options with `no` in schema definitions appears to be used more widely than initially thought.
The `noOption` can also be provided in the `angular.json` which makes this property definition less ambiguous, since boolean options don't get prefixed with `no` in the JSON config. Therefore, in order to reduce the community changes we remove the deprecation warning for such options and change the interim solution to permanent one.
None-the-less, it's still recommended that options are defined without the `no` prefix.
Previously when having completion enabled and the current workspaces has an older version of the Angular CLI installed in the terminal the below errors is show. This is because the older versions of the CLI do not implement this command. Now we exit gracefully.
```
The specified command ("completion") is invalid. For a list of available options,
run "ng help".
Did you mean "analytics"?
```
Closes#23518
With this change we improve the error message when a project for command cannot be determined
```
Error: Cannot determine project for command.
This is a multi-project workspace and more than one project supports this command. Run "ng build [project]" to execute the command for a specific project or change the current working directory to a project directory.
Available projects are:
- project-name-0
- project-name-1
- project-name-2
- project-name-3
- project-name-4
- project-name-5
- project-name-6
- project-name-7
- project-name-8
- project-name-9
```
Closes#23481
- Prevent additional properties being set in cli subproperties (i.e. cli.warnings.zzzz).
- Create cliGlobalOptions definition and reference in the global.cli schema.
- Use global.cli schema to validate changes made with --global flag.
- Add test coverage for validating global/local-only changes.
- Add test coverage for setting invalid properties and sub-properties.
With this commit we introduce an interim solution for options prefixed with `no` in `schema.json`
Previously, such options were handled as normal boolean option, but yargs handles options prefixed with `no` as negatations of the original option. Example with yargs, an option `noWatch` is will registered as `watch`.
Closes#23397
Running autocompletion with `14.0.1` installed globally in a `14.0.0` project logs the version warning in a very annoying fashion:
```
$ ng verYour global Angular CLI version (14.0.1) is greater than your local version (14.0.0). The local Angular CLI version is used.
To disable this warning use "ng config -g cli.warnings.versionMismatch false".
sion
```
This adds an exception for `ng completion` commands to avoid this edge case.
Currently, we don't register all available commands. For instance, when the CLI is ran inside a workspace the `new` command is not registered. Thus, this will cause a confusing error message when `ng new` is ran inside a workspace.
Example:
```
$ ng new
Error: Unknown command. Did you mean e?
```
With this commit we change this by registering all the commands and valid the command scope during the command building phase which is only triggered once the command is invoked but prior to the execution phase.
Prepares the `@angular/cli` package for the eventual change of enabling the
TypeScript `useUnknownInCatchVariables` option. This option provides additional
code safety by ensuring that the catch clause variable is the proper type before
attempting to access its properties. Similar changes will be needed in the other
packages in the repository prior to enabling `useUnknownInCatchVariables`.
When the workspace has multiple projects and we the project to use cannot be determined from the current working directory, we now issue an actionable error message.
Angular CLI versions prior to v14 may not exit correctly if not forcibly exited
via `process.exit`. When the local CLI version is less than v14, the CLI will now
use `process.exit` to ensure the process exits with these older CLI versions.
Fixes#23289
In certain situations the existing console logger created via `@angular-devkit/core` `createConsoleLogger`
could try to write to a closed stdout pipe stream. This would result in an error during
execution. For cases such as the completion script command, this would also prevent the
command from functioning. To mitigate these cases, `createConsoleLogger` is no longer used
and instead a logger instance is directly created within the CLI that uses `Console.log`
and `Console.error` to write output. Exiting the CLI also now waits for messages to be
logged before proceeding with the exit.
Previously, when a global configuration was not found on disk we forcefully created it even when it was not needed.
This causes issues in CI when multiple `ng` commands would run in parallel as it caused a read/write race conditions.
See: https://angular-team.slack.com/archives/C46U16D4Z/p1654089933910829
With this change we add a footer to indicate that more commands are available when running the CLI in a different context. Ie inside or outside of a workspace.
The package manager `--force` option is only relevant to npm 7+ wherein the option controls
the strictness of the npm 7+ peer dependency resolution. Yarn 2+ does not support a `--force`
option. When the `ng update` `--force` option was used, `ng update` was incorrectly
applying the package manager `--force` option to Yarn which lead to an installation failure.
This has now been corrected and the package manager `--force` option is now only applied to npm 7+.
Yarn 2 and higher no longer support the `--silent` flag.
The Angular CLI will now spawn package managers with the stdout ignored when silent
mode is needed and only show stderr when the process exits unsuccessfully. This
provides the necessary functionality for the CLI without relying on package manager
options.
npm 7+ can fail due to it incorrectly resolving peer dependencies that have valid SemVer
ranges during an `ng update`. Update will set correct versions of dependencies within the
package.json file. However, the failing npm package installation will cause the update process
to abort. To workaround these errors, the npm force option is set during package
installation when the npm package manager at version 7.0.0 or greater is used during an update.
Example error:
```
npm ERR! Conflicting peer dependency: @angular/compiler-cli@14.0.0-rc.0
npm ERR! node_modules/@angular/compiler-cli
npm ERR! peer @angular/compiler-cli@"^14.0.0 || ^14.0.0-rc" from @angular-devkit/build-angular@14.0.0-rc.0
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~14.0.0-rc.0" from the root project
```
With this change we change the how we handle `"format": "path"` schematic property option. We replace the formatter in favour of a `SmartDefaultProvider`, which ensures that nested schematics can access the `workingDirectory`.
If the user does not have a global install of the Angular CLI, the autocompletion prompt is skipped and `ng completion` emits a warning. The reasoning for this is that `source <(ng completion script)` won't work without `ng` on the `$PATH`, which is only really viable with a global install. Local executions like `git clone ... && npm install && npm start` or ephemeral executions like `npx @angular/cli` don't benefit from autocompletion and unnecessarily impede users.
A global install of the Angular CLI is detected by running `which -a ng`, which appears to be a cross-platform means of listing all `ng` commands on the `$PATH`. We then look over all binaries in the list and exclude anything which is a directo child of a `node_modules/.bin/` directory. These include local executions and `npx`, so the only remaining locations should be global installs (`/usr/bin/ng`, NVM, etc.).
The tests are a little awkward since `ng` is installed globally by helper functions before tests start. These tests uninstall the global CLI and install a local, project-specific version to verify behavior, before restoring the global version. Hypothetically this could be emulated by manipulating the `$PATH` variable, but `which` needs to be available (so we can't clobber the whole `$PATH`) and `node` exists in the same directory as the global `ng` command (so we can't remove that directory anyways). There's also no good way of testing the case where `which` fails to run.
Closes#23135.