Skip to content

Commit 57230d0

Browse files
committed
refactor: make small changes and excluded tests
1 parent fa0daa3 commit 57230d0

File tree

7 files changed

+17
-66
lines changed

7 files changed

+17
-66
lines changed

packages/schematics/angular/collection.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"aliases": ["lib-entry"],
122122
"factory": "./library-entrypoint",
123123
"schema": "./library-entrypoint/schema.json",
124-
"description": "Generate an library-entrypoint in an Angular library project."
124+
"description": "Generate a library-entrypoint in an Angular library project."
125125
},
126126
"web-worker": {
127127
"factory": "./web-worker",
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# <%= secondaryEntryPoint %>
22

3-
Secondary entry point of `<%= mainEntryPoint %>`. It can be used by importing from `<%= secondaryEntryPoint %>`.
3+
Secondary entry point of `<%= mainEntryPoint %>`. It can be used by importing from `<%= secondaryEntryPoint %>`

packages/schematics/angular/library-entrypoint/files/src/__entryFile__.ts.template

-5
This file was deleted.

packages/schematics/angular/library-entrypoint/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default function (options: LibraryOptions): Rule {
5959

6060
const pkg = host.readJson(pkgPath) as { name: string } | null;
6161
if (pkg === null) {
62-
throw new SchematicsException('Could not find package.json');
62+
throw new SchematicsException(`Could not find ${pkgPath}`);
6363
}
6464

6565
const mainEntryPoint = pkg.name;
@@ -80,6 +80,8 @@ export default function (options: LibraryOptions): Rule {
8080
secondaryEntryPoint,
8181
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(libDir),
8282
packageName: options.name,
83+
//TODO: fix this
84+
entryFile: 'index.ts',
8385
}),
8486
move(libDir),
8587
]);

packages/schematics/angular/library-entrypoint/index_spec.ts

+7-29
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88

99
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
10+
import { parse as parseJson } from 'jsonc-parser';
1011
import { Schema as LibraryOptions } from '../library/schema';
1112
import { Schema as WorkspaceOptions } from '../workspace/schema';
1213
import { Schema as GenerateLibrarySchema } from './schema';
13-
import { parse as parseJson } from 'jsonc-parser';
1414

