Prepares the `@angular-devkit/schematics` 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`.
Yarn 2 and higher no longer support the `--ignore-scripts` flag.
The `NodePackageInstallTask` will now spawn Yarn with environment variables to ignore
scripts instead of the commandline option. Other package managers remain unchanged.
This provides the necessary functionality for the task without relying on Yarn
commandline options.
Yarn 2 and higher no longer support the `--silent` flag.
The `NodePackageInstallTask` will now spawn package managers with the stdout ignored when quiet
mode is needed and only show stderr when the process exits unsuccessfully. This
provides the necessary functionality for the task without relying on package manager
options.
Previously, the `chain` base rule only accepted an `Array` of schematics rules.
In addition to still allowing an `Array`, `chain` now can accept either an `Iterable<Rule>`
or `AsyncIterable<Rule>`. This provides support for sync and async generator functions
with the `chain` rule.
In an effort to improve supply chain security, the `NodePackageInstallTask` will now use the package
manager's `--ignore-scripts` option by default. Without the option, all direct and transitive
dependencies would have their scripts executed during the task's package manager installation operation.
The change only affects the package manager behavior controlled by the Schematics `NodePackageInstallTask`.
First-party Angular schematics do not currently require any direct or transitive dependency
`install`/`postinstall` scripts to execute. Only two dependencies within a v14.0 new project would
potentially be affected by this: `nice-napi` (transitive from `piscina`) and `esbuild`. The `nice-napi`
functionality of `piscina` is unused within the Angular CLI with no plans to use it in the future.
Even if it was used, the `install` script runs `node-gyp-build` which would only have an effect
(based on the current version 1.0.2) on platforms that are not Windows, darwin-x64, or linux-x64.
In the event this functionality is eventually used, the Angular CLI could be setup to automatically execute
this particular script for unsupported platforms. For `esbuild`, the `postinstall` functionality
performs an optional native binary bootstrap optimization but would only be performed if not
using Windows or Yarn. As such, it would not be performed for many users regardless of the change in
this commit. If noticeable performance regressions on platforms where the optimization was previously
performed are reported, the script could also be setup to be automatically run by the Angular CLI during
project creation and/or first build.
BREAKING CHANGE: Schematics `NodePackageInstallTask` will not execute package scripts by default
The `NodePackageInstallTask` will now use the package manager's `--ignore-scripts` option by default.
The `--ignore-scripts` option will prevent package scripts from executing automatically during an install.
If a schematic installs packages that need their `install`/`postinstall` scripts to be executed, the
`NodePackageInstallTask` now contains an `allowScripts` boolean option which can be enabled to provide the
previous behavior for that individual task. As with previous behavior, the `allowScripts` option will
prevent the individual task's usage of the `--ignore-scripts` option but will not override the package
manager's existing configuration.
The schematics `Tree` now contains an additional `readJSON` method that supports directly
reading and parsing the content of a file as UTF-8 JSON with comment support. This avoids the need to manually
decode a Buffer, parse and handle JSON comments within a schematic when JSON content is needed.
If a file path does not exist, an exception will be thrown. While this differs from the semantics of `read`,
it helps reduce the amount of code needed for common schematic use cases. JSON parse errors will also result
in an exception being thrown with a message detailing the error.
The schematics `Tree` now contains an additional `readText` method that supports directly
reading the content of a file as UTF-8 text. This avoids the need to manually decode a Buffer
within a schematic when text content is needed. If a file path does not exist, an exception
will be thrown. While this differs from the semantics of `read`, it helps reduce the amount
of code needed for common schematic use cases.
The string helpers are predominantly used within schematics that will already depend and import from
the `@angular-devkit/schematics` package. By re-exporting from `@angular-devkit/schematics`, the need
to directly depend and import `@angular-devkit/core` within a schematic can be reduced and in many
cases eliminated.
The `_resolveReferenceString` abstract method of the `FileSystemEngineHostBase` class now has a third parameter
that provides the collection description of the schematic currently being resolved. This allows the resolver to
use any fields/options present within the collection description to adjust the resolution of the schematic. The
`encapsulation` optional field is also added to the `FileSystemCollectionDescription` type which will in the future
allow control of the `@angular/cli` VM context wrapping on an individual schematic collection basis.
These changes include fixes to tests, timeout and stop of architect to make tests work with Jasmine 4.
One noticeable change that when we didn't stop architect through `run.stop()` this causes Bazel to timeout now.
Example
```
-- Test timed out at 2022-03-24 12:07:07 UTC --
/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/sandbox/darwin-sandbox/398/execroot/angular_cli/bazel-out/darwin-fastbuild/bin/packages/angular_devkit/build_angular/build_angular_browser_test.sh.runfiles/angular_cli/packages/angular_devkit/build_angular/build_angular_browser_test.sh: line 424: 41835 Terminated: 15 "${node}" ${LAUNCHER_NODE_OPTIONS[@]+"${LAUNCHER_NODE_OPTIONS[@]}"} ${USER_NODE_OPTIONS[@]+"${USER_NODE_OPTIONS[@]}"} "${MAIN}" ${ARGS[@]+"${ARGS[@]}"} 0<&0
```
The return value of `listSchematicNames` will include hidden schematics when is invoked with true as first parameter.
By default, hidden schematics are not returned.
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
* docs: fix character code in expression example
Add '\' prefix so character code is rendered literally,
not as the character it represents.
* docs: format readme.md
Run `ng-dev format files` on readme.md.
This came up while fixing an issue in a Framework migration (https://github.com/angular/angular/pull/43776/files#diff-365738677fa9dfb9fb2c4fac7c75addb58e5a35182603e722e736cc3f24bbf5bR55). The `UpdateBuffer` stops recording changes if a removal with a zero length occurs. This doesn't appear to be an issue with `UpdateBuffer2`, but considering that the former is still being used and that the fix is trivial, I decided to proceed with it.
I've also aligned the behavior between `UpdateBuffer` and `UpdateBuffer2` when dealing with negative removals.
rules_nodejs 4 requires that a package_name property be specified within a ts_library rule for the output to be linked into the package repository. Failing to add the property can cause test failures due to unresolved packages.
This PR adds UpdateBuffer2 which should eventually
replace UpdateBuffer. UpdateBuffer2 internally uses
the magic-string library.
UpdateBuffer and related symbols have been marked
as deprecated.
Closes#21110
BREAKING CHANGE:
With this change we remove the following deprecated APIs
- `TslintFixTask`
- `TslintFixTaskOptions`
**Note:** this only effects schematics developers.
The dev-infra tooling now directly provides public API change testing capabilities that leverage the `api-extractor` utility. These new testing capabilities are shared with framework and components.
`ts-api-guardian` has been removed as a dependency as a result.
The new public API tooling searches for nested package.json files to determine the location of secondary entrypoints. All secondary entrypoints for the CLI related packages now contain a secondary entrypoint package.json file.
The internal monorepo package discovery script was also updated to support the presence of the nested package.json files.
The `esModuleInterop` option is recommended to be enable by TypeScript and corrects several assumptions TypeScript would otherwise make when importing CommonJS files.
This option change helps ensure compatibility as packages move towards ESM.
Reference: https://www.typescriptlang.org/tsconfig#esModuleInterop
With this change we fix an issue which caused a file not found error when trying to modify the file after it was renamed.
Closes#14255 and closes#21083
This change allows consumers of the `NodeWorkflow` to configure the package installation task to use a package manager's `--force` option. This will be used by the `@angular/cli` update command when the update command's force option is used. This change is not intended to enable a schematic to adjust the force option.
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.
With this change we update ajv to version 8
BREAKING CHANGE: support for JSON Schema draft-04 and draft-06 is removed. If you have schemas using the `id` keyword replace them with `$id`. For an interim period we will auto rename any top level `id` keyword to `$id`.
**NB**: This change only effects schematics and builders authors.