3262 Commits

Author SHA1 Message Date
Alan Agius
f6e67df1c4 feat(@angular-devkit/build-angular): inline Google and Adobe fonts located in stylesheets
`@import url()` to Google and Adobe fonts that are located in global and component CSS will now be inlined when using the esbuild based builders.

Input
```css
@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,500);
```

Output
```css
/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 500;
  src: url(https://fonts.gstatic.com/s/roboto/v30/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
```

Closes #23054
2023-12-09 08:17:43 +01:00
Alan Agius
bf5fbddd45 fix(@angular-devkit/build-angular): inlining of fonts results in jagged fonts for Windows users
We now replace the user agent string used to perform font inlining with a Windows one. This is because Google fonts will including hinting in fonts for Windows. Hinting is a technique used with Windows files to improve appearance however results in 20-50% larger file sizes, however this will make the fonts display correctly on all platforms.

More information about this can be found in:
- https://fonts.google.com/knowledge/glossary/hinting
- https://glyphsapp.com/learn/hinting-manual-truetype-hinting
- http://google3/java/com/google/fonts/css/OpenSansWebFontsCssBuilder.java?l=22

Closes #22248
2023-12-09 07:57:26 +01:00
Charles Lyding
125fb779ff perf(@angular-devkit/build-angular): reduce TypeScript JSDoc parsing in application builder
TypeScript 5.3 provides a new programmatically accessible option on the compiler host object
to control the amount of JSDoc parsing that the TypeScript parser will perform. The `tsc`
command line tool now uses the `ParseForTypeErrors` value which only parses JSDoc comments
that may affect type checking and is considered a good default for tools such as the Angular
CLI. The Angular CLI will now attempt to use the `ParseForTypeErrors` value as well when available.
Projects will need to use TypeScript 5.3+ for this option to be available. No behavior changes will
occur on TypeScript 5.2 projects. This should not only provide a small improvement to build times
but also a reduction in overall memory usage.
2023-12-08 13:03:38 -05:00
Alan Agius
4b3a965429 fix(@angular-devkit/build-angular): baseHref with trailing slash causes server not to be accessible without trailing slash
This commit fixes an issue were when using a `baseHref` with trailing slash, vite dev-server would have been only accessible via a URL with a trailing slash. As vite would redirect to an error page similar to the below;

```
The server is configured with a public base URL of /myapp/ - did you mean to visit [/myapp/](http://localhost:4200/myapp/) instead?
```

Closes: #26618
2023-12-08 10:25:23 -05:00
Angular Robot
5a8e18a653 build: update all non-major dependencies 2023-12-08 09:58:03 -05:00
Charles Lyding
d07ef2f0b9 fix(@angular-devkit/build-angular): ensure browser-esbuild is used in dev server with browser builder and forceEsbuild
To ensure that the `forceEsbuild` development server option chooses the correct underlying build implementation when
the project contains the `browser` builder within the build target, an explicit check and conversion of the builder
name is now performed during the initialization phase of the development server builder.
2023-12-08 09:57:38 -05:00
Charles Lyding
5b8e2d5e57 fix(@angular-devkit/build-angular): ensure port 0 uses random port with Vite development server
Vite appears to consider a port value of `0` as a falsy value and use the default Vite port of
`5173` when zero is used as a value for the development server port option. To workaround this
issue, the port checker code now explicitly handles the zero value case and determines a random
port as would be done automatically by the Webpack-based development server.
2023-12-08 09:57:22 -05:00
Alan Agius
204794c4f8 feat(@angular-devkit/build-angular): add support for --no-browsers in karma builder
This commit enables users to disable runnings tests against a browsers. This can be done by using the `--no-browsers` command line flag or setting `browsers` to `false` in the `angular.json`

Closes #26537
2023-12-07 16:40:28 +01:00
Alan Agius
364a16b7a6 feat(@angular-devkit/build-angular): move browser-sync as optional dependency
`browser-sync` is now an optional dependency of `@angular-devkit/build-angular`. This package is only needed when using the legacy `@angular-devkit/build-angular:ssr-dev-server` builder.

