2864 Commits

Author SHA1 Message Date
Charles Lyding
a9c6b449f6 fix(@angular-devkit/build-angular): normalize Vite dev-server Windows asset paths
When using the esbuild-based browser application builder with the Vite-based development
server on Windows, source asset paths were previously not normalized prior to being included
in request URLs. This could result in invalid asset request URLs due to invalid path
segment separators.
2023-05-15 12:49:28 +00:00
Angular Robot
419cc8282e build: update all non-major dependencies 2023-05-12 15:56:22 -04:00
Charles Lyding
d1f075e732 fix(@angular-devkit/build-angular): correctly generate serviceworker hashes for binary assets
When using the esbuild-based build system with the service worker enabled, binary assets were
unintentionally being hashed with the assumption of UTF-8 encoding. The assets are now hashed
directly to ensure correct output hashes.
2023-05-12 15:41:21 -04:00
Charles Lyding
d8930facc0 feat(@angular-devkit/build-angular): support incremental TypeScript semantic diagnostics in esbuild builder
When using the esbuild-based browser application builder with CLI caching enabled, TypeScript's `incremental`
option will also be enabled by default. A TypeScript build information file will be written after each build and
an attempt to load and use the file will be made during compilation setup. Caching is enabled by default within
the CLI and can be controlled via the `ng cache` command. This is the first use of persistent caching for the
esbuild-based builder. If the TypeScript `incremental` option is manually set to `false`, the build system will
not alter the value. This can be used to disable the behavior, if preferred, by setting the option to `false` in
the application's configured `tsconfig` file.
NOTE: The build information only contains information regarding the TypeScript compilation itself and does not
contain information about the Angular AOT compilation. TypeScript does not have knowledge of the AOT compiler
and it therefore cannot include that information in its build information file. Angular AOT analysis is still
performed for each build.
2023-05-12 11:33:51 -04:00
Charles Lyding
3ede1a2cac feat(@angular-devkit/build-angular): allow forcing esbuild builder with dev-server
To allow lower overhead trial of the developer preview of the esbuild-based builder system,
the development server now has an option to force the usage of the esbuild-based
build system while still retaining the default Webpack-based build system for the
`build` command. The `forceEsbuild`/`--force-esbuild` option can be added to the
`angular.json` options for the `serve` target or used on the command line, respectively.
The `browser-esbuild` builder will be used to build the application using the options
specified by the server configuration's `browserTarget` option. Unsupported build options
will be ignored. If using a third-party builder, a warning will be issued but the build
will still be attempted. Third-party builder usage in this context is considered
unsupported and may result in unexpected behavior or build failures.
2023-05-11 15:43:29 -04:00
Angular Robot
f6c1f088c9 build: update all non-major dependencies 2023-05-10 15:33:55 +00:00
Charles Lyding
1333a4e8c0 refactor(@angular-devkit/build-angular): emit affected files as a group in esbuild builder
The internal emit strategy for the TypeScript/Angular compiler has been adjusted to prefill
the memory cache during the initial phase of the build. Previously each file was emitted
during the bundling process as requested by the bundler. This change has no immediate effect
on the build process but enables future build performance improvements.
2023-05-10 11:20:43 +00:00
Charles Lyding
82bdc9e460 fix(@angular-devkit/build-angular): avoid CommonJS warnings for relative imports with esbuild builders
When using the esbuild-based browser application builder, CommonJS file warnings were incorrectly being
issued for relative file imports. The CommonJS warnings are only intended to be generated for node module
imports.
2023-05-09 15:52:38 +00:00
Charles Lyding
45e98a4f5b fix(@angular-devkit/build-angular): clean incoming index URL before processing in esbuild builder
When using the esbuild-based browser application builder with the development server, the incoming
URL for the index HTML may contain search parameters or other URL elements that can cause the index
HTML content to not be found or processed incorrected by the development server. These elements are
cleaned prior to comparison and the original URL is not longer passed to Vite to avoid unneeded
Vite specific processing of the content.
2023-05-09 14:05:20 +00:00
Charles Lyding
ca8e5087fb fix(@angular-devkit/build-angular): show error note for CSS url() tilde usage in esbuild builder
When using the esbuild-based browser application builder with a `url()` in a stylesheet that uses
that Webpack-specific tilde prefix, a note will be added to the resolution error providing additional
information regarding the removal of the tilde.
2023-05-09 14:00:33 +00:00
Angular Robot
c109fb6a16 build: update all non-major dependencies 2023-05-08 15:50:28 +00:00
Charles Lyding
892fcc6892 fix(@angular-devkit/build-angular): convert dev-server glob proxy entries for esbuild builder
When using the esbuild-based browser application builder with the development server, an
underlying Vite server is used. The Vite server currently does not support glob-based entries
for the proxy configuration. They must either be prefix strings or regular expressions. The
Webpack-based development server, however, does support globs. To remove the need to have
different proxy configuration files for the two servers, the entries will now be normalized
to regular expressions when using the Vite server. This allows existing proxy configurations
to work without modification.
2023-05-08 15:45:21 +00:00
Alan Agius
740610a902 Revert "fix(@angular-devkit/build-angular): set public class fields as properties (#24849)"
This reverts commit 04274afc15084ead2916e11055aa8f1d2f61951d.

