1350 Commits

Author SHA1 Message Date
Charles Lyding
24aaf1e37f feat(@angular/build): support import attribute based loader configuration
When using the application builder, a `loader` import attribute is now available
for use with import statements and expressions. The presence of the import
attribute takes precedence over all other loading behavior including JS/TS and
any `loader` build option values. This allows per file control over loading
behavior. For general loading for all files of an otherwise unsupported file
type, the `loader` build option is recommended.

For the import attribute, the following loader values are supported:
* `text` - inlines the content as a string
* `binary` - inlines the content as a Uint8Array
* `file` - emits the file and provides the runtime location of the file

Unfortunately, at this time, TypeScript does not support type definitions
that are based on import attribute values. The use of `@ts-expect-error`
or the use of individual type definition files (assuming the file is only
imported with the same loader attribute) is currently required.

Additionally, the TypeScript `module` option must be set to `esnext` to
allow TypeScript to successfully build the application code.

As an example, an SVG file can be imported as text via:
```
// @ts-expect-error TypeScript cannot provide types based on attributes yet
import contents from './some-file.svg' with { loader: 'text' };
```

When using the development server and a file that is referenced from a Node.js
package with a loader attribute, the package must be excluded from prebundling
via the development server `prebundle` option. This does not apply to relative
file references.
2024-07-15 08:08:35 -04:00
Angular Robot
81a3563b6f build: update all non-major dependencies 2024-07-12 11:19:35 +02:00
Mickaël Depardon
9baae6e22c fix(@angular-devkit/build-angular): skip undefined files when generating budget stats
When the sourceMaps are enabled they are generating some files that are computed by the budget stats. Now the method `generateBudgetStats` skip when the file is undefined.
2024-07-12 10:13:53 +02:00
Charles Lyding
5895e9fb01 test: enable no-case-declarations lint rule
The `no-case-declarations` rule is now enabled and all failures
in have been addressed within the published code. Unit tests
have been excluded.
2024-07-11 08:19:56 +02:00
Charles Lyding
eced3a8ecc test: enable no-fallthrough lint rule
The `no-fallthrough` rule is now enabled and all failures
have been addressed within the code.
2024-07-11 08:19:56 +02:00
Charles Lyding
1271e4a0e5 refactor(@angular/build): use listr2 for spinner and color support
The `ansi-color` and `ora` dependencies have been replaced with `listr2`.
This package provides both color and spinner capabilities and further
reduces the dependency count. This also aligns the dependencies with
the `@angular/cli` package with already uses `listr2`. The spinner also
now will not overwrite console output that happens to be written while
the spinner is active. Instead, the output will be written after the
spinner task is complete.
2024-07-11 08:19:19 +02:00
Alan Agius
01c1ec087e build: update Angular dependencies to version 18.2.0-next.0 2024-07-10 16:00:13 +02:00
Angular Robot
22d9369aef build: update all non-major dependencies 2024-07-10 09:07:48 +02:00
Charles Lyding
10f882c562 refactor(@angular/cli): use Node.js CommonJS wrapping for schematic encapsulation
The schematics encapsulation process now uses a similar wrapping setup to
Node.js itself. This removes some custom code and also provides a more
comprehensive global object which should provide improved compatibility
for third-party packages used within schematics.
2024-07-10 08:40:11 +02:00
Angular Robot
9204f625c1 build: update all non-major dependencies 2024-07-09 09:58:59 +02:00
Charles Lyding
fee575e126 fix(@angular/build): read WASM file from script location on Node.js
When using a WASM file on Node.js via SSR/SSG/etc. the path for the `readFile`
call will now be based on the location of the script using the WASM file
instead of the current working directory.
This change also adds a general Node.js WASM E2E test via prerendering.
2024-07-09 09:58:33 +02:00
Charles Lyding
4286bb03b5 refactor(@angular/build): remove direct usage of undici dependency for SSR
The Node.js types (`@types/node`) now contains the information for the `Response`
class and the global `fetch` function. The `Response` object is also globally
accessible in all versions of Node.js supported by the Angular CLI. This removes
the need to depend directly on the `undici` package.
The `undici` package is still used for unit-testing and remains as a development
dependency.
2024-07-08 18:54:18 +02:00
Charles Lyding
afbe3119bf refactor(@angular/cli): provide a default extract-i18n target for applications
The `extract-i18n` command will now use a default project target and builder
name if the target entry is not explicitly defined. This allows the removal
of additional configuration from an `angular.json` file. If the target is
already present than it will take priority over any default builder behavior.
Infrastructure is also now present to allow other architect commands to
have similar functionality in the future.
2024-07-08 12:08:44 +02:00
Angular Robot
89aa22a7ba build: update all non-major dependencies 2024-07-08 12:06:20 +02:00
Charles Lyding
aa88e68264 fix(@angular/build): check inlineSourceMap option with isolated modules optimization
The isolated modules transpilation option that was recently introduced is
currently disabled when source maps are enabled. TypeScript has two mutually
exclusive options that can be used to check for source map usage. Both of
these options (`sourceMap` and `inlineSourceMap`) are now checked to determine
if the direct transpilation optimization can be used.
2024-07-03 13:31:43 -04:00
Angular Robot
b0b39b30d3 build: update all non-major dependencies 2024-07-03 09:27:02 -04:00
Charles Lyding
2cb1fb350b feat(@angular/build): support WASM/ES Module integration proposal
Application builds will now support the direct import of WASM files.
The behavior follows the WebAssembly/ES module integration proposal. The usage
of this feature requires the ability to use native async/await and top-level
await. Due to this requirement, applications must be zoneless to use this new
feature. Applications that use Zone.js are currently incompatible and an error
will be generated if the feature is used in a Zone.js application. Manual
setup of a WASM file is, however, possible in a Zone.js application if WASM
usage is required. Further details for manual setup can be found here:
https://developer.mozilla.org/en-US/docs/WebAssembly/Loading_and_running

