287 Commits

Author SHA1 Message Date
Alan Agius
d21e511b6b refactor(@angular/build): split SSR server assets into separate chunks
This commit refactors the build process for server-side rendering (SSR) by dividing server assets into separate, importable chunks rather than bundling them into a single output file.
2024-11-04 20:31:03 +01:00
Angular Robot
316df8fbba build: update all non-major dependencies 2024-11-04 16:44:14 +01:00
Charles Lyding
d16a9aa437 fix(@angular/build): check referenced files against native file paths
When checking for bundler context invalidation for any referenced files,
the native path format is now used to ensure that the watch files can
be correctly matched. This is particularly important for Windows due to
the differing path segment separator.
2024-11-02 15:57:50 -04:00
Charles Lyding
aaaa4bc5f4 refactor(@angular/build): allow in-memory caching of server main code bundling during rebuilds
In addition to the other main code bundling steps, the server main code will
also be cached and invalidated based on file changes in watch mode.
2024-11-02 08:26:57 -04:00
Charles Lyding
7eabe7d4b3 refactor(@angular/build): avoid need to pre-import angular compiler package in dev server
Within the development server, the external stylesheet encapsulation logic has been
adjusted to avoid needing to asynchronously import the `@angular/compiler` package within
the request execution. This removes the need to pre-import the package at the start of the
development server which was previously used to avoid a delay in stylesheet response on
first use. The external stylesheet response execution is also now fully synchronous.
2024-11-01 18:42:00 -04:00
Charles Lyding
5efcf88a35 refactor(@angular/build): send error status code on invalid external style component ID
If an invalid component identifier is provided to the development server for an external
stylesheet requiring encapsulation, both a console message and a 400 status response will
now be sent. This removes the potential for invalid styles to be sent to the browser.
2024-11-01 18:42:00 -04:00
Alan Agius
505521e546 perf(@angular/ssr): integrate ETags for prerendered pages
When using the new developer preview API to serve prerendered pages, ETags are added automatically, enabling efficient caching and content validation for improved performance.
2024-11-01 19:52:03 +01:00
Charles Lyding
fba2799154 refactor(@angular/build): allow caching of TypeScript build contexts for rebuilds
Now that the TypeScript bundler contexts perform additional checks for validity,
they can now be cached in memory during watch modes. This allows the TypeScript
bundler contexts to skip rebundling when not affected by a file changed. This is
particularly beneficial for style related file changes where no code processing
is otherwise required.
2024-11-01 10:13:13 -04:00
Charles Lyding
2aa25a73a8 fix(@angular/build): ensure SVG template URLs are considered templates with external stylesheets
When using the development server with the application builder (default for new projects),
the external stylesheet functionality for component style hot replacement was incorrectly
considering SVG files as stylesheet resources. This resulted in a build error when using
SVG files as a template source. The file extension based checks have now been improved to
account for this usage.
2024-11-01 10:12:44 -04:00
Charles Lyding
abde078233 refactor(@angular/build): improve typescript bundling context rebuild checking
The TypeScript-based bundling contexts have now been separated from the other
bundling contexts that may be present in an application build. The later of which
include global styles, scripts, and non-TypeScript polyfills. This allows for
the TypeScript bundling contexts to perform additional checks during a rebuild to
determine if they actually need to be rebundled. The bundling context caching for
the TypeScript contexts has not yet been enabled but these changes prepare for the
switch to allow conditional rebundling on file changes.
2024-11-01 09:30:09 -04:00
Angular Robot
69768bdaa4 build: update all non-major dependencies 2024-11-01 08:25:17 -04:00
Charles Lyding
5c2aa2f4b1 refactor(@angular/build): allow experimental template update generation via environment variable
The experimental Angular component template hot replacement capabilities
will be initially controlled via an environment variable. Setting `NG_HMR_TEMPLATES=1`
with the development server that is using the application builder will generate the
runtime event code to support hot replacement of an individual component template.
The build system itself does not yet generate the component update build results needed
to trigger the runtime events. The environment variable is currently intended to support
integration of the remaining code to fully implement the feature.
2024-11-01 07:17:29 -04:00
Alan Agius
481ccdbc5a fix(@angular/ssr): enable serving of prerendered pages in the App Engine
This commit implements the capability for the App Engine to serve prerendered pages directly. Previously, we relied on frameworks like Express for this functionality, which resulted in inconsistent redirects for directories where in some cases a trailing slash was added to the route.

**Note:** This change applies only when using the new SSR APIs. When using the `CommonEngine`, a 3rd party static serve middleware is still required.
2024-11-01 10:45:05 +01:00
Alan Agius
3371f5b9ab fix(@angular/build): Exclude known --import from execArgv when spawning workers
This change prevents Bazel compilation issues in the ADEV build process.
2024-10-31 12:42:53 +01:00
Alan Agius
a3e2bcd6b4 refactor(@angular/build): remove experimental buildApplication overload
An experimental overload of `buildApplication` has been removed.
2024-10-30 19:47:40 -04:00
Charles Lyding
7172df1243 refactor(@angular/build): allow forcing bundler context rebundle
A bundle call for a `BundlerContext` can now force a rebundling in cases
where the cached version should not be used. This is currently not leveraged
within the code but will be used for improvements to typescript based context
rebuilds in the future.
2024-10-30 18:21:43 -04:00
Alan Agius
c242d2933a fix(@angular/build): set ngServerMode during vite prebundling
This commit sets the `ngServerMode` in the prebundled deps.
2024-10-30 23:19:10 +01:00
Charles Lyding
bc43f9567c build: add return types for component stylesheet bundler 2024-10-30 14:26:19 -04:00
Angular Robot
170bb19074 build: update all non-major dependencies 2024-10-30 12:27:43 -04:00
Charles Lyding
a9772068d5 refactor(@angular/build): directly bundle external component file-based style changes
When using the development server with the application builder, file-based component
styles will now be bundled during the main builder execution instead of within the
application code bundling step. This allows for these styles to be processed independently
from any code bundling steps and will support future changes that will allow the
builder to completely skip code bundling if only file-based component stylesheets are changed.
2024-10-30 11:07:53 -04:00
Charles Lyding
bc771ae2d0 fix(@angular/build): always record component style usage for HMR updates
When using the development server with the application builder, external
component stylesheet usage must always be record to ensure that any hot
replacement actions correctly reference the relevant components. Previously,
browser cached styles would return a 304 status prior to recording the usage.
This resulted in the development server not knowing that the component needed
a potential update in the future.
2024-10-29 13:14:00 -04:00
Alan Agius
8e2829c851 refactor(@angular/build): add handling for ngServerMode
Configure esbuild to add `ngServerMode` as define.
2024-10-29 07:44:55 +01:00
Angular Robot
afec9297dc build: update all non-major dependencies 2024-10-28 14:36:59 -04:00
Charles Lyding
4df44dcfb6 refactor(@angular/build): use ETags for dev-server resource requests
When using the development server with the application build system,
resource files managed by the build system will now using ETag headers
to avoid resending content that has not changed since the last request.
This includes such content as global stylesheet files, image/font files
referenced in stylesheets, and other files managed by the bundler.
2024-10-28 14:16:16 -04:00
Alan Agius
15677d0cb7 refactor: replace critters with beasties
The Critters project has been transferred to the Nuxt team, who will now manage its development and has been renamed to Beasties.

See: https://github.com/danielroe/beasties
2024-10-28 18:57:05 +01:00
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