Skip to content

Commit 18b7093

Browse files
committed
fix(@schematics/angular): Library should support pascalCasedNames
fixes angular/angular-cli#10255
1 parent 5918b7c commit 18b7093

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/schematics/angular/library/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ function addDependenciesToPackageJson() {
118118
};
119119
}
120120

121-
function addAppToWorkspaceFile(options: LibraryOptions, workspace: WorkspaceSchema): Rule {
121+
function addAppToWorkspaceFile(options: LibraryOptions, workspace: WorkspaceSchema,
122+
projectRoot: string): Rule {
122123
return (host: Tree, context: SchematicContext) => {
123124

124-
const projectRoot = `${workspace.newProjectRoot}/${options.name}`;
125125
// tslint:disable-next-line:no-any
126126
const project: any = {
127127
root: `${projectRoot}`,
@@ -175,7 +175,7 @@ export default function (options: LibraryOptions): Rule {
175175

176176
const workspace = getWorkspace(host);
177177
const newProjectRoot = workspace.newProjectRoot;
178-
const projectRoot = `${newProjectRoot}/${options.name}`;
178+
const projectRoot = `${newProjectRoot}/${strings.dasherize(options.name)}`;
179179
const sourceDir = `${projectRoot}/src/lib`;
180180

181181
const templateSource = apply(url('./files'), [
@@ -191,7 +191,7 @@ export default function (options: LibraryOptions): Rule {
191191

192192
return chain([
193193
branchAndMerge(mergeWith(templateSource)),
194-
addAppToWorkspaceFile(options, workspace),
194+
addAppToWorkspaceFile(options, workspace, projectRoot),
195195
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
196196
options.skipTsConfig ? noop() : updateTsConfig(name),
197197
schematic('module', {

packages/schematics/angular/library/index_spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function getJsonFileContent(tree: UnitTestTree, path: string) {
1616
return JSON.parse(tree.readContent(path));
1717
}
1818

19+
// tslint:disable:max-line-length
1920
describe('Library Schematic', () => {
2021
const schematicRunner = new SchematicTestRunner(
2122
'@schematics/ng_packagr',
@@ -82,6 +83,17 @@ describe('Library Schematic', () => {
8283
expect(workspace.projects.foo).toBeDefined();
8384
});
8485

86+
it('should handle a pascalCasedName', () => {
87+
const options = {...defaultOptions, name: 'pascalCasedName'};
88+
const tree = schematicRunner.runSchematic('library', options, workspaceTree);
89+
const config = getJsonFileContent(tree, '/angular.json');
90+
const project = config.projects.pascalCasedName;
91+
expect(project).toBeDefined();
92+
expect(project.root).toEqual('projects/pascal-cased-name');
93+
const svcContent = tree.readContent('/projects/pascal-cased-name/src/lib/pascal-cased-name.service.ts');
94+
expect(svcContent).toMatch(/providedIn: 'root'/);
95+
});
96+
8597
it('should export the component in the NgModule', () => {
8698
const tree = schematicRunner.runSchematic('library', defaultOptions, workspaceTree);
8799
const fileContent = getFileContent(tree, '/projects/foo/src/lib/foo.module.ts');

0 commit comments

Comments
 (0)