231 Commits

Author SHA1 Message Date
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
Charles Lyding
e9b29be33e refactor(@angular/build): remove deprecated Vite node server hot field usage
The `ViteServer` instance's `hot` field is deprecated and will eventually be
removed. The `ws` field can be used in its place.
2024-10-01 11:32:18 +02:00
Alan Agius
f63072668e feat(@angular/build): utilize ssr.entry during prerendering to enable access to local API routes
The `ssr.entry` (server.ts file) is now utilized during prerendering, allowing access to locally defined API routes for improved data fetching and rendering.
2024-10-01 09:35:29 +02:00
Angular Robot
a896b74ac1 build: update all non-major dependencies 2024-09-30 09:53:17 +02:00
Alan Agius
87a90afd46 fix(@angular/build): incomplete string escaping or encoding
See: https://github.com/angular/angular-cli/security/code-scanning/76
2024-09-27 21:45:18 +02:00
Jan Martin
0a4ef30263 feat(@angular-devkit/build-angular): karma-coverage w/ app builder 2024-09-27 12:06:52 -07:00
nosaku
ecfb2b2613 fix(@angular/build): add few more SVG elements animateMotion, animateTransform, and feBlend etc. to valid self-closing elements 2024-09-27 09:30:56 -04:00
Alan Agius
1a933c9dd3 refactor(@angular/build): improve HTML Code Sanitization in Manifest
See: https://github.com/angular/angular-cli/security/code-scanning/74
2024-09-26 17:54:43 +02:00
Charles Lyding
7c3bab95e0 refactor(@angular/build): use new encapsulate style helper for HMR
The `@angular/compiler` package now has an updated `encapsulateStyle` helper
that allows directly providing the component identifier as an argument.
This avoids needing to perform an additional regular expression replace
with the internal marker text.
Also, the component identifier validity check has been updated to support
unicode characters in the event they happen to be used for the application
identifier.
2024-09-26 09:31:54 -04:00
Alan Agius
dd499499c7 fix(@angular/build): add animate to valid self-closing elements
The `<animate>` tag, used for SVG animations, was incorrectly treated as a non-self-closing tag by the Angular build process. This resulted in errors during the build, as the parser expected a closing `</animate>` tag even when unnecessary.

Closes #28502
2024-09-26 15:19:53 +02:00
Alan Agius
b5ec679a15 refactor(@angular/build): add NG_BUILD_PARTIAL_SSR environment variable to disable prerendering and manifest generation
This change allows for forced disabling of prerendering and route extraction when using Vite with Angular CLI. In certain scenarios, such as when the application builder is invoked directly and not in watch mode (e.g. ADEV), an external configuration may be necessary.
2024-09-25 15:46:29 +02:00
Angular Robot
df46657df7 build: update all non-major dependencies 2024-09-25 09:13:04 -04:00
Charles Lyding
1548827a98 refactor(@angular/build): support external runtime styles for inline component styles
The build system will now transform inline styles into a corresponding external runtime
style with a URL for the Angular AOT compiler when the development server has enabled
component HMR for styles. This allows both file-based and inline component styles to
be eligible for component style HMR. The inline styles are provided to the development
server in an equivalent form to the file-based styles which the Angular runtime will
request via `link` elements during development. A unique identifier is produced for
each inline style that combines the containing file and order of the style within the
containing file to represent the location of the style. This provides an equivalent
unique identifier to the full path used by file-based styles.
2024-09-24 15:43:49 -04:00
Charles Lyding
9502d4644f refactor(@angular/build): support external runtime component stylesheets in application builder
To support automatic component style HMR, `application` builder in development mode now
provides support for generating external runtime component stylesheets. This capability
leverages the upcoming support within the AOT -compiler to emit components that generate
`link` elements instead of embedding the stylesheet contents for file-based styles
(e.g., `styleUrl`). In combination with support within the development server to handle
requests for component stylesheets, file-based component stylesheets will be able to be
replaced without a full page reload.

The implementation leverages the AOT compiler option `externalRuntimeStyles` which uses
the result of the resource handler's resolution and emits new external stylesheet metadata
within the component output code. This new metadata works in concert with the Angular runtime
to generate `link` elements which can then leverage existing global stylesheet HMR capabilities.

This capability is current disabled by default while all elements are integrated across the
CLI and framework and can be controlled via the `NG_HMR_CSTYLES=1` environment variable.
Once fully integrated the environment variable will unneeded.

This feature is only intended for use with the development server. Component styles within
in built code including production are not affected by this feature.

NOTE: Rebuild times have not yet been optimized. Future improvements will reduce the component
stylesheet only rebuild time case.
2024-09-24 15:43:49 -04:00
Alan Agius
a995c8ea6d fix(@angular/build): prevent prerendering of catch-all routes
Updated the build process to exclude catch-all routes from being prerendered.
2024-09-24 17:02:55 +02:00
Alan Agius
158774a5f6 refactor(@angular/build): move vite plugins into a seperate directory
Improve code structure
2024-09-23 22:34:55 +02:00
Alan Agius
92209dd2e9 feat(@angular/ssr): add createRequestHandler and createNodeRequestHandler utilities
Introduced the `createRequestHandler` and `createNodeRequestHandler` utilities to expose middleware functions from the `server.ts` entry point for use with Vite.
This provides flexibility in integrating different server frameworks, including Express, Hono, and Fastify, with Angular SSR.

Examples:

**Express**
```ts
export default createNodeRequestHandler(app);
```

**Nest.js**
```ts
const app = await NestFactory.create(AppModule);
export default createNodeRequestHandler(app);
```

**Hono**
```ts
const app = new Hono();
export default createRequestHandler(app.fetch);
```

