From c0933f2c0354a13ba3f752f29b24054177697faa Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 29 Jul 2024 06:55:05 +0000 Subject: [PATCH] fix(@angular/build): resolve error with `extract-i18n` builder for libraries The `extract-i18n` builder is only intended to be used with application projects. Closes #28109 (cherry picked from commit 0466fb74a2559e2b3cbcf0828de5b5e10b729ddb) --- .../build/src/builders/extract-i18n/builder.ts | 12 ++++++++++++ .../src/builders/extract-i18n/builder.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/angular/build/src/builders/extract-i18n/builder.ts b/packages/angular/build/src/builders/extract-i18n/builder.ts index b74164758345..9f1e80c57cd9 100644 --- a/packages/angular/build/src/builders/extract-i18n/builder.ts +++ b/packages/angular/build/src/builders/extract-i18n/builder.ts @@ -32,6 +32,18 @@ export async function execute( return { success: false }; } + const { projectType } = (await context.getProjectMetadata(projectName)) as { + projectType?: string; + }; + if (projectType !== 'application') { + context.logger.error( + `Tried to extract from ${projectName} with 'projectType' ${projectType}, which is not supported.` + + ` The 'extract-i18n' builder can only extract from applications.`, + ); + + return { success: false }; + } + // Check Angular version. assertCompatibleAngularVersion(context.workspaceRoot); diff --git a/packages/angular_devkit/build_angular/src/builders/extract-i18n/builder.ts b/packages/angular_devkit/build_angular/src/builders/extract-i18n/builder.ts index 0a32b45599d4..f6a56920ccfc 100644 --- a/packages/angular_devkit/build_angular/src/builders/extract-i18n/builder.ts +++ b/packages/angular_devkit/build_angular/src/builders/extract-i18n/builder.ts @@ -35,6 +35,18 @@ export async function execute( return { success: false }; } + const { projectType } = (await context.getProjectMetadata(projectName)) as { + projectType?: string; + }; + if (projectType !== 'application') { + context.logger.error( + `Tried to extract from ${projectName} with 'projectType' ${projectType}, which is not supported.` + + ` The 'extract-i18n' builder can only extract from applications.`, + ); + + return { success: false }; + } + // Check Angular version. assertCompatibleAngularVersion(context.workspaceRoot);