Skip to content

Commit 9636cf2

Browse files
committed
fixup! feat(@schematics/angular): use library builder and add entry-point schematic
1 parent b4486a5 commit 9636cf2

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎packages/schematics/angular/entry-point/index.ts‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,14 @@ export default createProjectSchematic<EntryPointOptions>((options, { project, tr
5656
throw new SchematicsException('Entry point name "package.json" is reserved.');
5757
}
5858

59-
const libDir = project.root;
60-
const sourceRoot = project.sourceRoot ?? join(libDir, 'src');
61-
const relativeSourceRoot = relative(libDir, sourceRoot);
62-
if (
63-
relativeSourceRoot &&
64-
!relativeSourceRoot.startsWith('..') &&
65-
(options.name === relativeSourceRoot || options.name.startsWith(`${relativeSourceRoot}/`))
66-
) {
59+
if (options.name === 'src' || options.name.startsWith('src/')) {
6760
throw new SchematicsException(
68-
`Entry point name "${options.name}" cannot be "${relativeSourceRoot}" or start with "${relativeSourceRoot}/" ` +
61+
`Entry point name "${options.name}" cannot be "src" or start with "src/" ` +
6962
'as it conflicts with the primary entry point source directory.',
7063
);
7164
}
7265

66+
const libDir = project.root;
7367
const packageJsonPath = join(libDir, 'package.json');
7468
if (!tree.exists(packageJsonPath)) {
7569
throw new SchematicsException(`Could not find package.json at "${packageJsonPath}".`);
@@ -84,7 +78,7 @@ export default createProjectSchematic<EntryPointOptions>((options, { project, tr
8478

8579
const isPrimary = options.name === '.';
8680
const entryFile = (options.entryFile ?? 'public-api').replace(/\.ts$/i, '');
87-
const entryPointDir = isPrimary ? sourceRoot : join(libDir, options.name, 'src');
81+
const entryPointDir = join(libDir, options.name, 'src');
8882
const exportKey = isPrimary ? '.' : `./${options.name}`;
8983
const exportTarget = `./${relative(libDir, join(entryPointDir, `${entryFile}.ts`))}`;
9084

‎packages/schematics/angular/library/index_spec.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ describe('Library Schematic', () => {
441441

442442
const workspace = JSON.parse(tree.readContent('/angular.json'));
443443
expect(workspace.projects.foo.architect.test.builder).toBe('@angular/build:unit-test');
444-
expect(workspace.projects.foo.architect.test.options.include).toEqual(['../**/*.spec.ts']);
445444

446445
const specTsConfig = getJsonFileContent(tree, '/projects/foo/tsconfig.spec.json');
447446
expect(specTsConfig.include).toEqual(['**/*.d.ts', '**/*.spec.ts']);

‎packages/schematics/angular/utility/workspace.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ export async function writeWorkspace(
116116
* @param project The project which will have its default path generated.
117117
*/
118118
export function buildDefaultPath(project: workspaces.ProjectDefinition): string {
119-
const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`;
119+
const root =
120+
project.sourceRoot && project.sourceRoot !== project.root
121+
? `/${project.sourceRoot}/`
122+
: `/${project.root}/src/`;
120123
const projectDirName =
121124
project.extensions['projectType'] === ProjectType.Application ? 'app' : 'lib';
122125

‎tests/e2e/tests/vitest/library.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ export default async function (): Promise<void> {
2828
};
2929
});
3030

31+
// 3. Update the component to use SCSS and import the shared file
32+
// Rename CSS to SCSS
33+
await ng('generate', 'component', 'styled-comp', '--project=my-lib', '--style=scss');
34+
35+
await appendToFile(
36+
'projects/my-lib/src/lib/styled-comp/styled-comp.scss',
37+
`
38+
@use 'vars';
39+
p { color: vars.$primary-color; }
40+
`,
41+
);
42+
43+
// 4. Generate a secondary entry point and verify its tests are also executed
44+
await ng('generate', 'entry-point', 'secondary', '--project=my-lib');
45+
3146
// Run the library tests
3247
const { stdout } = await ng('test', 'my-lib');
3348

0 commit comments

Comments
 (0)