84 Commits

Author SHA1 Message Date
Charles Lyding
cb9ee245d1 refactor(@angular-devkit/schematics): assert catch clause variable type before usage
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`.
2022-06-14 11:28:21 +02:00
Charles Lyding
526cdb263a feat(@angular-devkit/schematics): allow chain rule to accept iterables of rules
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.
2022-05-24 09:58:18 -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
Charles Lyding
33f9f3de86 feat(@angular-devkit/schematics): support reading JSON content directly from a Tree
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.
2022-04-26 19:24:55 -04:00
Charles Lyding
01297f4503 feat(@angular-devkit/schematics): support reading text content directly from a Tree
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.
2022-04-26 19:24:55 -04:00
Charles Lyding
25498ad5b2 feat(@angular-devkit/schematics): re-export core string helpers from schematics package
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.
2022-04-22 11:31:53 -04:00
Alan Agius
4b4cecf88f test: update tests to work with Jasmine version 4
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
```
2022-03-24 14:41:26 +01:00
Alan Agius
c9c781c7d5 feat(@angular-devkit/schematics): add parameter to listSchematicNames to allow returning hidden schematics.
The return value of `listSchematicNames` will include hidden schematics when is invoked with true as first parameter.

By default, hidden schematics are not returned.
2022-03-22 09:37:57 -07:00
Tobias Speicher
137651645c refactor: replace deprecated String.prototype.substr()
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
2022-03-21 12:27:52 -07:00
Alan Agius
44c1e6d0d2 refactor(@angular-devkit/schematics): remove deprecated analytics property
BREAKING CHANGE:

Deprecated `analytics` property has been removed from `TypedSchematicContext` interface
2022-01-28 11:01:52 -08:00
Doug Parker
eeccbcd82b build: update some types to be compatible with Node v14
See http://cl/406111801 with the google3 version of this change.
2021-10-29 13:00:03 +02:00
Kristiyan Kostadinov
b776d8d0d7 fix(@angular-devkit/schematics): handle zero or negative length removals in update buffer
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.
2021-10-11 10:24:01 +02:00
Lukas Spirig
0565ed62eb feat(@angular-devkit/schematics): add UpdateBuffer2 based on magic-string
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
2021-08-20 10:04:33 +01:00
Alan Agius
8954d1152b feat(@angular-devkit/schematics): remove deprecated isAction
BREAKING CHANGE:

`isAction` has been removed without replacement as it was unused.
2021-08-10 15:57:08 +02:00
Charles Lyding
1cb07caddc build: transition from ts-api-guardian to dev-infra api-golden utility
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.
2021-07-21 14:55:18 -07: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
Alan Agius
a30525b68b fix(@angular-devkit/schematics): handle updating renamed files
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
2021-06-09 19:59:45 +02:00
Alan Agius
e992c9a70b build: update files to be fix eslint header/header failures 2021-05-04 09:59:40 -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
08753138d3 feat(@angular-devkit/core): update schema validator
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.
2021-04-13 10:51:12 -04:00
Charles Lyding
495459a8a3 fix(@angular-devkit/schematics): merge external schematics after execution
When an `externalSchematic` rule was used, the input tree was branched but never merged back into the input tree.  This resulted in a different tree instance being returned from the rule.  The `externalSchematic` rule now behaves like the `schematic` rule which merges the trees.
2021-02-01 10:30:15 +01:00
Charles Lyding
8688de462e fix(@angular-devkit/schematics): check merge ancestry of delegate & scoped trees
This change ensures correct merge behavior when a `HostTree` is wrapped in a `ScopedTree` or `DelegateTree`.  Previously the ancestry of the HostTree was not available to the merge.
2021-02-01 10:30:15 +01:00
Mike Brocchi
a179828be3 fix(@angular-devkit/schematics): Fix merge that causes an overwrite
This fixes #11337 to allow for merging of a tree with another when the the file already exists in the tree being merged into.
2021-01-28 09:34:43 +01:00
Charles Lyding
0b0961c9c2 refactor(@angular-devkit/schematics): minor cleanup to reduce utility imports 2020-10-21 09:05:45 +02:00
Alan Agius
ffed990258 refactor(@angular-devkit/build-angular): deprecate unused analytics property
TypedSchematicContext `analytics` property has been deprecated without replacement.
2020-10-13 12:47:06 -04:00
Charles Lyding
5ce621e371 fix(@angular-devkit/schematics): resolve external schematics from requesting collection
This change first attempts to resolve a schematic referenced via the external schematic rule from the requesting schematic collection.  This allows schematic packages that are direct dependencies of another schematic package to be used with the external schematic rule without manual package resolution code within the schematic.

