From daa122e238f89cf898ebf471bb05230b3a1e40ab Mon Sep 17 00:00:00 2001 From: MeAkib Date: Thu, 29 Oct 2026 09:44:53 +0600 Subject: [PATCH] fix(@schematics/angular): keep the default ng-packagr output path in use-library-builder The migration only sets `outputPath` when the ng-packagr configuration has a `dest`. Without it, ng-packagr writes to `dist` within the package directory, while the library builder defaults to `dist/`, so the migrated library is silently built to a different location. Set `outputPath` to the ng-packagr default when `dest` is not set. A new spec fails without this change. --- .../migrations/use-library-builder/migration.ts | 5 +++-- .../migrations/use-library-builder/migration_spec.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/schematics/angular/migrations/use-library-builder/migration.ts b/packages/schematics/angular/migrations/use-library-builder/migration.ts index 4cbd8634f248..1bb938430af3 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration.ts @@ -244,8 +244,9 @@ function migrateTargetOptions( delete buildTarget.configurations?.['development']?.['tsConfig']; } - if (ngPackageConfig?.dest && typeof buildTarget.options['outputPath'] !== 'string') { - buildTarget.options['outputPath'] = join(projectDir, ngPackageConfig.dest); + if (typeof buildTarget.options['outputPath'] !== 'string') { + // `ng-packagr` writes to `dist` within the package directory when `dest` is not set. + buildTarget.options['outputPath'] = join(projectDir, ngPackageConfig?.dest ?? 'dist'); } if (ngPackageConfig?.assets?.length) { diff --git a/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts b/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts index 98fbe65fd5f6..7a86b9deb1df 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts @@ -121,6 +121,18 @@ describe('Migration to use the library builder', () => { expect(newTree.exists('/projects/my-lib/ng-package.json')).toBe(false); }); + it('should keep the default ng-packagr output path when dest is not set', async () => { + tree.overwrite( + '/projects/my-lib/ng-package.json', + JSON.stringify({ lib: { entryFile: 'src/public-api.ts' } }), + ); + + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const { projects } = newTree.readJson('/angular.json') as any; + expect(projects['my-lib'].architect['build'].options.outputPath).toBe('projects/my-lib/dist'); + }); + it('should migrate @angular/build:ng-packagr and promote tsConfig from development configuration', async () => { const angularJson = JSON.parse(tree.readContent('/angular.json')); angularJson.projects['my-lib'].architect.build = {