82 Commits

Author SHA1 Message Date
Alan Agius
d94a67353d refactor(@angular/cli): remove deprecated --all option from ng update
BREAKING CHANGE:

`--all` option from `ng update` has been removed without replacement. To update packages which don’t provide `ng  update` capabilities in your workspace `package.json` use `npm update`, `yarn upgrade-interactive` or `yarn upgrade` instead.
2022-01-27 11:06:51 -08:00
Alan Agius
b9cd68f691 fix(@angular/cli): exit with a non-zero error code when migration fails during ng update
In some cases, when a migration fails an error is not thrown, instead the `executeMigration` return a `false` value when resolved.

With this change, we fix an issue were failed migrations resulted in the process of not terminating with a non-zero error code.
2021-11-24 17:12:11 +01:00
Alan Agius
1e9e890bb0 fix(@angular/cli): logic which determines which temp version of the CLI is to be download during ng update
Previously, when using an older version of the Angular CLI, during `ng update`, we download the temporary `latest` version to run the update. The ensured that when running that the runner used to run the update contains the latest bug fixes and improvements.

This however, can be problematic in some cases. Such as when there are API breaking changes, when running a relatively old schematic with the latest CLI can cause runtime issues, especially since those schematics were never meant to be executed on a CLI X major versions in the future.

With this change, we improve the logic to determine which version of the Angular CLI should be used to run the update.

Below is a summarization of this.

- When using the `--next` command line argument, the `@next` version of the CLI will be used to run the update.
- When updating an `@angular/` or `@nguniversal/` package, the target version will be used to run the update. Example: `ng update @angular/core@12`,  the update will run on most recent patch version of `@angular/cli` of that major version `@12.2.6`.
- When updating an `@angular/` or `@nguniversal/` and no target version is specified. Example: `ng update @angular/core` the update will run on most latest version of the `@angular/cli`.
- When updating a third-party package, the most recent patch version of the installed `@angular/cli` will be used to run the update. Example if `13.0.0` is installed and `13.1.1` is available on NPM, the latter will be used.
2021-11-23 07:44:53 +01:00
Alan Agius
57d7eb5b16 fix(@angular/cli): error when updating Angular packages across multi-major migrations
With this change we show an error message when users try to update `@angular/` and `@nguniversal/` packages across multiple major versions.
2021-10-26 04:45:18 -05:00
Alan Agius
ebf2d62535 fix(@angular/cli): run stable migrations when package version is prerelease
With this change we fix an issue were migrations are not run when the version specified in migration collection is specified as stable example `13.0.0`, but the version specified in the `package.json` is still a prerelease example `13.0.0-rc.0`.