Closes #18098
Closes #11026
2020-09-18 14:53:44 -05:00
santoshyadavdev
8880e1c870 refactor(@angular-devkit/schematics): deprecate isAction 2020-09-08 18:28:32 +02:00
Charles Lyding
99f4ff00e1 refactor(@angular-devkit/schematics): allow rule to return void or rule promise
This allows a rule to conditionally not return a followup rule when asynchronous.  This is useful to handle error conditions where no further action should be taken and returning void best expresses this case.
2020-09-01 20:22:00 +03:00
Charles Lyding
4d6488e900 refactor(@angular-devkit/schematics): remove internal use of isAction helper 2020-08-27 21:53:29 +01:00
Charles Lyding
3f780804fd refactor(@angular-devkit/schematics): adjust types to support strict mode 2020-08-12 19:27:38 +01:00
Alan Agius
35c13a62e7 fix(@angular-devkit/schematics): set correct parent id in actions lists
Closes #18446
2020-08-05 12:00:33 -04:00
Alan Agius
05588fcee1 refactor: clean up unused code and imports 2020-07-24 08:01:52 +02:00
arturovt
7e899a111f fix(@angular-devkit/schematics): fix the isBinary function
Closes: #13829
2020-01-02 11:26:28 -08:00
Alan Agius
2aa73efa61 fix(@angular-devkit/schematics): only commit to disk when contents of file changes
Fixes: #16191
2019-11-14 11:10:19 -08:00
Alan Agius
341b18d8a6 refactor(@angular-devkit/schematics): remove several deprecated APIs
BREAKING CHANGE:

Removed several deprecated APIs:

- EngineHost `listSchematics` has been removed in favour of `listSchematicNames`.
- `FileSystemSink` - Use the new virtualFs.Host classes from `@angular-devkit/core`.
- `optimize` function has been remove as trees are automaticlly optimized.
- `DryRunSink` deprecated constructor that allowed to provide a directory path has been removed. Provide a `virtualFs.Host` instead.
2019-10-24 16:02:21 -07:00
Alan Agius
26dd51221a style: collapse if statements (#15449) 2019-08-27 10:25:14 -07:00
Simon Jespersen
0824e8beee refactor(@angular-devkit/schematics): remove optimize from host-tree
Remove unused optimize method marked for removal in version 7.0
2019-08-15 09:55:11 -07:00
Charles Lyding
3fc520278c refactor(@angular-devkit/schematics): update rxjs usage in rules
rxjs has improved over time and this updates the rules to take advantage of improvements where applicable.
2019-05-09 10:11:32 -07:00
clydin
4177b563c5 refactor(@angular-devkit/schematics): minor rule cleanup (#14313) 2019-05-07 12:35:57 -06:00
Charles Lyding
13abfd01ec fix(@angular-devkit/schematics): fully support async rules 2019-04-15 11:02:46 -07:00
Minko Gechev
a355e7d693 feat(@schematics/angular): drop es6 from modern polyfills
1. Remove imports of es6 polyfills introduced by the CLI.
2. Refactor the migrations for version 8 by moving the codelyzer and
polyfill transforms into different files.

The PR drops all `core-js/es6` polyfills that we've introduced with the
CLI, except the commented ones. We do not remove commented imports,
since they are not part of the internal es6 polyfills.

The migration automatically drops the
associated comments with the removed imports since they are part of the node - under its
`jsDoc` property.
2019-03-29 18:06:01 -07:00
Hans Larsen
15032aa2e8 feat(@angular-devkit/schematics): add support for analytics
Schematics context now have an (optional) analytics field that, if set,
should be used to report usage. This can be set even in some cases where
analytics is disabled (to a noop analytics).
2019-03-20 15:08:07 -07:00
clydin
b1477425d9 feat(@angular-devkit/schematics): support unicode character HTML element names (#13837)
The HTML specification allows for a wide variety of characters to be present within a custom element name.  The previous behavior limited the names to mostly alphanumeric characters.  This change opens up the names to include the characters specified within the specification for custom element names.
2019-03-07 16:01:41 -08:00
clydin
324d9f2d4f feat(@angular-devkit/schematics): support basic promise/async based rules (#13660)
Currently, all third-party schematic developers are forced to use and directly depend on `rxjs` if any logic is asynchronous.   Doing so can can also add overhead and unneeded complexity for organizations that have chosen to standardize on async/await usage. This change allows such parties to rely on native promise support if desired.
2019-03-07 15:51:03 -08:00
Alan Agius
ae13974f1d build: update to rxjs 6.4 2019-02-26 08:33:48 -08:00
Alan Agius
1fd4ed6c5d fix(@angular-devkit/schematics): use join instead of normal string concatenation
This leads to cleaner paths while debugging

Fixes #13654
2019-02-13 15:26:51 -08:00
Charles Lyding
d18f89d483 refactor(@angular-devkit/schematics): remove unused VirtualTree classes 2019-01-25 21:42:21 -08:00
Charles Lyding
757bca4edc fix(@angular-devkit/schematics): fully scope merge actions in ScopedTree 2019-01-18 12:14:29 -08:00