1620 Commits

Author SHA1 Message Date
Doug Parker
160dee33d7 fix(@schematics/angular): don't show server routing prompt when using browser builder
The new routing APIs don't support `browser` builder, but calling `ng add @angular/ssr` with a `browser` builder would still prompt the user to add them. If the user said "Yes", it would actually ignore that answer and not enable the new APIs.

With this change, `ng add @angular/ssr` when using `browser` builder does not show the prompt and assumes the answer is "No". It also throws an error if the user runs `ng add @angular/ssr --server-routing`.

I'm not aware of a built-in prompting mechanism in schematics beyond `x-prompt`, which can't be used here, so instead I just called Inquirer directly. Unfortunately testing the prompt is a little awkward, as Inquirier does not provide useful APIs in this space. I evaluated `@inquirer/testing`, but ultimately decided that was more intended for testing custom Inquirer prompts, not mocking usage of standard prompts. Schematics APIs do not provide a useful way to inject additional data like a mock, so instead I had to do this through a `setPrompterForTestOnly` function. I'm not a huge fan of it, but I don't see a more straightforward way of solving the problem.
2024-11-18 10:37:31 -08:00
Charles Lyding
9921271ce1 fix(@angular/build): fully disable component style HMR in JIT mode
The component stylesheet HMR functionality requires build-time analysis
of each component by the AOT compiler to provide the needed information
to identify initial styles and detect individual changes to each style.
Part of the style HMR rebuild logic was unintentionally enabled in JIT
mode. The initial load of the application operated correctly but subsequent
changes to file-based stylesheets were delayed by one rebuild cycle. To
avoid this misalignment, all component stylesheet HMR functionality is
now disabled when in JIT mode.
2024-11-18 10:06:45 -08:00
Jan Krems
d746de59f3 fix(@angular-devkit/build-angular): bring back style tags in browser builder 2024-11-18 08:48:37 -08:00
Jan Krems
3a017aa2b9 build: fix peer dep warning for listr2
The previous version specified `@inquirer/prompts < 7` which caused
a warning about invalid peer deps. The only difference between 2.0.17
and 2.0.18 is that this range was expanded to `< 8`.

See: https://github.com/listr2/listr2/issues/730

Fixes: https://github.com/angular/angular-cli/issues/28870
2024-11-15 11:03:50 -08:00
Doug Parker
114673ff8d refactor: removes @angular/ssr/tokens and imports the symbols from @angular/core
Since the symbols are exposed from `@angular/core`, there is no need for a separate export in `@angular/ssr/tokens` anymore.
2024-11-15 10:54:37 -08:00
Angular Robot
4fcce7dc0f build: update angular 2024-11-15 10:23:54 -08:00
cexbrayat
d77527db6d fix(@angular/ssr): export PrerenderFallback
Importing `PrerenderFallback` in a project throws at build time in 19.0.0-rc.2 with:

```ts
✘ [ERROR] No matching export in "node_modules/@angular/ssr/fesm2022/ssr.mjs" for import "PrerenderFallback"

    src/app/app.routes.server.ts:1:9:
      1 │ import { PrerenderFallback, RenderMode, ServerRoute } from '@angula...
```

This exports `PrerenderFallback` the same way `RenderMode` is exported to fix the issue.
2024-11-15 09:49:10 -08:00
Charles Lyding
f96bb86c4e fix(@angular/build): improve URL rebasing for hyphenated Sass namespaced variables
Sass variable namespaces can contain either a hyphen or underscore in the namespace
identifier. The URL rebasing support within the Angular CLI will now account for
these type of namespaces and rebase the evaluated URL as expected.
2024-11-13 10:30:57 -08:00
Paweł Fraś
af14769245 fix(@angular/cli): support default options for multiselect list x-prompt 2024-11-13 09:09:04 -08:00
Angular Robot
bec92d9fc8 build: update all non-major dependencies 2024-11-13 07:26:35 -08:00
Angular Robot
14bc784f09 build: update all non-major dependencies 2024-11-12 13:13:19 -08:00
Angular Robot
47f70d6423 build: update all non-major dependencies 2024-11-11 11:26:14 -08:00
Alan Agius
073e81ecfb refactor(@angular/ssr): remove redundant new URL
Re-use existing const
2024-11-08 22:33:09 +01:00
Charles Lyding
a325c9a969 fix(@angular/build): allow .js file replacements in all configuration cases
Previously the `fileReplacements` option within the `application` builder
would only replace `.js` files if the TypeScript `allowJs` option was enabled.
This differs from the `browser` builder which did not require the option.
To minimize friction when migrating to the new build system, the `allowJs`
option is no longer required for this file replacement case.
2024-11-08 20:07:36 +01:00
Alan Agius
b2e2be052f refactor(@angular/ssr): remove RenderMode.AppShell in favor of new configuration option
This commit removes the `RenderMode.AppShell` option. Instead, a new configuration parameter, `{ appShellRoute: 'shell' }`, is introduced to the `provideServerRoutesConfig` method.

