3462 Commits

Author SHA1 Message Date
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
67773bd66d refactor(@angular-devkit/build-angular): remove unneeded defaults from built-in karma config
Remove options that match the Karma defaults from the built-in karma config
2023-01-03 14:53:44 +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
Charles Lyding
7c87ce47c6 fix(@angular-devkit/build-angular): ensure Sass load paths are resolved from workspace root
When using the esbuild-based browser application builder, the Sass compiler will attempt to
resolve any relative load paths from the current working directory. However, the load paths
from the `angular.json` file should always be relative to the location of the `angular.json`
which is considered the workspace root. While the current working directory is typically
also the workspace root, it is not required nor always the same. To resolve this potential
mismatch, the load paths are now resolved from the workspace root prior to being passed to
the Sass compiler.
2023-01-03 14:52:33 +00:00
Alan Agius
e91734ff89 fix(@angular-devkit/build-angular): format esbuild error messages to include more information
Prior to this change esbuild errors during the javascript optimization phase in the Webpack builder were not being formatting properly which caused meaningful information to be lost.

Closes #24457
2023-01-03 14:52:15 +00:00
aanchal
dd322b6240 test: removed empty methods 2023-01-03 14:51:42 +00:00
Charles Lyding
839d0cb57a feat(@angular-devkit/build-angular): implement stats-json option for esbuild builder
When using the experimental esbuild-based browser application builder, the `--stats-json`
option can now be used to create an esbuild metafile named `stats.json` in the output
directory of the application. The metafile contents will contain information about the
application JavaScript, global stylesheets, and the component stylesheets used by the
Angular compiler. While the `--stats-json` option controls the output of the file onto
the filesystem, the metafile data is internally always created to support the future
integration of the bundle budget and console build stat output capabilities.
The metafile format follows the structure of the esbuild metafile format. Information
regarding the file format can be found here: https://esbuild.github.io/api/#metafile
2023-01-03 14:50:09 +00:00
Angular Robot
a9c0982f3a build: update all non-major dependencies 2022-12-15 20:48:46 +00:00
Angular Robot
320d072aac build: update all non-major dependencies 2022-12-14 16:25:55 +00:00
Charles Lyding
20376649c5 fix(@angular-devkit/build-angular): transform async generator class methods for Zone.js support
When using the experimental esbuild-based browser application builder, async generator class
methods will now be transformed to a downlevel form based on promise objects. This transformation
is performed by babel and was previously (and still is) performed on async generator functions.
This transformation is necessary to ensure Zone.js can hook async code via the Promise objects.
Only async generator transformation is currently performed via babel as esbuild can handle all other
native async syntax that requires transformation for Zone.js support.
2022-12-14 15:02:25 +00:00
Charles Lyding
310144d324 fix(@angular-devkit/build-angular): only set ngDevMode when script optimizations are enabled
When using the experimental esbuild-based browser application builder, the `ngDevMode` global
runtime variable was unintentionally always being set to false due to a previous bug fix that stopped
the variable from being replaced with the value of true when script optimizations were disabled.
By doing so, the fix caused the imported compiler-cli `GLOBAL_DEFS_FOR_TERSER_WITH_AOT` constant
to take precedence which contains an `ngDevMode` value of false. To prevent this situation for
development builds where a non-false `ngDevMode` is helpful to surface potential runtime problems,
`GLOBAL_DEFS_FOR_TERSER_WITH_AOT` will no longer change the value of `ngDevMode`. This fix does not
have any effect on production builds since `ngDevMode` would have been set to false regardless.
2022-12-13 14:28:24 +00:00
Charles Lyding
216991b9d9 feat(@angular-devkit/build-angular): support inline component Sass styles with esbuild builder
When using the experimental esbuild-based browser application builder, the `inlineStyleLanguage`
option and the usage of inline Angular component styles that contain Sass are now supported. The
`inlineStyleLanguage` option values of `css`, `sass`, and `scss` can be used and will behave as
they would with the default Webpack-based builder. The less stylesheet preprocessor is not yet
supported in general with the esbuild-based builder. However, when support is added for less,
the `inlineStyleLanguage` option will also be able to be used with the `less` option value.
2022-12-13 14:28:05 +00:00
Angular Robot
5f718fdebd build: update all non-major dependencies 2022-12-12 18:46:05 +00:00
Alan Agius
8fd08491a8 fix(@angular-devkit/build-angular): display actionable error when a style does not exist in Karma builder
Prior to this change the the error was not displayed correctly due to compilation being undefined.

