1710 Commits

Author SHA1 Message Date
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
Charles Lyding
1c527a9da5 feat(@angular-devkit/build-angular): add esbuild-based builder initial support for fileReplacements
Support for the `fileReplacements` option from the Webpack-based builder has now been integrated into
the experimental esbuild-based browser application builder. The option will no longer be ignored during
builds. Only the officially supported form of the option (`replace`/`with` fields) is implemented.
2022-09-16 11:35:57 -07:00
Alan Agius
fdc315d335 test(@angular-devkit/build-angular): rewrite app-shell unit test into e2e
This particular unit tests was really an e2e test.
2022-09-15 08:26:11 -07:00
Alan Agius
9beb878e2e feat(@schematics/angular): remove Browserslist configuration files from projects
The Browserslist configuration file is redundant as we set the defaults directly in @angular-devkit/build-angular. 8da926966e/packages/angular_devkit/build_angular/src/utils/supported-browsers.ts (L12-L19)

With this commit, we remove the `.browserlistrc` configuration file from the schematics application template and through a migration in existing projects when the Browserslist query result matches the default.

Users needing a finer grain support should still create a `.browserlistrc` in the root directory of the project.
2022-09-14 10:43:41 -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
7f1017e60f refactor(@angular-devkit/build-angular): remove old bundleDependencies enum logic
BREAKING CHANGE: server builder `bundleDependencies` option now only accept a boolean value.
2022-09-08 18:59:26 +02: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
Alan Agius
f86b384df4 fix(@angular-devkit/build-angular): handle service-worker serving with localize in dev-server
Previously, we tried to read the files from the wrong location as during localize we alter the output directory to a different temporary location.

7e64b1537d/packages/angular_devkit/build_angular/src/utils/i18n-options.ts (L251-L252)

Closes #23844
2022-09-02 12:25:20 -04:00
Alan Agius
130975c200 fix(@angular-devkit/build-angular): watch index file when running build in watch mode
Since the index augmentation happens outside of Webpack previously the index html was not being watched during watch mode.

Closes #23851
2022-09-02 11:24:43 -04:00
Charles Lyding
feb06753d5 perf(@angular-devkit/build-angular): use esbuild-based builder to directly downlevel for await...of
esbuild 0.15.6 now supports transforming `for await..of` syntax and will now be used instead of babel
when the syntax is found within code that will be bundled. Zone.js requires that all async/await
related code be downleveled to properly hook promise callbacks. esbuild does not yet support
transforming async generators and so babel is still used when async generator syntax is detected
in an input file.
esbuild 0.15.6 also adjusted the `supported` option to imply that all dependent features of a
disabled feature are disabled as well. For the CLI, this allows only needing to specify that
`async-await` is disabled in the esbuild options.
2022-08-31 08:38:33 -04:00
Alan Agius
9aab9ad54d fix(@angular-devkit/build-angular): issue warning when using deprecated tilde imports
With this change we add a warning when using deprecated tilde/`~` imports.
2022-08-30 12:26:14 -04:00
Charles Lyding
d50d09f98d fix(@angular-devkit/build-angular): allow esbuild-based builder to use SVG Angular templates
The experimental esbuild-based browser application builder will now consider SVG files as
Angular component templates. Previously, only HTML files were considered templates and this
resulted in the esbuild-based builder to try to process the SVG file as a stylesheet.
2022-08-29 08:17:47 -04:00
Alan Agius
1c042f38a6 refactor(@angular-devkit/build-angular): remove deprecated usage of canParse
All parsers now implement `parser.analyze`.
2022-08-29 08:17:31 -04:00
Charles Lyding
2b34935727 refactor(@angular-devkit/build-angular): reorganize esbuild builder setup steps
This contains several minor adjustments to the setup steps for the experimental
esbuild-based browser application builder. It better groups the output directory
deletion and creation steps as well as moves entry point normalization into the
normalize options helper function. This should reduce the size of the main
execution function as well as aid in future profiling of the build phases.
2022-08-29 08:15:49 -04:00
Charles Lyding
b647d8069f fix(@angular-devkit/build-angular): correct esbuild builder global stylesheet sourcemap URL
The sourcemap URL in the output CSS files for global stylesheets is now correctly updated to
reflect the name of the global stylesheet output file and not the internal `stdin` virtual
file name.
2022-08-25 10:18:08 -07:00
Charles Lyding
87a61aac36 perf(@angular-devkit/build-angular): with esbuild builder only load Sass compiler when needed
Previously, the Sass compiler was imported on the start of every build regardless of its usage.
The Sass compiler will now only be loaded if a Sass stylesheet is requested.
2022-08-23 12:31:52 -07:00
Charles Lyding
a910ae992c perf(@angular-devkit/build-angular): avoid extra string creation with no sourcemaps for esbuild sass
When using the experimental esbuild-based browser application builder with Sass stylesheets, an
additional string creation for each output stylesheet will now be avoided when sourcemaps are disabled.
2022-08-23 12:31:52 -07:00
Charles Lyding
823852d8c2 refactor(@angular-devkit/build-angular): process esbuild builder global stylesheets and code at the same time
The global stylesheet processing using esbuild and the code bundling that also uses esbuild are now executed
asynchronously. Previously, the global stylesheet processing was required to wait until the code bundling was
complete before starting. Any warnings and/or errors for global stylesheets will also now be shown even if there
are errors during code bundling.
2022-08-23 12:31:14 -07:00
Charles Lyding
4f4f9c9063 refactor(@angular-devkit/build-angular): move esbuild builder global stylesheet bundling into separate function
The global stylesheet bundling and processing code has been moved out of the main builder execution function
and into a separate function. This shortens the length of the main execution function for the builder and also
allows for further refactoring to allow the code and global stylesheet bundling to be executed at the same time.
2022-08-23 12:31:14 -07:00
Alan Agius
147f8c3ebb fix(@angular-devkit/build-angular): correctly handle parenthesis in url
PR #23691 introduced a regression that caused paranthesis in url not to be handled correctly.

