Skip to content

Commit a839ac2

Browse files
committed
feat(angular): support optional project option in ng-packagr executors and new builders (#31108)
- Update `project` option in `ng-packagr` executors to be optional - Update a few places to support new builders from the `@angular/build` package - Update e2e tests to reflect changes
1 parent b048d79 commit a839ac2

File tree

20 files changed

+70
-44
lines changed

20 files changed

+70
-44
lines changed

docs/generated/packages/angular/executors/ng-packagr-lite.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
"description": "Enable and define the file watching poll time period in milliseconds."
3838
}
3939
},
40-
"additionalProperties": false,
41-
"required": ["project"]
40+
"additionalProperties": false
4241
},
4342
"description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but it only produces ESM2022 bundles.",
4443
"aliases": [],

docs/generated/packages/angular/executors/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
"description": "Enable and define the file watching poll time period in milliseconds."
4040
}
4141
},
42-
"additionalProperties": false,
43-
"required": [
44-
"project"
45-
]
42+
"additionalProperties": false
4643
},
4744
"description": "Builds and packages an Angular library producing an output following the Angular Package Format (APF) to be distributed as an NPM package.\n\nThis executor is a drop-in replacement for the `@angular-devkit/build-angular:ng-packagr` and `@angular/build:ng-packagr` builders, with additional support for incremental builds.",
4845
"aliases": [],

e2e/angular/src/ng-add.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
115115
'.prettierrc',
116116
`apps/${project}/src/main.ts`,
117117
`apps/${project}/src/app/app.config.ts`,
118-
`apps/${project}/src/app/app.component.ts`,
118+
`apps/${project}/src/app/app.ts`,
119119
`apps/${project}/src/app/app.routes.ts`
120120
);
121121

@@ -178,9 +178,8 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
178178
const projectConfig = readJson(`apps/${project}/project.json`);
179179
expect(projectConfig.sourceRoot).toEqual(`apps/${project}/src`);
180180
expect(projectConfig.targets.build).toStrictEqual({
181-
executor: '@angular-devkit/build-angular:application',
181+
executor: '@angular/build:application',
182182
options: {
183-
outputPath: `dist/apps/${project}`,
184183
index: `apps/${project}/src/index.html`,
185184
browser: `apps/${project}/src/main.ts`,
186185
polyfills: [`zone.js`],
@@ -214,15 +213,15 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
214213
defaultConfiguration: 'production',
215214
});
216215
expect(projectConfig.targets.serve).toEqual({
217-
executor: '@angular-devkit/build-angular:dev-server',
216+
executor: '@angular/build:dev-server',
218217
configurations: {
219218
production: { buildTarget: `${project}:build:production` },
220219
development: { buildTarget: `${project}:build:development` },
221220
},
222221
defaultConfiguration: 'development',
223222
});
224223
expect(projectConfig.targets.test).toStrictEqual({
225-
executor: '@angular-devkit/build-angular:karma',
224+
executor: '@angular/build:karma',
226225
options: {
227226
polyfills: [`zone.js`, `zone.js/testing`],
228227
tsConfig: `apps/${project}/tsconfig.spec.json`,
@@ -249,7 +248,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
249248
});
250249

251250
runCLI(`build ${project} --configuration production --outputHashing none`);
252-
checkFilesExist(`dist/apps/${project}/browser/main.js`);
251+
checkFilesExist(`dist/${project}/browser/main.js`);
253252
});
254253

255254
it('should handle a workspace with cypress v9', () => {
@@ -436,7 +435,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
436435
expect(output).toContain(
437436
`Successfully ran target build for project ${project}`
438437
);
439-
checkFilesExist(`dist/apps/${project}/browser/main.js`);
438+
checkFilesExist(`dist/${project}/browser/main.js`);
440439

441440
output = runCLI(`build ${project} --outputHashing none`);
442441
expect(output).toContain(
@@ -454,7 +453,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
454453
expect(output).toContain(
455454
`Successfully ran target build for project ${app1}`
456455
);
457-
checkFilesExist(`dist/apps/${app1}/browser/main.js`);
456+
checkFilesExist(`dist/${app1}/browser/main.js`);
458457

459458
output = runCLI(`build ${app1} --outputHashing none`);
460459
expect(output).toContain(

e2e/nx-init/src/nx-init-angular.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('nx init (Angular CLI - legacy)', () => {
8585
expect(coldBuildOutput).toContain(
8686
`Successfully ran target build for project ${project}`
8787
);
88-
checkFilesExist(`dist/apps/${project}/browser/main.js`);
88+
checkFilesExist(`dist/${project}/browser/main.js`);
8989

9090
// run build again to check is coming from cache
9191
const cachedBuildOutput = runCLI(`build ${project} --outputHashing none`);

e2e/release/src/release-publishable-libraries.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ describe('release publishable libraries', () => {
230230
XXX.XXX kb fesm2022/proj-{project-name}.mjs
231231
XXX.XXX kb fesm2022/proj-{project-name}.mjs.map
232232
XXB index.d.ts
233-
XXB lib/{project-name}/{project-name}.component.d.ts
234233
XXXB package.json
235234
=== Tarball Details ===
236235
name: @proj/{project-name}

packages/angular/src/builders/dev-server/dev-server.impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export function executeDevServerBuilder(
153153

154154
const delegateBuilderOptions = getDelegateBuilderOptions(options);
155155
const isUsingWebpackBuilder = ![
156+
'@angular/build:application',
156157
'@angular-devkit/build-angular:application',
157158
'@angular-devkit/build-angular:browser-esbuild',
158159
'@nx/angular:application',

packages/angular/src/executors/extract-i18n/extract-i18n.impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default async function* extractI18nExecutor(
1717
buildTargetProjectConfiguration.targets[parsedBuildTarget.target];
1818

1919
const isUsingEsbuildBuilder = [
20+
'@angular/build:application',
2021
'@angular-devkit/build-angular:application',
2122
'@angular-devkit/build-angular:browser-esbuild',
2223
'@nx/angular:application',

packages/angular/src/executors/ng-packagr-lite/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@
3434
"description": "Enable and define the file watching poll time period in milliseconds."
3535
}
3636
},
37-
"additionalProperties": false,
38-
"required": ["project"]
37+
"additionalProperties": false
3938
}

packages/angular/src/executors/package/package.impl.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export function createLibraryExecutor(
5555
options: BuildAngularLibraryExecutorOptions,
5656
context: ExecutorContext
5757
) {
58+
options.project ??= join(
59+
context.projectsConfigurations.projects[context.projectName].root,
60+
'ng-package.json'
61+
);
62+
5863
const { dependencies } = calculateProjectBuildableDependencies(
5964
context.taskGraph,
6065
context.projectGraph,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { NgPackagrBuilderOptions } from '@angular-devkit/build-angular';
22

33
export interface BuildAngularLibraryExecutorOptions
4-
extends NgPackagrBuilderOptions {}
4+
extends NgPackagrBuilderOptions {
5+
project?: string;
6+
}

0 commit comments

Comments
 (0)