441 Commits

Author SHA1 Message Date
Alan Agius
4941725f9e refactor: remove unused methods and locals 2024-10-04 13:16:13 +02:00
Charles Lyding
909cfacf8a refactor(@angular-devkit/build-angular): avoid for await...of with promise arrays
The upcoming version of typescript Eslint rules will fail the `await-thenable`
rule for cases of for await...of that use promise arrays. This change
removes the usage to avoid lint failures during the version update.
Ref: https://typescript-eslint.io/rules/await-thenable/#async-iteration-for-awaitof-loops
2024-10-02 16:06:35 -04:00
Alan Agius
743188ba62 refactor: Add lines-around-comment rule
I often struggle with spacing around block comments, so I've decided to add the `lines-around-comment` lint rule to help manage this.

For more details, see the https://eslint.style/rules/js/lines-around-comment
2024-09-11 12:10:54 +02:00
Alan Agius
164c0d805d fix(@angular-devkit/build-angular): reduce the number of max workers to available CPUs minus one
This commit reduces the maximum number of workers to the available CPUs minus 1. This adjustment ensures that some resources are left for the main thread, preventing it from being starved of CPU cycles.
2024-07-01 15:11:59 +02:00
Charles Lyding
d56c8de284 refactor: minor code cleanup to improve code health
Several smaller code changes to improve type information and remove now
unneeded code structures based on improvements to both Node.js, TypeScript,
and underlying dependencies.
2024-06-25 16:57:16 -04:00
Charles Lyding
741cf7fe1e test: enable @typescript-eslint/await-thenable lint rule
The `@typescript-eslint/await-thenable` rule is now enabled and all failures
have been addressed within the code.
2024-06-25 16:57:03 -04:00
Charles Lyding
dd07049277 fix(@angular/build): use Node.js available parallelism for default worker count
The Node.js `os.availableParallelism` API now provides more accurate values
when used within containers such as many CI environments. This provides a
better default when using resource limited CI setups. The value is still
set to a maximum default of four. However, the `NG_BUILD_MAX_WORKERS`
environment variable can be used to set the value to an explicit value
if required.
2024-06-18 16:23:51 +02:00
Ash Ramirez
434a3740f0 refactor(@angular/cli): update aio links -> adev links
Updates for all angular.io links to the new angular.dev domain. Additionally, adjustment to new resources where the equivalent does not exist on the new site (e.g. Tour of Heroes tutorial)
2024-06-06 11:12:06 +02:00
Charles Lyding
4ffe07aa24 feat(@angular-devkit/build-angular): move Vite-based dev-server for application builder to new build system package
With the `application` builder already within the new `@angular/build` package,
the Vite-based `dev-server` builder is now also contained within this package.
Only the Vite-based aspects of the `dev-server` have been moved and only the
support for the `application` builder. The compatibility builder `browser-esbuild`
is not supported with `@angular/build:dev-server`. The existing `dev-server` builder
found within `@angular-devkit/build-angular` should continue to be used for both the
Webpack-based `browser` builder and the esbuild-based compatibility `browser-esbuild`
builder. To maintain backwards compatibility, the existing `@angular-devkit/build-angular:dev-server`
builder continues to support builders it has previously.

No change to existing applications is required.
2024-04-23 07:27:26 -04:00
Charles Lyding
810d213e18 feat(@angular/build): introduce new official build system package
The `@angular/build` package has been introduced to house the esbuild/Vite-based
build system that was newly introduced as stable in v17. The existing
`@angular-devkit/build-angular` package will continue to contain the Webpack-based
build system and to ensure backwards compatibility it will also provide aliases
for the esbuild/Vite-based build system. The changes here are the first stage
of the builder transition and moves the `application` builder into the new package.
The application builder can now be accessed when this package is installed directly
via `@angular/build:application`.

