1125 Commits

Author SHA1 Message Date
Alan Agius
88fddc0503 fix(@schematics/angular): remove bootstrapping wrapping in universal schematic
The bootstrapping wrapping is no longer necessary as of 15.1.3. See: https://github.com/angular/angular/pull/48868
2023-02-07 01:00:50 +00:00
Alan Agius
7b0c1ce0ca fix(@schematics/angular): update browserslist config to include last 2 Chrome version
https://github.com/angular/angular/pull/48669 added support for the last 2 Chrome versions
2023-01-20 18:37:22 +00:00
Alan Agius
c8a3b30000 fix(@schematics/angular): replace existing BrowserModule.withServerTransition calls when running universal schematic
This change fixes an issue where calling the universal schematic on an application with existing `BrowserModule.withServerTransition` will cause an additional `.withServerTransition` call to be added.

With this change we now remove the previous `withServerTransition` call to avoid misconfiguration.

Closes #24563
2023-01-18 17:13:23 +00:00
Alan Agius
e763db8691 refactor: change JSONFile to private instead of internal
This is so that this can be used in the Universal repo which is not failing because the type is not available.

https://app.circleci.com/pipelines/github/angular/universal/4483/workflows/25535db2-4a9c-43b0-84a5-3a55071013c6/jobs/20263
2023-01-12 14:32:16 +00:00
Alan Agius
ef39987e59 build: update Angular peer deps to support ^15.2.0-next.0 2023-01-12 12:24:11 +00:00
Alan Agius
759344d2e9 refactor(@schematics/angular): remove unused local variables
`messages` is unused from the spec and thus can be removed.
2023-01-09 14:40:33 +00:00
Angular Robot
df5ca315a6 build: update all non-major dependencies 2023-01-06 15:04:14 +00:00
Charles Lyding
7f93735e98 build: use bazel to perform release builds
When performing a release via the dev-infra `ng-dev` tooling, the release
builds for the packages that will be published are now performed using bazel.
Prior to this, the release builds were performed using a custom build script
that programmatically invoked TypeScript APIs. The Bazel build and discovery
process for the releasable packages is performed by a script that is based on
the scripts from components and framework repositories. Several small modifications
were performed to match the behavior and structure of the cli repository:
* Use of `packages` as the source root in the bazel query
* Use of `pkg_npm` rule in the bazel query
* Partial transition to native Node.js `fs` APIs instead of `shelljs`
* Directory creation per package when copying output (supports multiple package scopes)
* Copying of archives (tgz) for each package

The snapshot and local build capabilities are not modified as part of this change
but will be merged in a followup as part of a larger transition to use bazel
throughout the package build process.
2023-01-05 03:21:58 +00:00
Kristiyan Kostadinov
ba895b1af6 build: update to TypeScript 4.9
Updates the project to TypeScript 4.9.
2023-01-03 16:46:36 +00:00
Alan Agius
dd2b65943d feat(@schematics/angular): add configuration files generation schematic
This commits add a schematic to generate Karma and Browserlist files which since version 15 are no longer generated by default. This schematic should be used to generate these files when further customisation is needed.

Usage
```
ng generate config karma
ng generate config browserlist
```

Closes #24294
2023-01-03 14:53:44 +00:00
Alan Agius
ace34b7af3 docs: remove default project from schematic description
The default project is deprecated.
2023-01-03 14:49:19 +00:00
Charles Lyding
8d000d1563 feat(@schematics/angular): add environments generation schematic
A schematic has been added that will allow the generation of environment files
for all existing configurations within a project. The `fileReplacements` option
will also be setup to allow the replacement of the appropriate environment file.
Environment files themselves do not provide any special behavior beyond
that of other application TypeScript files and rely on the `fileReplacements`
option for build-time behavior. The schematic will skip generating environment files
for configurations that already have an appropriately named environment file. The
`fileReplacements` option addition will also be skipped if an appropriate entry
is already present.
2022-12-13 14:27:48 +00:00
Alan Agius
207358afb8 feat(@angular-devkit/schematics): add runSchematic and runExternalSchematic methods
These async methods are a replacement for the Observable based `runSchematicAsync` and `runExternalSchematicAsync` methods.

