3109 Commits

Author SHA1 Message Date
Angular Robot
0c302365a5 build: update all non-major dependencies 2023-07-24 13:24:55 -04:00
Angular Robot
a0bf9462f5 build: update all non-major dependencies 2023-07-18 15:30:12 -07:00
Charles Lyding
6bfd1800ef perf(@angular-devkit/build-angular): use in-memory Sass module resolution cache
When using Sass files with module import references in the esbuild-based browser application
builder, the module resolution attempts will now be cached in memory. This caching is only
local to each entry Sass file currently. However, this may be expanded to encompass all Sass
entries within a build in the future. In addition to caching the entire resolution attempt,
individual package root resolution is also cached for deep import attempts. This is useful
for packages (such as `@material/*`) which deep import to multiple different files in the
same package.
With this change combined with the previous lexer change, package managers (pnpm & Yarn PnP)
that require workarounds for functioning resolution will now perform at an equivalent level
to other package managers.
2023-07-18 15:29:39 -07:00
Angular Robot
881b60c1a8 build: update all non-major dependencies 2023-07-17 10:14:43 -07:00
Charles Lyding
61a652d912 perf(@angular-devkit/build-angular): inject Sass import/use directive importer information when resolving
To correctly resolve a package based import reference in a Sass file with pnpm or Yarn PnP, the importer
file path must be known. Unfortunately, the Sass compiler does not provided the importer file to import plugins.
Previously to workaround this issue, all previously resolved stylesheets were tried as the importer path. This
allowed the stylesheets to be resolved but it also could cause a potentially large increase in build time due
to the amount of previous stylesheets that would need to be tried. To avoid the performance impact and to also
provide more accurate information regarding the importer file, a lexer is now used to extract import information
for a stylesheet and inject the importer file path into the specifier. This information is then extracted from the
import specifier during the Sass resolution process and allows the underlying package resolution access to a viable
location to resolve the package for all package managers. This information is currently limited to specifiers
referencing the `@angular` and `@material` package scopes but a comprehensive pre-resolution process may be added
in the future.
2023-07-14 19:03:06 -04:00
Sergey Gultyayev
5048f6e82e fix(@angular-devkit/build-angular): Set chunk names explicitly
Explicitly set chunk name pattern to exclude them from Jest run
2023-07-14 17:50:31 -04:00
Charles Lyding
5908ede3d6 fix(@angular-devkit/build-angular): correctly wrap CommonJS exported enums when optimizing
When optimizing a CommonJS exported enum, the build optimizer enum wrapping pass was previously
dropping the `exports` object assignment from the enum wrapper function call expression. This
would not occur with application code but is possible with library code that was built with
TypeScript and shipped as CommonJS.

Assuming the following TypeScript enum:
```
 export enum ChangeDetectionStrategy {
   OnPush = 0,
   Default = 1,
 }
```

TypeScript 5.1 will emit an exported enum for CommonJS as follows:
```
exports.ChangeDetectionStrategy = void 0;
var ChangeDetectionStrategy;
(function (ChangeDetectionStrategy) {
    ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
    ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default";
})(ChangeDetectionStrategy || (exports.ChangeDetectionStrategy = ChangeDetectionStrategy = {}));
```