No changes are required for existing projects.
2024-04-18 17:24:23 +02:00
Alan Agius
d51cb598a7 feat(@angular-devkit/build-angular): inject event-dispatch in SSR HTML page
This commit add support in the Angular CLI to inject the event-dispatcher script when using the application builder.
2024-04-17 19:29:36 +02:00
Alan Agius
43816a5b2d fix(@angular-devkit/build-angular): remove type="text/css" from style tag
`type="text/css"` is deprecated, for more info see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style#deprecated_attributes

Closes: #27471
2024-04-16 17:18:43 +02:00
Charles Lyding
4d27c38cd4 refactor(@angular-devkit/build-angular): reduce Webpack specific overlap in bundle budget calculator
Webpack-specific types and imports have been reduced within the logic and test code for the bundle
budget calculator. This reduces the amount of unused code that needs to be loaded when not using
a Webpack-based bundler. The Webpack component style budget plugin was also updated to use only
the `checkBudgets` function instead of the previous two function setup which limits the needed
amount of runtime exports for the plugin.
2024-04-15 09:49:22 -04:00
Charles Lyding
e6582e6931 refactor(@angular-devkit/build-angular): reduce Webpack specific overlap in stats table generation
Webpack-specific types and imports have been reduced within the logic for the build stats table generation.
This reduces the amount of unused code that needs to be loaded when not using a Webpack-based bundler.
2024-04-15 12:33:50 +02:00
Charles Lyding
dcee94b282 refactor(@angular-devkit/build-angular): split Webpack-specific functionality from i18n option creation
The i18n option creation for a project, which is a combination of the `i18n` project field and the `localize`
build option, is now in a separate file from the Webpack specific i18n configuration setup.
This allows the i18n option creation to be used without loading anything Webpack specific.
2024-04-11 13:40:18 -04:00
Charles Lyding
75a01d6296 refactor(@angular-devkit/build-angular): directly resolve asset files in application builder
Instead of previously attempting to reuse the Webpack-based copy assets helper function,
the application builder will now only resolve all potential configured assets. This
avoids depending on non-obvious parameter behavior to prevent the actual copying of
the asset files.
2024-04-11 07:44:11 -04:00
Alan Agius
733fba2e29 build: update dependency http-proxy-middleware to v3 2024-04-10 15:58:17 +02:00
Charles Lyding
83b943a74b refactor(@angular-devkit/build-angular): use single search directory list for postcss/tailwind configuration setup
Both the postcss and tailwind configuration file searching during the `application` builder setup look
in the project and workspace root for one of the related configuration files. To avoid unneeded
repeat file access, both searches now reuse directory contents information.
2024-04-02 09:17:34 -07:00
Charles Lyding
b87b843a1e refactor(@angular-devkit/build-angular): remove unneeded package version from inline font cache key
Since the calculated cache path already contains the `@angular-devkit/build-angular` package version,
the version is not needed within the cache key for each font URL. This removes the need to import the
loaded version from the `package.json` in the font inline logic.
2024-03-28 13:17:11 -07:00
Charles Lyding
e308008df0 refactor(@angular-devkit/build-angular): use build version stamping for build cache path creation
The build process will automatically perform package version placeholder replacement within
source files. This allows for the package version to be injected into the build cache path
creation process as a constant. As the version is now a constant, there is no need to
attempt runtime loading of the package metadata to retrieve the package version.
2024-03-28 13:16:12 -07:00
Alan Agius
6530aa11be feat(@schematics/angular): replace assets with public directory
The `assets` directory is confusing for the users and commonly users place "assets" which are not meant to be copied but instead processed by the build system. This causes some files both bundled and copied.

