From 11d276062237ddf2fcb1c826debde36f4cb6d409 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Sat, 9 May 2026 13:53:35 +0200 Subject: [PATCH] Scripts: fallback to CP + rm for cross-disk dir move --- scripts/sandbox/generate.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/sandbox/generate.ts b/scripts/sandbox/generate.ts index 8fdcadadd2f7..32519f8e8c44 100755 --- a/scripts/sandbox/generate.ts +++ b/scripts/sandbox/generate.ts @@ -85,6 +85,20 @@ const emptyDir = async (dir: string): Promise => { await Promise.all(names.map((name) => rm(join(dir, name), { recursive: true, force: true }))); }; +const moveDir = async (from: string, to: string): Promise => { + try { + await rename(from, to); + } catch (error) { + // On some platforms (notably Windows), rename doesn't work across different disks volumes + if ((error as NodeJS.ErrnoException).code !== 'EXDEV') { + throw error; + } + + await cp(from, to, { recursive: true }); + await rm(from, { recursive: true, force: true }); + } +}; + const addStorybook = async ({ localRegistry, baseDir, @@ -266,7 +280,7 @@ const runGenerators = async ( await localizeYarnConfigFiles(createBaseDir, createBeforeDir); // Now move the created before dir into it's final location and add storybook - await rename(createBeforeDir, beforeDir); + await moveDir(createBeforeDir, beforeDir); // Make sure there are no git projects in the folder await rm(join(beforeDir, '.git'), { recursive: true, force: true });