Repository navigation
feat(@schematics/angular): use library builder and add entry-point schematic - #34645
alan-agius4 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new "entry-point" schematic to generate secondary entry points for Angular libraries, and transitions the library schematic to use the "@angular/build:library" builder instead of "ng-packagr" configuration files. Feedback is provided to deduplicate path mappings in "tsconfig.json" when updating the configuration to prevent duplicate entries upon multiple runs.
…hematic Update the library schematic to configure @angular/build:library with a single tsconfig.lib.json instead of @angular/build:ng-packagr, and add an entry-point schematic to generate secondary entry points under src/<name>/.
f95c4e5 to
c033dbc
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'entry-point' schematic to generate secondary entry points for Angular libraries, and refactors the existing 'library' schematic to use this new schematic for generating the primary entry point. It also replaces the 'ng-packagr' builder with the new '@angular/build:library' builder, removing obsolete configuration files like 'ng-package.json' and 'tsconfig.lib.prod.json'. Feedback on the changes suggests making the path resolution for 'tsConfigPathTarget' in the 'entry-point' schematic more robust by checking for existing relative or absolute path prefixes before prepending './'.
60ae3e1 to
b4486a5
Compare
1a5df35 to
98c90c5
Compare
| let root: string; | ||
| if (project.extensions['projectType'] === ProjectType.Library) { | ||
| root = | ||
| project.sourceRoot && project.sourceRoot !== project.root | ||
| ? `/${project.sourceRoot}/` | ||
| : `/${project.root}/src/`; | ||
| } else { | ||
| root = `/${project.sourceRoot || project.root}/`; // fallback for non-library projects | ||
| } |
There was a problem hiding this comment.
When project.sourceRoot is omitted on a non-library project, the else branch now evaluates to /${project.root}/ instead of /${project.root}/src/ (which was the previous behavior: project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/` ), dropping the src/ segment (e.g. /projects/app/app instead of /projects/app/src/app).
| let root: string; | |
| if (project.extensions['projectType'] === ProjectType.Library) { | |
| root = | |
| project.sourceRoot && project.sourceRoot !== project.root | |
| ? `/${project.sourceRoot}/` | |
| : `/${project.root}/src/`; | |
| } else { | |
| root = `/${project.sourceRoot || project.root}/`; // fallback for non-library projects | |
| } | |
| const isLibraryAtRoot = | |
| project.extensions['projectType'] === ProjectType.Library && | |
| project.sourceRoot === project.root; | |
| const root = | |
| project.sourceRoot && !isLibraryAtRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`; |
Could we also add unit tests for buildDefaultPath covering libraries with sourceRoot === root as well as applications with and without sourceRoot? (There's also a legacy shim copy in packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts if we want to keep it in sync.)
|
|
||
| const isPrimary = options.name === '.'; | ||
| const entryFile = (options.entryFile ?? 'public-api').replace(/\.ts$/i, ''); | ||
| const entryPointDir = join(libDir, options.name, 'src'); |
There was a problem hiding this comment.
For libraries migrated from ng-packagr via the use-library-builder migration, sourceRoot remains <root>/src and tsconfig.lib.json / tsconfig.spec.json still have include patterns scoped to src/**. Running ng g entry-point on a migrated library will place files under <root>/<name>/src/, outside sourceRoot, so ng test won't discover the generated spec files.
Should we update the use-library-builder migration (can be a follow-up) to align sourceRoot and the tsconfig include globs, or warn here when entryPointDir is outside project.sourceRoot?
Updates the
libraryschematic to configure@angular/build:librarywith a singletsconfig.lib.jsonand introduces anentry-pointschematic to generate library entry points undersrc/<name>/.Closes #19070