3194 Commits

Author SHA1 Message Date
Alan Agius
155341ffe7 fix(@angular-devkit/build-angular): add actionable error when file replacement is missing
This commits adds an actionable error when the file to replace with is missing.

Closes #26333
2023-11-15 16:49:31 -05:00
Alan Agius
44f2c4ebb4 fix(@angular-devkit/build-angular): do not process ssr entry-point when running ng serve
The ssr entry-point is not used by vite.
2023-11-15 18:57:28 +01:00
Alan Agius
9926123912 fix(@angular-devkit/build-angular): add support for vendor sourcemaps when using the dev-server
Prior to this change the vendor sourcemaps were never generated when using vite prebundling.
2023-11-15 18:11:33 +01:00
Charles Lyding
447761e92e fix(@angular-devkit/build-angular): cache stylesheet load errors with application builder
When using the `application` and/or `browser-esbuild` builders, stylesheets
that generate errors will now have the errors cached between rebuilds during
watch mode (include `ng serve`). This not only avoids reprocessing files that
contain errors and that have not changed but also provides file watching information
from the cache to ensure the error-causing files are properly invalidated.
2023-11-15 07:54:30 -05:00
Charles Lyding
fd2d72a79d fix(@angular-devkit/build-angular): maintain current watch files after build errors
When using the `application` and/or `browser-esbuild` builders, the current watch files
will be maintained in the event of a build error. This better ensures that files used
in the last build/rebuild that may have caused an error will continue to be watched and
refreshed when later changed. Only when a successful rebuild has occurred will any stale
watch files be removed from the watch list.
2023-11-15 07:54:30 -05:00
Charles Lyding
38b7667ce3 fix(@angular-devkit/build-angular): ensure compilation errors propagate to all bundle actions
If the TypeScript and/or Angular AOT compiler fails to initialize or emit files due to an error,
the shared compilation state between the browser code bundle action and any additional bundle actions
(polyfills, server, etc.) will now carry an error flag to ensure that the additional bundle actions
bypass file emit. The file emit bypass is necessary in these cases to prevent an unintentional and
misleading error about a file not being included in the compilation.
2023-11-15 07:53:59 -05:00
Alan Agius
286e5d32f2 fix(@angular-devkit/build-angular): rewire sourcemap back to original source root
Prior to this change, when a error occurs when using the SSR dev-server the stacktraces pointed back to the virtual root path.
2023-11-13 14:59:50 -05:00
Alan Agius
2b5409b4a5 refactor(@angular-devkit/build-angular): update deleteOutputDir to use FS promise APIs
As per commit title.
2023-11-13 08:29:10 +01:00
Alan Agius
000342079f fix(@angular-devkit/build-angular): deleteOutputPath when using esbuild-builder
Prior to this change the `deleteOutputPath` was not being used in the esbuild-builder.

Closes #26308
2023-11-13 08:29:10 +01:00
Alan Agius
2dbc7b99cd refactor(@angular-devkit/build-angular): remove unused plugin from server polyfills
RxJs is not imported in the server polyfills and thus we can safely remove this plugin.
2023-11-13 08:28:15 +01:00
Alan Agius
12acab8130 build: mark karma and dev-server tests are flaky
These tests have become flaky.
2023-11-13 08:28:00 +01:00
Alan Agius
6cf9342110 fix(@angular-devkit/build-angular): prerender default view when no routes are defined
Prior to the commit, when no routes were defined the default view was not prerendering.

