3413 Commits

Author SHA1 Message Date
Charles Lyding
fc5a2af97b refactor(@angular-devkit/build-angular): remove Webpack helpers from application builder option normalization
The usage of several Webpack-centric option helper functions has now been
removed from the `application` builder. This allows for more efficient
processing of incoming options but also removes additional imports across
builder code.
2024-03-06 09:14:36 +01:00
Alan Agius
b20dcae76b fix(@angular-devkit/build-angular): disable deployUrl when using vite dev-server
Prior to this commit, the deployUrl was incorrectly being set when using vite dev-server.
2024-03-05 16:28:04 +01:00
Alan Agius
2f70f9554b build: lock file maintenance 2024-03-05 15:59:07 +01:00
Alan Agius
b8054cb41e refactor(@angular-devkit/build-angular): remove vite deprecation warning
`optimizeDeps.disabled` has been deprecated in favor of `optimizeDeps.noDiscovery` to `true` and `optimizeDeps.include` to `undefined`

```
(!) Experimental ssr.optimizeDeps.disabled and deps pre-bundling during build were removed in Vite 5.1.
    To disable the deps optimizer, set ssr.optimizeDeps.noDiscovery to true and ssr.optimizeDeps.include as undefined or empty.
    Please remove ssr.optimizeDeps.disabled from your config.
```
2024-03-05 15:58:06 +01:00
Andrey "Zed" Zaikin
ce45522df6 docs: fix typo in json schema 2024-03-05 11:08:14 +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
Alan Agius
9ca3a54503 feat(@angular-devkit/build-angular): add deployUrl to application builder
This commit adds the deployUrl option ot the application builder.

Closes #26411
2024-03-04 16:24:30 +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
7a1a44305c fix(@angular-devkit/build-angular): avoid marking component styles as media with no output media directory
The logic to detect media output files was previously predicated on the presence of a media subdirectory
being defined. Prior to the ability to customize output path subcomponents there was a guaranteed media
subdirectory. However, now that customization is possible, there is the potential for media files to
not have a distinct subdirectory in the output. To facilitate output media detection in this scenario
a file extension based method is now employed. This avoids a dependence on output directory structure.
2024-03-04 09:35:51 +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
Charles Lyding
8d1a7c3f1a fix(@angular-devkit/build-angular): avoid implicit CSS file extensions when resolving
Unlike the non-ESM Node.js resolution for JS files, CSS does not have the concept
of implicit file extensions. To avoid incorrectly resolving a file as CSS,
stylesheet bundling no longer attempts to resolve implicit extensions. Preprocessors,
such as Sass, contain logic internally that handles any specific resolution cases
for their respective preprocessor and such behavior is unaffected.
2024-03-04 09:35:15 +01:00
Angular Robot
6acd091d0f build: update all non-major dependencies 2024-02-28 15:29:35 -05:00
Kristiyan Kostadinov
f06f4422c6 build: update to TypeScript 5.4
Updates the repo to TypeScript 5.4.
2024-02-28 12:59:28 -05:00
Angular Robot
30f182c7ad build: update all non-major dependencies 2024-02-26 14:29:44 -05:00
Charles Lyding
422a9eaa70 build: update webpack to v5.90.3 2024-02-26 13:18:37 -05:00
Charles Lyding
ce2c3ef0e9 fix(@angular-devkit/build-angular): ensure all related stylesheets are rebuilt when an import changes
This fixes a logic error wherein some stylesheets could potentially not be
rebuilt if a shared import was edited and triggered an application rebuild.
2024-02-23 07:11:09 -05:00
Charles Lyding
e98dde62de fix(@angular-devkit/build-angular): provide Vite client code source map when loading
The sourcemap for the Vite client code was previously not being loaded along with the
actual code. This could lead to browser 404 console messages when debugging applications.
2024-02-22 10:03:42 -08:00
Charles Lyding
9a6a77e2f1 build: update dart-sass to v1.71.1 2024-02-22 08:29:08 -05:00
Charles "Demurgos" Samborski
fa146b8e86 fix(@angular-devkit/build-angular): allow mts and cts file replacement
Updates the `fileReplacement` pattern to allow `.mts` and `.cts` files.
This enables support for TypeScript files with explicit ESM support.