DEPRECATED:
The Observable based `SchematicTestRunner.runSchematicAsync` and `SchematicTestRunner.runExternalSchematicAsync` method have been deprecated in favor of the Promise based `SchematicTestRunner.runSchematic` and `SchematicTestRunner.runExternalSchematic`.
2022-12-08 14:49:43 -08:00
Angular Robot
3d885fbb21 build: update all non-major dependencies 2022-12-08 12:09:04 -08:00
Alan Agius
5b18ce1545 feat(@schematics/angular): add guardType as an alias of implements in guard schematic
`implements` option will be removed in future in favor of `guardType`. This is because the implements guard pattern is deprecated in version 15.1
2022-12-05 11:07:46 -08:00
ced
49b313f27a fix(@schematics/angular): add missing import for functional interceptor spec 2022-12-02 09:04:50 +00:00
ced
2f92fe7e58 fix(@schematics/angular): add missing semicolon in functional guard/resolver/interceptor 2022-12-02 09:04:22 +00:00
ced
b11d3f6442 fix(@schematics/angular): use proper variable in functional guard spec 2022-11-28 14:02:26 +00:00
ced
451975f765 fix(@schematics/angular): use proper variable in resolver functional spec 2022-11-28 13:54:17 +00:00
ced
9b6d190f4a fix(@schematics/angular): remove EnvironmentInjector import in functional guard spec
It is unnecessary now that the spec uses `runInInjectionContext`
The resolver spec does not have this issue as the import was missing in the spec in the first place.
2022-11-28 13:38:08 +00:00
Andrew Scott
978274cb0b refactor(@schematics/angular): Use runInInjectionContext shorthand
The runInInjectionContext helper was added in 6acae1477a.
This is a shorthand for TestBed.inject(EnvironmentInjector).runInContext.
2022-11-28 13:16:52 +00:00
ced
9299dea649 feat(@schematics/angular): generate functional interceptors
Adds a `--functional` flag to the interceptor schematic to generate a functional interceptor (as we can now do for guards and resolvers)
2022-11-28 13:16:36 +00:00
Alan Agius
5a123a61ea fix(@schematics/angular): show warning when a TS Config is not found during migrations
Prior to this change an error was shown when a non existing tsconfig was referenced in the angular.json. This causes the update to fail.

Closes #24264
2022-11-17 16:32:11 -08:00
Alan Agius
11bb8ce26f perf(@angular-devkit/build-angular): add vendor chunking to server builder
With this change we add the `vendorChunk` option in the server builder. This option should only be used in development as it is intended to be used to improve the incremental re-build time.

This improves the rebuild time as Webpack will have less modules to analyse during a change in the application. Below, we can see the impact this change has in a `ng new` application.

Without vendor chunking
```
$ ng run ssr-vendor:server:development --watch --no-vendor-chunk
Build at: 2022-11-14T08:42:27.089Z - Hash: 0325905b63e43ddb - Time: 15357ms
Build at: 2022-11-14T08:42:37.565Z - Hash: 05cb180a02524656 - Time: 2498ms
Build at: 2022-11-14T08:42:40.325Z - Hash: c5a6996ed1924088 - Time: 1862ms
Build at: 2022-11-14T08:42:43.043Z - Hash: 92ce99f38a769c19 - Time: 1516ms
```

With vendor chunking
```
$ ng run ssr-vendor:server:development --watch --vendor-chunk
Build at: 2022-11-14T08:43:13.631Z - Hash: 28bdfea879d01a31 - Time: 15561ms
Build at: 2022-11-14T08:43:19.396Z - Hash: cc95e2b6cb403111 - Time: 1705ms
Build at: 2022-11-14T08:43:21.296Z - Hash: 204138490668a16c - Time: 848ms
Build at: 2022-11-14T08:43:23.835Z - Hash: 4fa294b261917944 - Time: 824ms
```
2022-11-15 10:14:02 -08:00
Angular Robot
363721bc88 build: update all non-major dependencies 2022-11-10 10:10:42 +01:00
Andrew Scott
b34c719769 fixup! feat(@schematics/angular): Add schematics for generating functional router guards and resolvers 2022-11-09 09:34:07 +01:00
Andrew Scott
6c39a162be feat(@schematics/angular): Add schematics for generating functional router guards and resolvers
Functional guards and resolvers were introduced in the Angular router in v14.2.
This commit adds the ability to generate functional router guards by
specifying `--guardType` instead of `--implements`. These guards are also
accompanied by a test that includes a helper function for executing the
guard in the `TestBed` environment so that any `inject` calls in the
guard will work properly. Functional resolvers are generated by adding
the `--functional` flag.
2022-11-09 09:34:07 +01:00
Andrew Scott
f837f6dab4 fix(@schematics/angular): guard schematics should include all guards (CanMatch)
The `CanMatch` guard was added in v14.1 but not added
to the list of possible interfaces to implement.
This commit adds `CanMatch` to the list of possible
interfaces to implement. It has the same type imports
as the CanLoad interface.
2022-11-02 08:49:38 -07:00
Angular Robot
469ad87499 build: update all non-major dependencies 2022-10-31 10:11:58 -07:00
Alan Agius
3ea658818d fix(@schematics/angular): remove TypeScript target from universal schematic
This is no longer needed due to the recent changes in the CLI which always use ES2022.
2022-10-26 08:57:33 -07:00
Felix Hamann
62121f89ab feat(@schematics/angular): add sideEffects:false to library package.json 2022-10-25 10:50:17 -07:00
Alan Agius
b29ae2feda fix(@schematics/angular): add @angular/localize as type when localize package is installed
The `@angular/localize` entrypoint now exposes the global `$localize` method type.

