3419 Commits

Author SHA1 Message Date
Charles Lyding
2d260eae7c refactor(@angular-devkit/build-angular): move bundler context setup into separate file
To reduce the amount of code within the main `application` builder execution function,
the bundler context setup has been moved into a separate file. This also reduces the
amount of imports within the main execution function's module.
2024-01-08 16:33:39 -08:00
Leosvel Pérez Espinosa
8d56365e7e fix(@angular-devkit/build-angular): fix normalization of the application builder extensions 2024-01-08 16:33:18 -08:00
Charles Lyding
481358618b fix(@angular-devkit/build-angular): show diagnostic messages after build stats
To improve the readability and discoverability of any warnings or errors present
during build, the diagnostic messages will be shown after the build stats are
displayed. For large projects the amount of generated files previously could cause
warnings to scroll off the screen and potentially be missed.
2024-01-05 10:47:50 +01:00
Angular Robot
2ead55d7db build: update all non-major dependencies 2024-01-05 10:38:14 +01:00
Doug Parker
4f53e0f4d8 refactor: remove process.cwd from Web Test Runner builder
Turns out this isn't needed for `application` builder to correctly resolve inputs. Not using `process.cwd` should make this builder a little less brittle for monorepo use cases or when running `ng test` inside a subdirectory.
2024-01-04 14:11:46 +01:00
Angular Robot
3451e9da7c build: update dependency @web/test-runner to ^0.18.0 2024-01-04 11:00:25 +01:00
Doug Parker
bdd4f2c5d8 refactor: log warnings for unsupported options in Web Test Runner
This helps notify users when they are attempting to use an option from Karma which hasn't been implemented yet.
2024-01-03 18:52:58 +01:00
Alan Agius
68dae539ad feat(@angular-devkit/build-angular): initial experimental implementation of @web/test-runner builder
This is a new `@angular-devkit/build-angular:web-test-runner` builder which invokes Web Test Runner to execute unit tests in a real browser.

The implementation calls `application` builder under the hood with some option overrides build the application to a temporary directory and then runs Web Test Runner on the output. This set up is still minimal, but sufficient to run and pass tests in the generated `ng new` application.

The `schema.json` file is directly copied from the `karma` builder, since this is intended to serve as a migration target for users coming from Karma. Most of the options don't actually work yet, which is logged when they are used.

The most interesting part of this change is configuring Jasmine to execute in Web Test Runner. This is done through the `testRunnerHtml` option which allows us to control the HTML page tests are executed on. We use `test_page.html` which very carefully controls the loading process. I opted to make a single `<script type="module">` which dynamic imports all the relevant pieces so the ordering can be directly controlled more easily. This is better than trying to manage multiple `<script>` tags and pass data between them. Ideally everything would be bundled into a single entry point, however this is not feasible due to the way that ordering requirements do not align with typical `import` structure. Jasmine must come before polyfills which must come before the runner which invokes user code. In an ideal world, this ordering relationship would be represented in `import` statements, but this is not practically feasible because Angular CLI doesn't own all the files (`./polyfills.js` is user-defined) and Jasmine's loading must be split into two places so Zone.js can properly patch it.

