Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/schematics/angular/entry-point/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ export default createProjectSchematic<EntryPointOptions>((options, { project, tr
throw new SchematicsException(`Project "${options.project}" is not a library project.`);
}

const buildTarget = project.targets.get('build');
if (buildTarget?.builder !== Builders.BuildLibrary) {
throw new SchematicsException(
`Project "${options.project}" does not use the "${Builders.BuildLibrary}" builder.`,
);
for (const target of project.targets.values()) {
if (target.builder === Builders.NgPackagr || target.builder === Builders.BuildNgPackagr) {
throw new SchematicsException(
`Project "${options.project}" is using the "${target.builder}" builder, which is not supported by the entry-point schematic. ` +
`Please migrate to "${Builders.BuildLibrary}" before generating entry points.`,
);
}
}

if (options.name === 'package.json') {
Expand Down Expand Up @@ -118,7 +120,7 @@ export default createProjectSchematic<EntryPointOptions>((options, { project, tr
: options.project
: basename(options.name);

const buildOptions = buildTarget.options;
const buildOptions = project.targets.get('build')?.options;
const distRoot =
typeof buildOptions?.['outputPath'] === 'string'
? buildOptions['outputPath']
Expand Down
38 changes: 33 additions & 5 deletions packages/schematics/angular/entry-point/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,42 @@ describe('EntryPoint Schematic', () => {
).toBeRejectedWithError('Project "my-app" is not a library project.');
});

it('should throw if the library project does not use @angular/build:library', async () => {
for (const builder of [
'@angular/build:ng-packagr',
'@angular-devkit/build-angular:ng-packagr',
]) {
it(`should throw if the library project uses ${builder}`, async () => {
const angularJson = getJsonFileContent(workspaceTree, '/angular.json');
angularJson.projects.foo.architect.build.builder = builder;
workspaceTree.overwrite('/angular.json', JSON.stringify(angularJson, null, 2));

await expectAsync(
schematicRunner.runSchematic('entry-point', defaultOptions, workspaceTree),
).toBeRejectedWithError(
`Project "foo" is using the "${builder}" builder, which is not supported by the entry-point schematic. ` +
'Please migrate to "@angular/build:library" before generating entry points.',
);
});
}

it('should allow library projects using a custom builder', async () => {
const angularJson = getJsonFileContent(workspaceTree, '/angular.json');
angularJson.projects.foo.architect.build.builder = '@angular/build:ng-packagr';
angularJson.projects.foo.architect.build.builder = '@custom/builders:library';
workspaceTree.overwrite('/angular.json', JSON.stringify(angularJson, null, 2));

await expectAsync(
schematicRunner.runSchematic('entry-point', defaultOptions, workspaceTree),
).toBeRejectedWithError('Project "foo" does not use the "@angular/build:library" builder.');
const tree = await schematicRunner.runSchematic('entry-point', defaultOptions, workspaceTree);
expect(tree.files).toContain('/projects/foo/secondary/src/public-api.ts');
});

it('should allow library projects with no build target', async () => {
const angularJson = getJsonFileContent(workspaceTree, '/angular.json');
delete angularJson.projects.foo.architect.build;
workspaceTree.overwrite('/angular.json', JSON.stringify(angularJson, null, 2));

const tree = await schematicRunner.runSchematic('entry-point', defaultOptions, workspaceTree);
expect(tree.files).toContain('/projects/foo/secondary/src/public-api.ts');
const tsConfigJson = getJsonFileContent(tree, '/tsconfig.json');
expect(tsConfigJson.compilerOptions.paths['foo/*']).toEqual(['./dist/foo/*']);
});

it('should throw if the library package.json is missing', async () => {
Expand Down
Loading