262 Commits

Author SHA1 Message Date
Charles Lyding
b73b98de65 refactor(@angular/build): use ETag headers for development external component styles
When using the development server, Angular component stylesheet requests that
use hot replacement (default for v19) will now use the `ETag` header to remove
the need to reprocess and resend encapsulated component styles if the styles
have not changed since last usage. The ETag value used is a combination of the
style content and the encapsulation component identifier.
2024-10-28 12:29:01 -04:00
Alan Agius
d8f926fa7f fix(@angular/build): simplify disabling server features with --no-server via command line
When `outputMode` is configured, `--prerender` and `--app-shell` become no-ops, making server feature disabling difficult without modifying the configuration.

This commit introduces the `--no-server` option, which can be used with `--output-mode static` to fully disable all server features.

```
ng build --output-mode static --no-server
```
2024-10-28 16:08:06 +01:00
Alan Agius
137e8e0ceb fix(@angular/build): add warning when --prerendering or --app-shell are no-ops
Both options are ineffective when used with `outputMode`, so a warning is now issued.
2024-10-28 16:08:06 +01:00
Angular Robot
1890fe4e94 build: update all non-major dependencies 2024-10-24 08:29:52 -07:00
Charles Lyding
31f903709c fix(@angular/build): avoid hashing development external component stylesheets
When using the development server with a production configuration or with bundle
hashing enabled, the external stylesheet files used by the development server for
hot replacement of component styles are no longer hashed. This ensures that the
requests from the runtime served by the development server match the available
generated component stylesheet files.
2024-10-24 10:15:32 -04:00
Angular Robot
ff88c3f6a1 build: update all non-major dependencies 2024-10-23 11:49:20 +02:00
Alan Agius
cc345b02d8 fix(@angular/build): Address build issue in Node.js LTS versions with prerendering or SSR
In Node.js 20, changes to ESM loader hooks result in the `--import` execArgv being passed from the parent to child workers.

This commit resolves the issue by setting an empty `execArgv` in the JavaScript transformer, preventing unintended propagation.

Closes #28683
2024-10-23 11:20:07 +02:00
Aaron Shim
efb434136d feat(@angular/build): Auto-CSP support as a part of angular.json schema
Following up on the logic provided in #28639, we want to offer an opt-in
option in angular.json to enable the auto-CSP transformation.

For now, builds for `ng serve` will have Auto-CSP disabled.
2024-10-22 15:47:23 -07:00
Alan Agius
b893a6ae9d refactor: remove workarounds for Safari 14 and 15
Both of these versions are no longer supported by Angular and thus these workers are no longer required.
2024-10-22 19:18:12 +02:00
Aaron Shim
6beffd138e refactor(@angular/build): Auto-CSP support as an index file transformation.
Auto-CSP is a feature to rewrite the `<script>` tags in a index.html
file to either hash their contents or rewrite them as a dynamic loader
script that can be hashed. These hashes will be placed in a CSP inside a
`<meta>` tag inside the `<head>` of the document to ensure that the
scripts running on the page are those known during the compile-time of
the client-side rendered application.
2024-10-22 09:57:16 -07:00
Charles Lyding
6486b575b9 refactor(@angular/build): add internal support for generating template update functions
The internal AOT Angular compilation processing can now generate the newly
introduced template update functions during development server rebuilds of
template only file changes. These template update functions are not yet used
but provide the infrastructure to enable template hot replacement in a
future change.
2024-10-22 05:53:14 -04:00
Angular Robot
1128773122 build: update all non-major dependencies 2024-10-21 14:32:48 -07:00
Charles Lyding
446fd9486f refactor(@angular/build): create component stylesheet bundler at start of build
The component stylesheet bundler is now created at the start of the build
and accessible prior to the bundling actions. This will provide support for
generating updated component styles and bypassing all code bundling when using
the development server and only component styles have been modified.
2024-10-21 07:21:28 -04:00
Charles Lyding
7fa971d0d5 refactor(@angular/build): move component stylesheet bundler out of compiler plugin
The component stylesheet bundler is now created during the setup of the Angular
compiler plugin options. This is an initial step to support more fine-grained
rebuild actions with the new component stylesheet development server support.
2024-10-21 07:21:28 -04:00
Angular Robot
c38ff43473 build: update all non-major dependencies 2024-10-18 19:54:45 +00:00
Charles Lyding
0b5e5c43de refactor(@angular/build): add helper types to internal HTML rewriter
The `StartTag` and `EndTag` types are now also exported along with the
`htmlRewritingStream` factory. These types are commonly used with the
rewriter and by exporting them reduces the need to manually extract them
from the underlying methods.
2024-10-18 10:18:04 -04:00
Charles Lyding
1654acf0ff fix(@angular/build): relax constraints on external stylesheet component id
The number of digits in the component identifier that is generated at runtime
can vary. The check for a valid identifier now accounts for this case.
2024-10-17 10:48:50 -04:00
Angular Robot
1f4428f0b3 build: update all non-major dependencies 2024-10-17 14:27:54 +00:00
Alan Agius
3cbbf456c1 refactor: handle standalone by default change
In tests, add `standalone: false` where it's missing.