Closes #24416
2022-12-12 17:21:06 +00:00
Alan Agius
97373016cf fix(@angular-devkit/build-angular): downlevel class private methods when targeting Safari <=v15
This commits enables `@babel/plugin-proposal-private-methods` when targeting Safari <=v15 as this is needed to handle private class methods when using `@babel/plugin-proposal-class-properties`.

Closes #24411
2022-12-12 14:48:09 +00:00
Alan Agius
afe9feaa45 fix(@angular-devkit/build-angular): update locale setting snippet to use globalThis.
This commit changes how we set the `LOCALE_ID` when using the `localize` option

- We now include the locale setting snippet only in the main bundle.
- We use `globalThis` to set the the value globally and be accessible across module boundaries. This is important as in some causes such as when using MF `@angular/core` can be located in a bundles others than `main` and `vendor`.
2022-12-09 13:52:28 -08:00
Alan Agius
27b22b02dc fix(@angular-devkit/build-angular): include sources in generated
Sass source maps

This commits enables `sourceMapIncludeSources` when using the modern Sass API so that sources are included in generated
source map.

Closes #24394
2022-12-08 14:49:55 -08: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
Charles Lyding
7a063238b8 fix(@angular-devkit/build-angular): explicitly send options to JS transformer workers
When using the experimental esbuild-based browser application builder, the JavaScript
transformation workers will now only receive the explicit options expected. Previously,
additional Angular compiler plugin options could have been serialized and sent as well.
While these would be unused, there was no need to serialize/deserialize these option values.
2022-12-06 14:33:32 -08:00
Charles Lyding
97716969c2 fix(@angular-devkit/build-angular): default preserve symlinks to Node.js value for esbuild
When using the experimental esbuild-based browser application builder, the `preserveSymlinks`
option will now default to the value of the Node.js `--preserve-symlinks` argument. This removes
the need to manually specify the option in two places if executing the build manually with Node.js
or via the `NODE_OPTIONS` environment variable. This behavior mimics that of the default Webpack-based
builder.
2022-12-05 11:08:35 -08:00
Charles Lyding
cf2f30afc0 fix(@angular-devkit/build-angular): downlevel class fields with Safari <= v15 for esbuild
To provide a workaround for a Safari bug involving class fields and variable scoping,
the esbuild-based browser application builder will now downlevel class fields if Safari
(desktop or iOS) v15.x or earlier is within the target browsers for an application.
This is an esbuild variant of the fix for the Webpack-based builder. For more details
regarding the issue, please see: #24357
2022-12-02 18:39:12 +00:00
Charles Lyding
a0f9db8f2e refactor(@angular-devkit/build-angular): update browserslist conversion to latest esbuild browsers
The conversion of browserslist targets to esbuild targets has been updated to reflect additions
to esbuild. Additional browsers are now supported and the major/minor versions have been normalized.
The later of which ensures that `.0` major versions are not misinterpreted as ranges rather than
specific versions.
2022-12-02 18:39:12 +00:00
Dominic Elm
65f78be267 refactor(@angular-devkit/build-angular): convert into a function to give more control when the readable stream is initialized 2022-12-02 10:20:35 +00:00
Paul Gschwendtner
25eaaa24b5 fix(@angular-devkit/build-angular): downlevel class properties when targeting Safari <=v15
The Angular compiler is dependent on static fields being attached to
user-defined classes. e.g. `static ecmp = defineComponent`.

These static fields sometimes rely on variables from outside of the
class. e.g. the Angular compiler generates constants for content
projection that are then accessed in the static field initializer.

Surprisingly such access to these variables may break in Safari <=v15
when a page is loaded without devtools open. The bug (already solved in
v16 of Safari)- is very subtle, hard to re-reproduce but basically
variable scope tracking is broken. This bug is triggered by additional
parenthesis in the initializer expression. See:
https://bugs.webkit.org/show_bug.cgi?id=236843.

The TypeScript compiler may generate such additional parenthesis when
it tries to adjust the `this` context when invoking methods, such as for
defining animations in the `ecmp` definition.

More details can be found here:
https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033

To ensure Angular applications are not subject to this bug when
targeting Safari <=v15. v15 Safari, both for iOS and Mac is still part of
the default CLI browserslist with `last 2 Safari majors` (at time of
writing).

Note that it is important that the Babel plugin properly handles the
downleveling of static block-defined members. TypeScript will transform
static fields, like `static ecmp` into `static { this.ecmp = X }` when
`useDefineForClassFields = false` (which is the case for CLI apps). The
class properties plugin from Babel seems to handle this in an acceptable
way. Unlike actual static fields, Babel will not use helpers like
`defineProperty` for such extracted static blocks though. e.g.

