Skip to content

Commit 4d78fff

Browse files
committed
refactor(@angular/build): provide a default for the ng-packagr project option
This option is now considered optional
1 parent e6083b5 commit 4d78fff

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

Diff for: goldens/public-api/angular/build/index.api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export type ExtractI18nBuilderOptions = {
166166
// @public
167167
export type NgPackagrBuilderOptions = {
168168
poll?: number;
169-
project: string;
169+
project?: string;
170170
tsConfig?: string;
171171
watch?: boolean;
172172
};

Diff for: packages/angular/build/src/builders/ng-packagr/builder.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function* execute(
3030
// Purge old build disk cache.
3131
await purgeStaleBuildCache(context);
3232

33-
const root = context.workspaceRoot;
33+
const workspaceRoot = context.workspaceRoot;
3434
let packager;
3535
try {
3636
packager = (await import('ng-packagr')).ngPackagr();
@@ -47,18 +47,22 @@ export async function* execute(
4747
throw error;
4848
}
4949

50-
packager.forProject(resolve(root, options.project));
51-
52-
if (options.tsConfig) {
53-
packager.withTsConfig(resolve(root, options.tsConfig));
54-
}
55-
5650
const projectName = context.target?.project;
5751
if (!projectName) {
5852
throw new Error('The builder requires a target.');
5953
}
6054

6155
const metadata = await context.getProjectMetadata(projectName);
56+
const ngPackagrConfig = options.project
57+
? join(workspaceRoot, options.project)
58+
: join(workspaceRoot, (metadata.root as string | undefined) ?? '', 'ng-package.json');
59+
60+
packager.forProject(ngPackagrConfig);
61+
62+
if (options.tsConfig) {
63+
packager.withTsConfig(resolve(workspaceRoot, options.tsConfig));
64+
}
65+
6266
const { enabled: cacheEnabled, path: cacheDirectory } = normalizeCacheOptions(
6367
metadata,
6468
context.workspaceRoot,

Diff for: packages/angular/build/src/builders/ng-packagr/schema.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@
2222
"description": "Enable and define the file watching poll time period in milliseconds."
2323
}
2424
},
25-
"additionalProperties": false,
26-
"required": ["project"]
25+
"additionalProperties": false
2726
}

Diff for: packages/schematics/angular/library/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ function addLibToWorkspaceFile(
9393
build: {
9494
builder: Builders.BuildNgPackagr,
9595
defaultConfiguration: 'production',
96-
options: {
97-
project: `${projectRoot}/ng-package.json`,
98-
},
9996
configurations: {
10097
production: {
10198
tsConfig: `${projectRoot}/tsconfig.lib.prod.json`,

Diff for: packages/schematics/angular/library/index_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ describe('Library Schematic', () => {
361361
const project = config.projects.foo;
362362
expect(project.root).toEqual('foo');
363363
const { options, configurations } = project.architect.build;
364-
expect(options.project).toEqual('foo/ng-package.json');
365364
expect(configurations.production.tsConfig).toEqual('foo/tsconfig.lib.prod.json');
366365

367366
const libTsConfig = getJsonFileContent(tree, '/foo/tsconfig.lib.json');

0 commit comments

Comments
 (0)