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 = {