mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
fix: import resolution within plugin modules (#11219)
use module.exports = require('..')
export * from '..' didn't work in some cases
This commit is contained in:
@@ -40,14 +40,24 @@ async function linkModules() {
|
|||||||
await Promise.all(Object.keys(modules).map(async (relPath) => {
|
await Promise.all(Object.keys(modules).map(async (relPath) => {
|
||||||
const srcPath = path.join(__dirname, '../../', modules[relPath]);
|
const srcPath = path.join(__dirname, '../../', modules[relPath]);
|
||||||
const destPath = path.join(__dirname, '../../build/public/src/modules', relPath);
|
const destPath = path.join(__dirname, '../../build/public/src/modules', relPath);
|
||||||
|
const destDir = path.dirname(destPath);
|
||||||
|
|
||||||
const [stats] = await Promise.all([
|
const [stats] = await Promise.all([
|
||||||
fs.promises.stat(srcPath),
|
fs.promises.stat(srcPath),
|
||||||
mkdirp(path.dirname(destPath)),
|
mkdirp(destDir),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
await file.linkDirs(srcPath, destPath, true);
|
await file.linkDirs(srcPath, destPath, true);
|
||||||
} else {
|
} 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, `module.exports = require('${relPath}');`);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user