Skip to content

Commit

Permalink
refactor(@schematics/angular): improve feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefiozie committed Jan 13, 2025
1 parent 50434a9 commit 518ff9f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
3 changes: 3 additions & 0 deletions packages/angular/cli/lib/config/workspace-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
"@schematics/angular:library": {
"$ref": "../../../../schematics/angular/library/schema.json"
},
"@schematics/angular:library-entrypoint": {
"$ref": "../../../../schematics/angular/library-entrypoint/schema.json"
},
"@schematics/angular:pipe": {
"$ref": "../../../../schematics/angular/pipe/schema.json"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/schematics/angular/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@
"schema": "./library/schema.json",
"description": "Generate a library project for Angular."
},
"library-secondary-entrypoint": {
"aliases": ["secondary"],
"factory": "./secondary-entrypoint",
"schema": "./secondary-entrypoint/schema.json",
"description": "Generate a secondary-entrypoint in a library project for Angular."
"library-entrypoint": {
"aliases": ["lib-entry"],
"factory": "./library-entrypoint",
"schema": "./library-entrypoint/schema.json",
"description": "Generate an library-entrypoint in an Angular library project."
},
"web-worker": {
"factory": "./web-worker",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
url,
} from '@angular-devkit/schematics';
import { JSONFile } from '../utility/json-file';
import { latestVersions } from '../utility/latest-versions';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { buildDefaultPath, getWorkspace } from '../utility/workspace';
import { ProjectType } from '../utility/workspace-models';
Expand All @@ -34,7 +33,7 @@ function updateTsConfig(packageName: string, ...paths: string[]) {
const file = new JSONFile(host, 'tsconfig.json');
const jsonPath = ['compilerOptions', 'paths', packageName];
const value = file.get(jsonPath);
file.modify(jsonPath, Array.isArray(value) ? [...value, ...paths] : paths);
file.modify(jsonPath, Array.isArray(value) ? [...paths, ...value] : paths);
};
}

Expand All @@ -50,7 +49,7 @@ export default function (options: LibraryOptions): Rule {

if (project?.extensions.projectType !== ProjectType.Library) {
throw new SchematicsException(
`Secondary Entrypoint schematic requires a project type of "library".`,
`Library entrypoint schematic requires a project type of "library".`,
);
}

Expand Down Expand Up @@ -81,8 +80,6 @@ export default function (options: LibraryOptions): Rule {
secondaryEntryPoint,
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(libDir),
packageName: options.name,
angularLatestVersion: latestVersions.Angular.replace(/~|\^/, ''),
tsLibLatestVersion: latestVersions['tslib'].replace(/~|\^/, ''),
}),
move(libDir),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "SchematicsLibrary",
"title": "Secondary Entrypoint Schema",
"title": "Library Entrypoint Schema",
"type": "object",
"description": "Creates a secondary entrypoint in a library project in a project.",
"description": "Generate an library entrypoint in an Angular library project.",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"description": "The name of the library.",
"pattern": "^(?:@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*/)?[a-zA-Z0-9-~][a-zA-Z0-9-._~]*$",
"pattern": "^[a-zA-Z0-9-._~]+/?[a-zA-Z0-9-._~]+$",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use for the secondary entrypoint?"
"x-prompt": "What name would you like to use for the entrypoint?"
},
"project": {
"type": "string",
Expand All @@ -30,5 +30,8 @@
"default": "public-api"
}
},
"required": ["name", "project"]
}
"required": [
"name",
"project"
]
}
3 changes: 2 additions & 1 deletion tests/legacy-cli/e2e/tests/build/library-with-demo-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { updateJsonFile } from '../../utils/project';

export default async function () {
await ng('generate', 'library', 'mylib');
await createLibraryEntryPoint('secondary');
await ng('generate', 'lib-entry', 'secondary');
// await createLibraryEntryPoint('secondary');
await createLibraryEntryPoint('another');

// Scenario #1 where we use wildcard path mappings for secondary entry-points.
Expand Down

0 comments on commit 518ff9f

Please sign in to comment.