See repro: https://gist.github.com/devversion/dec0dea26e348c509921bf62079b60be

```js
class Test {
  x = true;

  static b = true;
  static {
    this.a = true;
  }
}

// into

class X {
  constructor() {
    _defineProperty(this, "x", true);
  }
}
_defineProperty(X, "b", true);
X.a = true;
```

note that in practice TypeScript with `useDefineForClassFields = false`
will put non-static members into the constructor as normal assignments
regardless- so there would be no change by the Babel plugin.

Fixes #24355.
2022-12-02 09:05:29 +00:00
Charles Lyding
ef99a68b46 fix(@angular-devkit/build-angular): prevent optimization adding unsupported ECMASCript features
When optimization is enabled with the `@angular-devkit/build-angular:browser` builder, terser
is used as a second phase optimizer. The terser configuration previously set its `ecma` option
to `es2020` due to all officially supported browsers supporting the version. However, it is
possible to add browsers to the browserslist configuration that are not officially supported
that still may work but do not support es2020 syntax features. By setting the terser `ecma`
option to `es2015`, terser will not turn existing syntax into newer syntax features that might
be unsupported. Terser will also not downlevel any code based on this option.

Fixes #24347
2022-12-01 10:18:47 +00:00
Angular Robot
64c89439dc build: update all non-major dependencies 2022-11-30 14:19:37 +00:00
Angular Robot
80a7887883 build: update all non-major dependencies 2022-11-29 13:31:54 +00:00
Alan Agius
a07d701280 build: update all non-major dependencies
(cherry picked from commit 2dad0e7829325a69747fb702fa614bd73281ceb0)
2022-11-28 16:04:17 +00:00
Alan Agius
c9608f5ec9 Revert "fixup! test: run legacy-cli e2e tests via bazel"
This reverts commit 9e5777052d7436b879e3c8f64c123fd0f70a3c9a.
2022-11-28 15:25:48 +00:00
Jason Bedard
9e5777052d fixup! test: run legacy-cli e2e tests via bazel
fixup: add ChromeHeadlessNoSandbox browser to to karma builder
2022-11-28 13:39:15 +00:00
Juuso Valkeejärvi
012393d379 fix(@angular-devkit/build-angular): correctly set Sass quietDeps and verbose options
The logic to set these options was flipped which caused the warnings to
be displayed when verbose was disabled.
2022-11-28 13:17:05 +00:00
Alan Agius
6e9008c37a fix(@angular-devkit/build-angular): hide loader paths in webpack warnings
Similar to errors messages we now hide webpack paths in warnings to reduce clutter.

Before
```

./src/styles.scss.webpack[javascript/auto]!=!./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[6].rules[0].oneOf[0].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[6].rules[0].oneOf[0].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[6].rules[1].use[0]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[6].rules[1].use[1]!./src/styles.scss?ngGlobalStyle - Warning: Module Warning (from ./node_modules/sass-loader/dist/cjs.js):
Deprecation $weight: Passing a number without unit % (60) is deprecated.

To preserve current behavior: $weight * 1%

More info: https://sass-lang.com/d/function-units

@material/slider/_slider-theme.scss 77:5                                    @use
node_modules/@angular/material/slider/_slider-theme.scss 3:1                @use
node_modules/@angular/material/core/density/private/_all-density.scss 25:1  @forward
@angular/_index.scss 18:1                                                   @use
src/styles.scss 2:1                                                         root stylesheet
```