Closes: #21969
2021-10-18 11:24:16 -04:00
Charles Lyding
d8c9f6eaf4 fix(@angular/cli): update the update command to fully support Node.js v16
Node.js v16's `fs.rmdir` will now throw an `ENOENT` error if the path does not exist. `fs.rm` is now the preferred option when using Node.js v16 but since this function is not available on Node.js v12 both are tried with `fs.rm` given preference.
In the case of the update command, the usage was guarded by a try/catch block with the downside of leaving the `fs.rmdir` being that a deprecation warning would be shown when running the command which is not ideal.
2021-10-06 06:11:09 -05:00
Alan Agius
31ec09c111 refactor(@schematics/angular): remove migrations for unsupported versions 2021-09-24 15:38:33 -04:00
Charles Lyding
6f4bf38e9c refactor(@angular/cli): convert npm-pick-manifest usage from require to import
The removal of require usage supports the eventual shift to an ESM output for the CLI package.
2021-08-25 11:40:51 +01:00
Charles Lyding
9a828a4459 refactor(@angular/cli): convert npm-package-arg usage from require to import
The typings package was already present for `npm-package-arg` and the removal of require usage supports the eventual shift to an ESM output for the CLI package.
2021-07-27 12:52:02 -04:00
Charles Lyding
9afe185fc6 build: enable noImplicitOverride TypeScript option
The `noImplicitOverride` TypeScript option improves code quality by ensuring that properties from base classes are not accidentally overriden.
Reference: https://www.typescriptlang.org/tsconfig#noImplicitOverride
2021-07-02 06:40:36 -04:00
Charles Lyding
c1623c429e refactor(@angular/cli): use version class instead of requiring package.json
The CLI contains a helper class instance that provides the version of the executing CLI. By using this helper throughtout the code, repeat `require` calls are no longer necessary.
2021-06-22 17:39:38 +01:00
Charles Lyding
6926b37c0c fix(@angular/cli): clean node modules directory prior to updating
Prior to performing the initial updated package installation during the `ng update` process, the workspace node modules directory will be removed. This cleaning increases the guarantees that the package manager will hoist packages into the correct locations and avoid peer dependency inconsistencies.
2021-05-17 08:38:04 +02:00
Charles Lyding
3d8c16a433 fix(@angular/cli): propagate update's force option to package managers
When the CLI update command's `--force` option is used, the underlying package manager will also be executed with its force option. This behavior is especially important with the advent of npm 7 which will fail installation if any peer dependency version ranges are mismatched.
2021-05-10 16:21:25 +01:00
Alan Agius
d7ef0d0730 fix(@angular/cli): change package installation to async
With this change we change the package installation to async. This is needed as otherwise during `ng-add` the spinner gets stuck. With this change we also add the spinner in the installation methods.
2021-05-05 11:49:08 -04:00
Charles Lyding
c1512e4274 build: update files to be eslint compliant
All TypeScript files have been updated to pass the new eslint-based linting checks. eslint compatible disabling comments have also been added in place of the previous tslint comments.
2021-05-03 07:31:02 -04:00
Charles Lyding
37a06a7c37 build: format all files
All files are now formatted using the ng-dev tools via prettier.
2021-04-28 16:05:49 -07:00
Joey Perrott
003854257c build: migrate all file header to use Google LLC rather than Google Inc 2021-04-27 08:35:22 +02:00
Alan Agius
131379f49f fix(@angular/cli): run all migrations when updating from or between prereleases
With this change we consider the update schematics are idempotent. When updating from or between prereleases we will execute all migrations for the version.
2021-04-19 20:28:53 +02:00
Alan Agius
d68cb92dc2 fix(@angular/cli): add message update updating from non LTS versions of the CLI 2021-04-14 17:20:33 -04:00
Charles Lyding
2dd0cbd2e9 refactor(@angular/cli): inline @schematics/update:update schematic
This change removes the need for the `@schematics/update` package within the Angular tooling and removes the dependency from the `@angular/cli` package.
Only the `update` schematic from the `@schematics/update` package was used and this schematic's logic will eventually be folded into the update command logic directly.
2021-03-29 08:18:11 -06:00
Alan Agius
4b0223b64e build: automate @angular/cli schema.json generation
With this change we automate the generation of `@angular/cli/lib/config/schema.json`. While on paper we could use quicktype for this. Quicktype doesn't handle `patternProperties` and `oneOf` that well.

How does this works?
Relative `$ref` will be resolved and inlined as part of the root schema definitions.

Example
```json
"@schematics/angular:enum": {
    "$ref": "../../../../schematics/angular/enum/schema.json"
},
```

Will be parsed and transformed to
```json
"@schematics/angular:enum": {
  "$ref": "#/definitions/SchematicsAngularEnumSchema"
},
"definitions: {
  "SchematicsAngularEnumSchema": {
    "title": "Angular Enum Options Schema",
    "type": "object",
    "description": "Generates a new, generic enum definition for the given or default project.",
    "properties": {...}
   }
}
```
2021-03-11 21:51:37 +01:00
Charles Lyding
3d99468b45 fix(@angular/cli): support update migration packages with no entry points
Some schematic only packages may not have entry points defined (`main`/`exports`).  These type of packages will now be correctly resolved when attempting to locate update migrations.

