From 85d8117df6db79972b066f857cd876d8778097ae Mon Sep 17 00:00:00 2001 From: April Smith Date: Tue, 8 Mar 2022 14:40:28 +0000 Subject: [PATCH] Add check if the directory exist https://github.com/nodejs/node/pull/37216 In the future version of node, rmdirSync fails when the directory does not exist This change make sure our script doesn't break after we upgrade node. --- scripts/setup-modules.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/setup-modules.js b/scripts/setup-modules.js index 2e4868aae..9c884b246 100644 --- a/scripts/setup-modules.js +++ b/scripts/setup-modules.js @@ -113,9 +113,12 @@ const copyFonts = print( log("\x1b[32m%s\x1b[0m", "No fonts directory found, skipping"); // green return true; } - - fs.rmdirSync(rubyPath, { recursive: true }); - fs.rmdirSync(npmPath, { recursive: true }); + if (fs.existsSync(rubyPath)) { + fs.rmdirSync(rubyPath, {recursive: true}); + } + if (fs.existsSync(npmPath)) { + fs.rmdirSync(npmPath, {recursive: true}); + } fs.mkdirSync(rubyPath); fs.mkdirSync(npmPath); @@ -138,9 +141,12 @@ const copyImages = print( log("\x1b[32m%s\x1b[0m", "No images directory found, skipping"); // green return true; } - - fs.rmdirSync(rubyPath, { recursive: true }); - fs.rmdirSync(npmPath, { recursive: true }); + if (fs.existsSync(rubyPath)) { + fs.rmdirSync(rubyPath, {recursive: true}); + } + if (fs.existsSync(npmPath)) { + fs.rmdirSync(npmPath, {recursive: true}); + } fs.mkdirSync(rubyPath); fs.mkdirSync(npmPath); @@ -200,8 +206,9 @@ const sync = ({ verbose } = { verbose: false }) => { modules.forEach((mod) => { const rubyPath = rubyPathResolve(mod.directory); - - fs.rmdirSync(rubyPath, { recursive: true }); + if (fs.existsSync(rubyPath)) { + fs.rmdirSync(rubyPath, {recursive: true}); + } fs.mkdirSync(rubyPath); copyRubyModuleConfig(mod);