```ts
provideServerRoutesConfig(serverRoutes, { appShellRoute: 'shell' })
```
2024-11-08 19:51:35 +01:00
Alan Agius
553d3d7f6e fix(@angular/build): add missing redirect in SSR manifest
Corrected an issue where a redirect was not properly included in the SSR (Server-Side Rendering) manifest. This fix ensures that all necessary redirects are accounted for during the build process.
2024-11-08 19:23:01 +01:00
Charles Lyding
cdad25641f fix(@angular/build): avoid overwriting inline style bundling additional results
A component may contain multiple inline styles that will originate from the
same containing file. The content of the processed style is sent directly
to the Angular compiler. However, any additional result files are collected
and emitted in the application output. In most cases, this worked as expected
as inline styles rarely had resource references that would overwrite each other.
However, the potential is present for later inline styles for a component to
overwrite these output files. To avoid this potential problem, the internal
identifier now accounts for both the class name and order of the inline styles.
This ensures that each inline style retains a unique additional results entry.
2024-11-08 10:44:51 +01:00
Alan Agius
ffbe9b9a7b fix(@angular/ssr): support for HTTP/2 request/response handling
This commit introduces support for handling HTTP/2 requests and responses in the `@angular/ssr` package.

Closes #28807
2024-11-07 19:28:52 +01:00
Angular Robot
82de1dea4a build: update angular 2024-11-07 12:30:01 +01:00
Alan Agius
479bfd4fa7 fix(@angular/ssr): initialize the DI tokens with null to avoid requiring them to be set to optional
This commit initializes the `REQUEST`, `RESPONSE_INIT`, and `REQUEST_CONTEXT` DI tokens with `null` values by default.

Previously, these tokens lacked default values, which meant that developers had to explicitly mark them as optional when injecting them in constructors. This was necessary to avoid errors when these tokens were not provided, particularly in scenarios like client-side rendering or during development.