`jasmine_runner.js` serves the purpose of executing Jasmine tests and reporting their results to Web Test Runner. I tried to write `jasmine_runner.js` in TypeScript and compile it with a `ts_library`. Unfortunately I don't think this is feasible because it needs to import `@web/test-runner-core` at runtime. This dependency has some code generated at runtime in Web Test Runner, meaning we cannot bundle this dependency and must mark it as external and dynamic `import()` the package at runtime. This works fine in native ESM, but compiling with TypeScript outputs CommonJS code by default (and I don't believe our `@build_bazel_rules_nodejs` setup can easily change that), so any `import('@web/test-runner-core')` becomes `require('@web/test-runner-core')` which fails because that package is ESM-only. The `loadEsmModule` trick does work here either because Web Test Runner is applying Node module resolution at serve time, meaning it looks for `import('@web/test-runner-core')` and rewrites it to something like `import('/node_modules/@web/test-runner-core')`. In short, there is no easy syntax which circumvents the TypeScript compiler while also being statically analyzable to Web Test Runner.
2024-01-03 18:52:58 +01:00
Doug Parker
7a8bdee0f6 refactor: update application builder entry points to property treat bare strings as module specifiers
Previously an entry point `foo` would be incorrectly treated as a relative path, which meant it was not possible to use an NPM package as an entry point. This now requires `./foo` for relative paths while `foo` is treated as a module specifier referring to an NPM package called `foo`.
2024-01-03 18:52:58 +01:00
Doug Parker
bffaa773ca refactor: move findTestFiles to a common directory where it can be reused in multiple builders 2024-01-03 18:52:58 +01:00
Angular Robot
a6f3987341 build: update all non-major dependencies 2024-01-03 16:15:34 +01:00
Charles Lyding
5cffd3611b build: add function type annotation for bazel win32 build support
Due to the file structure of Bazel Windows builds, type annotations are
required in certain locations to successfully build the project. Function
return type annotations are generally recommended anyway within the code.
2024-01-03 09:46:56 +01:00
Alan Agius
10eebe9e69 build: update dependency browser-sync to v3
(cherry picked from commit 953780fdce795c9d65f54633f578470cf415858e)
2024-01-02 16:03:22 +01:00
Charles Lyding
c257e6e60e refactor(@angular-devkit/build-angular): support cache option with JavaScript transformer
The previously unused `reuseResults` option for the JavaScript transformer used by the
`application` builder has been removed and replaced with an optional cache option. This
option is currently unused by will allow the caching of JavaScript transformations including
the Angular linker.
2023-12-29 13:04:56 -05:00
Charles Lyding
8786daa2b1 refactor(@angular-devkit/build-angular): create reusable internal cache infrastructure
Several parts of application builder use slightly different variants of an in-memory
cache. To avoid duplication of code, unified cache infrastructure is now available for
use internally. This also allows for expanded use in other areas of the build system
including the future potential for adding additional backing cache stores.
2023-12-29 13:04:56 -05:00
Angular Robot
af43c3472a build: update all non-major dependencies 2023-12-29 12:39:11 +01:00
cexbrayat
bd26a18e7a fix(@angular-devkit/build-angular): typo in preloadInitial option description
The description had different types of quotes.
2023-12-27 12:56:01 -05:00
Alan Agius
116ee78613 refactor: remove unused code from CSS Lexer
This code is no longer used.
2023-12-27 15:05:51 +01:00
Alan Agius
a5f5561ba5 Revert "build: update dependency webpack-dev-middleware to v7"
This reverts commit 6741d2f8710416433a9276c9975f97c5ddb21cb9.
2023-12-27 09:01:22 -05:00
Angular Robot
6741d2f871 build: update dependency webpack-dev-middleware to v7 2023-12-27 09:03:25 +01:00
Alan Agius
49ed9a26cb fix(@angular-devkit/build-angular): emit error when using prerender and app-shell builders with application builder
The application builder has built-in prerendering and app-shell generation capabilities which makes using these builders redundant.
2023-12-26 10:19:00 -05:00
Angular Robot
db87e4f730 build: update all non-major dependencies 2023-12-26 10:16:04 -05:00
Charles Lyding
874e576b52 fix(@angular-devkit/build-angular): filter explicit external dependencies for Vite prebundling
To ensure that Vite does not unintentionally attempt to prebundle a module that was explicitly
marked as external (typically via the `externalDependencies` build option), the full list of
externalized imports is now filtered by the dependencies specified within the external configuration.
Vite currently will include a module for prebundling if it is present in the include list even though
it may also be present in the exclude list.
2023-12-22 08:17:57 +01:00
Angular Robot
1867a0a3cf build: update dependency mrmime to v2 2023-12-21 16:17:22 +01:00
Angular Robot
f167e5445b build: update all non-major dependencies 2023-12-20 19:31:19 +01:00
Alan Agius
47a064b146 feat(@angular-devkit/build-angular): emit external sourcemaps for component styles
This commits, changes the behaviour in the esbuild based builders by emitting component sourcemaps in external files instead of inlining them.

