chore(monorepo/server): find workaround to copy node modules

This commit is contained in:
Elian Doran 2025-04-18 21:52:50 +03:00
parent 81e6537007
commit 2325fbc72d
No known key found for this signature in database

View File

@ -28,6 +28,29 @@ function copyAssets(baseDir: string, destDir: string, files: string[]) {
} }
} }
/**
* Copies the dependencies from the node_modules directory to the build directory.
* We cannot copy the node_modules directory directly because we are in a monorepo and all the packages are gathered at root level.
*
* @param packageJsonPath
*/
function copyNodeModules(packageJsonPath: string) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const dependencies = packageJson.dependencies || {};
for (const dependency of Object.keys(dependencies)) {
if (dependency.startsWith("@triliumnext/")) {
// Skip copying @triliumnext dependencies since they are symlinked in the monorepo.
continue;
}
const src = path.join(rootDir, "node_modules", dependency);
const dest = path.join(DEST_DIR, "node_modules", dependency);
log(`${src} -> ${dest}`);
fs.copySync(src, dest);
}
}
try { try {
const clientAssets = [ const clientAssets = [
"./libraries", "./libraries",
@ -59,6 +82,7 @@ try {
"README.md" "README.md"
]; ];
copyNodeModules(path.join(serverDir, "package.json"));
copyAssets(clientDir, path.join(DEST_DIR, "src", "public"), clientAssets); copyAssets(clientDir, path.join(DEST_DIR, "src", "public"), clientAssets);
copyAssets(serverDir, path.join(DEST_DIR), serverAssets); copyAssets(serverDir, path.join(DEST_DIR), serverAssets);
copyAssets(rootDir, path.join(DEST_DIR), rootAssets); copyAssets(rootDir, path.join(DEST_DIR), rootAssets);