3627 Commits

Author SHA1 Message Date
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
Doug Parker
2d0943d73b refactor: loosen experimental warnings types
As is, the `browser` and `browser-esbuild` schemas needed to be identical to check for unsupported properties. This loosens it slightly by casting the `browser-esbuild` schema into the `browser` schema and looking for invalid properties. This makes the module more flexible as the `browser-esbuild` schema evolves _and_ more closely aligns with the actual mistake of users who incorrectly think of `browser-esbuild` as supporting all the options of `browser`, which it does not yet do so.
2023-04-24 22:43:32 +00:00
Alan Agius
688bb2db7b fix(@angular-devkit/build-angular): display warning when preserveWhitespaces is set in the tsconfig provided to the server builder
This commits add a check to display a warning when `preserveWhitespaces` is configured in `tsconfig.server.json`, as potentially this could cause issue with hydration.
2023-04-19 22:28:09 +00:00
Angular Robot
bda7e68848 build: update all non-major dependencies 2023-04-19 14:45:55 +00:00
Charles Lyding
694b1ead0d fix(@angular-devkit/build-angular): correctly filter lazy global styles in esbuild builder
Due to a typo in a conditional for the filtering of lazily defined global styles, global
styles were unintentionally always initial if no global scripts were present in the
application.
2023-04-19 14:42:49 +00:00
Charles Lyding
1f34e449eb refactor(@angular-devkit/build-angular): use helper to bundle all elements of esbuild builder
The code to execute the individual bundling elements of the esbuild-based browser application
builder has been consolidated within a bundler context helper method. This moves the execution
and result merging code into a single location and allows for more flexibility to control which
elements should be executed per build. The global styles and global scripts bundling is now fully
skipped if the options are not present in the build configuration.
2023-04-19 13:59:31 +00:00
Alan Agius
758b0695f3 fix(@angular-devkit/build-angular): update list of known tailwind configuration files
With this change we added `tailwind.config.mjs` and `tailwind.config.ts` to known tailwind config files.

Closes #24943
2023-04-18 16:28:00 +00:00
Charles Lyding
d5fed32096 refactor(@angular-devkit/build-angular): move TS/NG configuration reading into compiler classes
The TypeScript and Angular configuration reading (`tsconfig.json`) has now been moved into the
Angular compilation classes (AOT/JIT) directly. This removes compilation specific functionality
from the esbuild plugin and allows the plugin to focus primarily on integration with esbuild.
2023-04-18 10:56:36 +00:00
Angular Robot
8c4a84dc63 build: update all non-major dependencies 2023-04-17 19:39:13 +00:00
Charles Lyding
0c94254ad0 fix(@angular-devkit/build-angular): fully remove third-party sourcemaps when disabled in esbuild builder
When using the esbuild-based browser application builder, third-party sourcemaps will now be fully removed
when the `sourcemap` option's `vendor` sub-option is disabled. The `vendor` sub-option is disabled by default
and is only enabled if explicitly enabled within the project's configuration. Sourcemaps are considered
third-party if their referencing code is contained within a `node_modules` directory.
Previously, sourcemap URL comments may have been unintentionally left intact when processing third-party code
via the Babel-based JavaScript transformer. These sourcemap URL comments are now removed correctly when
code is both transformed and return directly when no transformation is required.
2023-04-14 21:53:47 +00:00
Charles Lyding
571f8947ce fix(@angular-devkit/build-angular): correctly show initial files in stat table with esbuild builder
When using the esbuild-based browser application builder, only actual initial files will be displayed
in the initial files section. Previously, certain dynamically imported files could unintentionally be
displayed in the stats output table as initial files. This was a display only error and had no effect
on the files added to the index HTML file.
2023-04-14 21:53:17 +00:00
Doug Parker
f50234f72c Revert "ci: bump Angular dependencies to 16.0.0-rc.0"
This reverts commit 290e06018d3934cf27a5734a60947dcd7b45fa58.

Release checks don't like being in an RC state and it's not strictly necessary since installing a `-next` package will install `-rc` because it alphabetically follows. This means generating applications with `-next` in the `package.json` will still pull the latest RC releases of Angular packages.
2023-04-13 16:54:22 +00:00
Charles Lyding
1e78cf99c1 perf(@angular-devkit/build-angular): cache Sass in memory with esbuild watch mode
To improve rebuild performance when using Sass stylesheets with the esbuild-based
browser application builder in watch mode, Sass stylesheets that are not affected
by any file changes will now be cached and directly reused. This avoids performing
potentially expensive Sass preprocessing on stylesheets that will not change within
a rebuild.
2023-04-13 16:14:22 +00:00
Doug Parker
290e06018d ci: bump Angular dependencies to 16.0.0-rc.0 2023-04-12 20:30:02 +00:00
Angular Robot
083ab8067c build: update all non-major dependencies 2023-04-12 20:00:35 +00:00
Charles Lyding
4d8d489aae fix(@angular-devkit/build-angular): normalize long-form asset option output to relative path
The output option for the long-form of the assets build option should be a relative path based
from the output path of the application. However, a rooted path was also considered relative
to the output path. To avoid two different ways of representing the path throughout the build
system. The output path is now normalized to a relative path at the beginning of the build
process.
2023-04-12 17:35:11 +00:00