Closes: #25161
2023-05-08 13:35:05 +00:00
Alan Agius
126b23edea fix(@angular-devkit/build-angular): disable runtime errors from being displayed in overlay
By default now webpack-dev-server adds runtime errors in an overlay. See: aab01b3c4e this commit disables this functionality.

Closes #25151
2023-05-08 13:34:49 +00:00
Angular Robot
0c3da6235a build: update angular 2023-05-08 13:07:27 +00:00
Leosvel Pérez Espinosa
e15100d597 fix(@angular-devkit/build-angular): fix index option const value for browser-esbuild 2023-05-08 13:06:48 +00:00
Charles Lyding
a68ef0bbb4 fix(@angular-devkit/build-angular): properly set base dev-server path with esbuild
When using the esbuild-based browser application builder with the development server,
the `baseHref` build option will now be properly propagated to the underlying Vite
server.
2023-05-08 13:06:01 +00:00
Charles Lyding
3aa1c4ec1a fix(@angular-devkit/build-angular): workaround for esbuild static block AOT generated code
esbuild currently has a defect involving self-referencing a class within a static code block or
static field initializer. This is not an issue for projects that use the default browserslist as these
elements are an ES2022 feature which is not support by all browsers in the default list. However, if a
custom browserslist is used that only has newer browsers than the static code elements may be present.
This issue is compounded by the default usage of the tsconfig `"useDefineForClassFields": false` option
present in generated CLI projects which causes static code blocks to be used instead of static fields.
esbuild currently unconditionally downlevels all static fields in top-level classes so to workaround the
Angular issue only static code blocks are disabled here.

Fixes #25127
2023-05-08 13:05:42 +00:00
Charles Lyding
57f0be7990 fix(@angular-devkit/build-angular): prevent relative import failure with Less in esbuild builder
When using the esbuild-based browser application builder, relative Less imports could cause
a fatal exception. This has now been corrected.
2023-05-04 20:26:54 +00:00
Charles Lyding
2a2817db74 fix(@angular-devkit/build-angular): avoid hash filenames for non-injected global styles/scripts
When using the esbuild-based browser application builder, non-injected global styles and scripts
were unintentionally being output with filenames that contain a hash. This can prevent the filenames
from being discoverable and therefore usable at runtime. The output filenames will now no longer
contain a hash component which matches the behavior of the Webpack-based builder.
2023-05-04 20:26:40 +00:00
Angular Robot
67e940635c build: update all non-major dependencies 2023-05-04 20:26:09 +00:00
Doug Parker
d160856958 refactor: widen peer dependencies to ^16.0.0 || ^16.1.0-next.0 2023-05-03 19:38:47 +00:00
Alan Agius
2fabeabf7f fix(@angular-devkit/build-angular): JIT support for standalone applications
This commit fixes and issue were standalone applications would fail during runtime because the `@angular/compiler` is not available.

