904 Commits

Author SHA1 Message Date
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
Doug Parker
2e15df9417 feat(@angular/cli): remember after prompting users to set up autocompletion and don't prompt again
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.
2022-05-03 14:38:49 -07:00
Doug Parker
4212fb8de2 feat(@angular/cli): add prompt to set up CLI autocompletion
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.
2022-05-03 14:38:49 -07:00
Doug Parker
022d8c7bb1 feat(@angular/cli): make ng completion set up CLI autocompletion by modifying .bashrc files
`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.
2022-05-03 14:38:49 -07:00
Renovate Bot
158424fbdc build: update all non-major dependencies 2022-04-29 09:31:05 -07:00
Wagner Maciel
4b07aa345d fix(@angular/cli): change wrapping of schematic code 2022-04-27 12:28:42 -04:00
Daniil Dubrava
78460e995a fix(@angular/cli): remove type casting and add optional chaining for current in optionTransforms 2022-04-18 09:38:31 +02:00
Renovate Bot
41982aa286 build: update all non-major dependencies 2022-04-15 09:42:16 +02:00
Alan Agius
c0eb926121 refactor(@angular-devkit/core): remove custom json parser
With this change we replace the workspace reader and write to use `jsonc-parser` instead of our custom build JSON parser
2022-04-14 17:13:52 +02:00
Alan Agius
bf15b202bb fix(@angular/cli): remove cache path from global valid paths
`cli.cache` cannot be configured globally and therefore it should not be listed as part of the `validCliPaths` Map.
2022-04-13 12:08:25 -07:00
Alan Agius
607a723f7d feat(@angular/cli): add support for auto completion
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
2022-04-13 12:07:45 -07:00
Alan Agius
8eaa680d5f refactor(@angular/cli): remove most of getWorkspaceRaw usages
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`.
2022-04-11 13:40:34 -07:00
Renovate Bot
cb6dd190f2 build: update all non-major dependencies 2022-04-11 11:48:06 -07:00
Alan Agius
ff4eba3d4a fix(@angular/cli): handle duplicate arguments
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-516566614

Closes #22956
2022-04-11 11:46:00 -07:00
Charles Lyding
d87b858d41 refactor(@angular/cli): add infrastructure support for schematics built-in modules
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.
2022-04-11 11:45:43 -07:00
Renovate Bot
78b3537731 build: update all non-major dependencies 2022-04-08 10:10:14 -07:00
Renovate Bot
ebbb0adf56 build: update dependency ini to v3 2022-04-07 14:46:12 -07:00
Renovate Bot
4b05c44d4f build: update all non-major dependencies 2022-04-06 13:00:39 -04:00
Alan Agius
0316dea676 feat(@angular/cli): add prompts on missing builder targets
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.
2022-04-06 10:41:07 -04:00
Alan Agius
3d77846dd7 refactor(@angular/cli): create a memoize decorator
With this change we clean up repeated caching code by creating a `memoize` decorator that can be used on get accessors and methods.
2022-04-01 12:16:34 -04:00
Alan Agius
f11fcaa634 refactor(@angular/cli): remove coercion from packages positional configuration
Configure the `packages` positional argument to be an array instead of using `coerce` method.
2022-03-31 16:32:30 -04:00
Alan Agius
94a9952963 refactor(@angular/cli): change workspace host to use async Node APIs 2022-03-30 20:45:35 +02:00
Alan Agius
811487f027 refactor(@angular/cli): remove unused testing option
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.
2022-03-30 20:45:35 +02:00
Alan Agius
9807291162 refactor(@angular/cli): remove getProjectsByPath config util
We already have a similar method `getProjectByCwd` that does the same thing.
2022-03-30 20:45:35 +02:00
Alan Agius
09f8659ced fix(@angular/cli): display package manager during ng update
This also aligns the output to have the same style of `ng add`
2022-03-30 18:22:30 +02:00
Alan Agius
1bbabb24ca refactor(@angular/cli): create package manager util class
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.
2022-03-30 17:33:37 +02:00
Alan Agius
746d0c596e refactor(@angular/cli): add global configuration in command context
With this change we add the angular configuration as part of the command context.
2022-03-30 17:33:37 +02:00
alkavats1
28721c3e64 refactor(@angular/cli): improved code quality
removed unused parameter and improved code quality
2022-03-30 17:17:27 +02:00
Renovate Bot
6a6386a1ef build: update all non-major dependencies 2022-03-30 17:17:15 +02:00
Alan Agius
efc3c32257 fix(@angular/cli): remove analytics prompt postinstall script
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.
2022-03-29 18:20:55 +02:00
Renovate Bot
17a7fdcd68 build: update all non-major dependencies 2022-03-26 08:25:40 +01:00
Alan Agius
797c652eb5 refactor(@angular/cli): clean up package-metadata retrieval logic
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.
2022-03-24 18:00:31 +01:00