diff --git a/src/js/core/plugin.js b/src/js/core/plugin.js index 85ca39a1..0ff7fc7a 100644 --- a/src/js/core/plugin.js +++ b/src/js/core/plugin.js @@ -806,29 +806,33 @@ class PluginLoader { await fs.ensureDir(targetPath); const copyFiles = async (dir, baseTarget, baseSource) => { - const items = await fs.readdir(dir, { withFileTypes: true }); const ignoreFiles = ['.', 'package.json', 'package-lock.json', 'LICENSE']; - for (const item of items) { - if (item.name.startsWith('.') || ignoreFiles.includes(item.name)) { - continue; - } + try { + const items = await fs.promises.readdir(dir, { withFileTypes: true }); + + await fs.promises.mkdir(baseTarget, { recursive: true }); + + for (const item of items) { + if (item.name.startsWith('.') || ignoreFiles.includes(item.name)) { + continue; + } - const sourceFull = path.join(dir, item.name); - const targetFull = path.join(baseTarget, path.relative(baseSource, sourceFull)); + const sourceFull = path.join(dir, item.name); + const targetFull = path.join(baseTarget, path.relative(baseSource, sourceFull)); - try { if (item.isDirectory()) { - await fs.ensureDir(targetFull); + await fs.promises.mkdir(targetFull, { recursive: true }); await copyFiles(sourceFull, baseTarget, baseSource); } else { - await fs.copyFile(sourceFull, targetFull); + await fs.promises.copyFile(sourceFull, targetFull); } } - catch (error) { - console.error(`Error copying ${sourceFull}:`, error); - } + } + catch (error) { + console.error(`Error in directory ${dir}:`, error); + throw error; } };