We now add the `@angular/compiler` as part of the bundle when JIT mode is enabled.
2023-04-28 18:00:36 +00:00
Charles Lyding
3dd584a21d refactor(@angular-devkit/build-angular): update esbuild builder option status messages
The status of the esbuild-based browser application builder has been changed to developer
preview. Warning messages for unsupported options are now updated to reflect this change.
2023-04-28 17:51:39 +00:00
Angular Robot
17112a38a0 build: update all non-major dependencies 2023-04-28 07:33:11 +00:00
Alan Agius
4a38e8ab35 refactor(@angular-devkit/build-angular): exclude @angular/platform-server/init from unsafe optimizations in esbuild
While currently esbuild is not use to bundle server bundles, it will in the future. This commit adds a check for the `@angular/platform-server/init` entry-point to be excluded from advanced optimizations.
2023-04-27 14:44:27 +00:00
Alan Agius
bf4229da22 fix(@angular-devkit/build-angular): always enable looseEnums build optimizer rule
With this change TypeScript enums are always processing in "loose" mode. Previously, this was only done for `@angular/` packages.
2023-04-27 14:44:27 +00:00
Alan Agius
24a6501ec6 refactor: replace node with process.execPath
This is ensure that the same node executable is used to spawn Jest
2023-04-27 12:52:38 +00:00
Alan Agius
3ec88270ba perf(@angular-devkit/build-angular): do not inline sourcemap when using vite dev-server
Vite inlines the source map as part of content (ba62be40b4/packages/vite/src/node/server/send.ts (L59-L63)) with no option to disable this behaviour. While this is improves performances when Vite is used without prebundling. When using prebundling this is causes an overhead as the response can grow drastically, in some cases over 50mb.
2023-04-27 12:26:35 +00:00
Alan Agius
621d0885b6 fix(@angular-devkit/build-angular): exclude @angular/platform-server/init from unsafe optimizations
`@angular/platform-server/init` entry-point is side-effectful and thus it's not safe to perform advanced optimizations.
2023-04-27 12:26:14 +00:00
Angular Robot
ae54da2990 build: update all non-major dependencies 2023-04-27 10:07:18 +00:00
Angular Robot
367ddabed0 build: update dependency rxjs to v7.8.1 2023-04-27 10:01:39 +00:00
Doug Parker
210b613334 refactor: configure Zone.js for Jest tests
This configures polyfills to set up the environment before executing Jest tests. We need to do three things:
1. Set the global `jest` symbol. Jest executing in ESM does not provide the `jest` global and users are expected to import from `@jest/globals` or `import.meta.jest`. Zone.js is not compatible with this yet, so we need to manually define the `jest` global for Zone to read it.
2. Run user polyfills, (typically including `zone.js` and `zone.js/testing`). Zone reads the `jest` global to recognize the environment it is in and patch the relevant functions to load fake async properly. Users can override this part if they are building a Zoneless application or have custom polyfills for other browser functionality.
3. Initalize `TestBed`. This configures the `TestBed` environment so users don't have to manually configure it for each test file.

Ordering is very important for these operations, which complicates the implementation somewhat. `zone.js/testing` does not include an import on `zone.js`, meaning there was no guarnatee the bundler would sort their executions in the correct order. Similarly, `zone.js` does not import anything from Jest, so it is not trivial to inject the `globalThis.jest = import.meta.jest;` line before Zone loads. Even setting polyfills to `[jestGlobal, 'zone.js, 'zone.js/testing', initTestBed]` doesn't work because code splitting rearranges the order of operations in an incompatible way. Instead, these are implemented as distinct entry points in `browser-esbuild` with Jest's `--setupFilesAfterEnv` option executing them in the correct order.

Ideally, we could drop the global initialization altogether once Zone.js knows to look for `import.meta.jest` in an ESM context. Also we might be able to reduce down to a single polyfills entry point if `zone.js/testing` had an import on `zone.js` to apply correct ordering.
2023-04-26 22:41:47 +00:00
Doug Parker
97c0cf86f5 refactor: add Jest test execution to Jest builder
This runs Jest on the outputs of the built test files and reports the results of the test execution. It depends on `jest` and `jest-environment-jsdom` as optional peer deps validated in the builder, so there isn't a strict dependency on Jest for applications which don't use it.

