Skip to content

Commit 0ea3c44

Browse files
committed
refactor(@angular-devkit/schematics): improve performance of move()
1 parent 0c4b4a6 commit 0ea3c44

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • packages/angular_devkit/schematics/src/rules

packages/angular_devkit/schematics/src/rules/move.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ export function move(from: string, to?: string): Rule {
2323
return noop;
2424
}
2525

26-
return tree => tree.visit(path => {
27-
if (path.startsWith(fromPath)) {
28-
tree.rename(path, toPath + '/' + path.substr(fromPath.length));
26+
return tree => {
27+
if (tree.exists(fromPath)) {
28+
// fromPath is a file
29+
tree.rename(fromPath, toPath);
30+
} else {
31+
// fromPath is a directory
32+
tree.getDir(fromPath).visit(path => {
33+
tree.rename(path, toPath + '/' + path.substr(fromPath.length));
34+
});
2935
}
36+
return tree;
3037
});
3138
}

0 commit comments

Comments
 (0)