1872 Commits

Author SHA1 Message Date
Alan Agius
6eed4609f4 refactor(@angular/ssr): move ignored messages as a global
Refactored the ignored log messages into a global constant.
2024-12-11 14:52:26 +01:00
Aaron Shim
210bf4e2b4 fix(@angular/build): Fixing auto-csp edge cases where
- <script> is the last tag before </head> close
- .appendChild is called before </head> (because document.body is undefined then)
- <script> tags with a src attribute and no specified type attribute should not write <script type="undefined" ...>
2024-12-10 18:23:41 -08:00
Alan Agius
43127ddfb6 refactor(@angular/build): add globalThis['ngServerMode'] only when externalDependencies are present
This code is unnecessary when no external dependencies are involved.
2024-12-10 16:21:14 +01:00
Alan Agius
41ece633b3 feat(@angular/ssr): redirect to preferred locale when accessing root route without a specified locale
When users access the root route `/` without providing a locale, the application now redirects them to their preferred locale based on the `Accept-Language` header.

This enhancement leverages the user's browser preferences to determine the most appropriate locale, providing a seamless and personalized experience without requiring manual locale selection.
2024-12-10 13:11:06 +01:00
Alan Agius
8d7a51dfc9 feat(@angular/ssr): add modulepreload for lazy-loaded routes
Enhance performance when using SSR by adding `modulepreload` links to lazy-loaded routes. This ensures that the required modules are preloaded in the background, improving the user experience and reducing the time to interactive.