See: https://github.com/angular/angular/pull/47763
2022-10-21 10:32:24 -04:00
Cédric Exbrayat
a1d596cdee test(@schematics/angular): test names typos 2022-10-12 11:37:15 +02:00
Alan Agius
979bce45e6 feat(@angular-devkit/build-angular): auto include @angular/platform-server/init during server builds
This changes removes the need to import `@angular/platform-server/init` in the `main.server.ts` instead we now include this as an entry-point when we are bundling as server bundle.
2022-10-12 08:57:29 +02:00
Alan Agius
a95d130ef4 feat(@angular-devkit/build-angular): auto include @angular/localize/init when found in types
With this change we remove the need to include the `@angular/localize/init` package as polyfills in `polyfills.ts`, `angular.json` and `main.server.ts`.

Instead when `@angular/localize/init` is included in the TypeScript `types` we add this as entry-point. The `@angular/localize/init` will be added as a parts of the `types` array in a seperate PR to address https://github.com/angular/angular/issues/47677 which is caused by the fact that `@angular/localize/init` types are no longer imported when `@angular/localize/init` is added as a polyfill in `angular.json`.
2022-10-12 08:57:29 +02:00
Alan Agius
639a3071c3 refactor: migrate analytics collector to use GA4
This change updates the analytics collector collector to use GA4 instead of UA. The motivation behind this change is that UA will stop collecting data in 2023.

BREAKING CHANGE:

`analyticsSharing` option in the global angular configuration has been
removed without replacement. This option was used to configure the Angular CLI to  access to your own users' CLI usage data.

If this option is used, it can be removed using `ng config --global cli.analyticsSharing undefined`.
2022-10-11 18:52:30 +02:00
Günhan Gülsoy
2230374e18 refactor: remove add implicate types for better code readability
When strictNullChecks in enabled in TS compiler, the following files
cause some failures in certain environments. Fix these failures.
Also update outdated goldens.
2022-10-10 12:22:56 +02:00
Alan Agius
b06421d15e feat(@schematics/angular): mark projectRoot as non hidden option in application schematic
This option is useful to create an application outside of the `newProjectRoot`.

Related to https://github.com/angular/angular-cli/pull/23994
2022-10-07 11:09:43 -04:00
Dariusz Ostolski
d8bff4f1e6 feat(@schematics/angular): Added --project-root option to the library schematics
With this change user is able to specify different project root for libraries than default one.

Closes: #11927
2022-10-07 10:51:31 -04:00
Alan Agius
f2a0682dc8 feat(@schematics/angular): generate new projects using TypeScript 4.8.2
Older versions of TypeScript are no longer supported.
2022-10-07 10:37:21 -04:00
Alan Agius
301b5669a7 feat(@schematics/angular): remove ngOnInit from component template
This commit removes the `constructor` and `ngOnInit` as most of the users prefer to add this manually if needed.