Closes #26349
2023-12-06 11:47:28 -05:00
Charles Lyding
10588c2fc3 refactor(@angular-devkit/build-angular): update Node.js module register load hook for new types 2023-12-06 11:26:12 -05:00
Alan Agius
e3ad8c42a7 fix(@angular-devkit/build-angular): app-shell generation incorrect content when using the application builder
In some cases, the index.html file emitted contained the wrong contents. This because in OutputFiles there were present multiple files with the same name.

Closes #26593
2023-12-06 10:19:06 -05:00
Angular Robot
b5b0432913 build: update all non-major dependencies 2023-12-06 10:01:09 -05:00
Angular Robot
bf08da7d8e build: update dependency vite to v5.0.5 [security] 2023-12-06 07:43:23 +01:00
Alan Agius
c1ae7f3b33 refactor: update rxjs imports
Remove `rxjs/operators` legacy import
2023-12-05 15:23:43 -05:00
Alan Agius
ffa2d07c8e fix(@angular-devkit/build-angular): watch symlink when using preserveSymlinks option
When using the esbuild based builder symlinks are not watched when `preserveSymlinks` is enabled.

Closes #26585
2023-12-05 10:25:12 -05:00
Angular Robot
b88534ef66 build: update dependency undici to v6 2023-12-05 10:06:13 -05:00
Charles Lyding
8e9b675133 fix(@angular-devkit/build-angular): check namespaced Sass variables when rebasing URLs
The `@use` Sass directive allows Sass variables to be accessed via a namespace. This was
previously not checked when performing URL path rebasing on imported Sass stylesheets.
These type of Sass variable references are now also ignored when attempting to rebase URL
paths during loading. The final rebased URL now also does not add a leading relative prefix
indicator (`./`) unless not already present.
2023-12-05 10:04:46 -05:00
Angular Robot
60b40cb3e3 build: update all non-major dependencies 2023-12-04 09:35:46 +01:00
Charles Lyding
f0c032dc58 fix(@angular-devkit/build-angular): normalize locale tags with Intl API when resolving in application builder
All specified locales in the i18n configuration for an application use the `application` or `browser-esbuild`
builders will now be normalized using the `Intl` API. This ensures that the provided locale tags are both
well-formed and correctly cased. This also more easily allowed an optimization for the default locale which
is already embedded into the framework and will now no longer be injected by the build process if active.
2023-12-04 09:33:17 +01:00
Alan Agius
aca0be06e8 test(@angular-devkit/build-angular): enable vite service worker unit tests
Enable service worker tests for vite.
2023-12-04 09:12:34 +01:00
Charles Lyding
9906ab7b47 fix(@angular-devkit/build-angular): normalize asset source locations in Vite-based development server
The Vite-based development server uses an allow list to permit access to configured assets. This list
is checked internally to Vite by using its normalized path form. To ensure that assets provided by the
build are checked correctly on all platforms, the asset list is now normalized with Vite's path
normalization prior to being used.
2023-12-04 09:12:06 +01:00
Charles Lyding
b10d2a7bb0 perf(@angular-devkit/build-angular): only enable advanced optimizations with script optimizations
When using the `application` or `browser-esbuild` builders, the internal advanced optimizations
can only be applied when in AOT mode. However, they were previously only checking the AOT mode
and not whether the project was configured to use script optimizations. The advanced optimizations
are now conditional on both AOT mode and the `optimization.scripts` option. This can greatly
improve the performance of builds in development since the Babel related processing can be skipped
for all TypeScript application code.
2023-12-02 16:03:32 -05:00
Alan Agius
a9fa561027 test(@angular-devkit/build-angular): enable dev-server watch tests for vite
These tests can now be enabled.
2023-12-01 19:39:27 +01:00
Charles Lyding
2d4b5483b7 refactor(@angular-devkit/build-angular): add watch builder teardown to application builder
An AbortController is now automatically linked to the `application` builder's teardown context
if one has not been provided. This supports reduced overhead in the unit tests by eliminating
the need to manually create and use an AbortController/AbortSignal in each test that uses watch
mode. Relevant tests that were previously doing this have also been updated.
2023-12-01 18:19:47 +01:00
Charles Lyding
dcc60c6ce4 fix(@angular-devkit/build-angular): correctly align error/warning messages when spinner is active
When using the `application` builder with progress enabled (the default), the spinner text will
now automatically contain a trailing newline. This ensures that any diagnostic messages are not
awkwardly printed on the same line as the spinner.
2023-12-01 16:40:45 +01:00
Angular Robot
1c32c192ee build: update all non-major dependencies 2023-12-01 16:40:26 +01:00
Alan Agius
03985a45ec refactor(@angular-devkit/build-angular): only use rename and change raw events
This commit updates the file watcher to only use rename and change events from raw events and will otherwise rely on all events to capture other file changes.

