3417 Commits

Author SHA1 Message Date
Charles Lyding
154c7ce8f0 refactor(@angular-devkit/build-angular): adjust wording of dev server client status messages
To minimize ambiguity, the update related log messages for the development server now consistently
indicate that the page reload, HMR update, or otherwise has actually been sent to any connected clients.
2023-11-23 14:24:08 +01:00
Kristiyan Kostadinov
3810bd4e0a build: update to TypeScript 5.3
Updates the repo to TypeScript 5.3.
2023-11-22 14:59:05 -05:00
Alan Agius
7b9b7fe1db fix(@angular-devkit/build-angular): treeshake unused class that use custom decorators
This changes enables wrapping classes in side-effect free modules that make use of custom decorators when using the esbuild based builders so that when such classes are unused they can be treeshaken.
2023-11-22 18:12:31 +01:00
Charles Lyding
6473b01603 fix(@angular-devkit/build-angular): ensure all configured assets can be served by dev server
The Vite-based development server restricts filesystem access by default. However, assets
configured by the build option `assets` are intended to be accessible by the application at
runtime. To ensure that these files are accessible, the allow list will now explicitly include
all configured assets found during the build.
2023-11-22 10:31:58 -05:00
Charles Lyding
96b5b10120 fix(@angular-devkit/build-angular): default to watching project root on Windows with application builder
When using the `application` or `browser-esbuild` builder in watch mode on Windows, the project root
will now be watched by default. This provides a workaround for users of Visual Studio which uses a
file save mechanism that causes the watch mode to not correctly trigger. By watching the entire
project root, this problem is avoided. However, this may result in additional rebuilds due to changes
of unrelated files in the project root.
This behavior can be disabled using the environment variable `NG_BUILD_WATCH_ROOT=0`. On non-Windows
platforms, disabled is the default.

Addresses #26437
2023-11-21 16:25:19 -05:00
Alan Agius
48b27327c1 perf(@angular-devkit/build-angular): only create one instance of postcss when needed
Prior to this change a postcss instance was created for every component style. This can cause a performance overhead when using tailwindcss, since each tailwind instance would do multiple IO calls to get the list of files specified in the `content` field.
2023-11-21 17:54:36 +01:00
Angular Robot
07834da68d build: update all non-major dependencies 2023-11-21 10:34:21 -05:00
Charles Lyding
c0db618e8a fix(@angular-devkit/build-angular): ensure service worker hashes index HTML file for application builder
The generated HTML files for the application were previously not included in the hash calculations for
the service worker. This has now been corrected and the index file for an application will not be included
when service worker support is enabled via the `serviceWorker` option.
2023-11-21 10:03:37 -05:00
Charles Lyding
1d82a7c200 fix(@angular-devkit/build-angular): always normalize AOT file reference tracker paths
The path comparisons for the TypeScript and AOT file reference tracking now use the native path normalization
functions. This avoids issues where the TypeScript paths which use POSIX separators may not correct match
system paths. The file reference tracking is used to trigger updates to both web workers as well as component
stylesheets that have preprocessor (Sass/Less/etc.) dependencies.
2023-11-20 09:34:14 -05:00
Charles Lyding
a21046f606 refactor(@angular-devkit/build-angular): fully disable Vite internal file watching
With the Vite-based development server, the build pipeline itself watches for files
and rebuilds the relevant parts of the application as needed. The Vite file watching
is unneeded and was previously setup to ignore all files. This worked but was not
ideal as chokidar was still initialized inside Vite. However, Vite now supports fully
disabling the file watching by passing `null` for the Vite watch option value.
2023-11-20 09:29:38 -05:00
Alan Agius
944e964c59 fix(@angular-devkit/build-angular): only include vendor sourcemaps when using the dev-server when the option is enabled
Prior to this change the vendor sourcemaps option was not being considered when in the vite JavaScript transformation pipeline.
2023-11-20 14:25:10 +01:00
Charles Lyding
43b09ce55a refactor(@angular-devkit/build-angular): use application builder for unknown builders in Vite dev server
The application builder logic will now be used when the Vite-based development server is used with a
custom builder. This aligns with the programmatic export of application builder. This allows consistent
behavior for custom builders that use both the application builder and dev server builder APIs.
2023-11-20 08:04:22 -05:00
Charles Lyding
d8edbfbbff test(@angular-devkit/build-angular): add template error recovery unit-test for application builder
A unit-test for the application builder has been added to that tests the rebuilds are triggered when
a template error has been introduced in a rebuild. The test also confirms that rebuilds continue to
function after the error has been corrected.
2023-11-20 08:04:05 -05:00
Angular Robot
81aa584baf build: update all non-major dependencies 2023-11-19 11:22:35 -05:00
Charles Lyding
b2224c56ce fix(@angular-devkit/build-angular): remove browser-esbuild usage warning
To avoid potential confusion when updating to v17, the usage warning as been removed
from the `browser-esbuild` builder. The `browser-esbuild` builder is considered stable
and fully supported. This is in addition to the other stable builders: `browser` and
`application`. The `browser-esbuild` builder provides similar behavior to the `browser`
builder but with the performance improvements of the `application` builder. However,
`browser-esbuild` does not have integrated SSR support and will not receive new/future
`application` builder options and features.
For more details on these builders, please see: https://angular.io/guide/esbuild
2023-11-17 18:29:42 -05:00
Charles Lyding
9e356754ce build: update Angular version to v17.1 prerelease
Angular package dependency versions and the version used to generate a new project have been updated to use 17.1.0-next.0.
2023-11-17 12:34:39 -05:00
Charles Lyding
08a6e46a84 fix(@angular-devkit/build-angular): ensure watch file paths from TypeScript are normalized
The TypeScript compiler converts all paths to use POSIX path separators. When on Windows,
this can cause problems when comparing paths from other parts of the build system including
the file watching provided by `chokidar`. The referenced files returned from the TypeScript
compiler are now normalized to the native path format to mitigate this problem. This also
avoids an issue where the same files but with differing path separators were included in
the watch files list on Windows due to the bundler using native paths and TypeScript using
converted paths.
2023-11-17 11:36:45 -05:00
Alan Agius
aa131407a4 fix(@angular-devkit/build-angular): emit root files when localize is enabled when using the esbuild based builders
This commit adds back the root files to the `outputFiles` when localize is enabled.

