Skip to content

Commit daa122e

Browse files
committed
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/<project>`, 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.
1 parent 321b475 commit daa122e

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎packages/schematics/angular/migrations/use-library-builder/migration.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ function migrateTargetOptions(
244244
delete buildTarget.configurations?.['development']?.['tsConfig'];
245245
}
246246

247-
if (ngPackageConfig?.dest && typeof buildTarget.options['outputPath'] !== 'string') {
248-
buildTarget.options['outputPath'] = join(projectDir, ngPackageConfig.dest);
247+
if (typeof buildTarget.options['outputPath'] !== 'string') {
248+
// `ng-packagr` writes to `dist` within the package directory when `dest` is not set.
249+
buildTarget.options['outputPath'] = join(projectDir, ngPackageConfig?.dest ?? 'dist');
249250
}
250251

251252
if (ngPackageConfig?.assets?.length) {

‎packages/schematics/angular/migrations/use-library-builder/migration_spec.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ describe('Migration to use the library builder', () => {
121121
expect(newTree.exists('/projects/my-lib/ng-package.json')).toBe(false);
122122
});
123123

124+
it('should keep the default ng-packagr output path when dest is not set', async () => {
125+
tree.overwrite(
126+
'/projects/my-lib/ng-package.json',
127+
JSON.stringify({ lib: { entryFile: 'src/public-api.ts' } }),
128+
);
129+
130+
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
131+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
132+
const { projects } = newTree.readJson('/angular.json') as any;
133+
expect(projects['my-lib'].architect['build'].options.outputPath).toBe('projects/my-lib/dist');
134+
});
135+
124136
it('should migrate @angular/build:ng-packagr and promote tsConfig from development configuration', async () => {
125137
const angularJson = JSON.parse(tree.readContent('/angular.json'));
126138
angularJson.projects['my-lib'].architect.build = {

0 commit comments

Comments
 (0)