From 8d1e2ac2c8151ba504e5351b9e785ed6be35efec Mon Sep 17 00:00:00 2001 From: MeAkib Date: Tue, 20 Oct 2026 00:43:05 +0600 Subject: [PATCH 1/5] fix(@schematics/angular): migrate ng-packagr glob string assets in use-library-builder ng-packagr treats an `assets` string that is neither a file nor a directory as a glob relative to the package root. The migration copied every string as a path, and the library builder treats such a path as a directory, so glob assets like `docs/**/*.md` copied nothing after the migration. Migrate strings that are neither a file nor a directory to `{ glob, input, output }` objects, as ng-packagr resolves them. --- .../use-library-builder/migration.ts | 14 ++++++++++- .../use-library-builder/migration_spec.ts | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/schematics/angular/migrations/use-library-builder/migration.ts b/packages/schematics/angular/migrations/use-library-builder/migration.ts index 68f9e8738e25..327818152113 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration.ts @@ -251,7 +251,19 @@ function migrateTargetOptions( : []; const migratedAssets = ngPackageConfig.assets.map((asset) => { if (typeof asset === 'string') { - return join(projectDir, asset); + const assetPath = join(projectDir, asset); + if (tree.exists(assetPath)) { + return assetPath; + } + + const assetDir = tree.getDir(assetPath); + if (assetDir.subfiles.length || assetDir.subdirs.length) { + return assetPath; + } + + // `ng-packagr` treats a string that is neither a file nor a directory as a glob relative + // to the package root, while the library builder only accepts files and directories. + return { glob: normalize(asset), input: join(projectDir, '.'), output: '/' }; } if (isJsonObject(asset) && typeof asset['input'] === 'string') { return { 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 11192f8e5897..c5a726259084 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts @@ -281,6 +281,7 @@ describe('Migration to use the library builder', () => { }); it('should migrate assets, styleIncludePaths, and sass options from ng-package.json', async () => { + tree.create('/projects/my-lib/CHANGELOG.md', '# Changelog'); tree.overwrite( '/projects/my-lib/ng-package.json', JSON.stringify( @@ -324,6 +325,30 @@ describe('Migration to use the library builder', () => { }); }); + it('should migrate ng-packagr glob string assets to glob objects', async () => { + tree.create('/projects/my-lib/docs/guide.md', '# Guide'); + tree.create('/projects/my-lib/CHANGELOG.md', '# Changelog'); + tree.overwrite( + '/projects/my-lib/ng-package.json', + JSON.stringify({ + assets: ['CHANGELOG.md', 'docs', 'docs/**/*.md'], + lib: { entryFile: 'src/public-api.ts' }, + }), + ); + + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); + const { + projects: { 'my-lib': lib }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } = newTree.readJson('/angular.json') as any; + + expect(lib.architect['build'].options.assets).toEqual([ + 'projects/my-lib/CHANGELOG.md', + 'projects/my-lib/docs', + { glob: 'docs/**/*.md', input: 'projects/my-lib', output: '/' }, + ]); + }); + it('should preserve existing stylePreprocessorOptions.includePaths when migrating styleIncludePaths', async () => { const angularJson = JSON.parse(tree.readContent('/angular.json')); angularJson.projects['my-lib'].architect.build.options.stylePreprocessorOptions = { From a99f33bb0157b8fe33ad84262cc0b313cc2638b0 Mon Sep 17 00:00:00 2001 From: Shuaib Hasan Akib <48770016+MeAkib@users.noreply.github.com> Date: Tue, 20 Oct 2026 00:53:13 +0600 Subject: [PATCH 2/5] fixup! fix(@schematics/angular): migrate ng-packagr glob string assets in use-library-builder --- .../angular/migrations/use-library-builder/migration.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/schematics/angular/migrations/use-library-builder/migration.ts b/packages/schematics/angular/migrations/use-library-builder/migration.ts index 327818152113..b98d79b9375d 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration.ts @@ -252,6 +252,10 @@ function migrateTargetOptions( const migratedAssets = ngPackageConfig.assets.map((asset) => { if (typeof asset === 'string') { const assetPath = join(projectDir, asset); + if (assetPath.startsWith('..')) { + return assetPath; + } + if (tree.exists(assetPath)) { return assetPath; } From 76929e6e77acc12f21a63f827b06f92842f7bace Mon Sep 17 00:00:00 2001 From: MeAkib Date: Tue, 20 Oct 2026 00:56:32 +0600 Subject: [PATCH 3/5] fixup! fix(@schematics/angular): migrate ng-packagr glob string assets in use-library-builder --- .../use-library-builder/migration_spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 c5a726259084..043784dba59e 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts @@ -349,6 +349,24 @@ describe('Migration to use the library builder', () => { ]); }); + it('should keep ng-packagr assets outside the project root as paths', async () => { + tree.overwrite( + '/projects/my-lib/ng-package.json', + JSON.stringify({ + assets: ['../../../shared-assets'], + lib: { entryFile: 'src/public-api.ts' }, + }), + ); + + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); + const { + projects: { 'my-lib': lib }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } = newTree.readJson('/angular.json') as any; + + expect(lib.architect['build'].options.assets).toEqual(['../shared-assets']); + }); + it('should preserve existing stylePreprocessorOptions.includePaths when migrating styleIncludePaths', async () => { const angularJson = JSON.parse(tree.readContent('/angular.json')); angularJson.projects['my-lib'].architect.build.options.stylePreprocessorOptions = { From 6a5f07e8aa1199abac1ad601015f187b13cbcde2 Mon Sep 17 00:00:00 2001 From: MeAkib Date: Tue, 20 Oct 2026 10:13:16 +0600 Subject: [PATCH 4/5] fixup! fix(@schematics/angular): migrate ng-packagr glob string assets in use-library-builder Co-authored-by: Alan Agius --- .../angular/migrations/use-library-builder/migration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/schematics/angular/migrations/use-library-builder/migration.ts b/packages/schematics/angular/migrations/use-library-builder/migration.ts index b98d79b9375d..285cdf9f2332 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration.ts @@ -267,7 +267,7 @@ function migrateTargetOptions( // `ng-packagr` treats a string that is neither a file nor a directory as a glob relative // to the package root, while the library builder only accepts files and directories. - return { glob: normalize(asset), input: join(projectDir, '.'), output: '/' }; + return { glob: asset, input: projectDir }; } if (isJsonObject(asset) && typeof asset['input'] === 'string') { return { From c39ccd0841a0312ba9db1033b3a12f593a534f0a Mon Sep 17 00:00:00 2001 From: MeAkib Date: Tue, 20 Oct 2026 10:13:18 +0600 Subject: [PATCH 5/5] fixup! fix(@schematics/angular): migrate ng-packagr glob string assets in use-library-builder Co-authored-by: Alan Agius --- .../angular/migrations/use-library-builder/migration_spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 043784dba59e..d54d5f62f61a 100644 --- a/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts +++ b/packages/schematics/angular/migrations/use-library-builder/migration_spec.ts @@ -345,7 +345,7 @@ describe('Migration to use the library builder', () => { expect(lib.architect['build'].options.assets).toEqual([ 'projects/my-lib/CHANGELOG.md', 'projects/my-lib/docs', - { glob: 'docs/**/*.md', input: 'projects/my-lib', output: '/' }, + { glob: 'docs/**/*.md', input: 'projects/my-lib' }, ]); });