The build optimizer would previously transform this into:
```
exports.ChangeDetectionStrategy = void 0;
var ChangeDetectionStrategy = /*#__PURE__*/ (() => {
  ChangeDetectionStrategy = ChangeDetectionStrategy || {};
  ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 5)] = "OnPush";
  ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 8)] = "Default";
  return ChangeDetectionStrategy;
})();
```
But this has a defect wherein the `exports` assignment is dropped. To rectify this situation, the build optimizer will now transform the code into:
```
exports.ChangeDetectionStrategy = void 0;
var ChangeDetectionStrategy = /*#__PURE__*/ (function (ChangeDetectionStrategy) {
  ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush";
  ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default";
  return ChangeDetectionStrategy;
})(ChangeDetectionStrategy || (exports.ChangeDetectionStrategy = ChangeDetectionStrategy = {}))
```
This retains the `exports` assignment.
2023-07-13 19:36:57 -04:00
Charles Lyding
953104ee17 refactor(@angular-devkit/build-angular): configure AOT compiler to skip NgModule scope metadata emit in esbuild
The esbuild plugin used within the esbuild-based browser application builder will now use the newly
introduced internal `supportJitMode` AOT compiler option to disable the emit of NgModule scope metadata
functions within the output code. This removes the need to perform an additional transformation of the
AOT compiler generated code to immediately remove the metadata. The Angular CLI neither previously nor currently
supports hybrid AOT/JIT mode. In the future if this support situation changes, additional behavior may
be added control the internal `supportJitMode` option.
2023-07-13 18:36:57 -04:00
Angular Robot
11ea13a9b8 build: update all non-major dependencies 2023-07-13 17:07:43 -04:00
Angular Robot
8a2a3703e8 build: update all non-major dependencies 2023-07-12 15:14:34 -04:00
Alan Agius
7defb3635c fix(@angular-devkit/build-angular): ensure that server dependencies are loaded also in ssr entrypoint
This commit ensure that server "polyfills" like `zone.js` and `@angular/compiler` are loaded as well when using the `ssr` option
2023-07-12 10:11:49 -04:00
Angular Robot
7e5da6ec81 build: update all non-major dependencies 2023-07-12 11:25:33 +02:00
Alan Agius
099cec758a feat(@angular-devkit/build-angular): add support for serving SSR with dev-server when using the application builder
This commit introduces experimental support for serving the application in SSR mode with the Vite based dev-server when using the application builder.
2023-07-11 08:05:55 -04:00
Alan Agius
bdee1ac556 refactor(@angular-devkit/build-angular): refactor prerendering code to aid code reusability
This commit refactors the prerending code and makes it more reusable. This is needed to implement SSR support in the dev-server.
2023-07-11 08:05:55 -04:00
Charles Lyding
304ec64892 refactor(@angular-devkit/build-angular): ensure TS resolution cache with file replacements
When overriding module resolution on a TypeScript Host object, TypeScript will not
automatically create a resolution cache for the Host. Within the application build system
the TypeScript resolution is only overrided if file replacements are used. A resolution
cache is now manually created and added to the TypeScript Host when file replacements are
present.
2023-07-11 08:05:08 -04:00
Alan Agius
e6b377436a feat(@angular-devkit/build-angular): add ssr option in application builder
This commit adds an `ssr` option to the application builder, this can be either a `boolean` or an `object` with an `entryPoint` property.

In the future, server bundles will only be emitted when the ssr option is truthy, as unlike SSR, SSG and AppShell do not require the server bundles to be written to disk.
2023-07-10 12:37:30 -04:00
Charles Lyding
a0a2c7aef6 perf(@angular-devkit/build-angular): only load browserslist in babel preset if needed
The `browserslist` package is only needed in the custom Babel application preset if
the `supportedBrowsers` option is specified. This option is not used within the esbuild-
based browser application builder. The `browserslist` is now lazily imported only when
needed and avoids the overhead of loading browser support data when not needed by the build.
2023-07-10 12:27:15 -04:00
Charles Lyding
974748cdf8 perf(@angular-devkit/build-angular): filter postcss usage based on content in esbuild builder
When using the esbuild-based browser application builder, stylesheets that do not need any
postcss processing will now skip the postcss step of the stylesheet build pipeline. Currently,
only Tailwind CSS leverages postcss and Tailwind CSS is an opt-in feature. As a result, postcss
will only be used if Tailwind CSS is configured for the project and a stylesheet contains one or
more of the directives/functions specific to Tailwind as provided by https://tailwindcss.com/docs/functions-and-directives.
This change should be most beneficial for component stylesheets which will rarely contain Tailwind
specific rules that need additional processing.
2023-07-10 12:24:16 -04:00
Alan Agius
eee0eff0e4 refactor: avoid loading babel-loader when running esbuild
This commit refactor the code to avoid loading babel-loader when not needed.
2023-07-10 09:54:57 -04:00
Alan Agius
ba7686283b build: update all non-major dependencies 2023-07-10 09:54:57 -04:00
Charles Lyding
2a4bb9f28b build: update prettier to v3.0.0 2023-07-07 11:15:49 -07:00
Alan Agius
cb165a75dc feat(@angular-devkit/build-angular): add pre-rendering (SSG) and App-shell support generation to application builder
This commit introduces experimental support to pre-render (SSG) and app-shell generation to the new application builder.

- `appShell`: option which can have a value of `true` or `false` has been added to support generating an app-shell.
- `prerender`: option which can have a value of `true`, `false` or an object with the below listed properties can be used to static render pages;
  - `routes`: Array of routes to render.
  - `discoverRoutes`: Whether the builder should statically discover routes.
  - `routesFile`: The path to a file containing routes separated by newlines.