Closes #27124
2024-02-21 14:20:43 -08:00
Angular Robot
749cc744da build: update all non-major dependencies 2024-02-15 15:43:35 +01:00
Angular Robot
a83fbf6dfb build: update all non-major dependencies 2024-02-15 08:46:22 +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
Angular Robot
9f088c5ae9 build: update all non-major dependencies 2024-02-13 13:16:02 +01:00
Charles Lyding
e75aa9b581 fix(@angular-devkit/build-angular): downgrade copy-webpack-plugin to workaround Node.js support issue
The `copy-webpack-plugin@12` package has a dependency on the `globby@14` package. The recently released
`globby@14.0.1` uses the `merge-streams@2.1.0` package which requires a minimum Node.js version higher
than the officially supported 18.13 for the Angular CLI. Due to both `globby` and `merge-streams` being
transitive dependencies in end-user projects, the Angular CLI cannot directly control the package versions.
However, `copy-webpack-plugin@11` uses `globby@13` which is not affected by the Node.js version problem.
To workaround the Node.js compatibility problem, `copy-webpack-plugin` has been downgraded to version 11.0.0
which is the latest version in the 11 major for the package. The `copy-webpack-plugin` is only used with the
Webpack-based builders when in watch mode. From a review of the commit history between 11.0.0 and 12.0.2 (latest
at the time of this commit), it appears the only notable changes are several performance improvements and the
major version update of `globby`.
2024-02-13 13:14:21 +01:00
Charles Lyding
5a2a963043 fix(@angular-devkit/build-angular): bypass Vite prebundling for absolute URL imports
To avoid the Vite-based development server's prebundling system from attempting to
prebundle import statements containing absolute URLs, the set of external specifiers
will now be pre-filtered before being passed onto Vite. Currently, the check for
an absolute URL is any specifier starting with `http://`, `https://`, or '//'.
2024-02-12 08:39:20 +01:00
Angular Robot
848eff7b4c build: update dependency vite to v5.1.1 2024-02-09 10:54:41 -05:00
Alan Agius
c9bc5076c9 build: update to vite 5.1.0 2024-02-09 15:41:01 +01:00
Charles Lyding
1aeeb7da09 fix(@angular-devkit/build-angular): ensure WebWorker main entry is used in output code
Previously, the check for determining the correct main entry point for a bundled web worker
found in application code could incorrectly use a lazy chunk created from the worker bundling
under certain situations. The check has now been made more strict to mitigate these situations.
2024-02-08 12:30:36 -05:00
Angular Robot
8d09b80be9 build: update dependency picomatch to v4 2024-02-08 11:31:38 +01:00
Charles Lyding
7f57123fd4 feat(@angular-devkit/build-angular): add define build option to application builder
The `application` builder now supports a new option named `define`. This option allows
global identifiers present in the code to be replaced with another value at build time.
This is similar to the behavior of Webpack's `DefinePlugin` which was previously used with
some custom Webpack configurations that used third-party builders. The option has similar
capabilities to the `esbuild` option of the same name. The documentation for that option
can be found here: https://esbuild.github.io/api/#define
The command line capabilities of the Angular CLI option are not yet implemented and will added
in a future change.

The option within the `angular.json` configuration file is of the form of an object. The keys
of the object represent the global identifier to replace and the values of the object represent
the corresponding replacement value for the identifier. An example is as follows:

```
"define": {
    "SOME_CONSTANT": "5",
    "ANOTHER": "'this is a string literal'"
}
```