Closes #26317
2023-11-13 08:27:43 +01:00
Angular Robot
4979d22001 build: update all non-major dependencies to v7.23.3 2023-11-09 11:53:40 +01:00
Charles Lyding
8e4802dd25 fix(@angular-devkit/build-angular): empty output directory instead of removing
When the `deleteOutputPath` option is enabled (default is enabled), the configured
`outputPath` for the project was previously removed directly. This was problematic
for cases such as when the path was mounted via a Docker setup. To alleviate these
issues, the contents of the output path will now be removed instead. This maintains
the existing output path directory itself but ensures an empty location to place the
new build output.
2023-11-09 10:43:30 +01:00
Angular Robot
0f98ea1010 build: update angular 2023-11-08 18:58:26 +01:00
Alan Agius
6d89c18807 test(@angular-devkit/build-angular): expand unit tests dev-server suite to include vite
This commit updates the dev-server unit test suit to run tests using vite
2023-11-08 16:46:14 +01:00
Alan Agius
c0921d61d4 refactor(@angular-devkit/build-angular): move teardown logic registration before
In some cases, this was regestered too late which caused the server never to terminate.
2023-11-08 16:46:14 +01:00
Angular Robot
cb0c22ee9b build: update all non-major dependencies 2023-11-08 15:04:56 +01:00
Charles Lyding
6f9ef1fbb1 fix(@angular-devkit/build-angular): disable Worker wait loop for TS/NG parallel compilation in web containers
When using the `application` builder, a parallel TS/NG compilation is used that is run inside a Node.js Worker.
This Worker by default uses an Atomics-based wait loop to improve performance while waiting for messages. This
loop relies on the synchronous API `receiveMessageOnPort`. While this works well in Node.js, the web container
execution environment does not currently support passing transferable objects via `receiveMessageOnPort`. Attempting
to do so will cause a serialization error and a failed application build. To avoid this problem, the wait loop
optimization is disabled when the web container execution environment is detected. This change is only needed
for the TS/NG compilation as no other parallel operation within the build system currently uses `receiveMessageOnPort`
with transferable objects.
2023-11-08 15:04:20 +01:00
Charles Lyding
36867680c9 Revert "fix(@angular-devkit/build-angular): disable parallel TS/NG compilation inside WebContainers"
This reverts commit 421c175ec94e737081ff7328caddb29de8575acc.
2023-11-08 15:04:20 +01:00
Alan Agius
0ccb4c7d0b build: update Angular packages to version 17 stable
Update all versions to stable
2023-11-08 13:56:40 +01:00
Charles Lyding
3470bff732 fix(@angular-devkit/build-angular): allow SSR compilation to work with TS allowJs option
When using the `application` builder with SSR enabled and the `allowJs` TypeScript option,
the build would previously generate warnings about undefined imports. This was caused by
the recently introduced initialization error handling that was not accounting for the early
exit of the SSR compiler plugin's `onStart` hook. This early exit prevent the error status
checking from completing which resulted in the SSR plugin load hook assuming an error had
occurred. This in turn caused JavaScript files that were not imported into TypeScript
files to be returned as empty content to avoid the not found error message. To remedy this
situation, the error status is now also set during the SSR early exit.
2023-11-07 20:29:36 +01:00
akhil biju
31f0286dba fix(@angular-devkit/build-angular): normalize exclude path
fix(@angular-devkit/build-angular): normalize exclude path
2023-11-07 18:11:32 +01:00
Charles Lyding
f76e1a06df fix(@angular-devkit/build-angular): convert AOT compiler exceptions into diagnostics
When using the `application` builder, exceptions thrown by the AOT compiler will
now be converted into error diagnostics. This allows for more actionable information
to be displayed in the build output. It also prevents the typically incorrect "missing
file" error from occurring in these cases which previously occurred due to TypeScript
files not being emitted as a result of the compiler failure.
2023-11-06 18:53:37 +01:00
Charles Lyding
421c175ec9 fix(@angular-devkit/build-angular): disable parallel TS/NG compilation inside WebContainers
When using the `application` or `browser-esbuild` builders, a parallel TS/NG compilation will
be used by default via a Node.js Worker. However, when used inside a Web Container, the
build will fail to initialize the compilation instance due to what appears to be a defect
within Web containers involving the transfer/serialization of a MessageChannel's MessagePort
objects. To avoid this problem, the parallel compilation is disabled by default when the
build system detects it is being executed from within a Web Container. A parallel compilation
can still be forced by using the `NG_BUILD_PARALLEL_TS=1` environment variable.
2023-11-06 17:51:37 +01:00
Alan Agius
07a8ffd5af fix(@angular-devkit/build-angular): keep dependencies pre-bundling validate between builds
Prior to this commit, the pre-bundling of dependencies was being invalidated for each build. This is because vite uses parts of the config among other things to generate a hash. In our case the config was not always consistent for the same project between different builds.

The main 2 problems areas were:
- Random `root` path
- `include` and `exclude` arrays were not always in the same order.
2023-11-06 16:35:53 +01:00
Alan Agius
7cb5d35a26 fix(@angular-devkit/build-angular): disable dependency optimization for SSR
It appears that Vite currently, has a number of limitation/bugs when using `optimizeDeps` for SSR bundles.