2023-07-07 11:15:09 -07:00
Alan Agius
3bb48c1c88 refactor(@angular-devkit/build-angular): remove resourcesOutputPath option from application builder.
This `resourcesOutputPath` option is removed from the application builder. Instead the CSS resources will always be emitted in a directory named `media`. This is preparation to output server and browser bundles in different directories.
2023-07-06 09:36:02 -07:00
Charles Lyding
93b743af00 fix(@angular-devkit/build-angular): normalize paths in loader cache with esbuild
When using the esbuild-based application builder, some plugins may return watch file
lists that contain POSIX paths on Windows systems. This can cause the file watcher
to not correctly invalidate files that need to be processed during a rebuild. All
watch files are now normalized prior to being added to the in-memory cache to avoid
this problem.
2023-07-05 10:25:53 -07:00
Alan Agius
73c57997b6 refactor: move browser, server and utils code generation options into a single file.
This helps with code and logic readability.
2023-07-05 10:25:24 -07:00
Alan Agius
bdcbd40633 refactor: force ESM resolution of rxjs when in server bundles
Rxjs conditional export for node points to the CJS version. This commits adds a resolver to replace the resolved path to the ESM version.
2023-07-05 10:25:24 -07:00
Alan Agius
565179e458 refactor: remove usage of internal plugin browser option from esbuild plugins
This option is no longer needed as `autoprefixer` is no longer used in the esbuild pipeline following https://github.com/angular/angular-cli/pull/25457
2023-07-05 10:25:24 -07:00
Alan Agius
095f5aba60 feat(@angular-devkit/build-angular): add initial support for server bundle generation using esbuild
This commit adds initial support to generate the server bundle using esbuild as the underlying bundler.
2023-07-05 10:25:24 -07:00
Charles Lyding
333da08ea2 build: update webpack to v5.88.1 2023-06-30 20:07:47 +02:00
Charles Lyding
376e3462d3 fix(@angular-devkit/build-angular): use absolute watch paths for postcss dependency messages
Postcss's directory dependency message can use a glob pattern to reflect that multiple files
within a given directory should be watched. When calculated the complete file set, the paths
must be absolute to ensure that the watch system correctly invalidates the stylesheet being
processed.
2023-06-29 14:28:36 +02:00
Alan Agius
08ff43b887 build: update Angular peer dependencies to ^16.0.0 || ^16.2.0-next.0
This is needed to cut the `next` prerelease.
2023-06-28 15:25:43 +02:00
Angular Robot
305957d712 build: update dependency terser to v5.18.2 2023-06-28 12:07:21 +02:00
Charles Lyding
145a8e7c66 refactor(@angular-devkit/build-angular): use built-in CSS vendor prefixing in esbuild
As of esbuild v0.18.9, vendor prefixing of CSS is now supported. The esbuild target option
is generated from a project's browserslist and the vendor prefixing will reflect the configured
browsers for a project. This improvement allows for the removal of the postcss autoprefixer
plugin from the build pipeline. This can provide a performance benefit for projects especially
when project stylesheets contain nothing that would require prefixing since postcss processing can
potentially be skipped completely.
2023-06-27 17:57:09 +02:00
Charles Lyding
9c02306e6a refactor(@angular-devkit/build-angular): use built-in async generator downleveling in esbuild
As of esbuild v0.18.8, async generators can be downleveled when not supported. This improvement
allows for the removal of the babel plugins to perform the async generator downleveling that were
previously used. This can provide a performance benefit for cases of async generator usage in
application and third-party library code.
2023-06-27 13:16:14 +02:00
Charles Lyding
0580230b29 refactor(@angular-devkit/build-angular): configure AOT compiler to skip class metadata in esbuild
The esbuild plugin used within the esbuild-based browser application builder will not use the
newly introduced internal `supportTestBed` AOT compiler option to disable the emit of class
metadata functions within the output code. This removes the need to perform an additional
transformation of the AOT compiler generated code to immediately remove the class metadata.
The class metadata is only needed when using TestBed with AOT generated code but testing
infrastructure within the CLI only performs unit-testing in JIT mode. In the future event,
that AOT enabled unit-testing is supported, this compiler option can be enabled for test
related builds.
2023-06-27 13:14:56 +02:00
Alan Agius
3bc37e38e4 refactor: remove keepNames esbuild option for server builds
This option is no longer needed due to the changes done in the forked version of Domino.
2023-06-27 13:14:17 +02:00
Angular Robot
fdd1958941 build: update all non-major dependencies 2023-06-27 07:00:12 +02:00
Charles Lyding
4cf83eb2ce fix(@angular-devkit/build-angular): use all style language watch files in esbuild builder
A recent change to better support Tailwind CSS in watch mode unintentionally caused part
of the watch files list for stylesheets to be ignored when Tailwind and/or autoprefixer
were required to be executed. This resulted in rebuilds occurring but all stylesheet changes
were not fully propagated to the development server. This has now been corrected.
2023-06-26 18:16:14 +02:00
Charles Lyding
f42f10135c fix(@angular-devkit/build-angular): ensure preload hints for external stylesheets are marked as styles
When a preload hint is added for a stylesheet that is referenced via an `@import` that has an URL that
does not contain a file extension, an `as` attribute is now correctly added to the hint to ensure that
the stylesheet is loaded properly. This case can happen when a font service URL is imported within a
initial stylesheet.
2023-06-26 18:15:18 +02:00
Alan Agius
c05c83be7c feat(@angular-devkit/build-angular): add initial application builder implementation
This commits add the initial application builder schema and build configuration and refactors several files.
2023-06-23 15:36:06 -04:00
Angular Robot
4d87b7d1f7 build: update dependency semver to v7.5.2 [security] 2023-06-23 15:35:03 -04:00
Charles Lyding
ba3b4ceac8 refactor(@angular-devkit/build-angular): allow NG_BUILD_MANGLE variable with esbuild builder
The development `NG_BUILD_MANGLE` environment variable is now supported when using the
esbuild-based browser application builder. This environment variable is intended only
for Angular CLI development and test purposes.
2023-06-23 09:44:11 -04:00
Charles Lyding
a6c06c4d7c fix(@angular-devkit/build-angular): allow linker JIT support with prebundling with esbuild builder
When using prebundling with the Vite-based development server, the Angular linker will now
correctly emit JIT module scope information. This information is required in JIT mode for
NgModules to successfully be used in an application.
2023-06-23 08:21:35 -04:00
Alan Agius
f3f618f206 build: update critters to 0.19.0
Update critters to the latest version.

