From 0126f945180253bf00116419b09a04a5d2c26bdd Mon Sep 17 00:00:00 2001 From: yuanchuan Date: Mon, 19 Feb 2024 14:49:02 +0800 Subject: [PATCH] Prevent error from creating files/dirs under temp dir. Fix 130 --- lib/has-native-recursive.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/has-native-recursive.js b/lib/has-native-recursive.js index 19c1b88..49092be 100644 --- a/lib/has-native-recursive.js +++ b/lib/has-native-recursive.js @@ -76,7 +76,17 @@ module.exports = function hasNativeRecursive(fn) { var child = stack.create('dir', parent); var file = stack.create('file', child); - stack.mkdir(parent, child); + try { + stack.mkdir(parent, child); + } catch (e) { + stack = new TempStack(); + // try again under current directory + TEMP_DIR = process.cwd(); + parent = stack.create('dir', TEMP_DIR); + child = stack.create('dir', parent); + file = stack.create('file', child); + stack.mkdir(parent, child); + } var options = { recursive: true }; var watcher;