Fixes #20032
2021-02-17 12:43:13 -06:00
Charles Lyding
9a44bf4aaf fix(@angular/cli): improve error logging when resolving update migrations
Failure to resolve a migration package from the workspace root will now not crash and instead error with a message.  Verbose logging (`--verbose`) is also added to provide more details regarding the resolution process.
2021-02-11 14:25:55 -05:00
Alan Agius
cae2209ca8 fix(@angular/cli): only show incompatible NPM error when NPM is used as package manager 2021-02-05 12:40:47 -05:00
Charles Lyding
331f628139 fix(@angular/cli): temporarily limit npm to version 6
This change will display an error message if using npm 7 (or versions earlier than 6). This is a temporarily change while npm 7 usability concerns are addressed.
2021-02-04 14:59:40 -08:00
Charles Lyding
30758d1cc4 fix(@angular/cli): resolve migration collections from containing package
This change ensures that migration collections defined in a package's `ng-update` metadata are resolved from the containing package.  This avoids issues that may arise from package manager hoisting behavior which can result in the wrong migration collection being chosen.  The `--migrate-only` option already contained this resolution logic and now the full update contains it as well.
2021-02-03 12:21:52 -05:00
Charles Lyding
86d69e22fb fix(@angular/cli): redirect Angular schematic dependency requests to known versions
This change adds logic to redirect module resolution requests for Angular schematics to ensure that the correct versions of core schematic related packages are used.  This also ensures that the runtime version of the schematics package matches the version used inside the schematic and that object instances passed into the schematic are compatible.
The current set of core schematic related packages are `@angular-devkit/*` and `@schematics/angular`.  Only first-party Angular schematics are currently affected by this change.
2021-01-28 12:44:34 +01:00
Lukas Spirig
01c99e9cd8 fix(@angular/cli): correctly read transitive dependency
For `ng update --migrateOnly ...` the update implementation checks for transitive
dependencies and tries to parse the containing directory as JSON. This PR
fixes this by providing the correct path to the package.json.
2020-11-03 17:43:14 -06:00
Alan Agius
212374a5f1 refactor(@angular/cli): remove install-package under utils
Remove the lone `install-package.ts` file from tasks to utilities
2020-10-19 19:28:13 +02:00
Drummond Dawson
7254d18ccb fix(@angular/cli): add blank line in migration commit message
Adds a blank line in the commit message between the subject and body in order to properly separate the two.
2020-10-04 16:50:00 -04:00
Charles Lyding
d903d39fc8 refactor(@angular/cli): use new NodeWorkflow schematic features
This change reduces the amount of schematic runtime setup code by leveraging the new options for the root path and schema validation in the NodeWorkflow class.
2020-10-02 18:56:11 -04:00
Charles Lyding
b2b536789b refactor(@angular/cli): discover/load workspace on startup
Previously, the workspace configuration file was found and loaded by individual commands potentially multiple times.  This change moves the initial workspace location discovery and loading of the workspace to the CLI startup.  It also provides the workspace to each command so that the commands can reuse the already loaded and parsed workspace configuration.
2020-10-02 07:53:07 -04:00
Alan Agius
824add1778 fix(@angular/cli): no-op ng update --all
'--all' functionality has been removed from `ng update` as updating multiple packages at once is not recommended. To update the depencencies in your workspace 'package.json' use the update command of your package manager.

Closes #15278
Closes #13095
Closes #12261
Closes #12243
Closes #18813
2020-09-29 16:48:51 +02:00
Alan Agius
64cc005f0b refactor: change UPDATE action color to cyan 2020-09-14 16:36:30 -04:00
Alan Agius
a21eb1588e fix(@angular/cli): improve logs in ng update
These addresses;
- When a large number of migration are executed, it's hard to differentiate between the title and description.
- Fix alignments of logs
2020-09-14 16:36:30 -04:00
Andrei Alecu
d01d647431 refactor(@angular/cli): improve update package discovery 2020-09-03 18:21:06 +02:00
Charles Lyding
5275892f63 refactor(@angular/cli): remove any type usage 2020-08-24 07:50:01 -04:00
Alan Agius
c824bbb4f7 refactor(@angular/cli): update CLI package to be strict compliant 2020-08-12 19:29:13 +01:00
Alan Agius
ef465487fd fix(@angular/cli): resolve external schematics from workspace root
Resolve schematics collections from the workspace root, as otherwise it will be resolved from the temporary installed CLI version

