From 89e059a0841f4265d16b28a99ebf847dd10fa055 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Tue, 24 Jan 2023 17:59:06 -0700 Subject: [PATCH] fix: import resolution within plugin modules (#11200) --- src/meta/js.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/meta/js.js b/src/meta/js.js index 454b682cc3..e7aab11509 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -40,14 +40,24 @@ async function linkModules() { await Promise.all(Object.keys(modules).map(async (relPath) => { const srcPath = path.join(__dirname, '../../', modules[relPath]); const destPath = path.join(__dirname, '../../build/public/src/modules', relPath); + const destDir = path.dirname(destPath); + const [stats] = await Promise.all([ fs.promises.stat(srcPath), - mkdirp(path.dirname(destPath)), + mkdirp(destDir), ]); + if (stats.isDirectory()) { await file.linkDirs(srcPath, destPath, true); } else { - await fs.promises.copyFile(srcPath, destPath); + // Get the relative path to the destination directory + const relPath = path.relative(destDir, srcPath) + // and convert to a posix path + .split(path.sep).join(path.posix.sep); + + // Instead of copying file, create a new file re-exporting it + // This way, imports in modules are resolved correctly + await fs.promises.writeFile(destPath, `export * from '${relPath}'`); } })); }