Closes #24049 and closes #26676
2023-12-20 19:30:12 +01:00
Alan Agius
ceffafe1a3 fix(@angular-devkit/build-angular): provide better error messages for failed file reads
This commit adds a more actionable error message when `readFile` fails during index generation.
2023-12-20 15:58:13 +01:00
Alan Agius
ce9bf81598 refactor(@angular-devkit/build-angular): remove no longer needed realpathSync
This is no longer needed since the path provided is already passed through `realpathSync`. 9d7d136b32/packages/angular_devkit/build_angular/src/builders/application/options.ts (L104-L109)
2023-12-19 19:25:46 +01:00
Charles Lyding
efe3bda483 fix(@angular-devkit/build-angular): ensure external dependencies are used by Web Worker bundling
When processing a Web Worker reference in application code, the Web Worker entry point is bundled
in a separate action. The external dependencies configuration was previously not passed on to this
action which caused the Web Worker bundling to attempt to bundle any configured external dependencies.
This could lead to build errors if the dependency does not exist within the project.
2023-12-19 12:47:58 -05:00
Charles Lyding
9d7d136b32 refactor(@angular-devkit/build-angular): pass full extensions to application builder for dev server
Experimental programmatically added build extensions are now passed to the internal application builder
when used with the development server. Previously, the plugins were not passed in a manner that would
allow them to be used if the `application` builder was selected as the builder for dev server usage.
2023-12-19 10:50:07 -05:00
Charles Lyding
d263cb2783 refactor(@angular-devkit/build-angular): use direct explicit external configuration for metadata
The metadata used by the development server to determine the prebundling and externalization behavior
is now created using the external configurations of each bundling operation context directly instead
of the higher level `externalDependencies` build option. This better captures the explicitly defined
external values as each bundling operation configuration could contain additional values based on
the needs and/or customization of each. This will have no current noticeable behavior change as the
default behavior currently does not differ from the higher level option.
2023-12-19 10:50:07 -05:00
Alan Agius
b3c1991a2e fix(@angular-devkit/build-angular): add missing tailwind @screen directive in matcher
`@screen` is not documented in tailwind documentation as it is not a recommanded option, however it still works and they don't have plans to remove it.

https://github.com/tailwindlabs/tailwindcss/discussions/7516

Closes #26709
2023-12-19 16:47:59 +01:00
Charles Lyding
7f2d162c0c refactor(@angular-devkit/build-angular): reduce promise creation during estimated transfer size calculation
The promise creation overhead when calculating the estimated transfer size of the output files during an
optimized build has been reduced by directly using the `brotliCompress` Node.js function instead of using
a promisified variant. Node.js Only provides a callback-based async variant for brotli compression. This
change allows for a single promise to be used.
2023-12-19 10:45:21 -05:00
Angular Robot
0457aa455a build: update all non-major dependencies 2023-12-18 14:10:56 -08:00
Charles Lyding
15a669c1ef feat(@angular-devkit/build-angular): allowing control of index HTML initial preload generation
The long-form variant of the `index` option for the `application` builder now supports
an addition sub-option named `preloadInitial`. This new option is a boolean option that controls
the generation of initial preload related link elements in the generated index HTML file
for the application. Preload related link elements include `preload`, `modulepreload`,
and `preconnect` link rels for initial JavaScript and stylesheet application files.
2023-12-18 07:34:38 -05:00
Angular Robot
1b6e9c34f3 build: update all non-major dependencies 2023-12-15 11:17:52 +01:00
Alan Agius
cc246d50ea feat(@angular-devkit/build-angular): allow customization of output locations
This update introduces the ability for users to define the locations for storing `media`, `browser`, and `server` files.

You can achieve this by utilizing the extended `outputPath` option.
```json
{
  "projects": {
    "my-app": {
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "outputPath": {
              "base": "dist/my-app",
              "browser": "",
              "server": "node-server",
              "media": "resources"
            }
          }
        }
      }
    }
  }
}
```

While not recommended, choosing to set the `browser` option empty will result in files being output directly under the specified `base` path. It's important to note that this action will generate certain files like `stats.json` and `prerendered-routes.json` that aren't intended for deployment in this directory.

**Validation rules:**
- `browser` and `server` are relative to the configuration set in the `base` option.
- When SSR is enabled, `browser` cannot be set to an empty string, and cannot be the same as `server`.
- `media` is relative to the value specified in the `browser` option.
- `media` cannot be set to an empty string.
- `browser`, `media`, or `server` cannot contain slashes.