Closes #26484
2024-12-10 12:39:47 +01:00
Alan Agius
d811a7ffb0
fix(@angular/build): handle external @angular/ packages during SSR (#29094)
This commit introduces `ngServerMode` to ensure proper handling of external `@angular/` packages when they are used as externals during server-side rendering (SSR).

Closes: #29092
2024-12-09 18:26:12 +01:00
Alan Agius
28bdbeb62c revert: fix(@angular/build): show error when Node.js built-ins are used during ng serve
This commit reverts 06f478bc18d3e0daa8902d0fef94e55a5d052348

Closes: #29077
2024-12-09 17:11:03 +01:00
Angular Robot
e126bf9018 build: update all non-major dependencies 2024-12-08 15:32:03 +01:00
Alan Agius
0a570c0c2e feat(@angular/build): add support for customizing URL segments with i18n
Previously, the `baseHref` option under each locale allowed for generating a unique base href for specific locales. However, users were still required to handle file organization manually, and `baseHref` appeared to be primarily designed for this purpose.

This commit introduces a new `subPath` option, which simplifies the i18n process, particularly in static site generation (SSG) and server-side rendering (SSR). When the `subPath` option is used, the `baseHref` is ignored. Instead, the `subPath` serves as both the base href and the name of the directory containing the localized version of the app.

Below is an example configuration showcasing the use of `subPath`:

```json
"i18n": {
  "sourceLocale": {
    "code": "en-US",
    "subPath": ""
  },
  "locales": {
    "fr-BE": {
      "subPath": "fr",
      "translation": "src/i18n/messages.fr-BE.xlf"
    },
    "de-BE": {
      "subPath": "de",
      "translation": "src/i18n/messages.de-BE.xlf"
    }
  }
}
```

The following tree structure demonstrates how the `subPath` organizes localized build output:
```
dist/
├── app/
│   └── browser/  # Default locale, accessible at `/`
│       ├── fr/  # Locale for `fr-BE`, accessible at `/fr`
│       └── de/  # Locale for `de-BE`, accessible at `/de`
```

DEPRECATED: The `baseHref` option under `i18n.locales` and `i18n.sourceLocale` in `angular.json` is deprecated in favor of `subPath`.

The `subPath` defines the URL segment for the locale, serving as both the HTML base HREF and the directory name for output. By default, if not specified, `subPath` will use the locale code.

Closes #16997 and closes #28967
2024-12-07 19:00:32 +01:00
Alan Agius
d7214e9610 fix(@angular/ssr): include Content-Language header when locale is set
The server now includes the `Content-Language` HTTP header in responses whenever a locale is explicitly set.
2024-12-07 18:46:14 +01:00
Angular Robot
ffad81a4de build: update all non-major dependencies 2024-12-06 10:14:31 +01:00
Alan Agius
6647247ec0 test(@angular/ssr): refine spec setup to resolve component ID collision warnings
This update addresses excessive log noise caused by the following warning:
`NG0912: Component ID generation collision detected. Components 'AppComponent' and 'AppComponent' with selector 'app-root' generated the same component ID. To fix this, you can change the selector of one of those components or add an extra host attribute to force a different ID. Find more at https://angular.dev/errors/NG0912`.
2024-12-06 08:24:11 +01:00
Alan Agius
b8b561d452 refactor(@angular/build): move getDepOptimizationConfig into utils file
Reduce the amount of code in vite-server.ts
2024-12-05 20:18:35 +01:00
Alan Agius
c832bac9b2 fix(@angular/build): show error when Node.js built-ins are used during ng serve
This commit ensures consistent behavior between `ng build` and `ng serve`. Previously, `ng serve` did not display an error message when Node.js built-in modules were included in browser bundles. By default, Vite replaces Node.js built-ins with empty modules, which can lead to unexpected runtime issues. This update addresses the problem by surfacing clear error messages, providing better developer feedback and alignment between the two commands.

Closes: #27425
2024-12-05 17:44:44 +01:00
Angular Robot
f717a54066 build: update angular 2024-12-05 16:52:35 +01:00
Alan Agius
1ca260e807 docs(@angular/ssr): remove duplicate @return comment
Remove duplicate `@return` tsdoc comment.
2024-12-05 16:21:37 +01:00
Charles Lyding
75998ebabb perf(@angular/build): reuse TS package.json cache when rebuilding
TypeScript 5.6 and higher added functionality that will search for a
`package.json` file for source files that are part of the program (e.g., `.d.ts`)
and within a node modules directory. This can be an expensive tasks especially
considering the large amount of `.d.ts` files within packages. TypeScript supports
using a cache of known `package.json` files to improve the performance of this task.
The Angular CLI will now provide and reuse this cache across rebuilds during watch
mode. This includes the use of `ng serve`.

The performance difference is most apparent for the Angular template diagnostic
step of the build. Internally the Angular compiler creates a new template typechecking
program which causes the `package.json` search process to occur. By leveraging the
cache, this process becomes a series of cache hits. In the event that files are modified
within the node modules directory, the cache is invalidated and the following rebuild
may be longer as a result.
2024-12-05 09:40:09 +01:00
Alan Agius
f897b7a7f1 fix(@angular/ssr): apply HTML transformation to CSR responses
Before this commit, HTML transformations were not applied to CSR responses, leading to the omission of the Vite client code.

Closes #29033
2024-12-04 15:37:32 +01:00
Alan Agius
f2571b3251 build: update all non-major dependencies 2024-12-04 15:37:27 +01:00
Alan Agius
4db4dd4315 refactor(@angular/ssr): replace Map with Record in SSR manifest
Replaced `Map` with `Record` in SSR manifest to simplify structure and improve testing/setup.
2024-12-04 10:13:39 +01:00
Charles Lyding
378624d3f7 refactor(@angular/build): add initial component HMR source file analysis
When component template HMR support is enabled (`NG_HMR_TEMPLATES=1`),
TypeScript file changes will now be analyzed to determine if Angular component
metadata has changed and if the changes can support a hot replacement. Any
other changes to a TypeScript file will cause a full page reload to avoid
inconsistent state between the code and running application. The analysis
currently has an upper limit of 32 modified files at one time to prevent
a large of amount of analysis to be performed which may take longer than
a full rebuild. This value may be adjusted based on feedback. Component
template HMR is currently experimental and may not support all template
modifications. Both inline and file-based templates are now supported.
However, rebuild times have not yet been optimized.
2024-12-03 18:00:25 +01:00
Charles Lyding
a8ea9cf6ad fix(@angular/build): avoid deploy URL usage on absolute preload links
The `deployUrl` option was unintentionally being prepended to preload
links with absolute URLs within the generated index HTML for an appplication.
This has now been corrected and absolute URLs will not be altered when a
deploy URL is configured.
2024-12-03 17:24:37 +01:00
Alan Agius
97897b710a fix(@angular/build): ensure correct handling of index.output for SSR
Previously, the index file was not being renamed correctly when using server-side rendering (SSR).

Closes: #29012
2024-12-03 15:10:03 +01:00
Angular Robot
d96b096704 build: update all non-major dependencies 2024-12-03 08:35:22 +01:00
Charles Lyding
5bd937b86e fix(@angular/build): apply define option to JavaScript from scripts option
The `define` option will now apply to JavaScript that is included in the output
via the `scripts` option.  This allows the replacement of identifiers within any
included scripts in addition to the already supported replacement within application
code.
2024-12-03 08:33:48 +01:00
Alan Agius
e4448bb3d4 fix(@angular/ssr): correctly handle serving of prerendered i18n pages
Ensures proper handling of internationalized (i18n) pages during the  serving of prerendered content.
2024-12-02 15:39:56 +01:00
Angular Robot
994a782337 build: update all non-major dependencies 2024-12-02 13:31:21 +01:00
Alan Agius
4e5585a27f build: update Angular packages to version 19.1.x 2024-12-02 13:12:00 +01:00
Alan Agius
42e16ddce0 refactor(@angular/ssr): mark @angular/platform-server as optional
Whlist, this package is not really optional, NPM will install the wrong verson of peer dependencies when the Angular CLI is in prerelease mode.

```ts
STDERR:
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: test-project@0.0.0
npm error Found: @angular/animations@19.1.0-next.0
npm error node_modules/@angular/animations
npm error   @angular/animations@"^19.1.0-next.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @angular/animations@"19.0.1" from @angular/platform-server@19.0.1
npm error node_modules/@angular/platform-server
npm error   peer @angular/platform-server@"^19.1.0-next.0 || ^19.0.0" from @angular/ssr@19.1.0-next.0
npm error   node_modules/@angular/ssr
npm error     @angular/ssr@"19.1.0-next.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
```
2024-12-02 13:12:00 +01:00
James Henry
692e990750
docs(@angular/cli): update angular-eslint reference (#29001) 2024-12-02 10:02:01 +01:00
Alan Agius
aed726fca3 fix(@angular/build): add timeout to route extraction
This commit introduces a 30-second timeout for route extraction.
2024-11-27 16:48:33 -05:00
Alan Agius
4ef45ecf99 fix(@angular/cli): correctly select package versions in descending order during ng add
When using the `ng add` command, the package version selection logic was not correctly selected based on the available versions in desc order. This could lead to selecting an unintended version of the package.

Closes: #28985
2024-11-27 15:00:59 +01:00
Angular Robot
3a22d4435b build: update all non-major dependencies 2024-11-27 08:39:52 -05:00
Angular Robot
7554cc1ec2 build: update angular 2024-11-26 21:38:28 -05:00
Alan Agius
3dd3b2218b fix(@angular/ssr): ensure compatibility for Http2ServerResponse type
Updated the `Http2ServerResponse` interface to eliminate dependency on generics, ensuring compatibility across multiple versions of `@types/node`.

Closes #28965
2024-11-26 17:46:34 +01:00
Alan Agius
18041aab70 build: update to vite version 6
This commit updates vite to version 6
2024-11-26 17:25:41 +01:00
Charles Lyding
c81dd817df fix(@angular/build): allow .json file replacements with application builds
When using the `application` builder, the `fileReplacements` option will
now work as it previous did with the `browser` builder when replacing
JSON files.
2024-11-26 08:59:32 -05:00
Alan Agius
c685c70150 fix(@angular/build): prevent errors with parameterized routes when getPrerenderParams is undefined
Ensure that parameterized routes do not cause errors when the `getPrerenderParams` function is undefined, specifically in cases where the routing API is not utilized.

Closes #28948
2024-11-25 15:17:31 -05:00
Charles Lyding
5320e875ce refactor(@angular/build): maintain previous compiler plugin factory signature
To minimize downstream breakage for consumers of the private API, the
`createCompilerPlugin` function signature has been adjusted to maintain
compatibility with v18.
2024-11-25 15:04:28 -05:00
Alan Agius
8f9fc59f2e fix(@angular/build): minimize reliance on esbuild inject to prevent code reordering
Resolved an issue where the use of `esbuild`'s `inject` feature caused incorrect reordering of class structures during bundling. This reordering affected extended classes, as illustrated below:

```js
class e extends Ur {
  constructor(n, r, i) {
    super(n, r, i);
  }
  ngOnDestroy() {
    this.flush();
  }
  static ɵfac = function (r) {
    return new (r || e)(pe(Xe), pe(Ti), pe(Di));
  };
  static ɵprov = oe({ token: e, factory: e.ɵfac });
}

var Ur = class {
  // Class properties and methods omitted for brevity
};
```

By reducing the reliance on `inject`, we ensure that the ordering of class properties and methods remains consistent, preserving the expected behavior.

Closes #28941
2024-11-25 15:02:35 -05:00
Angular Robot
399bbb7b77 build: update all non-major dependencies 2024-11-25 13:02:44 -05:00
Sheik Althaf
7ff933423c refactor(@angular/ssr): use appRef.whenStable instead of util function from angular core
using application whenStable function instead of custom util function from angular core.
2024-11-25 10:44:13 -05:00
Alan Agius
20411f696e refactor(@angular/ssr): replace :params with *
The SSR router relies on wildcard matching rather than params. This commit refactors the stored routes by removing the `:params`.
2024-11-22 10:40:11 -08:00
Alan Agius
34574b2906 fix(@angular/ssr): handle nested redirects not explicitly defined in router config
This commit ensures proper handling of nested redirects that are implicitly structured but not explicitly defined in the router configuration.

Closes #28903
2024-11-22 11:10:34 +01:00
Angular Robot
fe1af9fc97 build: update all non-major dependencies 2024-11-21 11:39:43 -08:00
Charles Lyding
1ded0b756b fix(@angular/build): use sha256 instead of sha-256 as hash algorithm name
Stackblitz appears to fail when attempting to use `crypto.createHash` with
an algorithm value of `sha-256`. Since Node.js supports both the hyphenated
and unhyphenated values, the later is now used to avoid issues when running
on Stackblitz.
2024-11-21 12:49:05 -05:00
Alan Agius
a6eaf2f668 refactor(@angular/build): adjust code to propagate errors from Piscina
Ensure that errors occurring during initialization are properly propagated,
as Piscina currently swallows errors during worker initialization.
For more details, see:
b647472334/src/worker.ts (L57)
2024-11-21 14:57:36 +01:00
Charles Lyding
96d604fd0c refactor(@angular/build): add initial infrastructure to support inline template HMR
The Angular AOT compilation logic for a rebuild has been updated to include
infrastructure for additional checks of stale TypeScript files against updated
files. The actual comparison aspects have not yet been implement and no behavior
changes are yet present for template HMR.
2024-11-21 08:38:19 -05:00
Alan Agius
8c534da649 fix(@angular/ssr): handle baseHref that start with ./
Updated function to support handling `baseHref` starting with './' path correctly.
2024-11-21 08:20:58 +01:00
Alan Agius
4d437ec193 fix(@angular/build): ensure accurate content length for server assets
Adjusts the server assets to use the original content length

Closes #28832
2024-11-20 13:15:26 +01:00