3589 Commits

Author SHA1 Message Date
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
Angular Robot
45820d2a17 build: update all non-major dependencies 2024-01-30 09:07:55 -08:00
Angular Robot
8515c6bb54 build: update all non-major dependencies 2024-01-29 15:27:28 -08:00
Charles Lyding
dda3d27aff refactor(@angular-devkit/build-angular): remove babel core runtime imports from elide-angular-metadata build optimizer pass
The `elide-angular-metadata` build optimization pass have been cleaned up
and restructured to remove the need for a direct runtime dependency on `@babel/core`.
2024-01-29 15:26:32 -08:00
Charles Lyding
b9ec9ee688 refactor(@angular-devkit/build-angular): remove babel core runtime imports from pure-toplevel-functions build optimizer pass
The `pure-toplevel-functions` build optimization pass have been cleaned up
and restructured to remove the need for a direct runtime dependency on `@babel/core`.
2024-01-29 15:26:17 -08: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
09c6f5f80b refactor(@angular-devkit/build-angular): remove dependency on text-table
Removes `text-table` from dependencies
2024-01-26 16:45:35 +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
37ffa5e4a0 fix(@angular-devkit/build-angular): resolve absolute output-path when using esbuild based builders
Prior to this change using an absolute path as a `output-path` resulted in the path to be combined with the workspace root instead of resolved which caused the output to be emitted in the incorrect directory or error in Windows.

Closes #26935
2024-01-26 15:39:21 +01:00
Angular Robot
760328c4a1 build: update all non-major dependencies 2024-01-26 08:55:23 +01:00
Alan Agius
bac79d4000 refactor(@angular-devkit/build-angular): increase type safety in bundle-context
Currently the `result` variable will be set to `any` which caused a large part of this file not to be safely typed.
2024-01-25 15:58:10 +01:00
Alan Agius
479b67fedd refactor(@angular-devkit/build-angular): disable SW and index generation during i18n extraction
This commit disables index and service worker generation when using the i18n extraction together with the esbuild builders.
2024-01-25 15:57:57 +01:00
Alan Agius
d6aea27dbc fix(@angular-devkit/build-angular): add required modules as externals imports
Prior to this change any module which was used using `require` was not listed as an external.

Closes #26833
2024-01-25 15:43:23 +01:00
Angular Robot
eadd898e96 build: update all non-major dependencies 2024-01-25 09:35:26 +01:00
Alan Agius
6c65730b60 build: update angular to 17.2.0-next 2024-01-25 09:11:51 +01:00
Alan Agius
8216b11b3c fix(@angular-devkit/build-angular): return 404 for assets that are not found
This commit updates the vite dev-server to return 404 for assets and files that are not found.

Closes #26917
2024-01-24 18:54:25 +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
Charles Lyding
789a5c49b0 refactor(@angular-devkit/build-angular): update Vite client code loading for v5
Vite v5 updated the client code's error dialog text. This requires that the
text replacement code also be updated to remove unactionable information from
the error dialog.
2024-01-24 07:52:36 +01:00
Angular Robot
de042ee80a build: update all non-major dependencies 2024-01-24 07:48:08 +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
Angular Robot
248b4c9a75 build: update all non-major dependencies 2024-01-23 10:52:36 +01:00
Charles Lyding
f83a4858d3 fix(@angular-devkit/build-angular): allow package file loader option with Vite prebundling
Previously, the `application` builder would consider all imports originating from a package
to be considered external when caching was enabled. This allows Vite's prebundling to function
and optimize the build/rebuild experience for the development server. However, when using the
newly introduced `loader` option, this also inadvertently caused files that should be affected
by the option that originate from a package to also be considered external. This behavior would
then prevent the loader customization from being performed. To rectify this situation, all files
that would be affected by a loader customization will not be marked as external for the purposes
of prebundling unless explicitly configured by the `externalDependencies` option.
2024-01-23 10:52:12 +01:00
Alan Agius
0b0df5a761 fix(@angular-devkit/build-angular): pre-transform error when using vite with SSR
This commit fixes a regression which causes a pre-transform error when using vite with ssr. The `request.url` is now passed to the index transformer instead of `request.originalUrl`. This is because the `request.url` will have a value of the `index.html`.

Closes #26897
2024-01-22 16:05:06 +01:00
Alan Agius
14b1be26b9 refactor(@angular-devkit/build-angular): use for loop instead of filter and forEach
Reduce iterations by using a `for loop`.
2024-01-22 15:56:44 +01:00
Alan Agius
af1f0da37f fix(@angular-devkit/build-angular): do not add internal CSS resources files in watch
This change fixes an issue which caused internal virtual inputs to be added to the watch, this cases watchpack to emit a removed event as this file does not exist on disk.

We fix this issue, by prefixing `css-resouces` namespace with `angular:` which the input to be filtered out, see: 4539961968/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts (L251)

Closes #26918
2024-01-22 15:56:32 +01:00