This change correct this behaviour and adds a test case to valid this.

Closes #23773
2022-08-22 16:01:14 -07:00
Alan Agius
4368c85983 refactor: remove unused local variables 2022-08-12 08:19:26 -04:00
Alan Agius
78cacc30e5 refactor(@angular-devkit/build-angular): remove workaround for handle options requests
The upstream fix https://github.com/webpack/webpack-dev-server/issues/4180 has been merged and released as part of `webpack-dev-server` version `4.10.0`
2022-08-11 09:40:42 -04:00
Charles Lyding
50c783307e fix(@angular-devkit/build-angular): use valid CSS comment for sourcemaps with Sass in esbuild builder
CSS does not support the single line JS comment (`//`) but rather only the multi-line comment (`/* */`).
When generating the sourcemap URL comment with the modern Sass API, the multi-line comment syntax will
now be used. This removes the esbuild warnings per Sass file that would have otherwise been generated
when stylesheet sourcemaps are enabled for the build.
2022-08-11 07:17:41 -04:00
Alan Agius
7de9b470cb fix(@angular-devkit/build-angular): avoid collect stats from chunks with no files
This commit updates to bundle stats logic to skip checking chunks with no files.

Closes #23717
2022-08-10 09:55:19 -04:00
Charles Lyding
f474bf532f fix(@angular-devkit/build-angular): process stylesheet resources from url tokens with esbuild browser builder
Stylesheet url tokens (`url(....)`) will now be processed when using the esbuild-based experimental browser
application builder. The paths will be resolved via the bundler's resolution system and then loaded
via the bundler's `file` loader. The functionality is implemented using an esbuild plugin to allow for all
file types to be supported without the need to manually specify each current and future file extension within
the build configuration.
The `externalDependencies` option also applies to the referenced resources. This allows for resource paths
specified with the option to remain unprocessed within the application output. This is useful if the relative
path for the resource does not exist on disk but will be available when the application is deployed.
2022-08-09 09:42:58 -04:00
Alan Agius
3fb569b5c8 feat(@angular-devkit/build-angular): switch to Sass modern API in esbuild builder
With this change we replace Sass legacy with the modern API in the experimental esbuilder. The goal is that in the next major version this change is propagated to the Webpack builder.

Based on the benchmarks that we did Sass modern API is faster compared to the legacy version.
2022-08-05 10:56:41 -07:00
Alan Agius
44c25511ea feat(@angular-devkit/build-angular): add ability to serve service worker when using dev-server
With this change we add the ability for the dev-server to serve service workers when configured in the browser builder.

