383 Commits

Author SHA1 Message Date
Alan Agius
740610a902 Revert "fix(@angular-devkit/build-angular): set public class fields as properties (#24849)"
This reverts commit 04274afc15084ead2916e11055aa8f1d2f61951d.

Closes: #25161
2023-05-08 13:35:05 +00:00
Alan Agius
126b23edea fix(@angular-devkit/build-angular): disable runtime errors from being displayed in overlay
By default now webpack-dev-server adds runtime errors in an overlay. See: aab01b3c4e this commit disables this functionality.

Closes #25151
2023-05-08 13:34:49 +00:00
Alan Agius
2fabeabf7f fix(@angular-devkit/build-angular): JIT support for standalone applications
This commit fixes and issue were standalone applications would fail during runtime because the `@angular/compiler` is not available.

We now add the `@angular/compiler` as part of the bundle when JIT mode is enabled.
2023-04-28 18:00:36 +00:00
Alan Agius
758b0695f3 fix(@angular-devkit/build-angular): update list of known tailwind configuration files
With this change we added `tailwind.config.mjs` and `tailwind.config.ts` to known tailwind config files.

Closes #24943
2023-04-18 16:28:00 +00:00
Charles Lyding
8e57db6518 fix(@angular-devkit/build-angular): show lazy files in stat table correctly with esbuild
When using the esbuild-based browser application builder, the output build file stat table
was incorrectly displaying non-injected global styles and scripts as initial files. These
output files will now be correctly shown as lazy files. Initial files will also now display
their respective name if available. The table entries are now sorted in descending order by
raw file size as was done in the Webpack-based builder.
2023-04-11 16:47:47 +00:00
Charles Lyding
ee8013f66f feat(@angular-devkit/build-angular): display build output table with esbuild
When using the experimental esbuild-based browser application builder, a build
output table will now be displayed upon completion. The table is formatted to
display output file information in a similar way to the default Webpack-based
browser application builder. Estimated transfer size is currently not displayed
but will be added in a future change.
2023-03-31 15:36:26 +00:00
Alan Agius
04274afc15
fix(@angular-devkit/build-angular): set public class fields as properties (#24849)
* fix(@angular-devkit/build-angular): set public class fields as properties

Configure Babel to use `setPublicClassFields: true`. As when shipping Angular packages without `"useDefineForClassFields": false` will increase the bundle size of an ng-new app
by ~2Kb when `useDefineForClassFields`  is not false. due to the additional `_defineProperty`, which will be added on every class property.

See: https://babeljs.io/docs/babel-plugin-proposal-class-properties

* fixup! fix(@angular-devkit/build-angular): set public class fields as properties

Co-authored-by: Charles <19598772+clydin@users.noreply.github.com>

---------

Co-authored-by: Charles <19598772+clydin@users.noreply.github.com>
2023-03-14 07:37:57 +00:00
Alan Agius
d4c450829d fix(@angular-devkit/build-angular): improve parsing of error messages
Webpack errors can sometimes be several hundred of thousands of characters long as it may contain the entire bundle. This can cause a ReDoS. This change improves the way we parse and remove stack traces from error messages.

Closes #24771
2023-02-24 19:13:16 +00:00
Charles Lyding
2435b46560 fix(@angular-devkit/build-angular): allow empty scripts to be optimized
When using the internal JavaScript optimizer plugin for Webpack with an
empty script file provided via the `scripts` option, the build would fail.
This was because of a safety check that was checking whether the terser
result was falsy. Since an empty string is considered falsy, the build
considered the result to be an error. The safety check now will only trigger
if the terser result is not a string value to avoid this case.
2023-02-16 19:11:34 +00:00
Alan Agius
8095268fa4 build: update to rxjs 7
G3 is now using RXJS version 7 which makes it possible for the CLI to also be updated to RXJS 7.

NB: this change does not remove all usages of the deprecated APIs.

Closes #24371
2023-02-16 14:59:40 +00:00
Alan Agius
1e52863262 perf(@angular-devkit/build-angular): reduce rebuilt times when using the scripts option
In some cases, using the `scripts` option caused a lot of `DescriptionFileUtils.loadDescriptionFile` calls which caused a bottleneck during build times.

The why to this is still unknown, but a workaround is to use the resolver from the Webpack compilation instead of the compiler.

Closes #24634
2023-02-14 14:59:37 +00:00
Alan Agius
c65b026e2f fix(@angular-devkit/build-angular): update the ECMA output warning message to be more actionable
Update the `TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022"` warning message to be more actionable.

Closes: #24697
2023-02-10 20:13:35 +00:00
Alan Agius
bf3be56db8 fix(@angular-devkit/build-angular): load polyfills and runtime as scripts instead of modules
This commit updates changes the way polyfills and runtime are loaded from modules to scripts. This is required as otherwise Jasmine will be loaded prior to Zone.js which causes clock patching not to work.

Closes #24651
2023-02-03 14:29:13 +00:00
Alan Agius
3512a03621 fix(@angular-devkit/build-angular): load JavaScript bundles as modules in karma
With this change we load bundles as modules when using the Karma builder.
2023-01-27 21:43:37 +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
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
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
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
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
Alan Agius
c83aaedb29 fix(@angular-devkit/build-angular): warn when components styles sourcemaps are not generated when styles optimization is enabled
With this change we add a warning to inform the users that sourcemaps are not generated when both styles sourcemaps and optimization are enabled. This is because component style sourcemaps are inline which would drastically increase the bundle size.

Closes #22834
2022-11-08 19:09:38 +01:00
Alan Agius
d754b72d4e fix(@angular-devkit/build-angular): only add @angular/platform-server/init when package is installed.
This commit fixes an issue where `@angular/platform-server/init` was added as an entry-point during the server build even when this was not installed.

Closes #24188
2022-11-07 19:04:26 +01:00
Alan Agius
de8d846b98 docs: replace browserslist with AIO link
https://angular.io/guide/build#configuring-browser-compatibility will be updated to include additional information.
2022-10-24 15:12:42 -07:00
Alan Agius
c49f1eea62 fix(@angular-devkit/build-angular): resolve transitive dependencies in Sass when using Yarn PNP
Enhanced resolver is unable to resolve transitive dependencies in Sass when using Yarn PNP. The main reason for this is that Sass doesn't provide context on which file is requesting the module. See: sass/sass#3247.

As a workaround for this we store previously resolved paths and when a new request comes in we try to resolve this from the previously resolved files if we are unable to resolve the request from the workspace root.
2022-10-14 16:05:53 +02:00
Charles Lyding
717bd03de6 fix(@angular-devkit/build-angular): account for package.json exports fields with CSS import statements
The `postcss-imports` package was previously used to support `@import` within CSS files. Unfortunately,
the package does not account for `package.json` exports fields. This prevents imports defined within that
field from working when used within a build.  The `css-loader` package does provide this functionality and
is now used to provide support for CSS `@import` instead of `postcss-imports`. This change does not affect
preprocessors that provide their own import behavior.
2022-10-14 09:36:08 +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
4fcb0a82b5 fix(@angular-devkit/build-angular): correctly resolve Sass partial files in node packages
Prior to this change non relative partial files were not resolved properly. Example we did not try to resolve `@material/button/button` as `@material/button/_button` which caused the compilation to fail.
2022-10-11 20:15:02 +02:00
Alan Agius
124be1cc9c refactor: add build and rebuild related statistics and analytics
The new build and rebuild statistics are used by the CLI to submit build related information to GA.
2022-10-11 18:52:30 +02:00
Alan Agius
c969152de6 refactor: remove analytics API from core and architect
All analytics is now in the @angular/cli package

BREAKING CHANGE: analytics APIs have been removed without replacement from `@angular-devkit/core` and `@angular-devkit/architect`.
2022-10-11 18:52:30 +02:00
Alan Agius
b6df9c1367 fix(@angular-devkit/build-angular): handle conditional exports in scripts and styles option
With this change scripts and styles options better support Yarn PNP resolution.

Closes #23568
2022-09-30 08:56:54 +02:00
Alan Agius
8f8e02c322 fix(@angular-devkit/build-angular): support Yarn PNP resolution in modern SASS API
This change add a Sass File importer that uses Webpack resolvers to better support scenarios when node packages are not stored in node_modules, such as Yarn PNP.
2022-09-28 17:37:33 +02:00
Alan Agius
05a98c0292 feat(@angular-devkit/build-angular): karma builder main option is now optional
The Karma builder `main` option is now optional. The default test bootstrapping is injected automatically in the bundle.
2022-09-27 18:59:08 +02:00
Alan Agius
308e3a017f feat(@angular-devkit/build-angular): switch to use Sass modern API
Sass modern API provides faster compilations times when used in an async manner.

|Application compilation duration | Sass API and Compiler|
|-- | --|
|60852ms | dart-sass legacy sync API|
|52666ms | dart-sass modern API|

Note: https://github.com/johannesjo/super-productivity was used for benchmarking.

Prior art: http://docs/document/d/1CvEceWMpBoEBd8SfvksGMdVHxaZMH93b0EGS3XbR3_Q?resourcekey=0-vFm-xMspT65FZLIyX7xWFQ

BREAKING CHANGE:

- Deprecated support for tilde import has been removed. Please update the imports by removing the `~`.

Before
```scss
@import "~font-awesome/scss/font-awesome";
```

After
```scss
@import "font-awesome/scss/font-awesome";
```

- By default the CLI will use Sass modern API, While not recommended, users can still opt to use legacy API by setting `NG_BUILD_LEGACY_SASS=1`.
2022-09-27 10:05:19 +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
c592ec584f feat(@angular-devkit/build-angular): amend polyfills option in all builders to support an array of module specifiers
This is the ground work to be able to remove the `polyfills.ts` file which today is primarily used to add `zone.js`.

Usage examples:
```js
polyfills: ['zone.js'],

polyfills: ['zone.js', 'zone.js/testing', 'src/polyfills.ts'],
```
2022-09-26 18:27:35 +02:00
Alan Agius
f393b09282 refactor(@angular-devkit/build-angular): disable requireContext parsing
`require.context` is a webpack specific feature which was only needed to support the old Karma test setup.

BREAKING CHANGE: `require.context` are no longer parsed. Webpack specific features are not supported nor guaranteed to work in the future.
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
d09da83d26 refactor: use addWarning and addError helpers to push Webpack diagnostics
With this change we replace all usage of `compilation.errors `and `compilation.warnings.push` with `addError` and `addWarning` respectively.

Also, we update the helpers in build-angular to use `WebpackError` from the current compilation to avoid mismatching instances.
2022-09-22 10:10:31 -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
Alan Agius
15d3fc6dc3 feat(@angular-devkit/build-angular): export @angular/platform-server symbols in server bundle
This commit adds an internal file to export needed symbols from `@angular/platform-server` when building a server bundle. This is needed.  This is needed so that DI tokens can be referenced and set at runtime outside of the bundle.

Also, it adds a migration to remove these exports from the users files as otherwise an export collision would occur due to the same symbol being exported multiple times.
2022-09-20 10:24:29 -04:00
Alan Agius
2ba44a433c refactor(@angular-devkit/build-angular): remove support for Stylus
The usage of Stylus in the CLI is minimal and this package never reached version 1.

BREAKING CHANGE:

Deprecated support for Stylus has been removed. The Stylus package has never reached a stable version and its usage in the Angular CLI is minimal. It's recommended to migrate to another CSS preprocessor that the Angular CLI supports.
2022-09-16 11:39:19 -07:00
Alan Agius
12931ba8c3 refactor(@angular-devkit/build-angular): remove deprecated ES5 support
Remove deprecated support for ES5 output.

BREAKING CHANGE: Producing ES5 output is no longer possible. This was needed for Internet Explorer which is no longer supported. All browsers that Angular supports work with ES2015+
2022-09-16 11:39:02 -07:00
Alan Agius
9798323d5e refactor(@angular-devkit/build-angular): simplify configuration of inlineStyleFileExtension
Remove redundant switch statement.
2022-09-16 11:36:33 -07:00
Alan Agius
2021e66a12 fix(@angular-devkit/build-angular): watch symbolic links
This commit addresses an issue which caused symbolic links not to be watched properly.

Closes #15100
2022-09-14 10:42:56 -07:00
Alan Agius
4f8a3d2582 fix(@angular-devkit/build-angular): correctly display error messages that contain "at" text.
Previously, the regexp was incorrectly matching messages which contained "at" as part of the text.

Closes #23865
2022-09-08 18:51:04 +02:00
Alan Agius
98bde526b4 refactor(@angular-devkit/build-angular): remove postcss-preset-env
This change removes the usage of `postcss-preset-env` as this is no longer needed since Angular no longer supports browsers that require polyfills for CSS stage 3 features https://preset-env.cssdb.org/features/#stage-3.

We replace this and use autoprefixer directly which is still needed.

```
npx autoprefixer --info
Browsers:
  Chrome: 105
  Edge: 105, 104
  Firefox: 104, 102, 91
  iOS Safari: 15.6, 15.5, 15.4, 15.2-15.3, 15.0-15.1, 14.5-14.8, 14.0-14.4
  Safari: 15.6, 15.5, 15.4, 15.2-15.3, 15.1, 15, 14.1, 14

These browsers account for 20.38% of all users globally

At-Rules:
  @resolution: webkit

Selectors:
  ::backdrop: webkit
  ::file-selector-button: webkit
  :autofill: webkit
  :fullscreen: webkit

Properties:
  appearance: webkit
  backdrop-filter: webkit
  backface-visibility: webkit
  background-clip: webkit
  box-decoration-break: webkit
  color-adjust: webkit, moz
  hyphens: webkit
  mask-border-outset: webkit
  mask-border-repeat: webkit
  mask-border-slice: webkit
  mask-border-source: webkit
  mask-border-width: webkit
  mask-border: webkit
  mask-clip: webkit
  mask-composite: webkit
  mask-image: webkit
  mask-origin: webkit
  mask-position: webkit
  mask-repeat: webkit
  mask-size: webkit
  mask: webkit
  print-color-adjust: webkit, moz
  text-decoration-color: webkit
  text-decoration-line: webkit
  text-decoration-skip-ink: webkit
  text-decoration-skip: webkit
  text-decoration-style: webkit
  text-decoration: webkit
  text-size-adjust: webkit
  user-select: webkit

Values:
  cross-fade: webkit
  element: moz
  fill-available: webkit
  fill: webkit
  fit-content: moz
  image-set: webkit
  isolate: webkit
  stretch: webkit, moz
```
2022-09-08 18:50:47 +02:00
Alan Agius
3b1f109a33 fix(@angular-devkit/build-angular): change service worker errors to compilation errors
Previously, when there was an error during a build that had service workers enabled, the dev-server crashed as the promise was rejected instead of emitting a compilation error.

With this change we update the logic so that any errors during the SW augmentation phase are changed to a compilation error and also update the logic so that when there are compilation errors we don't try to generate a SW.
2022-09-06 18:40:44 +02:00
Alan Agius
34479475ad refactor: remove Ivy checks
This checks are no longer needed as `enableIvy` option is now meaningless to the compiler
2022-09-06 17:36:00 +02:00