The following is a brief example of using a WASM file in the new feature
with the integration proposal behavior:
```
import { multiply } from './example.wasm';

console.log(multiply(4, 5));
```

NOTE: TypeScript will not automatically understand the types for WASM files.
Type definition files will need to be created for each WASM file to allow
for an error-free build. These type definition files are specific to each
individual WASM file and will either need to be manually created or provided
by library authors.

The feature relies on an active proposal which may change as it progresses
through the standardization process. This may result in behavioral differences
between versions.
Proposal Details: https://github.com/WebAssembly/esm-integration/tree/main/proposals/esm-integration

For more information regarding zoneless applications, you can visit https://angular.dev/guide/experimental/zoneless
2024-07-03 09:26:44 -04:00
Charles Lyding
2dc51d5c9c fix(@angular/build): support import attributes in JavaScript transformer
The babel-based JavaScript transformer currently requires a syntax plugin
to support import attributes. Import attributes are otherwise supported in
application code. However, in production builds the JavaScript transformations
such as the build optimizer passes would fail on code that contain any import
attributes. The inclusion of the babel syntax plugin removes this problem.
Once babel provides built-in support for this syntax feature, the plugin
can be removed.
2024-07-02 09:03:46 -04:00
Charles Lyding
fea8044f99 fix(@angular/build): allow top-level await in zoneless applications
With the potential future introduction of features such as WASM/ES module integration
and the experimental chunk optimizer, the need to restrict top-level await
usage is no longer needed and a blocker for new features. As such, top-level
await will now be available if an application has been configured to be
zoneless.
Zoneless Angular is currently experimental and more details can be found here:
https://angular.dev/guide/experimental/zoneless
2024-07-01 17:09:31 -04:00
Alan Agius
0a22e05dd2 fix(@angular/build): 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
Alan Agius
f16fbd82ad build: update all non-major dependencies 2024-07-01 13:44:11 +02:00
Angular Robot
9c26db46d7 build: update dependency https-proxy-agent to v7.0.5 2024-06-28 11:38:05 -07:00
Alan Agius
b5af8b59be refactor(@angular/build): move Vite middlewares into separate files
As the number of middlewares has increased over time, this commit enhances code health by relocating them into individual files.
2024-06-28 17:23:46 +02:00
Alan Agius
9a1c059f7c fix(@angular/build): redirect to path with trailing slash for asset directories
Prior to this commit, accessing a static asset directory without a trailing slash resulted in a 404 error. With this change, we now redirect to the path with a trailing slash, aligning with the behavior of express static.

