3227 Commits

Author SHA1 Message Date
Alan Agius
150a2e7754 fix(@angular-devkit/build-angular): serve assets from the provided serve-path
When the `serve-path` option is used assets are now correctly servered from this location.

Closes #26509
2023-11-28 16:56:05 +01:00
Charles Lyding
f679585b2e fix(@angular-devkit/build-angular): propagate localize errors to full build result
When using the `application` or `browser-esbuild` builders, localization errors were
previously not being propagated to the final build result. In the event that the
`i18nMissingTranslation` option was changed to error from the default of warning, the
final build result would previously indicate a success if there were any missing translations
present within the build. This has now been corrected and the build will now fully fail
including a non-zero exit code in this case.
2023-11-28 10:02:54 -05:00
Alan Agius
876ca1ec77 fix(@angular-devkit/build-angular): correct set locale when using esbuild based builders
In some cases the `$localize.locale` was being set prior to `$localize` being set through `@angular/localize`. This caused `$localize.locale` to be reset to `en-US`.

This change moves the order in which `$localize.locale` is set.

Partially addresses: #26350
2023-11-27 18:49:55 +01:00
Alan Agius
4da732ddf6 fix(@angular-devkit/build-angular): correctly watch files when app is in a directory that starts with a dot
This commit fixes an issue were previously, application files in a directory that starts with a dot were being ignored from watching.

Closes #26441
2023-11-27 13:43:38 +01:00
Alan Agius
555164b407 refactor(@angular-devkit/build-angular): remove piscina minThreads workaround
This is no longer needed since 4.2.0
2023-11-24 21:54:12 +01:00
Angular Robot
87b197c950 build: update dependency undici to v5.28.0 2023-11-24 11:19:35 +01:00
Alan Agius
36d9f19201 refactor(@angular-devkit/build-angular): remove no longer applicable comment
This comment is no longer correct.
2023-11-23 17:41:38 +01:00
Alan Agius
1725b91e35 fix(@angular-devkit/build-angular): improve file watching on Windows when using certain IDEs
This commit, fixes a file watching issue where file changes events are not triggered when using IDEs like Visual Studio (not VS Code).

The main changes to solve the issue are;

## Replace `watcher.on('all')` with `watcher.on('raw')`

Using `watcher.on('all')` does not capture some of events fired when using Visual studio and this does not happen all the time, but only after a file has been changed 3 or more times.

```
watcher.on('raw')
Change 1
rename | 'C:/../src/app/app.component.css'
rename | 'C:/../src/app/app.component.css'
change | 'C:/../src/app/app.component.css'

Change 2
rename | 'C:/../src/app/app.component.css'
rename | 'C:/../src/app/app.component.css'
change | 'C:/../src/app/app.component.css'

Change 3
rename | 'C:/../src/app/app.component.css'
rename | 'C:/../src/app/app.component.css'
change | 'C:/../src/app/app.component.css'

watcher.on('all')
Change 1
change | 'C:\\..\\src\\app\\app.component.css'

Change 2
unlink | 'C:\\..\\src\\app\\app.component.css'

Change 3
... (Nothing)
```

## Handle `rename` events
Some IDEs will fire a rename event instead of unlink/changed when a file is modified}

Closes #26437
2023-11-23 15:46:22 +01:00
Charles Lyding
ba8541e444 fix(@angular-devkit/build-angular): use workspace real path when not preserving symlinks
When not preserving symlinks (the default), the workspace root path should be converted
to the real path on the filesystem to ensure that resolution of all other path-based build
options reflects the actual location of the files. This ensures that typescript and esbuild
resolve files in a consistent manner and avoids hard to diagnose errors involving missing
files at build time.
2023-11-23 14:24:53 +01:00
Charles Lyding
0363da2a5f fix(@angular-devkit/build-angular): avoid native realpath in application builder
When the `preserveSymlinks` option is false (the default), the tsconfig path was
passed through realpath to ensure that the TypeScript source files were resolved
correctly. However, the promise version of the Node.js API was previously used.
This version used `realpath.native` internally but the native version has numerous
behavior problems on Windows systems. This includes potential case conversion
which can result in differing cases for files within the build system and in turn
failed path comparison checks. The synchronous version is now used which has a
JavaScript implementation that does not suffer from these problems.
2023-11-23 14:24:53 +01:00
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