Note: In the future, we should update our integration tests to use a standalone app.
2024-10-17 14:20:52 +00:00
Charles Lyding
816e3cb868 feat(@angular/build): enable component stylesheet hot replacement by default
When using the `application` builder (default for new projects) with the
development server, component style only changes will now automatically
replace the styles within the running application without a full reload
of the page. No application code changes are necessary and both file-based
(`styleUrl`/`styleUrls`) and inline (`styles`) component styles are supported.
Within a component template, `<style>` elements and `<link rel="stylesheet">`
elements with relative `href` attributes are also supported.

If any issues are encountered or it is preferred to not hot replace component
styles, the `NG_HMR_CSTYLES=0` environment variable can be used to disable
the feature. Setting the `liveReload` option to false will also disable all
updates.
2024-10-16 13:44:09 -04:00
Charles Lyding
13b65dfe19 fix(@angular/build): allow direct bundling of TSX files with application builder
When using the application builder with `isolatedModules`, the bundler will
directly handle TypeScript transpilation and bundling. Previously, any input
TSX files were loaded by the bundler as TS files. This difference caused errors
when attempting to process the files since the syntax differs between TSX and TS.
The appropriate loader will now be used if the input file is TSX in this situation.
2024-10-16 09:58:42 -04:00
Alan Agius
b6951f4482 feat(@angular/build): add sass to stylePreprocessorOptions in application builder
This commit introduces the functionality to configure a limited number of options for Sass processing in the Angular application builder. The following options have been added to enhance the Sass integration:

- **futureDeprecations**: Specifies features that are scheduled for deprecation. The compiler will treat these as active and emit warnings as necessary.
- **fatalDeprecations**: Identifies Sass features that are already deprecated and will cause build failures if used.
- **silenceDeprecations**: This option suppresses deprecation warnings for specified versions.

Usage example:
```json
"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:application",
    "options": {
      "outputHashing": "none",
      "namedChunks": true,
      "stylePreprocessorOptions": {
        "sass": {
          "futureDeprecations": ["color-functions"],
          "fatalDeprecations": ["color-functions"],
          "silenceDeprecations": ["1.77.0"]
        }
      }
    }
  }
}
```

For more information about these options, please refer to the  Sass documentation: https://sass-lang.com/documentation/js-api/interfaces/options/

Closes #28587
2024-10-16 10:31:05 +02:00
Charles Lyding
af52fb49bd fix(@angular/build): synchronize import/export conditions between bundler and TypeScript
To improve type-checking and reduce hard to diagnose errors when using the new
`production`/`development` conditions, the set of conditions used by the bundler
are now also synchronized with those used by TypeScript. This helps ensure
that type mismatches are avoided by type-checking against the actual file that
will be bundled into the output.
2024-10-15 09:37:55 -07:00
Angular Robot
e448cf6ee9 build: update all non-major dependencies 2024-10-15 09:30:59 -07:00
hborchardt
5f473affcf fix(@angular/build): avoid race condition in sass importer
On slow systems, a race condition can lead to the sass worker thread
being notified to wake up before a message is posted. This causes the
build to be aborted because the searched file is not found.

