From 9b4ba3af4d214d429478504aadc0e7cfcb652715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 15 May 2023 20:54:36 +0100 Subject: [PATCH] fix(core): normalize path in tree when accessing recorded changes (#17016) --- packages/nx/src/generators/tree.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/nx/src/generators/tree.ts b/packages/nx/src/generators/tree.ts index 73f636ce85cb9..5c24df08819ea 100644 --- a/packages/nx/src/generators/tree.ts +++ b/packages/nx/src/generators/tree.ts @@ -223,8 +223,11 @@ export class FsTree implements Tree { isDeleted: true, }; - // Delete directories when - if (this.children(dirname(this.rp(filePath))).length < 1) { + // Delete directory when is not root and there are no children + if ( + filePath !== '' && + this.children(dirname(this.rp(filePath))).length < 1 + ) { this.delete(dirname(this.rp(filePath))); } } @@ -282,7 +285,7 @@ export class FsTree implements Tree { res = [...res, ...this.directChildrenOfDir(this.rp(dirPath))]; res = res.filter((q) => { - const r = this.recordedChanges[join(this.rp(dirPath), q)]; + const r = this.recordedChanges[this.normalize(join(this.rp(dirPath), q))]; return !r?.isDeleted; }); // Dedupe