The rename and change events are watch are triggered when using IDEs that use atomic writes. This should improve cross-platform and cross IDE compatibility.
2023-12-01 08:50:03 +01:00
Alan Agius
7ccc210071 fix(@angular-devkit/build-angular): handle watch updates on Mac OSX when using native FSEvents API
By default, on Mac OSX chokidar will use the native darwin FSEvents API unless polling is enabled. In which case instead of listening on `raw` events we need to listen to `all` events.
2023-12-01 08:50:03 +01:00
Alan Agius
4bcee31675 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

(cherry picked from commit 1725b91e357f613f7fb7547d13d6499973ee3849)
2023-12-01 08:50:03 +01:00
Doug Parker
72760d44e0 Revert "fix(@angular-devkit/build-angular): improve file watching on Windows when using certain IDEs"
This reverts commit bbbe13d6782ba9d1b80473a98ea95bc301c48597.

Switching to `raw` event changes the event names such that some events are getting dropped and breaking watch mode rebuilds on Mac.
2023-11-29 15:29:56 -08:00
Angular Robot
399a4efb3c build: update all non-major dependencies 2023-11-29 20:09:04 +01:00
Charles Lyding
ccba849e48 feat(@angular-devkit/build-angular): support keyboard command shortcuts in application dev server
When using the `application` or `browser-esbuild` builders with the `dev-server`, interactive key
shortcuts are now available to use while the server is active. Once the build has successfully completed
and the development server has initialized, typing a single letter key followed by enter will execute
the associated action. These actions include forcing a browser full reload, clearing the console, or
quitting. More actions may be added in the future.

The following actions are currently available:
```
  press r + enter to force reload browser
  press u + enter to show server url
  press o + enter to open in browser
  press c + enter to clear console
  press q + enter to quit
```

The `h` action is also available which will display the above list at runtime.
2023-11-29 13:55:33 -05:00
Alan Agius
9b71f551db refactor: remove removeSpecialComments from webpack based builder app-shell builder
This option is not available in webpack based builders.
2023-11-29 19:28:49 +01:00
Alan Agius
e0b274b8ff feat(@angular-devkit/build-angular): add option to retain CSS special comments in global styles
Prior to this change special CSS comments `/*! comment */` were being removed during minification when using the application builder. This caused tools that ran post build that rely on such comments such as purgeCSS and critters not to function properly.

We now provide a `removeSpecialComments` option to enable retention of these comments in global CSS files.

Usage example:
```json
{
  "projects": {
    "my-app": {
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "configurations": {
            "production": {
              "optimization": {
                "styles": {
                  "removeSpecialComments": false
                }
              }
            }
          }
        }
      }
    }
  }
}
```

Closes: #26432
2023-11-29 17:32:29 +01:00
Angular Robot
8a84998c13 build: update all non-major dependencies 2023-11-28 16:56:39 +01:00
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