935 Commits

Author SHA1 Message Date
Alan Agius
669345998b fix(@angular/cli): remove deprecation warning of no prefixed schema options
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.
2022-07-11 11:52:16 -07:00
Alan Agius
2731fe7f67 fix(@angular/cli): handle cases when completion is enabled and running in an older CLI workspace
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
2022-07-07 20:39:36 +02:00
Alan Agius
cbccfd426a fix(@angular/cli): during an update only use package manager force option with npm 7+
In some cases previously we passed the `force` option to yarn which which lead to an installation failure.

Closes #23495
2022-07-06 16:33:02 +02:00
Alan Agius
dbe0dc1743 fix(@angular/cli): improve error message for project-specific ng commands when run outside of a project
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
2022-07-01 11:43:57 -04:00
Alan Agius
a69000407c refactor: clean up old ansi-colors castings
This has been fixed in https://github.com/doowb/ansi-colors/pull/44
2022-06-28 08:49:44 -04:00
Alan Agius
4fa039b692 fix(@angular/cli): remove color from help epilogue
In some cases gray doesn't provide enough contrast.
2022-06-27 09:09:33 -04:00
Alan Agius
5a012b5fce fix(@angular/cli): correctly handle --collection option in ng new
Previously, this option was ignored due to an incorrect deconstruction.

Closes #23414
2022-06-27 09:09:13 -04:00
renovate[bot]
04160c58ce build: update all non-major dependencies 2022-06-27 08:15:08 -04:00
Tim Bowersox
8b65abe1b0 fix(@angular/cli): improve global schema validation
- 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.
2022-06-24 09:51:21 -04:00
Alan Agius
3884b86526 fix(@angular/cli): add esbuild browser builder to workspace schema 2022-06-21 12:21:53 -07:00
Alan Agius
ba3f671936 fix(@angular/cli): temporarily handle boolean options in schema prefixed with no
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
2022-06-21 12:21:29 -07:00
Alan Agius
fd92eaa865 fix(@angular/cli): provide an actionable error when using --configuration with ng run
With this commit we issue a more actionable error message when using the unsupported
`--configuration` option with the`ng run` command.

Closes #23385
2022-06-17 16:25:54 +02:00
Charles Lyding
1e21440c10 build: mark external only bazel rules 2022-06-17 16:25:41 +02:00
Alan Agius
4f31b57df3 fix(@angular/cli): disable version check when running ng completion commands
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.
2022-06-16 13:32:39 +02:00
Alan Agius
82ec1af4e1 fix(@angular/cli): show more actionable error when command is ran in wrong scope
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.
2022-06-13 19:22:56 +02:00
Charles Lyding
e41dc3e5fe refactor(@angular/cli): assert catch clause variable type before usage
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`.
2022-06-10 09:26:44 -04:00
Doug Parker
f1dbdb95e0 fix(@angular/cli): correctly print package manager name when an install is needed
This was printing "Try installing with '[object Object] install'".
2022-06-08 15:31:22 -04:00
Alan Agius
f6e8ce2af1 fix(@angular/cli): handle project being passed as a flag
Yargs allows passing using positional arguments as flags. This we should handle this when retrieving the project.

Closes #23291
2022-06-08 10:03:50 -04:00
Alan Agius
79ea0f3ae3 fix(@angular/cli): provide actionable error when project cannot be determined
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.
2022-06-08 10:03:50 -04:00
Alan Agius
13234214a4 docs: remove azure builder reference
This builder is not compatible with newer versions of the Angular CLI.

See https://github.com/angular/angular-cli/issues/23255 for more context

Closes #23255
2022-06-08 09:11:55 -04:00
Charles Lyding
d78826353b fix(@angular/cli): ensure full process exit with older local CLI versions
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
2022-06-07 16:22:38 -04:00
Charles Lyding
f6f37821c8 fix(@angular/cli): improve resilience of logging during process exit
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.
2022-06-06 15:42:12 -04:00
Renovate Bot
450074ff69 build: update all non-major dependencies 2022-06-03 14:54:21 -04:00
Alan Agius
08c87c8d47 fix(@angular/cli): avoid creating unnecessary global configuration
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
2022-06-03 14:52:52 -04:00
Alan Agius
cefbffe6be fix(@angular/cli): add text to help output to indicate that additional commands are available when ran in different context
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.
2022-06-03 14:52:25 -04:00
Alan Agius
1846315b2e fix(@angular/cli): correct scope cache command
Currently, this was being shown available as a global command which shouldn't be the case.
2022-06-03 14:51:50 -04:00
Charles Lyding
ea1f2cee5d refactor(@angular/cli): remove deprecated rmdirSync usage
`rmdirSync` usage can be directly replaced with `rmSync`.
For additional Node.js deprecation details, see https://nodejs.org/docs/latest-v16.x/api/deprecations.html#dep0147-fsrmdirpath--recursive-true-
2022-06-03 14:51:24 -04:00
Charles Lyding
7ddc3fe899 fix(@angular/cli): during an update only use package manager force option with npm 7+
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+.
2022-06-03 14:51:24 -04:00
Doug Parker
81a68c0cde docs: remove hard line wrapping from auto-completion terminal snippet 2022-05-31 11:08:12 -07:00
Charles Lyding
5378557389 fix(@angular/cli): support silent package installs with Yarn 2+
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.
2022-05-27 14:08:11 -04:00
Renovate Bot
fb6ba6748c build: update all non-major dependencies 2022-05-26 11:39:17 -07:00
Charles Lyding
d79176e456 fix(@angular/cli): workaround npm 7+ peer dependency resolve errors during updates
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
```
2022-05-26 11:37:33 -07:00
Alan Agius
b485e48ef8 docs: correct completion.gif image path
Assets paths in AIO need to be relative. This also ensures that the base href element is respected if changed.