Waiting twice for a non-zero number in the signal handles this race
correctly, and the second wait should be a noop in the usual case.

Fixes #27167
2024-10-15 09:25:10 -07:00
Charles Lyding
0376167acf refactor(@angular/build): add component update middleware to development server
An additional development server middleware has been added that responds to
client `/@ng/component` requests from the Angular framework for hot component
template updates. These client requests are made by the framework after being
triggered by the development server sending a `angular:component-update`
WebSocket event. The Angular compiler's new internal `_enableHmr` option will
emit template replacement and reloading code that uses this new development
server update middleware. Within the development server, the component update
build result will be used to indicate that an event should be sent to active
clients. The build system does not yet generate component update results.
2024-10-15 09:01:11 -04:00
Jithil P Ponnan
a68e832aef fix(@schematics/angular): update browserslist config to include last 2 Android major versions 2024-10-14 09:35:06 -07:00
Angular Robot
fba1978af2 build: update dependency magic-string to v0.30.12 2024-10-11 08:45:51 -07:00
Angular Robot
7b994e49ea build: update all non-major dependencies 2024-10-11 10:03:29 +02:00
Alan Agius
bfa8fec9b1 fix(@angular/build): use named export reqHandler for server.ts request handling
Some cloud providers, such as Cloudflare, expect the default export to follow a specific structure (e.g., an object with a `fetch` property). To prevent the need for creating a separate `server.ts` file for production builds, the request handler is now exported as `reqHandler` instead of a default export.
2024-10-10 22:20:56 +02:00
Angular Robot
73b567a5f6 build: update all non-major dependencies 2024-10-10 10:21:38 -07:00
Charles Lyding
ac8f81e9d4 refactor(@angular/build): reduce inline style language value per call usage
The configured inline style language for Angular components is now set during
the construction of the component stylesheet bundler. This avoids needing to
repeatedly pass the value into each inline bundling call. The ability to
customize the language per call is retained to allow individual style control
if needed.
2024-10-10 07:12:28 -04:00
Jan Martin
c48d6947ed feat(@angular/build): set development/production condition
Ensures that we consistently set "development" for non-optimized and
"production" for optimized builds. This is consistent with other
bundlers (Vite/webpack/parcel/...).
2024-10-09 11:47:55 -07:00
Alan Agius
7d883a152e feat(@angular/build): introduce ssr.experimentalPlatform option
This commit introduces a new option called `experimentalPlatform` to the Angular SSR configuration.

The `experimentalPlatform` option allows developers to specify the target platform for the server bundle, enabling the generation of platform-neutral bundles suitable for deployment in environments like edge workers and other serverless platforms that do not rely on Node.js APIs.

This change enhances the portability of Angular SSR applications and expands their deployment possibilities.

**Note:** that this feature does not include polyfills for Node.js modules and is experimental, subject to future changes.
2024-10-09 20:31:00 +02:00
Alan Agius
292a4b7c2f feat(@schematics/angular): update app-shell and ssr schematics to adopt new Server Rendering API
This commit revises the app-shell and ssr schematics to incorporate the new Server Rendering API, along with the integration of server-side routes.

BREAKING CHANGE: The app-shell schematic is no longer compatible with Webpack-based builders.
2024-10-09 18:07:33 +02:00
Alan Agius
1bb68ba681 fix(@angular/build): move lmdb to optionalDependencies
A warning mechanism has been implemented to notify users when lmdb is unavailable. On Windows ARM64 systems, however, installing this package with pnpm appears to cause installation failures.

See: https://github.com/angular/angular-cli/issues/27882#issuecomment-2395029997

Closes #27882
2024-10-09 15:57:26 +02:00
Alan Agius
549c20a939 fix(@angular/build): Ctrl + C not terminating dev-server with SSR
This commit provides a workaround for https://github.com/angular/angular-cli/issues/28336, which occurs due to the interaction between `zone.js` and `listr2`. The issue prevents proper termination of the development server using Ctrl + C when dev-server.