Currently this causes a number of issues:
  - Deps are re-optimized everytime the server is started.
  - Added deps after a rebuild are not optimized.
  - Breaks RxJs (Unless it is added as external). See: #26235

We should follow up with Vite and try to get this solved as this would be a nice feature to use.

Closes #26235 and #26234
2023-11-06 15:20:13 +01:00
Alan Agius
ef2437fe95 refactor(@angular-devkit/build-angular): clean externalMetadata arrays on every rebuild
Currently, externalMetadata arrays get appended the same items over and over again on every rebuild. This commit cleans the array before it appending the new values.
2023-11-06 14:07:56 +01:00
Charles Lyding
988dce6eff refactor(@angular-devkit/build-angular): allow JS transformer result reuse for application dev-server builder
The `JavaScriptTransformer` class that is responsible for Angular linking and several build optimization
transformations can now be configured to track and reuse previous and pending transformation requests.
This allows for cases where multiple consumers of the class will not cause repeat transformation actions.
Pending results will be stored if the constructor option `reuseResults` is enabled. If two transformation
requests are issued for the same file, the same underlying result will be provided to each. This behavior
currently only applies to file transformation requests.
2023-11-06 11:53:39 +01:00
Alan Agius
17399244b3 perf(@angular-devkit/build-angular): start SSR dependencies optimization before the first request
Vite will only start dependency optimization of SSR modules when the first request comes in.

In some cases, this causes a long waiting time. To mitigate this, we call `ssrLoadModule` to initiate this process before the first request.
2023-11-05 18:38:03 +01:00
Alan Agius
64fdb31c78 fix(@angular-devkit/build-angular): exclude node.js built-ins from vite dependency optimization
This fixes the following warnings
```
Cannot optimize dependency: url, present in 'ssr.optimizeDeps.include'
Cannot optimize dependency: path, present in 'ssr.optimizeDeps.include'
```
2023-11-05 13:31:05 +01:00
Charles Lyding
f06a760344 fix(@angular-devkit/build-angular): avoid in-memory prerendering ESM loader errors
The in-memory ESM loader hooks have been adjusted to avoid potential errors when
resolving and loading the bundled server code during prerendering. These errors
could result in hard to diagnose build failures. E2E testing via the deprecated
protractor builder, would silently exit, for instance. To ensure on disk files
including node modules are resolved from the workspace root, a virtual file root
is used for all in memory files. This path does not actually exist but is used to
overlay the in memory files with the actual filesystem for resolution purposes.
A custom URL schema (such as `memory://`) cannot be used for the resolve output
because the in-memory files may use `import.meta.url` in ways that assume a file
URL. `createRequire` from the Node.js `module` builtin is one example of this usage.
2023-11-05 13:30:53 +01:00
Angular Robot
fdee8b799d build: update all non-major dependencies 2023-11-04 11:35:42 +01:00
Charles Lyding
3b6a999fc1 fix(@angular-devkit/build-angular): ensure secondary Angular compilations are unblocked on start errors
When using the esbuild-based builders (`application`/`browser-esbuild`), the secondary Angular compilations
will wait for the primary compilation to finish prior to bundling. This can potentially occur for polyfills
that contain TypeScript files and the server code if enabled. However, if the Angular compilation throws
an error during the start of the bundling process, the secondary compilations were never notified and instead
would wait indefinitely. To avoid this situation, the compilations will now always be notified at the end of
the compilation which will occur regardless. The build error that will be generated in these situations is
currently not ideal and more verbose than needed but will provide information pertaining to the root cause.
2023-11-03 18:56:37 +01:00
Alan Agius
8c76cb2830 fix(@angular-devkit/build-angular): media files download files in vite
Unlike assets, output file were not prefixed with a `/`. This change alings these and now files are always prefixed with a slash.

Closes #26215
2023-11-03 16:47:01 +01:00
Alan Agius
59908753b6 perf(@angular-devkit/build-angular): optimize server or browser only dependencies once
This commit splits the retrieval of external dependencies into two. Server imports and browser imports. This is so that we avoid vite from optimizing server or browser only dependencies twice.

This also fixes an issue were in some cases Vite would issue a warning like `Cannot optimize dependency: path, present in 'optimizeDeps.include'`. This was caused because of server only dependencies ended up trying to be optimized for a browser build.
2023-11-03 16:06:32 +01:00
Alan Agius
5547095693 refactor: import path methods individually
Minor style change
2023-11-03 15:47:12 +01:00
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