By initializing these tokens with `null`, we eliminate the need for developers to mark them as optional, simplifying the code and improving the developer experience.
2024-11-06 17:13:19 +01:00
Jan Krems
2c9904ec7a fix(@angular-devkit/build-angular): handle basename collisions 2024-11-06 07:19:43 -08:00
Alan Agius
8f6ee1ac83 fix(@angular/build): skip wildcard routes from being listed as prerendered routes
This fix ensures that the wildcard routes are not included in the prerendered list, improving the accuracy of prerendered route generation.
2024-11-06 13:39:28 +01:00
Charles Lyding
a2f5ca9908 refactor(@angular/build): use structured component stylesheet tracking for hot replacement
When using the development server with the application builder, the internal state of
any external component stylesheets is now more comprehensively tracked. This allows
for more flexibility in both debugging potential problems as well as supporting additional
stylesheet preprocessing steps including deferred component stylesheet processing.
2024-11-06 10:26:56 +01:00
Alan Agius
e16cbb9ad5 refactor(@angular/ssr): remove duplicate code and streamline functionality
This commit cleans up duplicate code left from the previous implementations of process, serve, and render. Additionally, prerender serve now exclusively handles HEAD and GET requests, aligning with updated handling requirements. The private `renderStatic` method has been removed in favor of the `handle` method for improved maintainability.
2024-11-06 10:14:07 +01:00
Alan Agius
18b6aea397 refactor(@angular/ssr): Add RequestHandlerFunction and NodeRequestHandlerFunction to public API
These additions are necessary to ensure their inclusion in adev.
2024-11-05 19:39:13 +01:00
Alan Agius
27315d1acc docs(@angular/ssr): add missing @developerPreview annotations
Added `@developerPreview` annotations to the relevant API functions and properties within the `@angular/ssr` package. This change ensures that the documentation accurately reflects the preview status of these elements, clarifying their intended use and stability level for developers.
2024-11-05 19:39:02 +01:00
Alan Agius
7c6b9e5b3d docs: enhance documentation by adding @see references
Improve the documentation `adev` API reference by incorporating `@see` references. This addition enhances cross-referencing within the documentation, making it easier for users to navigate related content and gain better context.
2024-11-05 19:39:02 +01:00
Alan Agius
58a648aadc fix(@angular/ssr): add validation to prevent use of provideServerRoutesConfig in browser context
Introduced an error check to ensure that 'provideServerRoutesConfig' is not utilized in the browser part of the application. This helps avoid unintended behavior.
2024-11-05 19:38:39 +01:00
Charles Lyding
e6ff801ba0 fix(@angular/build): workaround Vite CSS ShadowDOM hot replacement
When using the development server with the application builder (default for new projects),
Angular components using ShadowDOM view encapsulation will now cause a full page reload.
This ensures that these components styles are correctly updated during watch mode. Vite's
CSS hot replacement client code currently does not support searching and replacing `<link>`
elements inside shadow roots. When support is available within Vite, an HMR based update
for ShadowDOM components can be supported as other view encapsulation modes are now.
2024-11-05 17:27:50 +01:00
Alan Agius
a1fa483633 fix(@angular/build): handle APP_BASE_HREF correctly in prerendered routes
This commit resolves path stripping issues when `APP_BASE_HREF` does not align with the expected value.

Closes #28775
2024-11-05 17:19:38 +01:00
Alan Agius
daea0ab685 docs: replace @note with @remarks
Updated TSDoc comments by replacing @note with @remarks across the codebase. This aligns with TSDoc's preferred conventions, where @remarks is used for supplementary explanations and additional context.
2024-11-05 15:00:05 +01:00
Charles Lyding
46335625eb fix(@angular/build): disable dev-server websocket when live reload is disabled
When live reload is disabled (`"liveReload": false`/`no-live-reload`) within
the development server, the Vite websocket server will no longer be initialized.
Additionally, the client code will not be loaded by the browser. This allows the
development server to be used in test scenarios that would prefer to more fully
represent the production fielded configuration such as E2E testing or other forms
of browser-based testing.
2024-11-05 10:59:24 +01:00
Charles Lyding
9f5b5eb46e fix(@angular/build): correctly use dev-server hmr option to control stylesheet hot replacement
The development server's `hmr` option will now disable both global and component
stylesheet hot replacement if explicitly disabled. These features are enabled by
default for all projects.
2024-11-05 10:59:24 +01:00
Charles Lyding
ae9dfddbe5 refactor(@angular/build): integrate template update function generation with builder results
When using the development server with the application builder (default for new projects),
experimental support for component template hot replacement is now available for use. To
enable support, the `NG_HMR_TEMPLATES=1` environment variable must present when executing
the development server (for example, `NG_HMR_TEMPLATES=1 ng serve`). Once support has become
stable, template hot replacement will be enabled by default.
2024-11-05 10:30:58 +01:00
Charles Lyding
99192a791b fix(@angular/build): always clear dev-server error overlay on non-error result
Now that additional result object types can be returned from the build
system, the error overlay must be cleared on all non-error results. The
introduction of component update results and eventual incremental results
will now properly clear the error overlay after a successful build.
2024-11-05 08:23:17 +01:00
Alan Agius
71b3de8364 fix(@angular/build): ensure accurate content size in server asset metadata
Updated the calculation to use `Buffer.byteLength()` for determining the length of escaped file content. This change ensures that the `size` property in server asset metadata accurately represents the length of the escaped content.
2024-11-04 20:31:03 +01:00
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
7c6cb9593a fix(@angular/cli): recommend optional application update migration during v19 update
The optional application builder migration will now default to enabled and
recommended during the update process (`ng update`) for v19. The migration
is still optional and can be unselected if preferred when updating.
2024-11-01 11:29:14 -04:00
Angular Robot
227f303e38 build: update angular 2024-11-01 11:28:53 -04: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