Skip to content

Commit db2fc68

Browse files
committed
feat: migrate to @angular/build
- Update custom-esbuild to use @angular/build instead of @angular-devkit/build-angular for better performance - Update import paths to use @angular/build/private for internal APIs - Update dev-server builder context patching to use @angular/build:application - Update schema references to use @angular/build builders - Update README documentation for Angular 20 and @angular/build - Add TypeScript import fixes for better ESM support - Improve Jest examples with better Cypress config and TypeScript usage - Update common module loading logic for better CommonJS/ESM compatibility - Fix e2e tsconfig references to use correct parent tsconfig files This migration provides better performance and aligns with Angular's new build system architecture.
1 parent 2c114d9 commit db2fc68

File tree

16 files changed

+50
-29
lines changed

16 files changed

+50
-29
lines changed

examples/custom-webpack/full-cycle-app/e2e/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../tsconfig.base.json",
2+
"extends": "../tsconfig.json",
33
"include": ["**/*.ts"],
44
"compilerOptions": {
55
"sourceMap": false,

examples/jest/multiple-apps/projects/my-first-app/e2e/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.json",
33
"include": ["**/*.ts"],
44
"compilerOptions": {
55
"sourceMap": false,

examples/jest/multiple-apps/projects/my-second-app/e2e/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.base.json",
2+
"extends": "../../../tsconfig.json",
33
"include": ["**/*.ts"],
44
"compilerOptions": {
55
"sourceMap": false,

examples/jest/simple-app/src/app/link/link.component.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ describe('LinkComponent', () => {
1616
fixture.detectChanges();
1717
});
1818

19-
it('should create', () => {
20-
expect(component).toBeTruthy();
21-
});
22-
2319
it('should create 3 links', () => {
2420
expect(fixture.debugElement.nativeElement.querySelectorAll('a').length).toEqual(3);
2521
});

packages/common/src/load-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export async function loadModule<T>(
107107
// The file could be either CommonJS or ESM.
108108
// CommonJS is tried first then ESM if loading fails.
109109
try {
110-
return require(modulePath);
110+
return require(modulePath).default || require(modulePath);
111111
} catch (e: any) {
112112
if (e.code === 'ERR_REQUIRE_ESM') {
113113
// Load the ESM configuration file using the TypeScript dynamic import workaround.

packages/custom-esbuild/README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ Allow customizing ESBuild configuration
2424
<details>
2525
<summary>Click to expand</summary>
2626

27+
- [Version 19](https://github.com/just-jeb/angular-builders/blob/19.x.x/packages/custom-esbuild/README.md)
28+
- [Version 18](https://github.com/just-jeb/angular-builders/blob/18.x.x/packages/custom-esbuild/README.md)
2729
- [Version 17](https://github.com/just-jeb/angular-builders/blob/17.x.x/packages/custom-esbuild/README.md)
2830

2931
</details>
3032

3133
## Prerequisites:
3234

33-
- [Angular CLI 18](https://www.npmjs.com/package/@angular/cli)
35+
- [Angular CLI 20](https://www.npmjs.com/package/@angular/cli)
3436

3537
# Usage
3638

@@ -118,7 +120,7 @@ Builder options:
118120
119121
In the above example, we specify the list of `plugins` that should implement the ESBuild plugin schema. These plugins are custom user plugins and are added to the original ESBuild Angular configuration. Additionally, the `indexHtmlTransformer` property is used to specify the path to the file that exports the function used to modify the `index.html`.
120122
121-
The plugin file can export either a single plugin or a list of plugins. If a plugin accepts configuration then the config should be provided in `angular.json`:
123+
The plugin file can export either a single plugin, a list of plugins or a factory function that returns a plugin or list of plugins. If a plugin accepts configuration then the config should be provided in `angular.json`:
122124
123125
```ts
124126
// esbuild/plugins.ts
@@ -143,13 +145,13 @@ import type { Plugin, PluginBuild } from 'esbuild';
143145

144146
function defineEnv(pluginOptions: { stage: string }): Plugin {
145147
return {
146-
name: 'define-env',
148+
name: 'define-env',
147149
setup(build: PluginBuild) {
148150
const buildOptions = build.initialOptions;
149151
buildOptions.define.stage = JSON.stringify(pluginOptions.stage);
150152
},
151153
};
152-
};
154+
}
153155

154156
export default defineEnv;
155157
```
@@ -180,6 +182,25 @@ const updateExternalPlugin: Plugin = {
180182
export default [defineTextPlugin, updateExternalPlugin];
181183
```
182184
185+
Or:
186+
187+
```ts
188+
// esbuild/plugins.ts
189+
import type { Plugin, PluginBuild } from 'esbuild';
190+
import type { ApplicationBuilderOptions } from '@angular-devkit/build-angular';
191+
import type { Target } from '@angular-devkit/architect';
192+
193+
export default (builderOptions: ApplicationBuilderOptions, target: Target): Plugin => {
194+
return {
195+
name: 'define-text',
196+
setup(build: PluginBuild) {
197+
const options = build.initialOptions;
198+
options.define.currentProject = JSON.stringify(target.project);
199+
},
200+
};
201+
};
202+
```
203+
183204
## Custom ESBuild `dev-server`
184205
185206
The `@angular-builders/custom-esbuild:dev-server` is an enhanced version of the `@angular-devkit/build-angular:dev-server` builder that allows the specification of `middlewares` (Vite's `Connect` functions). It also obtains `plugins` and `indexHtmlTransformer` from the `:application` configuration to run the Vite server with all the necessary configuration applied.
@@ -239,7 +260,7 @@ It is useful when you want to transform your `index.html` according to the build
239260
`index-html-transformer.js`:
240261
241262
```js
242-
module.exports = (indexHtml) => {
263+
module.exports = indexHtml => {
243264
const i = indexHtml.indexOf('</body>');
244265
const content = `<p>Dynamically inserted content</p>`;
245266
return `${indexHtml.slice(0, i)}

packages/custom-esbuild/e2e/custom-esbuild-schema.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ describe('Custom ESBuild schema tests', () => {
1010
customEsbuildDevServerSchema = require('../dist/dev-server/schema.json');
1111
});
1212

13-
it('should fit the schema of the `@angular-devkit/build-angular:application`', () => {
13+
it('should fit the schema of the `@angular/build:application`', () => {
1414
const path = resolvePackagePath('@angular/build', 'src/builders/application/schema.json');
1515
const originalApplicationSchema = require(path);
1616
customEsbuildApplicationSchema.properties['plugins'] = undefined;
1717
customEsbuildApplicationSchema.properties['indexHtmlTransformer'] = undefined;
1818
expect(originalApplicationSchema.properties).toEqual(customEsbuildApplicationSchema.properties);
1919
});
2020

21-
it('should fit the schema of the `@angular-devkit/build-angular:dev-server`', () => {
22-
const originalDevServerSchema = require('@angular-devkit/build-angular/src/builders/dev-server/schema.json');
21+
it('should fit the schema of the `@angular/build:dev-server`', () => {
22+
const path = resolvePackagePath('@angular/build', 'src/builders/dev-server/schema.json');
23+
const originalDevServerSchema = require(path);
2324
customEsbuildDevServerSchema.properties['middlewares'] = undefined;
2425
expect(originalDevServerSchema.properties).toEqual(customEsbuildDevServerSchema.properties);
2526
});

packages/custom-esbuild/src/custom-esbuild-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApplicationBuilderOptions, DevServerBuilderOptions } from '@angular-devkit/build-angular';
1+
import { ApplicationBuilderOptions, DevServerBuilderOptions } from '@angular/build';
22

33
export type PluginConfig = string | { path: string; options?: Record<string, unknown> };
44

packages/custom-esbuild/src/dev-server/patch-builder-context.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { BuilderContext, Target } from '@angular-devkit/architect';
22

33
const executorToBuilderMap = new Map<string, string>([
4-
['@angular-builders/custom-esbuild', '@angular-devkit/build-angular:application'],
5-
['@angular-builders/custom-esbuild:application', '@angular-devkit/build-angular:application'],
4+
['@angular-builders/custom-esbuild', '@angular/build:application'],
5+
['@angular-builders/custom-esbuild:application', '@angular/build:application'],
66
]);
77

88
function cleanBuildTargetOptions(options: any) {
@@ -15,9 +15,9 @@ export function patchBuilderContext(context: BuilderContext, buildTarget: Target
1515
const originalGetBuilderNameForTarget = context.getBuilderNameForTarget;
1616

1717
// We have to patch `getBuilderNameForTarget` because Angular CLI checks
18-
// whether the runnable target is `@angular-devkit/build-angular:application`
18+
// whether the runnable target is `@angular/build:application`
1919
// and then defines the server to run. If the `builderName` (returned by
20-
// `context.getBuilderNameForTarget`) is not an `@angular-devkit/build-angular:application`,
20+
// `context.getBuilderNameForTarget`) is not an `@angular/build:application`,
2121
// then it will use the Webpack server for the `dev-server target`. By patching
2222
// the return value, Angular will use the Vite server for the `dev-server` target.
2323
context.getBuilderNameForTarget = async target => {

packages/custom-esbuild/src/load-index-html-transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { loadModule } from '@angular-builders/common';
22
import { logging } from '@angular-devkit/core';
33
import { Target } from '@angular-devkit/architect';
4-
import type { IndexHtmlTransform } from '@angular/build/src/utils/index-file/index-html-generator';
4+
import type { IndexHtmlTransform } from '@angular/build/private';
55

66
export async function loadIndexHtmlTransformer(
77
indexHtmlTransformerPath: string,

0 commit comments

Comments
 (0)