**Fastify**
```ts
export default createNodeRequestHandler(async (req, res) => {
  await app.ready();
  app.server.emit('request', req, res);
});
```
2024-09-23 22:34:55 +02:00
Alan Agius
bbc290133f feat(@angular/build): utilize ssr.entry in Vite dev-server when available
When `ssr.entry` (server.ts) is defined, Vite will now use it in the dev-server. This allows API and routes defined in `server.ts` to be accessible during development. This feature requires the new `@angular/ssr` APIs, which are currently in developer preview.
2024-09-23 22:34:55 +02:00
Angular Robot
1434d621f9 build: update all non-major dependencies 2024-09-23 08:57:37 -04:00
Angular Robot
b65ef44cbe build: update all non-major dependencies 2024-09-20 15:05:14 -07:00
Angular Robot
a442153fa8 build: update all non-major dependencies 2024-09-19 16:03:56 -07:00
Alan Agius
3b00fc908d feat(@angular/build): introduce outputMode option to the application builder
The `outputMode` option accepts two values:
- **`static`:**  Generates a static output (HTML, CSS, JavaScript) suitable for deployment on static hosting services or CDNs. This mode supports both client-side rendering (CSR) and static site generation (SSG).
- **`server`:** Generates a server bundle in addition to static assets, enabling server-side rendering (SSR) and hybrid rendering strategies. This output is intended for deployment on a Node.js server or serverless environment.

- **Replaces `appShell` and `prerender`:**  The `outputMode` option simplifies the CLI by replacing the `appShell` and `prerender` options when server-side routing is configured.
- **Controls Server API Usage:**  `outputMode` determines whether the new server API is utilized. In `server` mode, `server.ts` is bundled as a separate entry point, preventing direct references to `main.server.ts` and excluding it from localization.

Closes #27356, closes #27403, closes #25726, closes #25718 and closes #27196
2024-09-19 21:29:34 +02:00
Alan Agius
fedeeb0a30 refactor(@angular/build): update SSR Vite middleware to utilize the enhanced API
Updated the SSR Vite middleware to align with the latest API improvements
2024-09-19 18:51:50 +02:00
Charles Lyding
13a3e430da fix(@angular/build): allow missing HTML file request to fallback to index
If a HTTP request is made to the development server that explicitly requests
an HTML file (i.e., `/abc.html`), the development server will now attempt to
fallback to the root `index.html` file if the requested HTML file does not exist.
Since this may indicate a defect or other application misconfiguration such as a
missing asset, a warning will also be issued in the console during development to
notify the developer that something may be wrong.
2024-09-19 12:47:03 -04:00
Angular Robot
bd782dbe36 build: update all non-major dependencies 2024-09-18 11:16:50 -07:00
Charles Lyding
f6b7cd925d fix(@angular/build): support HTTP HEAD requests for virtual output files
When using the development server, HTTP HEAD requests will now correctly
respond for the virtual output files generated from the Angular build
system.  Previously Vite only handled GET requests for the files. While
HEAD requests are not common in development workflows, it can be needed in
more complex cases with additional servers/proxies/etc. during development.
2024-09-18 09:31:37 -04:00
Charles Lyding
f249e7e856 perf(@angular/cli): enable Node.js compile code cache when available
The Angular CLI will now enable the Node.js compile cache when available
for use. Node.js v22.8 and higher currently provide support for this feature.
The compile cache stores the v8 intermediate forms of JavaScript code for the Angular
CLI itself. This provides a speed up to initialization on subsequent uses the Angular CLI.
The Node.js cache is stored in a temporary directory in a globally accessible
location so that all Node.js instances of a compatible version can share the
cache. The code cache can be disabled if preferred via `NODE_DISABLE_COMPILE_CACHE=1`.

Based on initial profiling, this change provides an ~6% production build time
improvement for a newly generated project once the cache is available.

```
Benchmark 1: NODE_DISABLE_COMPILE_CACHE=1 node ./node_modules/.bin/ng build
  Time (mean ± σ):      2.617 s ±  0.016 s    [User: 3.795 s, System: 1.284 s]
  Range (min … max):    2.597 s …  2.640 s    10 runs

Benchmark 2: node ./node_modules/.bin/ng build
  Time (mean ± σ):      2.475 s ±  0.017 s    [User: 3.555 s, System: 1.354 s]
  Range (min … max):    2.454 s …  2.510 s    10 runs

Summary
  node ./node_modules/.bin/ng build ran
    1.06 ± 0.01 times faster than NODE_DISABLE_COMPILE_CACHE=1 node ./node_modules/.bin/ng build
```
2024-09-18 09:30:57 -04:00
Alan Agius
2640bf7a68 fix(@angular/ssr): correct route extraction and error handling
This commit introduces the following changes:
- Disallows paths starting with a slash to match Angular router behavior.
- Errors are now stored and displayed at a later stage, improving UX by avoiding unnecessary stack traces that are not useful in this context.
2024-09-16 21:22:10 +02:00
Angular Robot
d60f3fef30 build: update dependency @inquirer/confirm to v4 2024-09-16 17:32:05 +02:00
Angular Robot
c9324e7ee8 build: update all non-major dependencies 2024-09-16 08:19:09 +02:00
Alan Agius
902dbf3a88 refactor(@angular/build): assign name to custom Vite middleware for better debugging
Naming the custom middleware improves the ability to identify middleware order during debugging.
2024-09-13 17:54:54 +02:00
Alan Agius
740c6486e2 refactor(@angular/build): implement custom middleware for header appending
Replaced multiple `appendServerConfiguredHeaders` calls with a single custom middleware to append headers to all responses, simplifying the code and ensuring consistency.
2024-09-13 17:54:54 +02:00