https://app.circleci.com/pipelines/github/angular/angular/46755/workflows/ea228e6e-62ab-4d7f-9764-2c1056ad0366/jobs/1173152
2022-05-25 11:10:29 -07:00
Alan Agius
e751464ea3 fix(@angular/cli): populate path with working directory in nested schematics
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`.
2022-05-24 10:19:30 -07:00
Alan Agius
be67977c52 fix(@angular/cli): remove incorrect warning during ng update
The `next` option is not ignored when using the `migrate-only` option. This option is used to determine if a newer version of the CLI needs to be downloaded.

3d76cef369/packages/angular/cli/src/commands/update/cli.ts (L876)
2022-05-24 09:54:08 -07:00
Renovate Bot
0fc1c33a7c build: update all non-major dependencies 2022-05-19 15:00:48 -07:00
Doug Parker
b79b0f0aae fix(@angular/cli): skip prompt or warn when setting up autocompletion without a global CLI install
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.
2022-05-18 10:28:57 -07:00
Doug Parker
f6b52e47a3 docs: add Angular CLI autocompletion doc
This explains how to set up autocompletion with the Angular CLI:

1. Via the automated prompt on first execution.
2. Via `ng completion`.
3. Manually via appending `source <(ng completion script)` to the user's `~/.bashrc` file.

It also specifically calls out supported and unsupported platforms as well as the requirement for a global install of the Angular CLI.
2022-05-18 13:22:59 -04:00
Alan Agius
f99c08ce00 fix(@angular/cli): ng doc doesn't open browser in Windows
In Windows, `process.exit` was being called prior of opening the browser which caused the browser never to open.

Closes #23105
2022-05-18 12:46:05 -04:00
Charles Lyding
5ad5bdad3d fix(@angular/cli): ensure all available package migrations are executed
For v14, the update command migration execution logic was incorrectly exiting after
the success of the first package's migrations. This prevented any other updated
packages from executing migrations automatically. The success check is now a failure
check and will allow the migration execution process to continue to execute migrations
until complete or a failure occurs.
2022-05-18 12:42:50 -04:00
George Kalpakas
9f5550e3a4 fix(@angular/cli): correctly handle --search option in ng doc
When the `--search` option is passed to `ng doc`, it should open a URL
that does a search across the whole website (instead of the default
behavior of limiting the search to API docs).
Fix the `ng doc` command to implement the iteded behavior (previously,
it did the opposite).
2022-05-18 12:03:10 -04:00
Alan Agius
c71832f3a9 fix(@angular/cli): resolve relative schematic from angular.json instead of current working directory
Relative schematics referenced in `angular.json` `schematicCollections` and `defaultCollection` were always resolved from the current working directory, which is not correct and caused the collection not to be resolved when the this is different from the location of the workspace config.

Closes #23136
2022-05-17 14:00:52 -07:00
Alan Agius
f00da00e86 fix(@angular/cli): print schematic errors correctly
Previously, the errors were JSON stringified (https://github.com/angular/angular-cli/blob/main/packages/angular/cli/lib/cli/index.ts#L80) which caused them not to be displayed correctly.

Closes #23141
2022-05-17 14:00:20 -07:00
Renovate Bot
9fd042dcce build: update all non-major dependencies 2022-05-16 09:13:32 -04:00
Renovate Bot
4be7cdce82 build: update all non-major dependencies 2022-05-12 09:43:13 -04:00
Alan Agius
6f8499d2d6 fix(@angular/cli): display option descriptions during auto completion
It appears that enabling this no longer causes a slugish experience.
2022-05-10 10:26:50 -07:00
Renovate Bot
70e6c863f6 build: update all non-major dependencies 2022-05-09 10:43:47 -07:00
Kristiyan Kostadinov
0301cf6c10 build: prepare TypeScript 4.7
Expands the version range to allow TypeScript 4.7 and makes the necessary code changes in order to support it.
2022-05-06 15:51:02 -07:00
Doug Parker
3ab1142983 fix(@angular/cli): improve error message for Windows autocompletion use cases
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.
2022-05-04 17:03:50 -07:00
Doug Parker
fb06228932 feat(@angular/cli): don't prompt to set up autocompletion for ng update and ng completion commands
`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.
2022-05-03 14:38:49 -07:00