Skip to content

Commit 9d82814

Browse files
committed
fix(@schematics/angular): Library should support pascalCasedNames
fixes angular/angular-cli#10255
1 parent 4096f40 commit 9d82814

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}`,
@@ -176,7 +176,7 @@ export default function (options: LibraryOptions): Rule {
176176

177177
const workspace = getWorkspace(host);
178178
const newProjectRoot = workspace.newProjectRoot;
179-
const projectRoot = `${newProjectRoot}/${options.name}`;
179+
const projectRoot = `${newProjectRoot}/${strings.dasherize(options.name)}`;
180180
const sourceDir = `${projectRoot}/src/lib`;
181181
const relativeTsLintPath = projectRoot.split('/').map(x => '..').join('/');
182182

@@ -195,7 +195,7 @@ export default function (options: LibraryOptions): Rule {
195195

196196
return chain([
197197
branchAndMerge(mergeWith(templateSource)),
198-
addAppToWorkspaceFile(options, workspace),
198+
addAppToWorkspaceFile(options, workspace, projectRoot),
199199
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
200200
options.skipTsConfig ? noop() : updateTsConfig(name),
201201
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',
@@ -83,6 +84,17 @@ describe('Library Schematic', () => {
8384
expect(workspace.projects.foo).toBeDefined();
8485
});
8586

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

0 commit comments

Comments
 (0)