Skip to content

Commit 4f6b98d

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

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • packages/angular_devkit/schematics/src/rules

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ 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
}
30-
});
36+
37+
return tree;
38+
};
3139
}

0 commit comments

Comments
 (0)