With this change we rename the `assets` directory to `public` and also move the `favicon.ico` inside this newly created directory.
2024-03-25 17:10:29 +01:00
Alan Agius
c71e954a25 fix(@angular-devkit/build-angular): service-worker references non-existent named index output
This commit addresses an issue where the service worker incorrectly referenced a non-existent `index.html` when utilizing the output index option. Additionally, it ensures proper resolution of the service worker configuration when the option value is set to `true`.
2024-03-25 13:34:50 +01:00
Alan Agius
c7b208555e refactor(@angular/cli): remove support for Node.js versions <18.19.1 and <20.11.1
BREAKING CHANGE: Node.js support for versions <18.19.1 and <20.11.1 has been removed.
2024-03-12 16:51:03 +01:00
Alan Agius
51debcdb78 refactor(@angular-devkit/build-angular): properly display errors originating in ESM loader hooks
Currently, errors occurring in ESM loader hooks while using `--import` are not correctly displayed, as they cannot be transferred from the worker to the main thread. Although the error is an instance of Error, it contains non-transferable properties and cannot be transmitted from a worker when --import is used. Consequently, when read outside of the worker, the error object displays as `[Object object]`. To address this issue, we reconstruct the error message.

See: https://github.com/angular/angular-cli/issues/27251
2024-03-12 15:28:19 +01:00
Charles Lyding
01fa0472e9 refactor(@angular-devkit/build-angular): use direct type assertions for cache option normalization 2024-03-12 09:46:20 -04:00
Charles Lyding
560ec400c0 refactor(@angular-devkit/build-angular): reduce usage of @angular-devkit/core types
Logging types are now based on the BuilderContext's type instead of the
`@angular-devkit/core` type. This reduces the need to directly depend
on this package while also allowing the builder logging type to diverge
if needed. The two usages of the BaseException type which is a small
wrapper around Error have also been removed.
2024-03-11 10:06:36 -04:00
Charles Lyding
93e918e4dd refactor(@angular-devkit/build-angular): improve i18n project option validation
The `i18n` project field is used to configure i18n behavior for a project.
The validation code has been reorganized to use two helper functions to
centralize the type validation and exception throwing. This reduces the complexity
of the analysis code as well as removing the need to rely on `@angular-devkit/core`.
2024-03-11 10:06:23 -04:00
Alan Agius
97973059ec refactor(@angular-devkit/build-angular): remove Sass legacy implementation
This commit removes the legacy Sass implementation previously used with Webpack.

BREAKING CHANGE: The support for the legacy Sass build pipeline, previously accessible via `NG_BUILD_LEGACY_SASS` when utilizing webpack-based builders, has been removed.
2024-03-06 18:15:32 +01:00
Charles Lyding
8a29b61d41 refactor(@angular-devkit/build-angular): remove extra exist check when purging stale build caches
When purging stale build cache entries, the `readdir` call will fail if
the cache base path does not exist. This allows for a single check and
the removal of the previous separate `existSync` call. Additionally,
a repeat join call has also been removed during the stale directory check.
2024-03-05 08:52:52 +01:00
Charles Lyding
a0ed46bbd8 refactor(@angular-devkit/build-angular): use Node.js builtin instead of custom removeColor helper
The Node.js `node:util` builtin contains a helper (`stripVTControlCharacters`) that
can be used to remove ANSI color characters from a string. Usage removes the need
for a custom helper within the package.
2024-03-04 13:46:49 -05:00
Charles Lyding
b55bbde9c3 refactor(@angular-devkit/build-angular): use async pipeline helper in HTML rewriting stream
The Node.js async `pipeline` helper function reduces the amount of infrastructure code
needed to pipe HTML content through the parse5 transform stream.
2024-03-04 18:22:20 +01:00
Charles Lyding
ffeb3eb74e refactor(@angular-devkit/build-angular): use TextDecoder for index reading during index HTML generation
The globally available TextDecoder class will automatically handle the presence of a BOM in
text files when decoding. This allows the removal of the utility function present in the
package to do the same.
2024-03-04 16:25:57 +01:00
Charles Lyding
14189b27c5 refactor(@angular-devkit/build-angular): remove direct require usage from Angular version check
To support future package building as ESM, the direct usage of require has now been
removed from the Angular compatibility check code used by various builders.
Additionally, the limited use of `@angular-devkit/core` has also been removed from
the check code as it was only used to adjust string values for error messages which
can be done directly instead.
2024-03-04 09:35:59 +01:00
Charles Lyding
ccb60abd25 refactor(@angular-devkit/build-angular): disable Piscina timing information recording
The latest version of the worker pool package used by the build system (`Piscina`) now
has an option to disable performance timing information. Since the build system does
not currently use that information, disabling it avoids the extra overhead of histogram
creation and usage. This information collection could potentially be enabled conditionally
in the future if needed.
2024-03-04 09:35:48 +01:00
Alan Agius
6e8d32638b fix(@angular-devkit/build-angular): support string as plugin option in custom postcss plugin config
In certain cases, the plugin option may be a string value, as shown in the example below:

```json
{
 "plugins": {
  "tailwindcss/nesting": "postcss-nesting"
  }
}
```

In certain cases, the plugin option may be a string value, as shown in the example below:

```json
{
 "plugins": {
  "tailwindcss/nesting": "postcss-nesting"
  }
}
```

See: https://tailwindcss.com/docs/using-with-preprocessors#nesting
2024-02-14 16:56:48 +01:00
Alan Agius
f4f535653a feat(@angular-devkit/build-angular): add JSON build logs when using the application builder
This change implements the capability to display JSON build logs in the terminal instead of a format readable by humans. This is particularly useful for hosting providers, as it allows them to effortlessly access the necessary information without having to parse the JSON configuration.

To enable this output, set the `NG_BUILD_LOGS_JSON=1` environment variable. Additionally, warnings, errors, and logs are automatically colorized when the standard output is a WritableStream. You can disable the colors by using the `FORCE_COLOR=0` environment variable.

```
FORCE_COLOR=0 NG_BUILD_LOGS_JSON=1 ng b
{
  "errors": [],
  "warnings": [],
  "outputPaths": {
    "root": "file:///usr/local/test/home//test-project/dist/test-project",
    "browser": "file:///usr/local/test/home//test-project/dist/test-project/browser",
    "server": "file:///usr/local/test/home//test-project/dist/test-project/server"
  },
  "prerenderedRoutes": [
    "/"
  ]
}
```

```
NG_BUILD_LOGS_JSON=1 ng b
{
  "errors": [],
  "warnings": [],
  "outputPaths": {
    "root": "file:///usr/local/test/home//test-project/dist/test-project",
    "browser": "file:///usr/local/test/home//test-project/dist/test-project/browser",
    "server": "file:///usr/local/test/home//test-project/dist/test-project/server"
  },
  "prerenderedRoutes": [
    "/"
  ]
}
```
2024-01-31 17:51:15 +01:00
Charles Lyding
7c522aa874 feat(@angular-devkit/build-angular): support using custom postcss configuration with application builder
When using the `application` builder, the usage of a custom postcss configuration is now supported.
The builder will automatically detect and use specific postcss configuration files if present in
either the project root directory or the workspace root. Files present in the project root will have
priority over a workspace root file. If using a custom postcss configuration file, the automatic
tailwind integration will be disabled. To use both a custom postcss configuration and tailwind, the
tailwind setup must be included in the custom postcss configuration file.

The configuration files must be JSON and named one of the following:
* `postcss.config.json`
* `.postcssrc.json`

A configuration file can use either an array form or an object form to setup plugins.
An example of the array form:
```
{
    "plugins": [
        "tailwindcss",
        ["rtlcss", { "useCalc": true }]
    ]
}
```

The same in an object form:
```
{
    "plugins": {
        "tailwindcss": {},
        "rtlcss": { "useCalc": true }
    }
}
```