Closes #26386
2023-11-17 14:07:15 +01:00
Angular Robot
a4f32cda46 build: update all non-major dependencies 2023-11-17 07:48:48 -05:00
Charles Lyding
03ce964858 refactor(@angular-devkit/build-angular): use native path normalization for angular compiler caching
The path comparisons for the TypeScript emit file lookups now use the native path normalization
functions. This removes the special handling previously used and better ensures that cache checks
are valid. The separate babel cache Map has also been combined with the already present memory
load cache within the Angular plugin. This removes the need for extra handling of another Map and
allows it to use the common logic of the load cache. To support this usage, the load cache will
also now automatically include the request path in the file dependencies if the request is from
the `file` namespace. This removes the need to manually specify the request path file for each
load result return value.
2023-11-17 07:48:20 -05:00
Charles Lyding
3b93df42da feat(@angular-devkit/build-angular): allow configuring loaders for custom file extensions in application builder
When using the `application` builder, a new `loader` option is now available for use.
The option allows a project to define the type of loader to use with a specified file extension.
A file with the defined extension can then used within the application code via an import statement
or dynamic import expression, for instance.
The available loaders that can be used are:
* `text` - inlines the content as a string
* `binary` - inlines the content as a Uint8Array
* `file` - emits the file and provides the runtime location of the file
* `empty` - considers the content to be empty and will not include it in bundles

The loader option is an object-based option with the keys used to define the file extension and the values used
to define the loader type.

An example to inline the content of SVG files into the bundled application would be as follows:
```
loader: {
    ".svg": "text"
}
```
An SVG file can then be imported:
```
import contents from './some-file.svg';
```
Additionally, TypeScript needs to be aware of the module type for the import to prevent type-checking
errors during the build. This can be accomplished with an additional type definition file within the
application source code (`src/types.d.ts`, for example) with the following or similar content:
```
declare module "*.svg" {
  const content: string;
  export default content;
}
```
The default project configuration is already setup to use any type definition files present in the project
source directories. If the TypeScript configuration for the project has been altered, the tsconfig may
need to be adjusted to reference this newly added type definition file.
2023-11-16 12:11:33 -05:00
Alan Agius
40c16760c4 fix(@angular-devkit/build-angular): normalize paths in ssr sourcemaps to posix when using vite
Path normalization that fixes a tests on windows
2023-11-16 17:08:51 +01:00
Alan Agius
117628f796 build: update dependency vite to v5
(cherry picked from commit 5b93b9d1dddd34b2b2d7b6ec9e84be8dfc0e52c6)
2023-11-16 15:27:41 +01:00
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