Jest exports a `runJest()` function, however it can't be used directly because we need to opt-in to `--experimental-vm-modules` in ordre to run Jest on native ESM JavaScript as produced by `browser-esbuild`. This means we need a Node subprocess in order to add this flag, because the `ng` command cannot add a Node flag to its own current execution. This unfortunately means we can't just `import * as jest from 'jest';` or even `require.resolve('jest')` because that returns the library entry point exporting `runJest()`, rather than a script which actually runs Jest on load. Fortunately, Jest exports it's `node_modules/.bin/jest` entry point from its `package.json` under `jest/bin/jest`, so we `require.resolve()` _that_ to get the path to the correct file.

Executing Jest is fairly straightforward, running on the output of the `browser-esbuild` execution with outputs streamed to the console. We opted to use JSDom over Domino in order to align with the existing Jest ecosystem.
2023-04-26 22:41:47 +00:00
Doug Parker
7fe6570c27 refactor: add experimental jest builder
For now this just runs ESBuild-er to build test code, Jest is not actually invoked yet.

This uses `glob` to find test files matching the given pattern. I went out of my way to limit `glob` functionality as much as possible in case we change the implementation later.
2023-04-26 22:41:47 +00:00
Charles Lyding
2800e2f871 refactor(@angular-devkit/build-angular): separate change logic in esbuild dev-server
The change detection logic for the output files is now moved to a separate function
to reduce the code line count for the main dev-server function.
Also changed the setup function for the vite server to return the actual configuration
to allow for better reuse and testability.
2023-04-26 17:28:35 +00:00
Charles Lyding
90091757f9 refactor(@angular-devkit/build-angular): consolidate esbuild stylesheet files
The stylesheet related files for the esbuild-based browser application builder
have now been moved into a `stylesheets` directory to better organize the code.
2023-04-26 17:28:35 +00:00
Charles Lyding
b973b0fc06 refactor(@angular-devkit/build-angular): separate esbuild compiler plugin diagnostic utilities
The TypeScript diagnostic to esbuild diagnostic conversion utilities are now contained in a
separate file. This lowers the line count of the main compiler plugin file and also removes
an additional direct usage of the `typescript` dependency from the compiler plugin file.
2023-04-26 17:28:35 +00:00
Alan Agius
a416b4eff5 fix(@angular-devkit/build-angular): provide option to run build-optimizer on server bundles
This commit adds the option to run build-optimizer on the server bundles.

This is needed as in some cases, there can be restrictions on the size of
server bundles that can be executed. One of these cases is CloudFlare workers
 which by default does not work with an `ng-new` application due to the size of the
 bundle mainly due to the retention of the `@angular/compiler`.