Closes #27949
2024-06-28 15:37:52 +02:00
Charles Lyding
a5f1b918fd refactor(@angular/build): add experimental chunk optimizer for production application builds
An experimental chunk optimizer is now available for initial usage.
To enable the optimization, script optimization must be enabled as well as
an environment variable `NG_BUILD_OPTIMIZE_CHUNKS=1`. This build step uses
`rollup` internally to process the build files directly in memory. The main
bundling performs all resolution, bundling, and tree-shaking of the application.
The chunk optimizer step then only needs to access the in-memory built files and does not
need to perform any disk access or module resolution. This allows the step to be
performed fairly quickly but it does add time to the overall production build.
The `NG_BUILD_DEBUG_PERF=1` environment variable can be used to view how long the step
takes within a build via the `OPTIMIZE_CHUNKS` entry. In the future, this optimization
step may be automatically enabled based on initial file entry count and size.
There are several current known issues:
1) Bundle budgets for named lazy chunks may not work as expected.
2) The console output may not show names (files will be present) for lazy chunk files.
3) The stats file (`--stats-json` option) will not exactly reflect the final written application files. This is similar to the current behavior of the `browser` builder with Webpack's stat file.
2024-06-28 08:59:12 -04:00
Angular Robot
7c4e0918d9 build: update all non-major dependencies 2024-06-27 10:09:22 -07:00
ddereszkiewicz
4947f29cfa fix(@angular/cli): make ng update to keep newline at the end of package.json
As stated in https://github.com/angular/angular-cli/issues/11744,
`ng update` command removed the newline at the end of the package.json file.
This commit makes `ng update` to preserve newline, if it was present before running the command.

Fixes #11744
2024-06-27 10:08:29 -07:00
Charles Lyding
75abe2cc52 refactor(@angular/build): use build output files directly in stats and budgets
The bundle budget calculators and the console build stats output are now
calculated directly from the build output file information instead of the
esbuild metafile where possible. This provides a more generic method of
accessing the information and can more accurately account for post-processing
steps that may alter the output files. The metafile is still used for
component style budgets and lazy chunk name information.
2024-06-27 12:37:48 -04:00
Alan Agius
f3ba2080f9 fix(@angular/build): correctly name entry points to match budgets
This commit addresses an issue where some lazy entry points were not name correctly to align with specified budgets.

Closes: #27936
2024-06-27 13:45:47 +02:00
Alan Agius
30473f9203 fix(@angular/build): normalize paths during module resolution in Vite
Before this update, the importer path was not normalized, causing mismatches during SSR on Windows.
2024-06-27 13:43:10 +02:00
Charles Lyding
e6d5c7e0b8 refactor(@angular/build): improve BuildOutputFile property access
The `BuildOutputFile` type's helper functions have been adjusted to cache
commonly accessed property values to avoid potentially expensive repeat
processing. This includes encoding/decoding UTF-8 content and calculating
hash values for the output file content. A size property has also been
added to allow consumers to more directly determine the byte size of the
output file. The size property is currently unused but will be leveraged
in forthcoming updates to bundle budgets and console info logging.
2024-06-27 07:28:16 -04:00
Angular Robot
169daf1a2e build: update dependency piscina to v4.6.1 2024-06-26 08:31:48 -07: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
fa9bce0e9a test: enable @typescript-eslint/no-unnecessary-type-assertion lint rule
The `@typescript-eslint/no-unnecessary-type-assertion` rule is now enabled and all failures
have been addressed within the code.
2024-06-25 16:57:03 -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
Alan Agius
0d2d9860fd build: remove @types/browserslist
`browserslist` now ships it's own typings
2024-06-25 21:20:26 +02:00
Alan Agius
aebfde28c7 build: update all non-major dependencies
Closes #27881
2024-06-25 20:53:49 +02:00
Charles Lyding
137949e8ff refactor(@angular/cli): use non-experimental decorators for internal memoize
With standard decorator support now available for use, the memoize decorator
has been updated to be a standard decorator instead of a TypeScript experimental
decorator. This change also removes the only usage of decorators within the
Angular CLI code itself. This change does not affect application code.
2024-06-25 09:31:57 -07:00
Charles Lyding
17e168379e build: additional fixes for tsetse rule compliance
Due to bazel rules_nodejs caching, several additional `JSON.parse` usages were not
caught in the first set of fixes. These have now been addressed. Also,
the `must-use-promises` rule has been patched to match the behavior of the
`@typescript-eslint/no-floating-promises` for consistency.
The bazel option `suppressTsconfigOverrideWarnings` was also removed from the
`tsconfig` as it is a no-op and was previously used for now removed feature.
Test files are currently excluded from the `JSON.parse` rule to avoid large
changes to test code.
2024-06-25 11:17:33 -04:00
Charles Lyding
579f81798f build: remove tsetse rule exclusions
To remove the tsetse rule exclusions, several usages of `JSON.parse` that
did not have type casting where adjusted to add types. This removed the
need for the manual configuration within the tsconfig.
2024-06-24 12:50:55 -04:00
Alan Agius
3e359da8df fix(@angular/build): address rxjs undefined issues during SSR prebundling
Replacing the paths to ESM in Vite can cause prebundling to fail in some cases, resulting in errors similar to the following:

```
12:55:12 PM [vite] Error when evaluating SSR module /chunk-CHB4JJIP.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)

12:55:12 PM [vite] Error when evaluating SSR module /chunk-GQZ5BKXC.mjs:
|- TypeError: Cannot read properties of undefined (reading 'Subject')
    at eval (//src/app/shared/snackbar/snackbar.service.ts:2:25)
    at async instantiateModule (file:////node_modules/vite/dist/node/chunks/dep-BcXSligG.js:53408:5)
```

Closes: #27907
2024-06-24 16:14:08 +02:00
Charles Lyding
39f946a848 build: enabled isolated modules TypeScript option
The TypeScript `isolatedModules` option is now enabled for all TypeScript
code within the repository. As a result, all packages will now be built
with the option enabled. This does not affect projects created with the CLI
and is only related to the building of the actual Angular CLI code.
The `isolatedModules` option ensures that code can be emitted without the
TypeScript typechecker and allows tools other than TypeScript to potentially
be used. Code was updated to correct all errors after the option was enabled.
Additionally, some early code fixes were done to add function and accessor
return types to prepare for future `isolatedDeclarations` usage. More changes
would be needed to consider turning on `isolatedDeclarations`, however.
2024-06-23 15:34:49 +02:00
Charles Lyding
1e8fd70c6f fix(@angular/build): show JavaScript cache store initialization warning
If the persistent cache store for the JavaScript transformations fails
to initialize, a warning will now be shown to better explain the outcome
and to allow the build to continue. The build will still complete without
the cache but may be slower to finish.
2024-06-21 11:44:36 -04:00
Charles Lyding
1a481c55ea refactor(@angular/build): support directly merging bundler results
The bundler context class now has a static helper method to support merging
bundler results outside of a specific bundle action. This will be used in the
future to support more complex bundling hierarchies.
2024-06-21 10:42:24 -04:00
Charles Lyding
db1a6ae55a refactor(@angular/build): move generic Angular tools into separate source directory
The Angular compiler code that is not specific to esbuild has been moved
into a separate `tools` subdirectory. This allows for potential reuse internal
reuse outside of the Angular esbuild plugin.
2024-06-21 16:27:31 +02:00
Charles Lyding
8b6ae4cf24 refactor(@angular/cli): allow tty and color helpers to use a stream
The `isTTY` and `supportColor` helpers can now accept a stream to check
instead of assuming stdout. This is useful if stderr needs to be checked,
for instance. Also, color checking now uses Node.js `hasColors` where
possible which has been available since Node.js v10.
2024-06-21 16:26:45 +02:00
Charles Lyding
438b530750 refactor(@angular/build): include Angular compiler plugin in private API
Add `createCompilerPlugin` function to the private export of the package.
Note that these are not considered part of the public API and
are intended for use only with the `@angular-devkit/build-angular` package.
2024-06-21 10:27:54 +02:00
Angular Robot
a442f8c3a3 build: update all non-major dependencies 2024-06-20 09:15:40 +02:00
Charles Lyding
18226c6f57 refactor(@angular/cli): remove ora spinner dependency from package
The ora package has been removed now that the progress indicator for the
update command is now based on the `listr2` package that is also used
by the `ng add` command.
2024-06-19 09:52:24 +02:00
Charles Lyding
4c96537378 refactor(@angular/cli): remove ora-based spinner from update command
The `listr2` dependency that was recently introduced to improve the console
UI for the `ng add` command is now used for the package installation step
of the `ng update` command process.
2024-06-19 09:52:24 +02:00