build: move cleanupNodeModules to its own file

this is necessary, since for Docker and electron-forge, we need to run this as an extra step after copy-dist

for electron-forge: after it is done with its own "pruning", as we otherwise would need to also take care of certain electron related pruning

for Docker: as a last step in the build stage
This commit is contained in:
Panagiotis Papadopoulos
2025-03-25 09:02:03 +01:00
parent cd8401089d
commit 1ceaafa1e8
5 changed files with 110 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
const path = require("path");
const fs = require("fs-extra");
const { execSync } = require("child_process");
const APP_NAME = "TriliumNext Notes";
const BIN_PATH = path.normalize("./bin/electron-forge");
@@ -18,8 +19,6 @@ module.exports = {
// we run electron-forge inside the ./build folder,
// to have it output to ./dist, we need to go up a directory first
outDir: "../dist",
// we prune ourselves via copy-dist
prune: false,
packagerConfig: {
executableName: "trilium",
name: APP_NAME,
@@ -41,6 +40,22 @@ module.exports = {
"translations/",
"node_modules/@highlightjs/cdn-assets/styles"
],
afterPrune: [
(buildPath, _electronVersion, _platform, _arch, callback) => {
// buildPath is a temporary directory that electron-packager creates - it's in the form of
// /tmp/electron-packager/tmp-SjJl0s/resources/app
try {
const cleanupNodeModulesScript = path.join(buildPath, "bin", "cleanupNodeModules.ts");
// we don't have access to any devDeps like 'tsx' here, so use the built-in '--experimental-strip-types' flag instead
const command = `node --experimental-strip-types ${cleanupNodeModulesScript} '${buildPath}'`;
// execSync throws, if above returns any non-zero exit code
execSync(command);
callback()
} catch(err) {
callback(err)
}
}
],
afterComplete: [
(buildPath, _electronVersion, platform, _arch, callback) => {
// Only move resources on non-macOS platforms