diff --git a/goldens/public-api/angular/build/index.api.md b/goldens/public-api/angular/build/index.api.md index bf620bfa15c4..6c0c2f19145b 100644 --- a/goldens/public-api/angular/build/index.api.md +++ b/goldens/public-api/angular/build/index.api.md @@ -166,7 +166,7 @@ export type ExtractI18nBuilderOptions = { // @public export type NgPackagrBuilderOptions = { poll?: number; - project: string; + project?: string; tsConfig?: string; watch?: boolean; }; diff --git a/packages/angular/build/src/builders/ng-packagr/builder.ts b/packages/angular/build/src/builders/ng-packagr/builder.ts index f2dc60ebf30c..24b606aeede1 100644 --- a/packages/angular/build/src/builders/ng-packagr/builder.ts +++ b/packages/angular/build/src/builders/ng-packagr/builder.ts @@ -30,7 +30,7 @@ export async function* execute( // Purge old build disk cache. await purgeStaleBuildCache(context); - const root = context.workspaceRoot; + const workspaceRoot = context.workspaceRoot; let packager; try { packager = (await import('ng-packagr')).ngPackagr(); @@ -47,18 +47,22 @@ export async function* execute( throw error; } - packager.forProject(resolve(root, options.project)); - - if (options.tsConfig) { - packager.withTsConfig(resolve(root, options.tsConfig)); - } - const projectName = context.target?.project; if (!projectName) { throw new Error('The builder requires a target.'); } const metadata = await context.getProjectMetadata(projectName); + const ngPackagrConfig = options.project + ? join(workspaceRoot, options.project) + : join(workspaceRoot, (metadata.root as string | undefined) ?? '', 'ng-package.json'); + + packager.forProject(ngPackagrConfig); + + if (options.tsConfig) { + packager.withTsConfig(resolve(workspaceRoot, options.tsConfig)); + } + const { enabled: cacheEnabled, path: cacheDirectory } = normalizeCacheOptions( metadata, context.workspaceRoot, diff --git a/packages/angular/build/src/builders/ng-packagr/schema.json b/packages/angular/build/src/builders/ng-packagr/schema.json index da76255f092a..0aa80ed6fe5f 100644 --- a/packages/angular/build/src/builders/ng-packagr/schema.json +++ b/packages/angular/build/src/builders/ng-packagr/schema.json @@ -22,6 +22,5 @@ "description": "Enable and define the file watching poll time period in milliseconds." } }, - "additionalProperties": false, - "required": ["project"] + "additionalProperties": false } diff --git a/packages/schematics/angular/library/index.ts b/packages/schematics/angular/library/index.ts index f59c8420619b..68f9f8f513c4 100644 --- a/packages/schematics/angular/library/index.ts +++ b/packages/schematics/angular/library/index.ts @@ -93,9 +93,6 @@ function addLibToWorkspaceFile( build: { builder: Builders.BuildNgPackagr, defaultConfiguration: 'production', - options: { - project: `${projectRoot}/ng-package.json`, - }, configurations: { production: { tsConfig: `${projectRoot}/tsconfig.lib.prod.json`, diff --git a/packages/schematics/angular/library/index_spec.ts b/packages/schematics/angular/library/index_spec.ts index 7787571472e5..62b9d0b87f47 100644 --- a/packages/schematics/angular/library/index_spec.ts +++ b/packages/schematics/angular/library/index_spec.ts @@ -361,7 +361,6 @@ describe('Library Schematic', () => { const project = config.projects.foo; expect(project.root).toEqual('foo'); const { options, configurations } = project.architect.build; - expect(options.project).toEqual('foo/ng-package.json'); expect(configurations.production.tsConfig).toEqual('foo/tsconfig.lib.prod.json'); const libTsConfig = getJsonFileContent(tree, '/foo/tsconfig.lib.json');