3157 Commits

Author SHA1 Message Date
Alan Agius
98a61ff932 fix(@angular-devkit/build-angular): in vite skip SSR middleware for path with extensions
Do not try to SSR a request that has extensions.

Closes #26199
2023-11-03 15:47:12 +01:00
Alan Agius
e453695009 refactor(@angular-devkit/build-angular): remove redundant async from render-worker
The `async` keyword is not needed here.
2023-11-03 14:50:55 +01:00
Alan Agius
196e9d9e83 fix(@angular-devkit/build-angular): remove CJS usage warnings for inactionable packages
This commit add `critters` and `express` to the CJS allowed deps.
2023-11-03 14:50:55 +01:00
Charles Lyding
bcd3a86db8 refactor(@angular-devkit/build-angular): add experimental extension points to Vite-based dev server
When using the experimental programmatic API for the development server with an esbuild-based
builder (`application`/`browser-esbuild`), express compatible middleware can now be added.
Also, the index HTML transformer that previously only worked with the Webpack-based development
server is also now enabled.
However, usage of these options may result in unexpected application output and/or build failures.
They are also not officially supported and SemVer guarantees are not present.
Stable and supported methods for build process extension are being evaluated for a future release.
2023-11-03 13:51:09 +01:00
Alan Agius
7ffc46c70d refactor(@angular-devkit/build-angular): remove __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION` code
This is now done by default in zone.js versions greater than  `0.14.1`
2023-11-03 13:06:33 +01:00
Charles Lyding
6d8d948ad0 refactor(@angular-devkit/build-angular): cache compiled load ESM file helper
The dynamically compiled ESM import helper is now cached to prevent the need
to recompile the helper function everytime a load ESM helper call is made.
This helper is currently used to workaround dynamic import limitations with
the TypeScript compilation output. Once the build process is updated, it will
no longer be required.
2023-11-03 10:36:27 +01:00
Alan Agius
4c1265a9bf fix(@angular-devkit/build-angular): prebundle dependencies for SSR when using Vite
The commit introduces dependencies prebundling and optimisation for SSR dependencies. This is primarily needed for Angular linking and async/await downlevelling. To enable this, we need to use the undocumented `optimizeDeps` setting under the `ssr` option. This is because, the top level `optimizeDeps` vite config option  only controls browser dependencies.

For the above mentioned option to take effect and transform node packages, we also need to use `noExternal` and use a catch all `RegExp`. Note: setting this option to `true` has a different effect from a catch all `RegExp`, as the former will cause the `external` option to be ignored.

Additionally together with `externalMetadata.explicit` we add Node.js build-ins as `external`.

Closes: #26192
2023-11-02 16:03:34 +01:00
Leosvel Pérez Espinosa
f5ec7899aa fix(@angular-devkit/build-angular): expose ssr-dev-server builder in the public api 2023-11-02 14:00:51 +01:00
Charles Lyding
271d561cf4 refactor(@angular-devkit/build-angular): reduce complexity of bundle budget threshold regex
The extra whitespace matching can be removed via a trim call prior to matching and casing
can be handled by the `i` flag.
2023-11-01 19:04:15 +01:00
Alan Agius
a9da656085 fix(@angular-devkit/build-angular): fail build on non bundling error when using the esbuild based builders
This change fixes an issue were non bundling related errors that happen during prerendering, index generation and bundle budget failures did not cause the build to terminate with an error.
2023-11-01 19:03:43 +01:00
Charles Lyding
974acb7fe1 fix(@angular-devkit/build-angular): ensure all SSR chunks are resolved correctly with dev server
The `server-utils` SSR generated chunk was not previously included in the ESM in memory loader for
prerendering which resulted in the ESM resolver incorrectly attempting to resolve non-relative
dependencies. This would lead to resolution errors when using the development server with caching
enabled. In this scenario, the Angular dependencies would be marked external and the server utilities
output chunk would contain non-relative imports and fail to prerender.
2023-11-01 14:48:47 +01:00
Charles Lyding
5b4f50c7ca fix(@angular-devkit/build-angular): provide server baseUrl result property in Vite-based dev server
The protractor E2E builder relies on a development server `baseUrl` result property to determine the address
to connect when testing the application. The Vite-based development server now also provides this
property. While the protractor builder is considered deprecated, it is still used in CLI E2E tests.
2023-11-01 14:48:47 +01:00
Charles Lyding
2aa55ec096 fix(@angular-devkit/build-angular): use browserslist when processing global scripts in application builder
When using the `scripts` option with the esbuild-based builders (`application`/`browser-esbuild`), the
JavaScript code from the scripts will now be processed based on the targets provided in the application's
browserslist file. This prevents unsupported syntax from being present in the output script chunk that is
generated.
2023-11-01 14:48:47 +01:00
Angular Robot
ca9b5cccb6 build: update all non-major dependencies 2023-11-01 09:31:03 +01:00
Alan Agius
dbb63299d2
fix(@angular-devkit/build-angular): Windows Node.js 20 prerendering failure (#26186)
* fix(@angular-devkit/build-angular): Windows Node.js 20 prerendering failure

On Node.js 20 prerendering failed on Windows with `An unhandled exception occurred: No handler function exported` error. This appears to be caused by transforming Piscina CJS bundles using the `JavaScriptTransformer`. interestingly, this does not effect other OS like Linux and Mac.

* fixup! fix(@angular-devkit/build-angular): Windows Node.js 20 prerendering failure

Co-authored-by: Charles <19598772+clydin@users.noreply.github.com>

---------

Co-authored-by: Charles <19598772+clydin@users.noreply.github.com>
2023-10-31 15:32:43 +01:00
Charles Lyding
06b8fe65df fix(@angular-devkit/build-angular): only watch used files with application builder
When using the application builder in watch mode (including `ng serve`), the file watching
will now only watch files used or relevant to the used files. Previously, all files within
the project root were watched. This previous behavior could result in unneeded rebuilds when
unrelated files were changed. An environment variable named `NG_BUILD_WATCH_ROOT` is also
now available to enable the previous behavior in cases where it is still preferred as well
as for testing and debugging purposes.
2023-10-31 12:10:07 +01:00
Kristiyan Kostadinov
260267934a fix(@angular-devkit/build-angular): elide setClassDebugInfo calls
Angular v17 adds another dev-mode-only function that needs to be removed called `ɵsetClassDebugInfo`. These changes update the Babel plugin to account for it.
2023-10-31 11:50:03 +01:00
Charles Lyding
d641c94508 refactor(@angular-devkit/build-angular): lazily initialize JS transformer worker pool
The Worker thread pool that is used by the JavaScript Transformer within the application
builder is now only initialized if there is JavaScript that must be transformed. This
removes any overhead associated with the worker pool if no work is required. This is
particularly useful when using the development server with caching enabled and all the
dependencies have already been prebundled.
2023-10-31 08:58:54 +01:00
Angular Robot
d539286340 build: update all non-major dependencies 2023-10-31 08:58:15 +01:00
Charles Lyding
e588e84160 test: remove node-fetch package usage
Native fetch support is now available in Node.js and the `node-fetch` package can now be removed.
2023-10-31 08:57:42 +01:00
Alan Agius
11420667f9 build: use single Node.js toolchain to run unit tests
E2E tests are used to run tests on multiple platforms and node.js versions.
2023-10-30 17:50:47 +01:00
Alan Agius
187accb376 fix(@angular-devkit/build-angular): log number of prerendered routes in console
This changes add a log to the console to prints the total number of prerendered routes.
2023-10-30 17:43:05 +01:00
Alan Agius
51351bf285 perf(@angular-devkit/build-angular): only rebundle server polyfills on explicit changes
The newly introduced incremental bundler result caching is now used for server polyfills. This allows the bundling steps to be skipped in watch mode when no related files have been modified.
2023-10-30 14:12:38 +01:00
Charles Lyding
2f1b650554 fix(@angular-devkit/build-angular): remove unactionable error overlay suggestion from Vite-based dev server
The Vite-based development server that is used with the esbuild-based builders (`application`/`browser-esbuild`)
will show an error overlay when the application build encounters an error. This overlay previously provided a
suggestion to edit the `vite.config.js` configuration file to disable the error overlay. Since Vite usage is
encapsulated within the Angular CLI, this suggestion is unactionable and may lead to user confusion due to
no Vite configuration file being present within the project nor would creating one have an effect on the build
process.
2023-10-30 11:27:45 +01:00
Charles Lyding
f4aebf5f47 refactor(@angular-devkit/build-angular): format post-bundle diagnostic messages for esbuild builders
Any errors or warnings generated from post-bundling steps of the build will now be formatted and displayed
in a similar manner to the bundling errors and warnings. This should be most noticeable with bundle budgets.
2023-10-30 11:27:28 +01:00
Charles Lyding
bb13e406c7 perf(@angular-devkit/build-angular): only rebundle browser polyfills on explicit changes
The newly introduced incremental bundler result caching is now used for browser polyfills (`polyfills` option).
This allows the bundling steps to be skipped in watch mode when no related files for have been modified.
2023-10-30 11:20:57 +01:00
Alan Agius
68b6a5701f perf(@angular-devkit/build-angular): patch fetch to load assets from memory
This commit refactors the assets SSG asset loading from memory to use a patched version of `fetch` instead of spawning a separate server.
2023-10-30 10:05:07 +01:00
Charles Lyding
09682e5f2c fix(@angular-devkit/build-angular): ensure correct web worker URL resolution in vite dev server
When using the application builder with the development server, Web Worker URLs previously may
have been incorrectly resolved. This caused Vite to consider the Web Worker URLs as outside
the project root and generate a special file system URL. While this worked on Mac/Linux, it
would fail on Windows. Since Vite does not appear to support resolve plugins for Web Workers,
the virtual project root for the in-memory build has now been adjusted to allow the referencing
file to have a path that resolves the Web Worker URL to a project relative location.
2023-10-30 09:01:55 +01:00
Charles Lyding
44ea76af26 fix(@angular-devkit/build-angular): skip checking CommonJS module descendants
When CommonJS module checking is enabled in the esbuild-based builders (`application`/`browser-esbuild`),
the checker will now skip all descendants of a CommonJS module. Previously it would only skip them if
the module was not allowed. This change now provides the same module checking behavior as the Webpack-based
check. This makes the build behavior more consistent when migrating to the new build system.
2023-10-30 09:01:28 +01:00
Angular Robot
0155ae73b2 build: update dependency picomatch to v3 2023-10-30 08:59:54 +01:00
Charles Lyding
5a2539883b fix(@angular-devkit/build-angular): only show changed output files in watch mode with esbuild
Similar to how the Webpack-based `browser` builder only shows the output files that have changed
during watch mode (including `ng serve`), the esbuild-based builders will now also only show changed
files. For large applications, this can greatly reduce the amount of text shown in the console when
actively developing in watch mode.
2023-10-27 09:28:54 -07:00
Alan Agius
a64d8edfd6 fix(@angular-devkit/build-angular): add a maximum rendering timeout for SSR and SSG during development
There might be cases were currently, the render application promise does not resolve because the application never becomes stable in most cases this is due to errors, this causes the worker to never exit and the build to keep running until it's manually terminated.

With this change, we add a maximum rendering timeout of 30seconds for each page.
2023-10-27 09:28:29 -07:00
Alan Agius
a0f8fac4b3 refactor: update inquirer to version 9.0.6
Update the mentioned package.
2023-10-26 16:11:36 +02:00
Alan Agius
8178c23c88 fix(@angular-devkit/build-angular): handle HTTP requests to assets during SSG in dev-server
This commit fixes an issue were during SSG/SSR in the dev-server http requests to assets causes the page rendering to fail.
2023-10-26 16:01:39 +02:00
Charles Lyding
4bc6debdd5 perf(@angular-devkit/build-angular): only rebundle global scripts/styles on explicit changes
The newly introduced incremental bundler result caching is now used for both global styles
(`styles` option) and global scripts (`scripts` option). This allows the bundling steps
to be skipped in watch mode when no related files for either have been modified. This
can be especially beneficial for applications with large global stylesheets.
2023-10-26 14:59:17 +02:00
cexbrayat
62a7019a47 fix(@angular-devkit/build-angular): ensure that externalMetadata is defined
`ng serve` might fail with: `Cannot read properties of undefined (reading 'explicit')` because `result.externalMetadata` is optional.
This commit guards the access and should fix the issue related to the fix 9768c184e0
2023-10-26 14:59:04 +02:00
Charles Lyding
142a36a99f refactor(@angular-devkit/build-angular): prevent vite from resolving explicit external dependencies
When using the Vite-based development server combined with the `externalDependencies` option, Vite
will no longer attempt to resolve the explicitly marked externals.
This is still not ideal since it vite will still transform the import specifier to `/@id/${source}`
but is currently closer to a raw external than a resolved file path. Further investigation with
a possible feature request for Vite may be needed to achieve the desired outcome of an unresolved
and untransformed external import specifier.
2023-10-26 14:58:53 +02:00
Charles Lyding
cdea51865a fix(@angular-devkit/build-angular): avoid binary content in architect results with browser-esbuild
The builder system (architect) currently attempts to treat all results as JSON and
attempts to validate the object with a JSON schema validator. This can lead to slow
build completion (even after the actual build is fully complete) or crashes if the
size and/or quantity of output files is large. Architect only requires a `success`
property so that is all that will be passed here if the infrastructure settings have
not been explicitly set to avoid writes. Writing is only disabled when used directly
by the dev server which bypasses the architect behavior.
2023-10-26 14:58:40 +02:00
Alan Agius
82f855049f perf(@angular-devkit/build-angular): remove JavaScript transformer from server polyfills bundling
This is no longer needed as the server polyfills file there are no longer Angular deps that require to be "linked".
2023-10-26 13:47:55 +02:00
Angular Robot
405b2ccada build: update dependency sass to v1.69.5 2023-10-26 13:06:56 +02:00
Alan Agius
62d26db17c fix(@angular-devkit/build-angular): do not perform advanced optimizations on @angular/common/locales/global
This entry-points are side effectful.
2023-10-26 13:06:30 +02:00
Charles Lyding
9768c184e0 fix(@angular-devkit/build-angular): automatically include known packages in vite prebundling
When using the Vite-based development server, the application build step already contains the
list of known packages that would need to be prebundled. This information can be passed to Vite
directly to avoid Vite needing to perform discovery on every output file that will be requested.
This also avoids the Vite server behavior where Vite forces a reload of the page when it discovers
a new dependency. This behavior can result in lost state during lazy loading of a route.
2023-10-25 12:52:46 +02:00
Charles Lyding
ca4426150f fix(@angular-devkit/build-angular): normalize paths when invalidating stylesheet bundler
To avoid incorrectly invalidating the stylesheet bundler within the application builder
on Windows, the paths of changed files are now first normalized. This ensures that any
changed files properly cause affected component stylesheets to be reprocessed.
2023-10-25 12:52:35 +02:00
Alan Agius
5b3541040b fix(@angular-devkit/build-angular): handle HTTP requests to assets during prerendering
This commit fixes an issue were during prerendering (SSG) http requests to assets causes prerendering to fail.

Closes #25720
2023-10-25 12:45:11 +02:00
Charles Lyding
26c3b82fc9 refactor(@angular-devkit/build-angular): increase JS transformer worker pool idle timeout to 1 second
The idle timeout for threads in the JavaScript transformer worker pool for the esbuild-based builders
(`application`/`browser-esbuild`) is now set at 1 second. This prevents the default of immediate shutdown
of an idle worker from occurring. The immediate shutdown causes additional worker threads to be created
due to the variable time between bundler requests for node module JavaScript files. The shutdown and
subsequent recreation of the threads during the build causes unneeded extra processing that can now be
avoided.
2023-10-24 08:51:37 -07:00
Charles Lyding
902089044b perf(@angular-devkit/build-angular): fully avoid rebuild of component stylesheets when unchanged
With the full set of dependencies and watch files tracked within the bundler context object for
component stylesheets, the entire bundler output can be cached in memory and reused when none of
the relevant files have changed since the last rebuild. This is particularly useful for scenarios
when a large tree of components are considered affected and must be recompiled by the AOT compiler.
2023-10-24 08:51:22 -07:00
Alan Agius
6067f8577d fix(@angular-devkit/build-angular): silence xhr2 not ESM module warning
This is used inernally by '@angular/platform-server' and is in a seperate chunk that is unused when using `provideHttpClient(withFetch())`.
2023-10-24 16:11:56 +02:00
Charles Lyding
175ad37d6e fix(@angular-devkit/build-angular): warn if using partial mode with application builder
The Angular compiler's partial compilation mode is only intended for use when building libraries.
If attempting to use the mode while building an application, the application would fail. A warning
is now issued if partial mode is configured for the application and the mode is switched to full
compilation mode to prevent the build from failing due to the option value.
2023-10-23 16:30:49 -07:00
Charles Lyding
df1aba1ea4 fix(@angular-devkit/build-angular): ensure css url() prefix warnings support Sass rebasing
The stylesheet url() resource plugin will now correctly issue warnings for the usage of Webpack
specific prefixes such as the tilde when used in an imported Sass file. Previously, these URLs
would be rebased by the Sass processing step which would cause the tilde prefix to no longer
be a prefix. This would then no longer be considered a warning due to the tilde no longer being
the first character of the URL value. Additionally, a warning is also now issued for the previously
unsupported but available caret prefix. Removing the caret prefix and adding the path to the
`externalDependencies` build option should provide equivalent behavior.
2023-10-23 18:55:43 -04:00
Charles Lyding
5e47d82aa8 refactor(@angular-devkit/build-angular): show build time on failures with application builder
The build time is now shown when bundling fails. Previously only the errors were shown. This
provides additional information that the build did indeed fail and how long it took to fail.
2023-10-23 18:55:26 -04:00