Closes: #28336
2024-10-09 13:33:56 +02:00
Alan Agius
7c50ba9e2f fix(@angular/build): ensure index.csr.html is always generated when prerendering or SSR are enabled
This commit addresses an issue where `index.csr.html` was not being generated when SSR was disabled and prerendering was enabled.

Closes #28580
2024-10-09 10:29:13 +02:00
Angular Robot
4656c541d2 build: update all non-major dependencies 2024-10-08 10:10:55 -07:00
Alan Agius
9233e5ef47 fix(@angular/build): show error message when error stack is undefined
Handle cases where the error stack is missing by displaying a relevant message.

Closes #28590
2024-10-08 17:28:49 +02:00
Charles Lyding
834925d0fd refactor(@angular/build): only ignore watching node modules when watching root
The application builder performs fine-grained file watching now which removes
the need to watch the project root by default as it did in early implementations.
As a result, the need to ignore the `node_modules` directory is not longer necessary
by default and is only needed when the `NG_BUILD_WATCH_ROOT` environment variable
is enabled.
2024-10-08 07:49:02 -04:00
Angular Robot
6ce5c693f3 build: update dependency @inquirer/confirm to v5 2024-10-08 10:11:06 +02:00
Ihar Sazanavets
1d9db138f3 fix(@angular/build): always generate a new hash for optimized chunk 2024-10-07 09:44:15 -07:00
Charles Lyding
3264c1763c test(@angular/build): add test harness rebuild case helper function
To reduce duplicate code within tests for rebuild/watch scenarios, a new
helper has been added to the builder test harness.  This helper allows
passing in an array of test case functions that are executed in order per
rebuild. The development server's watch option tests have been updated to
use the new helper.
2024-10-04 09:58:24 +02:00
Alan Agius
6c618d495c fix(@angular/build): update logic to support both internal and external SSR middlewares
The previous logic was not on point

Closes #28556
2024-10-04 07:30:58 +02:00
Angular Robot
523c2c9e52 build: update all non-major dependencies 2024-10-03 09:21:55 +02:00
Alan Agius
80686beaa2 refactor(@angular/build): avoid hydration warnings when RenderMode.Client is set
With the introduction of the `RenderMode` configuration for routes, some routes may be set to `RenderMode.Client` while still including the `provideClientHydration()` function in the provider list during bootstrap. This led to a false-positive warning in the console, incorrectly suggesting a hydration misconfiguration.

This commit introduces a DOM marker that allows the framework to bypass these unnecessary checks, preventing the misleading warnings.

See: https://github.com/angular/angular/pull/58004
2024-10-02 15:08:21 +02:00
Alan Agius
c33e862328 refactor(@angular/build): Enable SSR with Prerendering Disabled in Vite
This commit enables server-side rendering (SSR) in Vite when prerendering is turned off. It also imports `@angular/compiler` in the SSR middleware to resolve the following issue:

```
[vite] Internal server error: The injectable 'PlatformNavigation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.

The injectable is part of a library that has been partially compiled. However, the Angular Linker has not processed the library to utilize JIT compilation as a fallback.

Ideally, the library should be processed with the Angular Linker for complete AOT compilation.
```

Closes #28523
2024-10-02 15:08:03 +02:00
Alan Agius
c0b76e3377 fix(@angular/build): separate Vite cache by project
Previously, Vite prebundled dependencies were stored in a shared directory across all projects, which caused the `_metadata.json` files to be overwritten. This resulted in undefined behavior, such as re-optimizing dependencies on each run when multiple projects were present in the workspace. Additionally, it introduced conflicts when running multiple `ng serve` processes simultaneously.

Closes #28536
2024-10-01 18:18:33 +02:00
Alan Agius
475340aa4f refactor(@angular/build): incomplete string escaping or encoding
See: https://github.com/angular/angular-cli/security/code-scanning/77
2024-10-01 16:32:36 +02:00