Closes #18083
2020-07-01 11:29:25 -07:00
Alan Agius
4f50aa0e40 fix(@angular/cli): display post migration message when updating from previous major version
Fixes #17256
2020-03-23 14:18:06 -07:00
Alan Agius
66b218c5f6 fix(@angular/cli): print ng update errors stack to log file
When an error occurs during ng update we currently discard the stack trace which in some cases made it hard to identify the cause of the error.

Now, we print the stack trace to a log file similarly to unhandled exceptions.

Example of CMD output;
```cmd
** Executing migrations of package '@angular/core' **

> Static flag migration.
  Removes the `static` flag from dynamic queries.
  As of Angular 9, the "static" flag defaults to false and is no longer required for your view and content queries.
  Read more about this here: https://v9.angular.io/guide/migration-dynamic-flag
× Migration failed: x
  See "C:\Users\alag\AppData\Local\Temp\ng-NgmC1G\angular-errors.log" for further details.
```

Example of log file contents:
```txt
[error] Error: x
    at UpdateCommand.executeSchematic (C:\git\angular-cli\test\node_modules\@angular\cli\commands\update-impl.js:98:19)
    at UpdateCommand.executePackageMigrations (C:\git\angular-cli\test\node_modules\@angular\cli\commands\update-impl.js:167:39)
    at UpdateCommand.executeMigrations (C:\git\angular-cli\test\node_modules\@angular\cli\commands\update-impl.js:161:21)
    at UpdateCommand.run (C:\git\angular-cli\test\node_modules\@angular\cli\commands\update-impl.js:394:38)
    at async UpdateCommand.validateAndRun (C:\git\angular-cli\test\node_modules\@angular\cli\models\command.js:134:28)
    at async Object.runCommand (C:\git\angular-cli\test\node_modules\@angular\cli\models\command-runner.js:201:24)
    at async default_1 (C:\git\angular-cli\test\node_modules\@angular\cli\lib\cli\index.js:62:31)
```
2020-02-18 12:43:35 -08:00
John Papa
5f3ff00dd8 fix(@angular/cli): added clarity on angular cli version issues
fixes #16888
2020-02-10 16:01:49 -08:00
Charles
835100c908 refactor(@angular/cli): allow update version check to be disabled (#16543)
This allows the CLI version check during update bootstrapping to be disabled via the `NG_DISABLE_VERSION_CHECK` environment variable.  This is not considered an officially supported option and is intended mainly for testing/troubleshooting scenarios.
2020-01-04 11:13:53 -08:00
Charles
d9d233e39a fix(@angular/cli): inform user and error if schematics package is in unreachable location (#16466)
This is a workaround for the schematics runtime to support the requirement of packages containing migrations (or other schematics) to not have a direct/runtime dependency on the schematics package.

Closes: #16392
2019-12-20 16:34:05 -08:00
Alan Agius
35ca3901ac refactor: strip leading slash to prevent confusion 2019-12-02 10:10:34 -08:00
Alan Agius
0ee5f2fdb9 fix(@angular/cli): support running a single migration from a package 2019-11-15 10:43:07 -08:00
Doug Parker
823c6589ae fix(@angular/cli): Renames final message to "Migration completed". (#16016)
We don't actually know for certain that the migration was successful, only that it finished. This updates the messaging to be more clear about this distinction. I also removed the check mark and green coloring which implied success.
2019-11-13 11:11:14 -08:00
Alan Agius
a6f3d14c08 fix(@angular/cli): clarify ng update outdated message 2019-11-12 11:46:07 -08:00
Doug Parker
208a7008b0 fix(@angular/cli): Prints out when a commit is made in ng update.
Fixes #16060.

Any time a `git commit` is made, the CLI now prints out the hash and short message. For migrations, the message is simply the first line of the commit. For schematics, the commit message isn't all that helpful, so I used the list of packages instead.
2019-11-11 16:51:44 -08:00
Alan Agius
524bff6f43 fix(@angular/cli): add link to update guide post running Angular migrations 2019-11-09 11:52:42 -08:00