From bfb5675bdcc531b7e04aaab6afd94b0934c000bd Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Wed, 4 Mar 2026 09:15:13 +0000 Subject: [PATCH] fix(@angular/build): resolve style include paths relative to `ng-package.json` in unit-test builder When using the `unit-test` builder with an `ng-packagr` build target, the `styleIncludePaths` from `ng-package.json` were being used relative to the workspace root instead of the library's directory. This caused build failures when libraries specified style include paths. This change ensures that these paths are correctly resolved relative to the directory containing `ng-package.json`. --- .../build/src/builders/unit-test/builder.ts | 15 +++++++------- tests/e2e/tests/vitest/library.ts | 20 +++++-------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/packages/angular/build/src/builders/unit-test/builder.ts b/packages/angular/build/src/builders/unit-test/builder.ts index fb9faa3b8576..97c3c0dce055 100644 --- a/packages/angular/build/src/builders/unit-test/builder.ts +++ b/packages/angular/build/src/builders/unit-test/builder.ts @@ -375,16 +375,15 @@ async function transformNgPackagrOptions( }); } - const lib = ngPackageJson['lib'] || {}; - const styleIncludePaths = lib['styleIncludePaths'] || []; - const assets = ngPackageJson['assets'] || []; - const inlineStyleLanguage = ngPackageJson['inlineStyleLanguage']; + const { lib: { styleIncludePaths = [] } = {}, assets = [], inlineStyleLanguage } = ngPackageJson; + + const includePaths = styleIncludePaths.map((includePath: string) => + path.resolve(path.dirname(ngPackagePath), includePath), + ); return { - stylePreprocessorOptions: styleIncludePaths.length - ? { includePaths: styleIncludePaths } - : undefined, + stylePreprocessorOptions: includePaths.length ? { includePaths } : undefined, assets: assets.length ? assets : undefined, - inlineStyleLanguage: typeof inlineStyleLanguage === 'string' ? inlineStyleLanguage : undefined, + inlineStyleLanguage, } as ApplicationBuilderInternalOptions; } diff --git a/tests/e2e/tests/vitest/library.ts b/tests/e2e/tests/vitest/library.ts index ba1e31dc38f8..0bb989057279 100644 --- a/tests/e2e/tests/vitest/library.ts +++ b/tests/e2e/tests/vitest/library.ts @@ -1,12 +1,9 @@ import assert from 'node:assert/strict'; import { updateJsonFile } from '../../utils/project'; -import { ng, silentNpm } from '../../utils/process'; -import { createDir, writeFile } from '../../utils/fs'; +import { ng } from '../../utils/process'; +import { appendToFile, createDir, writeFile } from '../../utils/fs'; export default async function (): Promise { - // Install Vitest deps - await silentNpm('install', 'vitest@^4.0.8', 'jsdom@^27.1.0', '--save-dev'); - // Generate a library await ng('generate', 'library', 'my-lib', '--test-runner', 'vitest'); @@ -25,17 +22,10 @@ export default async function (): Promise { // 3. Update the component to use SCSS and import the shared file // Rename CSS to SCSS - await ng( - 'generate', - 'component', - 'styled-comp', - '--project=my-lib', - '--style=scss', - '--skip-import', - ); + await ng('generate', 'component', 'styled-comp', '--project=my-lib', '--style=scss'); - await writeFile( - 'projects/my-lib/src/lib/styled-comp/styled-comp.component.scss', + await appendToFile( + 'projects/my-lib/src/lib/styled-comp/styled-comp.scss', ` @use 'vars'; p { color: vars.$primary-color; }