Closes: #26632 and closes: #26057
2023-12-14 23:50:17 +01:00
Charles Lyding
66edac4bbd refactor(@angular-devkit/build-angular): add index HTML transformer to application programmatic usage
Similar to the `dev-server` builder, the `application` builder's programmatic usage can now transform
the index HTML that is generated during a build. As is the case for the existing builder JavaScript
exports from the package, the new export (`buildApplication`) is also considered experimental and does
not provide the support nor semver guarantees that the builders have when used via `angular.json` configuration.

The third parameter of the `buildApplication` function can now be an extensions object with one of the fields
being `indexHtmlTransformer`. This newly introduced field allows adjusting the index HTML content.

Closes #26299
2023-12-14 12:01:46 +01:00
Alan Agius
a5d4735b80 fix(@angular-devkit/build-angular): construct SSR request URL using server resolvedUrls
With vite `header.host` is undefined when SSL is enabled. This resulted in an invalid URL to be constructed.

Closes #26652
2023-12-13 20:14:37 +01:00
Angular Robot
7f86757a5b build: update all non-major dependencies 2023-12-13 19:53:14 +01:00
Charles Lyding
0fa1e3419f fix(@angular-devkit/build-angular): ensure empty optimized Sass stylesheets stay empty
When an optimized Sass stylesheet becomes an empty string the AOT Angular host adapter
was previously treating this as a falsy value and using the original content of the
stylesheet. Empty strings are now considered valid values and will be passed to the
AOT compiler as such.
2023-12-13 18:16:25 +01:00
Marco Steinhoff
e9a51a37f6 refactor(@angular-devkit/build-angular): unify proxy config loading in dev-server and ssr-dev-server
This improvement harmonizes the proxy configuration loading mechanisms between the dev-server and ssr-dev-server. Previously, these servers used different methods for loading the proxy configuration, leading to inconsistencies. Notably, the ssr-dev-server was limited to loading configurations only in JSON format. This change enables the ssr-dev-server to support various configuration formats, aligning it with the dev-server's capabilities and improving overall developer experience.
2023-12-13 17:43:53 +01:00
Alan Agius
4a63d1f4a7 Revert "build: update dependency vite to v5.0.8"
This reverts commit 7eb412c4f2f2fb60471cdadad627788f277f09fa as it causes CI to hang when used with 18.13 tests/legacy-cli/e2e/tests/basic/serve.ts
2023-12-13 14:22:03 +01:00
Angular Robot
8df2043216 build: update dependency piscina to v4.2.1 2023-12-13 10:44:24 +01:00
Alan Agius
0f253a1fc6 fix(@angular-devkit/build-angular): file is missing from the TypeScript compilation with JIT
Before this update, removing the modified file entry from `typeScriptFileCache` when a file was saved but unmodified created an issue. The TypeScript compiler didn't re-emit the file using `emitNextAffectedFile` because the file hashes remained unchanged. Consequently, this led to missing files in the esbuild compilation process.

In the current update, we no longer delete entries from typeScriptFileCache. This adjustment resolves the problem by ensuring the proper handling of file recompilation and prevents files from going missing during the esbuild compilation.

Closes #26635
2023-12-12 18:37:40 +01:00
Alan Agius
7a50df5c04 fix(@angular-devkit/build-angular): update ESM loader to work with Node.js 18.19.0
In Node.js 18.19 ESM loaders works the same way as Node.js 20.9+

Closes #26648
2023-12-12 18:10:36 +01:00
Alan Agius
72bd0ab9d0 fix(@angular-devkit/build-angular): allow vite to serve JavaScript and TypeScript assets
This commit fixes an issue which caused vite to transform JavaScript and TypeScript assets.

Closes #26641
2023-12-12 17:43:29 +01:00
Angular Robot
7eb412c4f2 build: update dependency vite to v5.0.8 2023-12-12 11:46:59 +01:00
Angular Robot
11d61223ae build: update all non-major dependencies 2023-12-12 10:10:39 +01:00
Charles Lyding
12f4433afb fix(@angular-devkit/build-angular): cache loading of component resources in JIT mode
The load result caching capabilities of the Angular compiler plugin used within the
`application` and `browser-esbuild` builders is now used for both stylesheet and
template component resources when building in JIT mode. This limits the amount of
file system access required during a rebuild in JIT mode and also more accurately
captures the full set of watched files.
2023-12-12 09:42:02 +01:00