2009 Commits

Author SHA1 Message Date
Charles Lyding
096aaba85f refactor(@angular-devkit/build-angular): remove unneeded option type casting from several builders
Multiple cases where builder options were being cast to the `JsonObject` type
have been removed. These casts are no longer needed and unnecessarily added
complexity to the code.
2024-03-12 09:46:20 -04:00
Alan Agius
1034bb155b fix(@angular-devkit/build-angular): provide better error message when server option is required but missing
This improves the error message when the server entry-point is required but missing

Closes #27251
2024-03-12 10:06:27 +01:00
Alan Agius
e729f6ea10 build: update dependency webpack-dev-server to v5 2024-03-11 19:00:54 +01: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
f112a0af16 refactor(@angular-devkit/build-angular): add warnings for unsupported vite options
This commit adds warnings when using unsupported dev-server options with vite.
2024-03-11 08:08:47 +01:00
Alan Agius
518afd80cc fix(@angular-devkit/build-angular): ensure proper display of build logs in the presence of warnings or errors
Previously, a race condition could occur due to the spinner, resulting in the deletion of the last printed log when warnings or errors were present. With this update, we ensure that logs are printed after the spinner has stopped.

Fixes #27233
2024-03-08 16:26:23 +01: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
0b7a101062 refactor(@angular-devkit/build-angular): remove unneeded relative URL modification for public path
Only the injected index HTML file references and component stylesheets require
the modification of relative URLs with a public path when specified. Other
usages are already resolved relative to their containing file location with
the `application` builder.
2024-03-06 09:15:16 +01:00
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
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
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
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
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
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
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
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
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
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
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
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