Closes #23678
2022-10-04 12:45:30 -04:00
Cédric Exbrayat
84e3f7727d fix(@schematics/angular): remove empty lines
The recet removal of enableProdMode in 283b564d1de985f0af8c2fcb6192801a90baacda introduced unnecessary empty lines in main.ts
2022-09-29 18:58:01 +02:00
Alan Agius
b6897dbb0a feat(@schematics/angular): remove karma.conf.js from newly generated projects
`@angular-devkit/build-angular` now has a built in Karma config. Users can still create their own Karma configuration if they want to override the default configuration.
2022-09-28 17:37:53 +02:00
Alan Agius
283b564d1d feat(@schematics/angular): remove environment files in new applications
This commit removes the usage of environment files and `fileReplacements` in new application projects. Previously, the environment files was used to distinguish between a prod build to invoke `enableProdMode`. The `enableProdMode` however needed only for the case of JIT mode in production mode, which is a rare case as JIT mode is recommanded to be used in production.

In the CLI, calling `enableProdMode` is not needed as `ngDevMode` it's set using the minifier.
2022-09-27 19:48:34 +02:00
Alan Agius
56a1e8f9f5 feat(@schematics/angular): remove test.ts file from new projects
The test.ts is now included in `@angular-devkit/build-angular` and unless this needs to be customized is no longer needed to be provided.

Default config:
```js
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
  errorOnUnknownElements: true,
  errorOnUnknownProperties: true
});
```
2022-09-27 18:59:08 +02:00
Alan Agius
597bfea1b2 feat(@schematics/angular): drop polyfills.ts file from new templates
With this change we drop the `polyfills.ts` from new application projects and add the polyfills directly in the `angular.json`. This is possible as now the `polyfills` option accept an array of module specifiers.

This change also fixes another open issue (#14432) which was caused by the missing polyfills file in the library test setup.

Closes #14432
2022-09-26 18:27:35 +02:00
Alan Agius
766d4a0895 feat(@schematics/angular): add migration to remove require calls from karma builder main file
With the recent changes in build-angular the `require.context` calls have become unneeded.
2022-09-26 17:39:55 +02:00
Alan Agius
dbcea96274 refactor(@angular-devkit/build-angular): simplify how specs are found and loaded
Prior to this change specs where found and loaded using Webpack's `require.context` API. The `require.context` is found in the users project `test.ts`. This resulted in a complex and hacky setup especially to filter tests when the `include` builder option is provided, were we had to amend the `test.ts` in memory.

With this change we find all the specs files and add them as part of the main entrypoint.

Closes #23751 and closes #22531
2022-09-23 18:52:26 -04:00
Alan Agius
9c13fce162 feat(@angular-devkit/build-angular): remove bundleDependencies from server builder
This commit removes the usages of `bundleDependencies` which does not correctly work as webpack will use `require` to import ESM module since we configure the server bundle to be outputted in CJS. Migrating fully to ESM is also currently not viable due to the lack of support from Domino.
Even if full ESM was possible, using this option would have resulted in a runtime overhead as Angular libraries would be linked during runtime instead of compile time.

BREAKING CHANGE:
The server builder `bundleDependencies` option has been removed. This option was used pre Ivy. Currently, using this option is unlikely to produce working server bundles.

The `externalDependencies` option can be used instead to exclude specific node_module packages from the final bundle.

Closes #23905
2022-09-23 15:41:30 -04:00
Alan Agius
1e5d4a7508 feat(@angular-devkit/build-angular): use Browserslist to determine ECMA output
With this change we reduce the reliance on the TypeScript target compiler option to output a certain ECMA version. Instead we now use the browsers that are configured in the Browserslist configuration to determine which ECMA features and version are needed. This is done by passing the transpiled TypeScript to Babel preset-env.

**Note about useDefineForClassFields**: while setting this to `false` will output JavaScript which is not spec compliant, this is needed because TypeScript introduced class fields many years before it was ratified in TC39. The latest version of the spec have a different runtime behavior to TypeScript’s implementation but the same syntax. Therefore, we opt-out from using upcoming ECMA runtime behavior to better support the ECO system and libraries that depend on the non spec compliant output. One of biggest case is usages of the deprecated `@Effect` decorator by NGRX and potentially other existing code as well which otherwise would cause runtime failures. Dropping `useDefineForClassFields` will be considered in a future major releases. For more information see: https://github.com/microsoft/TypeScript/issues/45995.

BREAKING CHANGE: Internally the Angular CLI now always set the TypeScript `target` to `ES2022` and `useDefineForClassFields` to `false` unless the target is set to `ES2022` or later in the TypeScript configuration. To control ECMA version and features use the Browerslist configuration.
2022-09-21 11:23:35 -04:00