NOTE: Using a custom postcss configuration may result in reduced build and rebuild
performance. Postcss will be used to process all global and component stylesheets
when a custom configuration is present. Without a custom postcss configuration,
postcss is only used for a stylesheet when tailwind is enabled and the stylesheet
requires tailwind processing.
2024-01-31 17:51:03 +01:00
Alan Agius
822e7a482d fix(@angular-devkit/build-angular): handle regular expressions in proxy config when using Vite
This commit enables proxies to have a RegExp as context when using Vite. See: https://vitejs.dev/config/server-options#server-proxy

Closes #26970
2024-01-26 16:46:30 +01:00
Alan Agius
dbd3984f24 fix(@angular-devkit/build-angular): correctly handle glob negation in proxy config when using vite
This commit fixes an issue were negated globs in proxy config were not process correctly when using vite.

Closes #26970
2024-01-26 16:21:08 +01:00
Alan Agius
c93ea15278 fix(@angular-devkit/build-angular): handle handle load event for multiple stylesheets and CSP nonces
The `load` event for each stylesheet may not always be triggered by Google Chrome's handling. Refer to: https://crbug.com/1521256

This results in the media attribute persistently being set to print, leading to distorted styles in the UI. To address this issue, we substitute the onload logic by replacing `link.addEventListener('load', ...` with `document.documentElement.addEventListener('load', ...` and filtering for link tags.

Closes #26932
2024-01-24 14:58:54 +01:00
Alan Agius
1f119be00d fix(@angular-devkit/build-angular): provide actionable error message when server bundle is missing default export
This change improves the error message when the server bundle does not export a default export.

Closes #26922
2024-01-23 16:23:18 +01:00
Charles Lyding
7d1cff0276 refactor(@angular-devkit/build-angular): allow internal Angular compilation control of diagnostic modes
To support generate diagnostics in varying ways, the internal compilation classes
now support a `modes` argument when diagnosing files during a build using the `application` builder.
This is not exposed as an option at this time but can be experimented with a build using the
`NG_BUILD_TYPE_CHECK` environment variable. This environment variable is not considered part of the
public API and may be removed or altered in the future. Its current purpose is to allow profiling
of the type checking diagnostics functionality of the build system.
2024-01-16 08:21:15 -05:00
Doug Parker
bffaa773ca refactor: move findTestFiles to a common directory where it can be reused in multiple builders 2024-01-03 18:52:58 +01:00
Alan Agius
ceffafe1a3 fix(@angular-devkit/build-angular): provide better error messages for failed file reads
This commit adds a more actionable error message when `readFile` fails during index generation.
2023-12-20 15:58:13 +01:00
Marco Steinhoff
e9a51a37f6 refactor(@angular-devkit/build-angular): unify proxy config loading in dev-server and ssr-dev-server
This improvement harmonizes the proxy configuration loading mechanisms between the dev-server and ssr-dev-server. Previously, these servers used different methods for loading the proxy configuration, leading to inconsistencies. Notably, the ssr-dev-server was limited to loading configurations only in JSON format. This change enables the ssr-dev-server to support various configuration formats, aligning it with the dev-server's capabilities and improving overall developer experience.
2023-12-13 17:43:53 +01:00
Alan Agius
7a50df5c04 fix(@angular-devkit/build-angular): update ESM loader to work with Node.js 18.19.0
In Node.js 18.19 ESM loaders works the same way as Node.js 20.9+

Closes #26648
2023-12-12 18:10:36 +01:00
Charles Lyding
6a44989f54 fix(@angular-devkit/build-angular): retain symlinks to output platform directories on builds
The `deleteOutputPath` option will now empty specific build artifact directories instead of
removing them completely. This allows for symlinking or mounting the directories via Docker.
This is similar to the current behavior of emptying the root output path to allow similar
actions. All previous files will still be removed when the `deleteOutputPath` option is enabled.
This is useful in situations were the browser output files may be symlinked onto another
location on disk that is setup as a development server, or a Docker configuration mounts the browser
and server output to different locations on the host machine.
2023-12-11 10:29:46 +01:00
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
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