The default set of metadata fields provided to all builders executed via the BuilderHarness is controlled programmatically. The BuilderHarness is eventually intended to operate in-memory and without file system access unlike the legacy unit tests. The `cli.cache.enabled` option must therefore be set within the BuilderHarness initialization code. `cli.cache.enabled` set to false provides improved test isolation guarantees by disabling Webpack’s caching.
The unit-tests where intended to not use build caching to better ensure test isolation. However, the configuration format was incorrect and did not disable the build caching.
By adding the `es2020` and `es2015` condition names, the build process will now use ES2020 or ES2015 specific files if a package's exports entries contain files for either of those conditions. This allows packages to provide multiple variants of the code that the bundler can then use based on the bundler's configuration. As of Angular v13, ES2020 code is preferred. However, some packages may prefer to export other variants by default but provide an `es2020`/`es2015` condition to allow other variants if requested.
The server configuration is intentional not altered since the server output executes on Node.js and should use the `node` condition which is automatically added by Webpack based on the output target.
DEPRECATED: `@angular-devkit/build-optimizer`
It's functionality has been included in `@angular-devkit/build-angular` so this package is no longer needed by the CLI and we will stop publishing the package soon. It has been an experimental (never hit `1.0.0`) and internal (only used by Angular itself) package and should be not be used directly by others.
With this change we disable critical css inline by default. The main motivations are the following issues #20760 and #20864.
BREAKING CHANGE:
Inlining of critical CSS is no longer enable by default. Users already on Angular CLI version 12 and have not opted-out from using this feature are encouraged to opt-in using the browser builder `inlineCritical` option.
The motivation behind this change is that the package used to parse the CSS has a number of defects which can lead to unactionable error messages when updating to Angular 13 from versions priors to 12. Such errors can be seen in the following issue #20760.
```json
"configurations": {
"production": {
"optimization": {
"styles": {
"inlineCritical": true,
}
},
...
}
```
Persistent disk build cache is now enabled by default. A number of options have been added to allow fine tuning of the cache.
The options can be configuration in `cli.cache` section in the `angular.json` as shown below.
- `enabled`: Configure whether disk caching is enabled. Defaults to `true`
- `environment`: Configure in which environment disk cache is enabled. Valid values `ci`, `local` or `all`. Defaults to: `local`
- `path`: cache base path. Defaults to `.angular/cache`
DEPRECATED: `NG_BUILD_CACHE` environment variable option will be removed in the next major version. Configure `cli.cache` in the workspace configuration instead.
BREAKING CHANGE: `NG_PERSISTENT_BUILD_CACHE` environment variable option no longer have effect. Configure `cli.cache` in the workspace configuration instead.
```json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"cache": {
"enabled": true,
"path": ".custom-cache-path",
"environment": "all"
}
}
...
}
```
With the removal of support for the string form of `loadChildren` within the Angular router, the usage of `System.import` has also been removal from `@angular/core`. This removal allows for the additional removal of all workarounds within the Angular CLI due to the `System.import` usage. Webpack's deprecated support for `System.import` was previously required to be enabled which resulted in warnings that then needed to be suppressed. A Webpack context dependency replacement was also previously required to prevent Webpack from failing due to the otherwise unknown behavior of the `System.import` call. All of these workarounds have now been removed.
The `NodeJsSyncHost`/`NodeJsAsyncHost` classes' `delete` method uses `fs.rmdirSync`/`fs.rmdir` to delete directories. However, Node.js v16's `fs.rmdirSync`/`fs.rmdir` will now throw an `ENOENT` error if the path does not exist. `fs.rmSync`/`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.rmSync`/`fs.rm` given preference.
Once Node.js 12 support is dropped, the `delete` method could potentially be refactored to avoid the `isDirectory` check and only use `fs.rmSync`/`fs.rm` which supports both files and directories.
This change uses the `@ampproject/remapping` package to merge sourcemaps generated from the customized babel loader used to perform the partial compilation linking in applications as well as other optimization and downleveling transformations. This provides more accurate output mapppings as well as improved performance and lower memory usage when source maps are enabled within a build.
rxjs 6 requires directory imports which are not support in ES modules. Disabling `fullySpecified` allows Webpack to ignore cases such as this until the package can be updated to use package exports.
The regular expressions based checks for TypeScript and JavaScript files used by Webpack module rules have been updated to include all current extension variations.
JavaScript files can be either `.js`, `.mjs`, or `.cjs`. TypeScript files as of the upcoming version 4.5 can be either `.ts`, `.mts`, or `.cts`.
Also while not officially supported by Angular, the TypeScript compiler can attempt to process any of the previous extensions with an `x` suffix which indicates a JSX/TSX file.
BREAKING CHANGE: With this change a number of deprecated dev-server builder options which proxied to the browser builder have been removed. These options should be configured in the browser builder instead.
The removed options are:
- `aot`
- `sourceMap`
- `deployUrl`
- `baseHref`
- `vendorChunk`
- `commonChunk`
- `optimization`
- `progress`
This is a follow-up to fb210e5b747ce0351dd9ee7d482770b9cfa71133 which
added support for the ESM-variant of the `@angular/localize` package,
and also prepared for the `tools/` secondary entry-point we will expose
as of v13.
Unfortunately this change currently does not pass-through the ESM-loaded
plugin creators as the option (which is passed to the Babel plugin) is
incorrect. This was hidden due to a type cast. This commit fixes the
issue and also ensures TS would complain in the future if the option
names differ.
A Babel webpack loader specific `@angular/localize` package `Diagnostics` object is now created that is optimized for the diagnostics reporting case. This removes the need to manually create and patch an instance of a Diagnostics object. Future work will potentially allow a reporter to be passed directly to the translation plugins to remove the need to create a new object entirely.
Previously, the search for a locale's data when using i18n was performed by a series of file system accesses that searched through the `@angular/common` package. The search is now conducted via Node.js module resolution which has several advantages. The internal structure of the package is no longer assumed and allows the `@angular/common` package to change its internal implementation without affecting the locale data search. File extensions of the locale data files are also not hard-coded as only the name of the locale data is needed to perform a search. There are also less direct file system access calls and the search can leverage whatever internal caching Node.js performs during module resolution.
With the Angular CLI currently being a CommonJS package, this change uses a dynamic import to load `@angular/localize` which may be ESM. CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript will currently, unconditionally downlevel dynamic import into a require call. require calls cannot load ESM code and will result in a runtime error. To workaround this, a Function constructor is used to prevent TypeScript from changing the dynamic import. Once TypeScript provides support for keeping the dynamic import this workaround can be dropped and replaced with a standard dynamic import.
With Angular Package Format v13, we will be using a more recent version of rollup. Rollup
always suffixed exports to avoid collisions, but with the most recent version, the order
has changed slightly changed. e.g. previously for `@angular/core`, there were two instances
of the `ViewEncapsulation` enum part of the `fesm` bundle. The second instance of the enum
orginated from the compiler <--> core facade and it got renamed to avoid conflicts with the
actual declaration of `ViewEncapsulation`. Now this has changed, and the first export is
being renamed instead. This now breaks at runtime because the first export is being incorrectly
transformed by the adjust enum plugin of `build-angular`. The plugin always had this problem
of incorrectly transforming the enums, but it never surfaced because only the face enum has been
transformed (which is not used at runtime). e.g.
consider the following input in `core.mjs`:
```
var ViewEncapsulation$1;
(function (ViewEncapsulation) {
ViewEncapsulation[ViewEncapsulation["Emulated"] = 0] = "Emulated";
})(ViewEncapsulation$1 || (ViewEncapsulation$1 = {}));
```
this is transformed into:
```
var ViewEncapsulation$1 = /*#__PURE__*/(() => {
ViewEncapsulation$1 = ViewEncapsulation$1 || {};
ViewEncapsulation[ViewEncapsulation["Emulated"] = 0] = "Emulated";
}());
```
Note how the enum assignment for `Emulated` incorrectly still uses the non-suffixed
identifier that previously was part of the callee wrapper function.
The `proxyConfig` option now supports loading ESM configuration files in addition to JSON and CommonJS files. ESM files (such as those ending with `.mjs`) must provide a default export with the configuration object.
For example, a `proxy.config.mjs` containing the follow is now possible:
```
export default { "/api/*": { "target": "http://127.0.0.1:5001" } };
```
Closes#21623
Absolute import paths, especially on Windows, must be `file://` URLs when using ESM. Otherwise, Windows drive letters (e.g., `C:`) would be interpreted as a protocol instead of a drive letter when performing the import.
With the Angular CLI currently being a CommonJS package, this change uses a dynamic import to load `@angular/service-worker/config` which may be ESM. CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript will currently, unconditionally downlevel dynamic import into a require call. require calls cannot load ESM code and will result in a runtime error. To workaround this, a Function constructor is used to prevent TypeScript from changing the dynamic import. Once TypeScript provides support for keeping the dynamic import this workaround can be dropped and replaced with a standard dynamic import.
This is a followup PR for #21771 that addresses partial compilation linker usage.
With the Angular CLI currently being a CommonJS package, this change uses a dynamic import to load `@angular/compiler-cli/linker[/babel]` which may be ESM. CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript will currently, unconditionally downlevel dynamic import into a require call. require calls cannot load ESM code and will result in a runtime error. To workaround this, a Function constructor is used to prevent TypeScript from changing the dynamic import. Once TypeScript provides support for keeping the dynamic import this workaround can be dropped and replaced with a standard dynamic import.
In the event that the Angular CLI is executed on a platform that does not yet have native support for esbuild, the WASM-based variant of esbuild will now be used. If the first attempt to optimize a file fails to execute the native variant of esbuild, future executions will instead use the WASM-based variant instead which will execute regardless of the native platform. The WASM-based variant, unfortunately, can be significantly slower than the native version (some cases can be several times slower). For install time concerns regarding the esbuild post-install step, esbuild is now listed as an optional dependency which will allow the post-install step to fail but allow the full npm install to pass. This install scenario should only occur in the event that the esbuild native binary cannot be installed or is otherwise unavailable.
Webpack-dev-server doesn't handle concurrency very well. When using port 0, and 2 processes start at the same time, they end up being given the same port. The main reason for the issue is that it find a free port, put only uses at a later stage.