@@ -89,9 +89,7 @@ describe('EntryPoint Schematic', () => {
8989 expect ( pkgJson . exports [ './feature/sub' ] ) . toBe ( './src/feature/sub/public-api.ts' ) ;
9090
9191 const tsConfigJson = getJsonFileContent ( tree , '/tsconfig.json' ) ;
92- expect ( tsConfigJson . compilerOptions . paths [ 'foo/feature/sub' ] ) . toEqual ( [
93- './dist/foo/feature/sub' ,
94- ] ) ;
92+ expect ( tsConfigJson . compilerOptions . paths [ 'foo/*' ] ) . toEqual ( [ './dist/foo/*' ] ) ;
9593 } ) ;
9694
9795 it ( 'should support custom entryFile option' , async ( ) => {
@@ -133,6 +131,7 @@ describe('EntryPoint Schematic', () => {
133131 '.' : './src/public-api.ts' ,
134132 './secondary' : './src/secondary/public-api.ts' ,
135133 } ) ;
134+ expect ( Object . keys ( pkgJson ) [ 0 ] ) . toBe ( 'name' ) ;
136135 } ) ;
137136
138137 it ( 'should convert string exports in library package.json to an exports object' , async ( ) => {
@@ -177,23 +176,23 @@ describe('EntryPoint Schematic', () => {
177176 } ) ;
178177 } ) ;
179178
180- it ( 'should add paths mapping to root tsconfig.json' , async ( ) => {
179+ it ( 'should add wildcard paths mapping to root tsconfig.json' , async ( ) => {
181180 const tree = await schematicRunner . runSchematic ( 'entry-point' , defaultOptions , workspaceTree ) ;
182181
183182 const tsConfigJson = getJsonFileContent ( tree , '/tsconfig.json' ) ;
184183 expect ( tsConfigJson . compilerOptions . paths [ 'foo' ] ) . toEqual ( [ './dist/foo' ] ) ;
185- expect ( tsConfigJson . compilerOptions . paths [ 'foo/secondary ' ] ) . toEqual ( [ './dist/foo/secondary ' ] ) ;
184+ expect ( tsConfigJson . compilerOptions . paths [ 'foo/* ' ] ) . toEqual ( [ './dist/foo/* ' ] ) ;
186185 } ) ;
187186
188187 it ( 'should not duplicate existing paths mapping in root tsconfig.json' , async ( ) => {
189188 const tsConfig = getJsonFileContent ( workspaceTree , '/tsconfig.json' ) ;
190- tsConfig . compilerOptions . paths [ 'foo/secondary ' ] = [ './dist/foo/secondary ' ] ;
189+ tsConfig . compilerOptions . paths [ 'foo/* ' ] = [ './dist/foo/* ' ] ;
191190 workspaceTree . overwrite ( '/tsconfig.json' , JSON . stringify ( tsConfig , null , 2 ) ) ;
192191
193192 const tree = await schematicRunner . runSchematic ( 'entry-point' , defaultOptions , workspaceTree ) ;
194193
195194 const tsConfigJson = getJsonFileContent ( tree , '/tsconfig.json' ) ;
196- expect ( tsConfigJson . compilerOptions . paths [ 'foo/secondary ' ] ) . toEqual ( [ './dist/foo/secondary ' ] ) ;
195+ expect ( tsConfigJson . compilerOptions . paths [ 'foo/* ' ] ) . toEqual ( [ './dist/foo/* ' ] ) ;
197196 } ) ;
198197
199198 it ( 'should respect custom outputPath in angular.json for tsconfig paths mapping' , async ( ) => {
@@ -204,9 +203,7 @@ describe('EntryPoint Schematic', () => {
204203 const tree = await schematicRunner . runSchematic ( 'entry-point' , defaultOptions , workspaceTree ) ;
205204
206205 const tsConfigJson = getJsonFileContent ( tree , '/tsconfig.json' ) ;
207- expect ( tsConfigJson . compilerOptions . paths [ 'foo/secondary' ] ) . toEqual ( [
208- './custom-dist/foo/secondary' ,
209- ] ) ;
206+ expect ( tsConfigJson . compilerOptions . paths [ 'foo/*' ] ) . toEqual ( [ './custom-dist/foo/*' ] ) ;
210207 } ) ;
211208
212209 it ( 'should respect custom sourceRoot in angular.json' , async ( ) => {
@@ -239,7 +236,7 @@ describe('EntryPoint Schematic', () => {
239236 ) ;
240237
241238 const tsConfigJson = getJsonFileContent ( tree , '/tsconfig.json' ) ;
242- expect ( tsConfigJson . compilerOptions . paths [ 'foo/secondary ' ] ) . toBeUndefined ( ) ;
239+ expect ( tsConfigJson . compilerOptions . paths [ 'foo/* ' ] ) . toBeUndefined ( ) ;
243240 } ) ;
244241
245242 it ( 'should inherit prefix from the library project in angular.json' , async ( ) => {
@@ -268,6 +265,17 @@ describe('EntryPoint Schematic', () => {
268265 expect ( componentContent ) . toContain ( "selector: 'custom-secondary'" ) ;
269266 } ) ;
270267
268+ it ( 'should fallback to "lib" prefix when project prefix is empty in angular.json' , async ( ) => {
269+ const angularJson = getJsonFileContent ( workspaceTree , '/angular.json' ) ;
270+ angularJson . projects . foo . prefix = '' ;
271+ workspaceTree . overwrite ( '/angular.json' , JSON . stringify ( angularJson , null , 2 ) ) ;
272+
273+ const tree = await schematicRunner . runSchematic ( 'entry-point' , defaultOptions , workspaceTree ) ;
274+
275+ const componentContent = tree . readContent ( '/projects/foo/src/secondary/lib/secondary.ts' ) ;
276+ expect ( componentContent ) . toContain ( "selector: 'lib-secondary'" ) ;
277+ } ) ;
278+
271279 it ( 'should allow overriding prefix via option' , async ( ) => {
272280 const tree = await schematicRunner . runSchematic (
273281 'entry-point' ,
@@ -316,8 +324,8 @@ describe('EntryPoint Schematic', () => {
316324 } ) ;
317325
318326 const tsConfigJson = getJsonFileContent ( tree , '/tsconfig.json' ) ;
319- expect ( tsConfigJson . compilerOptions . paths [ '@my-scope/my-lib/secondary ' ] ) . toEqual ( [
320- './dist/my-scope/my-lib/secondary ' ,
327+ expect ( tsConfigJson . compilerOptions . paths [ '@my-scope/my-lib/* ' ] ) . toEqual ( [
328+ './dist/my-scope/my-lib/* ' ,
321329 ] ) ;
322330 } ) ;
323331
@@ -335,6 +343,24 @@ describe('EntryPoint Schematic', () => {
335343 expect ( tree . files ) . not . toContain ( '/projects/foo/src/secondary/lib/secondary.spec.ts' ) ;
336344 } ) ;
337345
346+ it ( 'should not be affected by workspace component schematic type and exportDefault defaults' , async ( ) => {
347+ const angularJson = getJsonFileContent ( workspaceTree , '/angular.json' ) ;
348+ angularJson . schematics = {
349+ '@schematics/angular:component' : {
350+ type : 'component' ,
351+ exportDefault : true ,
352+ } ,
353+ } ;
354+ workspaceTree . overwrite ( '/angular.json' , JSON . stringify ( angularJson , null , 2 ) ) ;
355+
356+ const tree = await schematicRunner . runSchematic ( 'entry-point' , defaultOptions , workspaceTree ) ;
357+
358+ expect ( tree . files ) . toContain ( '/projects/foo/src/secondary/lib/secondary.ts' ) ;
359+ const componentContent = tree . readContent ( '/projects/foo/src/secondary/lib/secondary.ts' ) ;
360+ expect ( componentContent ) . toContain ( 'export class Secondary' ) ;
361+ expect ( componentContent ) . not . toContain ( 'export default' ) ;
362+ } ) ;
363+
338364 describe ( 'standalone=false' , ( ) => {
339365 it ( 'should create an NgModule and export it in the entry file' , async ( ) => {
340366 const tree = await schematicRunner . runSchematic (
@@ -394,6 +420,16 @@ describe('EntryPoint Schematic', () => {
394420 ) . toBeRejectedWithError ( 'Project "my-app" is not a library project.' ) ;
395421 } ) ;
396422
423+ it ( 'should throw if the library project does not use @angular/build:library' , async ( ) => {
424+ const angularJson = getJsonFileContent ( workspaceTree , '/angular.json' ) ;
425+ angularJson . projects . foo . architect . build . builder = '@angular/build:ng-packagr' ;
426+ workspaceTree . overwrite ( '/angular.json' , JSON . stringify ( angularJson , null , 2 ) ) ;
427+
428+ await expectAsync (
429+ schematicRunner . runSchematic ( 'entry-point' , defaultOptions , workspaceTree ) ,
430+ ) . toBeRejectedWithError ( 'Project "foo" does not use the "@angular/build:library" builder.' ) ;
431+ } ) ;
432+
397433 it ( 'should throw if the library package.json is missing' , async ( ) => {
398434 workspaceTree . delete ( '/projects/foo/package.json' ) ;
399435
@@ -402,32 +438,50 @@ describe('EntryPoint Schematic', () => {
402438 ) . toBeRejectedWithError ( 'Could not find package.json at "projects/foo/package.json".' ) ;
403439 } ) ;
404440
405- it ( 'should throw if the entry-point name is "lib" or starts with "lib/ "' , async ( ) => {
441+ it ( 'should throw if the entry-point name is "package.json "' , async ( ) => {
406442 await expectAsync (
407443 schematicRunner . runSchematic (
408444 'entry-point' ,
409445 {
410- name : 'lib ' ,
446+ name : 'package.json ' ,
411447 project : 'foo' ,
412448 } ,
413449 workspaceTree ,
414450 ) ,
415- ) . toBeRejectedWithError (
416- 'Entry point name "lib" cannot be "lib" or start with "lib/" as it conflicts with the primary entry point source directory.' ,
417- ) ;
451+ ) . toBeRejectedWithError ( 'Entry point name "package.json" is reserved.' ) ;
452+ } ) ;
418453
419- await expectAsync (
420- schematicRunner . runSchematic (
421- 'entry-point' ,
422- {
423- name : 'lib/sub' ,
424- project : 'foo' ,
425- } ,
426- workspaceTree ,
427- ) ,
428- ) . toBeRejectedWithError (
429- 'Entry point name "lib/sub" cannot be "lib" or start with "lib/" as it conflicts with the primary entry point source directory.' ,
430- ) ;
454+ it ( 'should throw if the entry-point name is "lib" or contains a "lib" segment' , async ( ) => {
455+ for ( const invalidName of [ 'lib' , 'lib/sub' , 'feature/lib' , 'feature/lib/sub' ] ) {
456+ await expectAsync (
457+ schematicRunner . runSchematic (
458+ 'entry-point' ,
459+ {
460+ name : invalidName ,
461+ project : 'foo' ,
462+ } ,
463+ workspaceTree ,
464+ ) ,
465+ ) . toBeRejectedWithError (
466+ `Entry point name "${ invalidName } " cannot be "lib" or contain a "lib" segment ` +
467+ 'as it conflicts with the entry point source directory.' ,
468+ ) ;
469+ }
470+ } ) ;
471+
472+ it ( 'should reject invalid entry-point names via schema validation' , async ( ) => {
473+ for ( const invalidName of [ '.' , '../foo' , 'foo..bar' , '/secondary' , 'secondary/' , './sub' ] ) {
474+ await expectAsync (
475+ schematicRunner . runSchematic (
476+ 'entry-point' ,
477+ {
478+ name : invalidName ,
479+ project : 'foo' ,
480+ } ,
481+ workspaceTree ,
482+ ) ,
483+ ) . toBeRejected ( ) ;
484+ }
431485 } ) ;
432486
433487 it ( 'should throw if the entry point already exists in package.json exports' , async ( ) => {
0 commit comments