Skip to content

Commit af415a2

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): Handle Windows paths for generate names
fixes #11501
1 parent 8fd1040 commit af415a2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/schematics/angular/utility/parse-name.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
* found in the LICENSE file at https://angular.io/license
88
*/
99
// import { relative, Path } from "../../../angular_devkit/core/src/virtual-fs";
10-
import { Path, basename, dirname, normalize } from '@angular-devkit/core';
10+
import { Path, basename, dirname, join, normalize } from '@angular-devkit/core';
1111

1212
export interface Location {
1313
name: string;
1414
path: Path;
1515
}
1616

1717
export function parseName(path: string, name: string): Location {
18-
const nameWithoutPath = basename(name as Path);
19-
const namePath = dirname((path + '/' + name) as Path);
18+
const nameWithoutPath = basename(normalize(name));
19+
const namePath = dirname(join(normalize(path), name) as Path);
2020

2121
return {
2222
name: nameWithoutPath,

packages/schematics/angular/utility/parse-name_spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ describe('parse-name', () => {
3636
it('should handle name has a higher path above root', () => {
3737
expect(() => parseName('src/app', '../../../foo')).toThrow();
3838
});
39+
40+
it('should handle Windows paths', () => {
41+
const result = parseName('', 'foo\\bar\\baz');
42+
expect(result.name).toEqual('baz');
43+
expect(result.path).toEqual('/foo/bar');
44+
});
3945
});

0 commit comments

Comments
 (0)