Skip to content

Commit 85d8117

Browse files
committed
Add check if the directory exist
nodejs/node#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.
1 parent 2bb5f6c commit 85d8117

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

scripts/setup-modules.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ const copyFonts = print(
113113
log("\x1b[32m%s\x1b[0m", "No fonts directory found, skipping"); // green
114114
return true;
115115
}
116-
117-
fs.rmdirSync(rubyPath, { recursive: true });
118-
fs.rmdirSync(npmPath, { recursive: true });
116+
if (fs.existsSync(rubyPath)) {
117+
fs.rmdirSync(rubyPath, {recursive: true});
118+
}
119+
if (fs.existsSync(npmPath)) {
120+
fs.rmdirSync(npmPath, {recursive: true});
121+
}
119122

120123
fs.mkdirSync(rubyPath);
121124
fs.mkdirSync(npmPath);
@@ -138,9 +141,12 @@ const copyImages = print(
138141
log("\x1b[32m%s\x1b[0m", "No images directory found, skipping"); // green
139142
return true;
140143
}
141-
142-
fs.rmdirSync(rubyPath, { recursive: true });
143-
fs.rmdirSync(npmPath, { recursive: true });
144+
if (fs.existsSync(rubyPath)) {
145+
fs.rmdirSync(rubyPath, {recursive: true});
146+
}
147+
if (fs.existsSync(npmPath)) {
148+
fs.rmdirSync(npmPath, {recursive: true});
149+
}
144150

145151
fs.mkdirSync(rubyPath);
146152
fs.mkdirSync(npmPath);
@@ -200,8 +206,9 @@ const sync = ({ verbose } = { verbose: false }) => {
200206

201207
modules.forEach((mod) => {
202208
const rubyPath = rubyPathResolve(mod.directory);
203-
204-
fs.rmdirSync(rubyPath, { recursive: true });
209+
if (fs.existsSync(rubyPath)) {
210+
fs.rmdirSync(rubyPath, {recursive: true});
211+
}
205212
fs.mkdirSync(rubyPath);
206213

207214
copyRubyModuleConfig(mod);

0 commit comments

Comments
 (0)