All replacement values are defined as strings within the configuration file. If the replacement
is intended to be an actual string literal, it should be enclosed in single quote marks. This
allows the flexibility of using any valid JSON type as well as a different identifier as a replacement.

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 const SOME_CONSTANT: number;
declare const ANOTHER: string;
```
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.

An important caveat to the option is that it does not function when used with values
contained within Angular metadata such as a Component or Directive decorator. This
limitation was present with previous third-party builder usage as well.
2024-02-07 13:40:51 -05:00
Angular Robot
ad52f8ee86 build: update all non-major dependencies 2024-02-07 12:34:12 -05:00
Alan Agius
8d5af1d5c7 fix(@angular-devkit/build-angular): ensure correct .html served with Vite dev-server
Prior to this commit, the Vite html fallback middleware failed to handle the in-memory assets generated by Angular CLI, resulting in incorrect fallback behavior. For instance, when an `index.html` existed as an asset under a specific path, the generated `index.html` would be served instead.

This fix addresses the issue, ensuring that the appropriate `.html` is served when using the Vite dev-server.

Closes #27044
2024-02-07 13:53:25 +01:00
Charles Lyding
b59f663e57 feat(@angular-devkit/build-angular): allow control of Vite-based development server prebundling
Previously, the Vite-based development server that is automatically used with the `application`
and `browser-esbuild` builders would always use prebundling if the Angular CLI caching was enabled.
The development server now has a specific `prebundle` option to allow more control over prebundling
while still allowing other forms of caching within the Angular CLI. The `prebundle` option
can be a boolean value of `true` or `false` that will enable or disable prebundling, respectively.
Additionally, the option also has an object long-form. This long-form enables prebundling and
currently contains one property named `exclude`. The `exclude` property supports cases where a
package should not be prebundled and rather should be bundled directly into the application code.
These cases are not common but can happen based on project specific requirements.
If the `prebundle` option is enabled when using the `browser` builder or any other Webpack-based
builder, it will be ignored as the Webpack-based development server does not contain such
functionality.
2024-02-06 10:45:50 -05:00
Alan Agius
5e6f1a9f43 fix(@angular-devkit/build-angular): avoid preloading server chunks
41ea985f93 (diff-239ad7beb7d8a76046cdc7b4d2263b2e05c300e3e0510916cb907e93efec5af0) introduced a regression which causes server enter-points
2024-02-06 15:55:54 +01:00
Angular Robot
ccdaed4e49 build: update all non-major dependencies 2024-02-06 08:42:54 -05:00
Alan Agius
7a12074dc9 feat(@angular-devkit/build-angular): provide option to allow automatically cleaning the terminal screen during rebuilds
When setting `"clearScreen": true` to the appliction builder during rebuilds the terminimal screen will be cleaned.

```json
{
  "projects": {
    "my-app": {
      "projectType": "application",
      "root": "",
      "sourceRoot": "src",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "clearScreen": true
          }
        }
      }
    }
  }
}
```

Closes #25699
2024-02-02 18:00:10 +01:00
Alan Agius
1011f3185d build: update all non-major dependencies 2024-02-02 09:56:02 -05:00
Angular Robot
5f916e7810 build: update all non-major dependencies 2024-02-01 08:31:07 -08:00
Charles Lyding
83000bdef2 refactor(@angular-devkit/build-angular): allow internal externalPackages option to exclude packages
To support future use cases, the internal `externalPackages` application builder option now also
accepts an object form with an `exclude` array field in addition to the existing boolean value.
The `exclude` capability allows for specifying individual packages that should always be bundled
when using the external packages functionality. Currently the external packages functionality is
only used by the Vite-based development server.
2024-02-01 10:58:10 -05:00
Alan Agius
2a25e06eae fix(@angular-devkit/build-angular): allow ./ baseHref when using vite based server
Since this change 4b3a965429
A warning is displayed when using `./` as a base href
```
(!) invalid "base" option: ".". The value can only be an absolute URL, "./", or an empty string.
```
2024-02-01 16:37:53 +01:00
Alan Agius
d5a35d7108 refactor(@angular-devkit/build-angular): remove casting since setSourceMapsEnabled is in typings now
Remove redundant casting.
2024-02-01 16:37:41 +01:00
Angular Robot
26424818de build: update dependency css-loader to v6.10.0 2024-01-31 10:04:49 -08: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
Alan Agius
476a68daa9 fix(@angular-devkit/build-angular): add output location in build stats
This can be used by users to determine where the output path is located without needing to read the angular.json.
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
944cbcdb1a fix(@angular-devkit/build-angular): limit the number of lazy chunks visible in the stats table
Prior to this change in the stats table we listed all the lazy chunk, in some cases this could be hundreds of files.

With this change, we limit the number of files listed. To display all entire list of files users would need to use the `--verbose` flag.
2024-01-30 21:05:35 +01:00
Alan Agius
41ea985f93 fix(@angular-devkit/build-angular): display server bundles in build stats
This commit adds server bundle information to the build logs

Closes #25855
2024-01-30 21:05:35 +01:00