After
```

./src/styles.scss - Warning: Module Warning (from ./node_modules/sass-loader/dist/cjs.js):
Deprecation $weight: Passing a number without unit % (60) is deprecated.

To preserve current behavior: $weight * 1%

More info: https://sass-lang.com/d/function-units

@material/slider/_slider-theme.scss 77:5                                    @use
node_modules/@angular/material/slider/_slider-theme.scss 3:1                @use
node_modules/@angular/material/core/density/private/_all-density.scss 25:1  @forward
@angular/_index.scss 18:1                                                   @use
src/styles.scss 2:1                                                         root stylesheet
```
2022-11-23 13:42:56 +00:00
Charles Lyding
84dc05d28a fix(@angular-devkit/build-angular): use url function lexer to rebase Sass URLs
When rebasing URLs found within Sass files (sass/scss), the previous regular expression
based searching has been replaced with a lexer that scans the Sass files for CSS url()
functions and extracts URL values. This change allows for more accurate discovery of
URLs as well as reducing the amount of content traversals per file. The lexer logic
is based on CSS Syntax Module Level 3 (https://www.w3.org/TR/css-syntax-3/).
2022-11-23 13:34:37 +00:00
Charles Lyding
ecd6ec4a54 refactor(@angular-devkit/build-angular): encapsulate Angular compilation within esbuild compiler plugin
The creation of the esbuild Angular plugin's Angular compilation has now been consolidated in a separate
class. This refactor reduces the amount of code within the plugin's main start function as well as centralizing
initialization, analysis, and source file emitting for the Angular build process.
2022-11-23 13:31:32 +00:00
Angular Robot
489d4df0ed build: update angular 2022-11-21 11:07:16 -05:00
Angular Robot
70a7c96e12 build: update dependency webpack-dev-middleware to v6 2022-11-21 10:55:45 -05:00
Angular Robot
4e3c62b6d0 build: update all non-major dependencies 2022-11-21 10:55:10 -05:00
Charles Lyding
67752a4104 fix(@angular-devkit/build-angular): improve package deep import Sass index resolution in esbuild plugin
When resolving Sass imports in the experimental esbuild-based browser application builder's Sass plugin,
previously imported modules are used as the base for resolution attempts to workaround the lack of the
importer file provided by Sass. When attempting to resolve a deep import into a package (including the
potential Sass index files), these previously imported modules also need to be checked. This is
particularly relevant when using the Yarn PnP or pnpm package managers which enforce strict dependency
resolution.

Fixes #24271
2022-11-21 10:54:04 -05:00
Charles Lyding
0c01532cb5 perf(@angular-devkit/build-angular): use worker pool for JavaScript transforms in esbuild builder
When using the experimental esbuild-based browser application builder, the JavaScript transformation
steps of the build process will now be performed within a worker pool to allow for the steps to be
executed in parallel when possible. This also moves the steps off of the main thread which provides
more time for the build orchestration and esbuild integration code to execute.
2022-11-21 10:53:22 -05:00
Alan Agius
012746e759 test: remove target in tsconfig.server.json
This is no longer needed as the CLI uses es2022 internally.
2022-11-18 11:03:15 -08:00
Alan Agius
c29df69546 feat(@angular-devkit/build-angular): add assets option to server builder
This commits adds the `assets` option to the server builder. This can be useful to copy server specific assets such as config files.

Closes #24203
2022-11-18 11:03:15 -08:00
Alan Agius
78ce78cc7e build: remove regenerator-runtime from dependencies
This dependency is no longer needed since we no longer generate es5 output.
2022-11-18 11:03:02 -08:00
Charles Lyding
bc8578cb13 refactor(@angular-devkit/build-angular): preprocess Sass resolve cache entries in esbuild Sass plugin
When performing Sass import resolution within the experimental esbuild-based browser application builder,
the directory cache entries will now be preprocessed during the first directory search operation. This
will allow a more streamlined search operation on later resolution attempts for the same directory.
The caching is still limited to sharing per render request but this change provides for cache entries
that can more easily be serialized and shared between workers in the future.
2022-11-17 16:31:54 -08:00
Angular Robot
69306ddb0e build: update all non-major dependencies 2022-11-16 13:37:03 -08:00
Charles Lyding
2397eed123 refactor(@angular-devkit/build-angular): move esbuild angular compiler host creation to separate function
The creation of the esbuild Angular plugin's Angular compiler host has now been consolidated in a separate
function. This refactor reduces the amount of code within the plugin's main start function as well as centralizing
all initialization of the host into one location.
2022-11-15 10:15:58 -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
Charles Lyding
6cc45f69b8 fix(@angular-devkit/build-angular): show file replacement in TS missing file error in esbuild builder
When using the experimental esbuild-based browser application builder with the `fileReplacements` option,
TypeScript missing compilation file errors will now contain a note that the requested file was a
replacement for another file and show the path of the file.
2022-11-14 10:14:28 -08:00
Angular Robot
e333eabef9 build: update all non-major dependencies 2022-11-14 09:30:15 -08:00
Charles Lyding
3f193be775 perf(@angular-devkit/build-angular): add initial global styles incremental rebuilds with esbuild builder
When using the experimental esbuild-based browser application builder in watch mode, global stylesheets
configured with the `styles` option will now use the incremental rebuild mode of esbuild. This allows
for a reduction in processing when rebuilding the global styles. CSS stylesheets benefit the most currently.
Sass stylesheets will benefit more once preprocessor output caching is implemented.
2022-11-14 09:28:55 -08:00