From d35cb7f188fd1e8cd590912cd541ecbe0580e0d1 Mon Sep 17 00:00:00 2001 From: Gudine Date: Tue, 9 Jul 2024 15:39:00 -0300 Subject: [PATCH] Backslash-related fixes for Windows (#151) * fix: makes glob patterns accept backslashes as separators again * fix: normalizes tree view path separator on Windows * style: fixes lint error --------- Co-authored-by: Westbrook Johnson --- src/core.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 31dc35ff..6562a42b 100644 --- a/src/core.js +++ b/src/core.js @@ -277,7 +277,12 @@ export function filesToTree(allFiles, level = 0) { */ export async function writeFilesToDisk() { const treeFiles = []; - const root = process.cwd(); + const root = process.cwd().replace(/\\/g, '/'); + + virtualFiles.forEach((vFile, i) => { + virtualFiles[i].path = vFile.path.replace(/\\/g, '/'); + }); + virtualFiles.sort((a, b) => { const pathA = a.path.toLowerCase(); const pathB = b.path.toLowerCase(); @@ -369,7 +374,7 @@ export function copyTemplate(fromPath, toPath, data, ejsOptions = {}) { */ export function copyTemplates(fromGlob, toDir = process.cwd(), data = {}, ejsOptions = {}) { return new Promise(resolve => { - glob(fromGlob, { dot: true }, (er, files) => { + glob(fromGlob, { dot: true, windowsPathsNoEscape: true }, (er, files) => { const copiedFiles = []; files.forEach(filePath => { if (!fs.lstatSync(filePath).isDirectory()) {