Closes #25388
2023-06-22 11:27:18 -04:00
Charles Lyding
5c6e3ec48d fix(@angular-devkit/build-angular): track postcss provided file dependencies in esbuild builder
Postcss plugins may provide result messages that contain stylesheet dependencies that should
be watched and should trigger a rebuild of the stylesheet being processed. These files will
now be linked to the stylesheet and will allow the provided file dependencies to be
watched and in-memory caches to be invalidated. Both the `dependency` and `dir-dependency`
postcss messages are supported.
2023-06-22 10:59:30 -04:00
Charles Lyding
518149d451 refactor(@angular-devkit/build-angular): use direct fs caching for font inlining
The `cacache` package was only minimally used within the font inlining post-build
processing. The usage has now been replaced with direct filesystem access and key
hashing to cache any font files. This not only lowers the overall dependency count
but also provides a small performance improvement by removing the need to resolve,
load, and evaluate additional JavaScript at build time.
2023-06-22 10:47:25 -04:00
Charles Lyding
e827c69234 fix(@angular-devkit/build-angular): watch all bundler provided inputs with esbuild builder
When using the esbuild-based browser application builder in watch mode (including `ng serve`),
all input files provided by the bundler via the internal metafile information will now be
watched and will trigger rebuilds if changed. This allows for files outside of the TypeScript
compilation that are also outside of the project source root to be watched. This situation
can be encountered in monorepo setups where library code is directly referenced within an application.
2023-06-22 10:42:32 -04:00
Paul Gschwendtner
9d9a668453 fix(@angular-devkit/build-angular): experimental esbuild pipeline, add es2015 to main fields for RxJS v6 compatibility
Currently, for RxJS v6, no conditions are available, and the ESBuild
pipeline will select the ES5 distribution based on the `module` main
field. This is fine in most cases, but applications could benefit from
better optimization with the use of the ES2015 output + there are
certain code differences that currently would cause runtime breakages
when e.g. `rxjs/testing` is used.

See: https://github.com/angular/angular-cli/issues/25405 for more details.

Fixes #25405.
2023-06-20 12:16:17 -04:00
Charles Lyding
02bf9f2b78 refactor(@angular-devkit/build-angular): remove unneeded static block workaround
esbuild 0.18.2 contains a fix that removes the need for the workaround of disabling
support for static class blocks.
Related issue: https://github.com/evanw/esbuild/issues/2950
2023-06-16 12:28:58 -04:00
Charles Lyding
de5c731a3c test: update autoprefixer behavior tests to not use metadata emit 2023-06-16 10:20:27 -04:00