1503 Commits

Author SHA1 Message Date
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
Angular Robot
5c57e1da36 build: update dependency @inquirer/prompts to v7 2024-10-07 09:44:53 -07:00
Ihar Sazanavets
1d9db138f3 fix(@angular/build): always generate a new hash for optimized chunk 2024-10-07 09:44:15 -07:00
Alan Agius
4941725f9e refactor: remove unused methods and locals 2024-10-04 13:16:13 +02: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
Alan Agius
638715ecd4 refactor(@angular/ssr): Convert crypto unavailable error to a soft error
This update changes the handling of the crypto unavailable error in the Angular SSR environment. Instead of throwing a hard error, which could interrupt the application flow, the error is now treated as a soft error
2024-10-04 07:30:33 +02:00
Angular Robot
523c2c9e52 build: update all non-major dependencies 2024-10-03 09:21:55 +02:00
Angular Robot
5c72d5aa58 build: update angular 2024-10-02 16:50:33 +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
12ff37adbe perf(@angular/ssr): cache generated inline CSS for HTML
Implement LRU cache for inlined CSS in server-side rendered HTML.

This optimization significantly improves server-side rendering performance by reusing previously inlined styles and reducing the overhead of repeated CSS inlining.

Performance improvements observed:
Performance improvements observed:
* **Latency:** Reduced by ~18.1% (from 1.01s to 827.47ms)
* **Requests per Second:** Increased by ~24.1% (from 381.16 to 472.85)
* **Transfer per Second:** Increased by ~24.1% (from 0.87MB to 1.08MB)

These gains demonstrate the effectiveness of caching inlined CSS for frequently accessed pages, resulting in a faster and more efficient user experience.
2024-09-30 08:41:58 +02:00
Angular Robot
be3f3ff82f build: update dependency pacote to v19 2024-09-28 15:24:09 -04: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
Angular Robot
c0b1221ef4 build: update dependency npm-package-arg to v12 2024-09-27 11:20:07 -04: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
Angular Robot
0b4294af4a build: update dependency npm-pick-manifest to v10 2024-09-27 09:29:02 -04:00
Alan Agius
64c52521d0 fix(@angular/ssr): show error when multiple routes are set with RenderMode.AppShell
This change introduces error handling to ensure that when multiple routes are configured with `RenderMode.AppShell`, an error message is displayed. This prevents misconfiguration and enhances clarity in route management.
2024-09-26 22:50:37 +02:00
Alan Agius
50df631960 fix(@angular/ssr): improve handling of route mismatches between Angular server routes and Angular router
This commit resolves an issue where routes defined in the Angular server routing configuration did not match those in the Angular router. Previously, discrepancies between these routes went unnoticed by users. With this update, appropriate error messages are now displayed when mismatches occur, enhancing the developer experience and facilitating easier troubleshooting.
2024-09-26 22:50:37 +02:00
Jan Martin
e52ae7f6f5 perf(@angular/ssr): prevent potential stampede in entry-points cache
If multiple concurrent requests hit `getEntryPointExports`, all of
them would previously see the cache miss for entry point. With this
change, only the first request will and the others can leverage the
cache.

This can be important when instances are added to a pool under high
traffic.
2024-09-26 09:14:53 -07: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
Alan Agius
1d70e3b468 perf(@angular/ssr): cache resolved entry-points
Improve request throughput by 4.34% and reduce latency by caching resolved entry-points.
2024-09-26 17:02:33 +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
Angular Robot
c6dd4696bf build: update angular 2024-09-25 15:45:46 -04:00
Alan Agius
65b6e75a5d fix(@angular/ssr): export RESPONSE_INIT, REQUEST, and REQUEST_CONTEXT tokens
This commit exports that the `RESPONSE_INIT`, `REQUEST`, and `REQUEST_CONTEXT` tokens.
2024-09-25 17:08:42 +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
Alan Agius
ad014c7d9b refactor(@angular/ssr): update HtmlTransformHandler type to include URL parameter
Modified the `HtmlTransformHandler` type to accept a context object containing a URL and HTML content. This change supports the `html:transform:pre` hook, enhancing the handler's capability to process transformations based on the request URL.
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
8c9bf694da build: update angular 2024-09-18 11:34:04 -07:00