1515
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1616
function getJsonFileContent(tree: UnitTestTree, path: string): any {
@@ -35,7 +35,6 @@ describe('Secondary Entrypoint Schematic', () => {
3535
};
3636
const libaryOptions: LibraryOptions = {
3737
name: 'foo',
38-
entryFile: 'my-index',
3938
standalone: true,
4039
skipPackageJson: false,
4140
skipTsConfig: false,
@@ -45,12 +44,12 @@ describe('Secondary Entrypoint Schematic', () => {
4544
let workspaceTree: UnitTestTree;
4645
beforeEach(async () => {
4746
workspaceTree = await schematicRunner.runSchematic('workspace', workspaceOptions);
47+
workspaceTree = await schematicRunner.runSchematic('library', libaryOptions, workspaceTree);
4848
});
4949

5050
it('should create correct files', async () => {
51-
workspaceTree = await schematicRunner.runSchematic('library', libaryOptions, workspaceTree);
5251
const tree = await schematicRunner.runSchematic(
53-
'secondary',
52+
'library-entrypoint',
5453
{ ...defaultOptions },
5554
workspaceTree,
5655
);
@@ -60,47 +59,28 @@ describe('Secondary Entrypoint Schematic', () => {
6059
jasmine.arrayContaining([
6160
'/projects/foo/src/lib/foo-secondary/README.md',
6261
'/projects/foo/src/lib/foo-secondary/ng-package.json',
63-
'/projects/foo/src/lib/foo-secondary/src/public-api.ts',
6462
]),
6563
);
6664
});
6765

6866
it('should set correct main and secondary entrypoints in the README', async () => {
69-
workspaceTree = await schematicRunner.runSchematic('library', libaryOptions, workspaceTree);
7067
const tree = await schematicRunner.runSchematic(
71-
'secondary',
68+
'library-entrypoint',
7269
{ ...defaultOptions },
7370
workspaceTree,
7471
);
7572
const content = tree.readContent('/projects/foo/src/lib/foo-secondary/README.md');
7673
expect(content).toMatch('# foo/foo-secondary');
7774
});
7875

79-
it('should set a custom entryfile', async () => {
80-
workspaceTree = await schematicRunner.runSchematic('library', libaryOptions, workspaceTree);
81-
const tree = await schematicRunner.runSchematic(
82-
'secondary',
83-
{ ...defaultOptions, entryFile: 'my-index' },
84-
workspaceTree,
85-
);
86-
const files = tree.files;
87-
expect(files).toEqual(
88-
jasmine.arrayContaining([
89-
'/projects/foo/src/lib/foo-secondary/README.md',
90-
'/projects/foo/src/lib/foo-secondary/ng-package.json',
91-
'/projects/foo/src/lib/foo-secondary/src/my-index.ts',
92-
]),
93-
);
94-
});
95-
9676
it('should handle scope packages', async () => {
9777
workspaceTree = await schematicRunner.runSchematic(
9878
'library',
9979
{ ...libaryOptions, name: '@scope/package' },
10080
workspaceTree,
10181
);
10282
const tree = await schematicRunner.runSchematic(
103-
'secondary',
83+
'library-entrypoint',
10484
{ ...defaultOptions, name: 'testing', project: '@scope/package' },
10585
workspaceTree,
10686
);
@@ -109,7 +89,6 @@ describe('Secondary Entrypoint Schematic', () => {
10989
jasmine.arrayContaining([
11090
'/projects/scope/package/src/lib/testing/README.md',
11191
'/projects/scope/package/src/lib/testing/ng-package.json',
112-
'/projects/scope/package/src/lib/testing/src/public-api.ts',
11392
]),
11493
);
11594
});
@@ -121,7 +100,7 @@ describe('Secondary Entrypoint Schematic', () => {
121100
workspaceTree,
122101
);
123102
const tree = await schematicRunner.runSchematic(
124-
'secondary',
103+
'library-entrypoint',
125104
{ ...defaultOptions, name: 'testing', project: '@scope/package' },
126105
workspaceTree,
127106
);
@@ -150,14 +129,13 @@ describe('Secondary Entrypoint Schematic', () => {
150129
}),
151130
);
152131
const tree = await schematicRunner.runSchematic(
153-
'secondary',
132+
'library-entrypoint',
154133
{ ...defaultOptions, name: 'testing', project: '@scope/package' },
155134
workspaceTree,
156135
);
157136

158137
const tsConfigJson = getJsonFileContent(tree, 'tsconfig.json');
159138
expect(tsConfigJson.compilerOptions.paths['@scope/package/testing']).toEqual([
160-
'libs/*',
161139
'./dist/scope/package/testing',
162140
]);
163141
});

packages/schematics/angular/library-entrypoint/schema.json

+4-13
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"$id": "SchematicsLibrary",
44
"title": "Library Entrypoint Schema",
55
"type": "object",
6-
"description": "Generate an library entrypoint in an Angular library project.",
6+
"description": "Generate a library entrypoint in an Angular library project.",
77
"additionalProperties": false,
88
"properties": {
99
"name": {
1010
"type": "string",
11-
"description": "The name of the library.",
11+
"description": "The name of the entrypoint to create.",
1212
"pattern": "^[a-zA-Z0-9-._~]+/?[a-zA-Z0-9-._~]+$",
1313
"$default": {
1414
"$source": "argv",
@@ -22,16 +22,7 @@
2222
"$default": {
2323
"$source": "projectName"
2424
}
25-
},
26-
"entryFile": {
27-
"type": "string",
28-
"format": "path",
29-
"description": "The path at which to create the library's secondary public API file, relative to the workspace root.",
30-
"default": "public-api"
3125
}
3226
},
33-
"required": [
34-
"name",
35-
"project"
36-
]
37-
}
27+
"required": ["name", "project"]
28+
}

tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts

+1-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { updateJsonFile } from '../../utils/project';
1313
export default async function () {
1414
await ng('generate', 'library', 'mylib');
1515
await ng('generate', 'lib-entry', 'secondary');
16-
// await createLibraryEntryPoint('secondary');
17-
await createLibraryEntryPoint('another');
16+
await ng('generate', 'lib-entry', 'another');
1817

1918
// Scenario #1 where we use wildcard path mappings for secondary entry-points.
2019
await updateJsonFile('tsconfig.json', (json) => {
@@ -48,17 +47,3 @@ export default async function () {
4847

4948
await ng('build');
5049
}
51-
52-
async function createLibraryEntryPoint(name: string): Promise<void> {
53-
await createDir(`projects/mylib/${name}`);
54-
await writeFile(`projects/mylib/${name}/index.ts`, `export const foo = 'foo';`);
55-
56-
await writeFile(
57-
`projects/mylib/${name}/ng-package.json`,
58-
JSON.stringify({
59-
lib: {
60-
entryFile: 'index.ts',
61-
},
62-
}),
63-
);
64-
}

0 commit comments

Comments
 (0)