2023-04-26 15:58:53 +00:00
Charles Lyding
e891786dcc fix(@angular-devkit/build-angular): avoid double sourcemap comments with esbuild dev-server
When using the esbuild-based browser application builder with the dev-server builder, sourcemap
URL comments were unintentionally doubled due to vite adding an additional inline sourcemap comment
when processing the JavaScript files for the application. To avoid this, JavaScript files now have
any sourcemap URL comments removed prior to being processed by vite. The sourcemap content is already
passed directly to vite and allows the sourcemaps to be processed and provided to the browser as needed
without the previously existing sourcemap URL comment. The removal is done without modifying the esbuild-
based builder's options to avoid assuming the builder used with the dev-server has sourcemap options that
allow hidden sourcemap generation.
2023-04-26 11:55:19 +00:00
Angular Robot
f3a27fa13e build: update dependency sass to v1.62.1 2023-04-26 11:53:50 +00:00
Charles Lyding
b0d04f77b3 fix(@angular-devkit/build-angular): add sourcemap x_google_ignoreList support for esbuild builder
When using the esbuild-based browser application builder with source maps enabled, the Chrome
DevTools `x_google_ignoreList` extension will be added to JavaScript source maps. This extension
supports an improved developer experience with Chrome DevTools. For more information, please see
https://developer.chrome.com/articles/x-google-ignore-list/
2023-04-26 05:21:26 +00:00
Alan Agius
b2a4f3569b fix(@angular-devkit/build-angular): update esbuild builder complete log
The complete log has been updated to match the RegExp in c045c99667/packages/schematics/angular/workspace/files/__dot__vscode/tasks.json.template (L18) as otherwise vscode debugged will not work correctly when using vscode launcher to launch the dev-server.
2023-04-25 15:21:26 +00:00
Alan Agius
603d24f966 fix(@schematics/angular): rename app.server.module.ts to app.module.server.ts
This fixes an issue were we generated files using inconsistent names example `app.server.module.ts` and `app.config.server.ts`.
2023-04-25 15:19:36 +00:00
Charles Lyding
480eb3eeff fix(@angular-devkit/build-angular): use preserveSymlinks option for tsconfigs in esbuild builder
When using the esbuild-based browser application builder, the tsconfig path will now be properly
converted to the realpath when the `preserveSymlinks` option is disabled (the default). This ensures
that TypeScript source files will be properly matched with the bundler's resolved paths when symlinks
are used and the `preserveSymlinks` option is not enabled. This is needed to properly support the use
of bazel with rules_js.
2023-04-25 15:19:20 +00:00
Angular Robot
7a7ad7fe85 build: update all non-major dependencies 2023-04-25 15:18:20 +00:00
Doug Parker
c045c99667 refactor: add outExtension to browser-esbuild as an internal option
The `outExtension` option allows users to generate `*.mjs` files, which is useful for forcing ESM execution in Node under certain use cases. The option is limited to `*.js` and `*.mjs` files to constrain it to expected values. `*.cjs` could theoretically be useful in some specific situations, but `browser-esbuild` does not support that output format anyways, so it is not included in the type.

I also updated `index.html` generation, which will correctly insert a `<script />` tag with the `*.mjs` extension. I opted to explicitly ban a "non-module" `*.mjs` file, since that would be very counterintuitive and I can't think of a valid use case for it.
2023-04-24 22:43:32 +00:00
Doug Parker
0d4a40fd6e refactor: make index option nullable for browser-esbuild
For testing use cases, we don't need an `index.html` file in the same capacity as a typical application. The builder already omits an `index.html` page when not set, this just updates the schema to reflect that.

The parameter could be left optional, rather than required but allowing `false`. However doing it this way prevents users from accidentally forgetting to provide an index while still allowing users to explicitly disable index generation. We use `false` instead of `null` so users can write `--no-index` on the command line and get the same behavior, which would not be possible with `null`.
2023-04-24 22:43:32 +00:00
Doug Parker
e22352ba09 refactor: add absolute entry point support to browser-esbuild
This allows `browser-esbuild` to consume absolute file paths and `entryPoints`. Absolute paths will always output in the root of the output directory with the same basename, since they are not within the workspace root and cannot exist at any guaranteed unique relative path. No attempt is made to check if the absolute path is actually within the workspace root, since this would require a call to `fs.realpath()` and make this logic dependent on the actual file system structure which introduces a lot of complexity we'd rather avoid.

Longer term, the ideal approach is probably to leverage virtual files in some capacity, but this should be sufficient for now.

`main` functionality is left alone, and absolute paths like `/main.ts` are treated as relative to the workspace root. This is to preserve existing functionality and discourage public API usage of file paths outside the workspace.
2023-04-24 22:43:32 +00:00
Doug Parker
71e87fc332 refactor: add entryPoints to browser-esbuild as an internal option
This makes the `main` parameter optional and allows multiple entry points instead. `main` is still technically required by the schema, since it should almost always be set when invoked by a user. However, it now supports `null` as a value so it can be explicitly omitted.

Longer term, we may choose to remove `main` and fold it into `entryPoints`, but for now we want to keep compatibility with the existing `browser` builder.

Since `entryPoints` is an internal-only options (cannot be set in `angular.json` and isn't exposed in the schema), I made a new `buildEsbuildBrowserInternal()` function which adds the extra private option. This way direct invocations of the builder can provide this extra information without compromising the public API surface defined in the schema.
2023-04-24 22:43:32 +00:00