Closes #9869
2022-08-04 11:26:30 -07:00
Charles Lyding
3e3dc6962d perf(@angular-devkit/build-angular): reduce babel transformation in esbuild builder
When using the experimental esbuild-based browser application builder, babel transformation
is now only performed on a file if the file requires the specific transformations enabled
for the build. This has the benefit of removing the need to parse and process files that
will not be affected by the enabled transformations.
From initial testing, this provides a 30% build time improvement for development builds of a
newly generated application and a 10% improvement for production builds.
2022-08-04 11:26:15 -07:00
Charles Lyding
8f9cee351e perf(@angular-devkit/build-angular): use esbuild in esbuild builder to downlevel native async/await
esbuild now allows specifying whether individual JavaScript features should be supported in addition
to specifying the target JavaScript version for the output. This capability is now used to provide
the native async/await downleveling that is required by Zone.js when using the experimental esbuild-
based browser application builder. Since esbuild does not yet support downleveling async iteration
or async generators, Babel is still used when either of these syntax features are detected.
2022-08-04 11:26:15 -07:00
Alan Agius
70bc35456a fix(@angular-devkit/build-angular): correctly handle data URIs with escaped quotes in stylesheets
Previously, the RegExp didn't correctly handle cases where data URIs had escaped quotes like the below

```css
url("data:image/svg+xml;charset=utf-8,<svg width=/"16/" height=/"15/"></svg>")
```

Closes #23680
2022-08-04 11:25:25 -07:00
Angular Robot
afdb266ad1 build: update all non-major dependencies 2022-08-03 10:34:50 -07:00
Alan Agius
173823d772 build: remove dependency on font-awesome
This dependency is only used to valid that node packages are resolved correctly.

With this change we mock the structure of font-awesome to avoid having to install it.
2022-08-03 09:20:29 -07:00
Alan Agius
b4a1b0f104 fix(@angular-devkit/build-angular): correctly respond to preflight requests
With this commit, we add a middleware that handles preflight requests as currently responses for this type of requests returning 404.

This is a temporary workaround until this issue is fixed upstream. See: https://github.com/webpack/webpack-dev-server/issues/4180

Closes #23639
2022-08-02 09:47:52 -07:00
Alan Agius
cdbb48f7b2 test(@angular-devkit/build-angular): re-write live-reload tests to use new test harness.
With this change we replace the live-reload proxy tests to use the new test harness. This is an effort to reduce the flakiness of these tests.
2022-08-01 11:19:48 -07:00
Jason Bedard
35c43577d5
test: use random e2e test ports (#23541)
* test: use random e2e test ports

* test: use random ng serve ports
2022-07-28 19:23:42 +02:00
Alan Agius
8fd3e9fb3c fix(@angular-devkit/build-angular): catch clause variable is not an Error instance
Errors thrown in RxJs are not instanceof Error and therefore the check will always fail.

Closes #23631
2022-07-28 09:46:53 +02:00
Alan Agius
aa83feb373 fix(@angular-devkit/build-angular): correctly set ngDevMode in esbuilder
During development we should not set `ngDevMode` to `true`, as this is expected to be an object literal.

Closes #23627
2022-07-22 12:48:39 -04:00
Charles Lyding
6a142a22f8 fix(@angular-devkit/build-angular): allow the esbuild-based builder to fully resolve global stylesheet packages
The esbuild-based experimental builder will now leverage the bundler to perform resolution of CSS imports.
This allows for more comprehensive resolution including packages which use the `sass` and/or `style` custom
conditions within a `package.json` exports field.
2022-07-22 10:45:31 -04:00
Victor Porof
f3087dc434 feat(@angular-devkit/build-angular): Identify third-party sources in sourcemaps
This PR includes a webpack plugin which adds a field to source maps that identifies which sources are vendored or runtime-injected (aka third-party) sources. These will be consumed by Chrome DevTools to automatically ignore-list sources.

When vendor source map processing is enabled, this is interpreted as the developer intending to debug third-party code; in this case, the feature is disabled.

Signed-off-by: Victor Porof <victorporof@chromium.org>
2022-07-18 15:33:33 -04:00
Alan Agius
d8cfe8b226 fix(@angular-devkit/build-angular): fallback to use projectRoot when sourceRoot is missing during coverage
With this change we fallback to use the projectRoot when the sourceRoot is missing for files to be included in coverage.

Closes: #23591
2022-07-18 12:25:59 -04:00
Alan Agius
449be8868f test: update live-reload test to reduce flakes
- assign dynamic port to proxy server
- remove RXJS `finalize` in favor of `finally`
2022-07-12 10:20:26 -07:00
Charles Lyding
b3a14d0562 fix(@angular-devkit/build-angular): allow third-party sourcemaps to be ignored in esbuild builder
The `sourcemap.vendor` build option for the esbuild-based browser application builder will now
properly be considered when processing sourcemaps for third-party code (code originating from
a `node_modules` directory).
2022-07-12 10:20:12 -07:00