From 17d5fdb4b000481eb78d6efead400abc5ad15176 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 15 Mar 2025 13:41:58 +0100 Subject: [PATCH 01/28] build(copy-dist): get rid of manual node_module copying this is useless at the moment, as all build processes are running "npm ci --omit=dev" anyways, i.e. they will just install everything remaining again --- bin/copy-dist.ts | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index eaa79808e..67c3579a6 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -11,13 +11,6 @@ function log(...args: any[]) { } } -function copyNodeModuleFileOrFolder(source: string) { - const destination = path.join(DEST_DIR, source); - log(`Copying ${source} to ${destination}`); - fs.ensureDirSync(path.dirname(destination)); - fs.copySync(source, destination); -} - try { const assetsToCopy = new Set([ @@ -61,47 +54,6 @@ try { fs.copySync(dir, path.join(PUBLIC_DIR, path.basename(dir))); } - const nodeModulesFile = new Set([ - "node_modules/react/umd/react.production.min.js", - "node_modules/react/umd/react.development.js", - "node_modules/react-dom/umd/react-dom.production.min.js", - "node_modules/react-dom/umd/react-dom.development.js", - "node_modules/katex/dist/katex.min.js", - "node_modules/katex/dist/contrib/mhchem.min.js", - "node_modules/katex/dist/contrib/auto-render.min.js", - "node_modules/@highlightjs/cdn-assets/highlight.min.js", - ]); - - const nodeModulesFolder = new Set([ - "node_modules/@excalidraw/excalidraw/dist/prod/fonts/", - "node_modules/katex/dist/", - "node_modules/dayjs/", - "node_modules/boxicons/css/", - "node_modules/boxicons/fonts/", - "node_modules/jquery/dist/", - "node_modules/jquery-hotkeys/", - "node_modules/split.js/dist/", - "node_modules/i18next/", - "node_modules/i18next-http-backend/", - "node_modules/vanilla-js-wheel-zoom/dist/", - "node_modules/mark.js/dist/", - "node_modules/normalize.css/", - "node_modules/jquery.fancytree/dist/", - "node_modules/autocomplete.js/dist/", - "node_modules/codemirror/lib/", - "node_modules/codemirror/addon/", - "node_modules/codemirror/mode/", - "node_modules/codemirror/keymap/", - "node_modules/@highlightjs/cdn-assets/languages", - "node_modules/@highlightjs/cdn-assets/styles", - "node_modules/leaflet/dist" - ]); - - - - for (const nodeModuleItem of [...nodeModulesFile, ...nodeModulesFolder]) { - copyNodeModuleFileOrFolder(nodeModuleItem); - } console.log("Copying complete!") } catch(err) { From 164000029110227fb94c71ed5e245ffa321df30b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 01:04:17 +0100 Subject: [PATCH 02/28] build(build-server): move "build:prepare-dist" call to build-server from copy-trilium in preparation to get rid of the file altogether - rest of the functionality will be merged into copy-dist.ts --- bin/build-server.sh | 6 ++++++ bin/copy-trilium.sh | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/build-server.sh b/bin/build-server.sh index 052a8131b..fc1807ee0 100755 --- a/bin/build-server.sh +++ b/bin/build-server.sh @@ -26,6 +26,12 @@ NODE_VERSION=22.14.0 BUILD_DIR="./build" DIST_DIR="./dist" + +# Trigger the build +echo "Build start" +npm run build:prepare-dist +echo "Build finished" + ./bin/copy-trilium.sh NODE_FILENAME=node-v${NODE_VERSION}-linux-${ARCH} diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index 55c5cf6de..b80c97632 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -10,11 +10,6 @@ if ! [[ $(which npm) ]]; then exit 1 fi -# Trigger the build -echo Build start -npm run build:prepare-dist -echo Build finished - # Patch package.json main sed -i 's|./dist/electron-main.js|electron-main.js|g' "$BUILD_DIR/package.json" From 89774929811ab3da35b3eaeb359f4cd26a77bc59 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 01:12:55 +0100 Subject: [PATCH 03/28] build(copy-dist): move "pruning" to copy-dist from copy-trilium.sh --- bin/copy-dist.ts | 4 ++++ bin/copy-trilium.sh | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 67c3579a6..2505c31c3 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -1,5 +1,6 @@ import fs from "fs-extra"; import path from "path"; +import { execSync } from "node:child_process"; const DEST_DIR = "./build"; @@ -56,6 +57,9 @@ try { console.log("Copying complete!") + // TriliumNextTODO: for Docker this needs to run separately *after* build-stage + console.log("Pruning npm packages...") + execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`); } catch(err) { console.error("Error during copy:", err) process.exit(1) diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index b80c97632..515c3ccc6 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -13,9 +13,6 @@ fi # Patch package.json main sed -i 's|./dist/electron-main.js|electron-main.js|g' "$BUILD_DIR/package.json" -# run in subshell (so we return to original dir) -(cd $BUILD_DIR && npm ci --omit=dev) - if [[ -d "$BUILD_DIR"/node_modules ]]; then # cleanup of useless files in dependencies for d in 'image-q/demo' \ From 6fb270e4f8d8ed5c8a0367fb47ea59463b0bfade Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 01:17:46 +0100 Subject: [PATCH 04/28] build(copy-dist): copy over existing node_modules helps avoiding downloading the packages a 2nd time during our prune stage --- bin/copy-dist.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 2505c31c3..6d9fcf0e0 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -15,6 +15,7 @@ function log(...args: any[]) { try { const assetsToCopy = new Set([ + // copy node_module, to avoid downloading packages a 2nd time during pruning "./node_modules", "./images", "./libraries", From 8feb201d3d0c7a0490b8467fbdf006b5b3f7dbe2 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 01:21:21 +0100 Subject: [PATCH 05/28] build(electron-forge): set prune to false since we our own more "sophisticated" pruning during copy-dist, we need to set this to false, as otherwise build will fail --- forge.config.cjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/forge.config.cjs b/forge.config.cjs index ba3d8c3ff..763cb80e8 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -18,6 +18,8 @@ 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, From bee7793d32a5dc01b2342d5caee075afa3b03174 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 01:30:52 +0100 Subject: [PATCH 06/28] build(copy-trilium): remove now unnecessary package.json patching this is not needed anymore since commit 6b9d8f0d677763f29d29abd0816b1a5d40e858c8 --- bin/copy-trilium.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index 515c3ccc6..629138048 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -10,9 +10,6 @@ if ! [[ $(which npm) ]]; then exit 1 fi -# Patch package.json main -sed -i 's|./dist/electron-main.js|electron-main.js|g' "$BUILD_DIR/package.json" - if [[ -d "$BUILD_DIR"/node_modules ]]; then # cleanup of useless files in dependencies for d in 'image-q/demo' \ From 6260ea1532e284c67b450f20fd80808063a94f8b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 01:50:59 +0100 Subject: [PATCH 07/28] build(copy-dist): add initial cleanupNodeModules functionality adapted from copy-trilium.sh --- bin/copy-dist.ts | 23 +++++++++++++++++++++++ bin/copy-trilium.sh | 5 ----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 6d9fcf0e0..f5901225b 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -61,7 +61,30 @@ try { // TriliumNextTODO: for Docker this needs to run separately *after* build-stage console.log("Pruning npm packages...") execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`); + + cleanupNodeModules(); + } catch(err) { console.error("Error during copy:", err) process.exit(1) } +function cleanupNodeModules() { + const nodeDir = fs.readdirSync(path.join(DEST_DIR, "./node_modules"), { recursive: true, withFileTypes: true }); + + const filterableDirs = new Set([ + "test", + "docs", + "demo", + "example", + ]); + + const filteredDirs = nodeDir + .filter(el => el.isDirectory() && filterableDirs.has(el.name)) + .map(el => path.join(DEST_DIR, el.parentPath, el.name)); + + filteredDirs.forEach(dir => { + fs.removeSync(dir); + }) + +} + diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index 629138048..e99bf08b9 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -19,11 +19,6 @@ if [[ -d "$BUILD_DIR"/node_modules ]]; then '@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do [[ -e "$BUILD_DIR"/node_modules/"$d" ]] && rm -r "$BUILD_DIR"/node_modules/"$d" done - - # delete all tests (there are often large images as test file for jimp etc.) - for d in 'test' 'docs' 'demo' 'example'; do - find "$BUILD_DIR"/node_modules -name "$d" -exec rm -rf {} + - done fi find $BUILD_DIR/libraries -name "*.map" -type f -delete From a9643174ccc5b990e9b846abe90e36e4ec000780 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 01:53:14 +0100 Subject: [PATCH 08/28] build(copy-dist): add further folders to list of filterableDirs same as before, but some of the modules use singular/plural, so just check for both --- bin/copy-dist.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index f5901225b..586650811 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -72,10 +72,14 @@ function cleanupNodeModules() { const nodeDir = fs.readdirSync(path.join(DEST_DIR, "./node_modules"), { recursive: true, withFileTypes: true }); const filterableDirs = new Set([ - "test", - "docs", "demo", + "demos", + "doc", + "docs", "example", + "examples", + "test", + "tests" ]); const filteredDirs = nodeDir From 8275f3c867fff674db44e938f96ce059fa3002df Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 02:10:47 +0100 Subject: [PATCH 09/28] build(copy-dist): execute filterableDirs cleanup in one chain --- bin/copy-dist.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 586650811..38413b1b9 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -82,13 +82,10 @@ function cleanupNodeModules() { "tests" ]); - const filteredDirs = nodeDir + nodeDir .filter(el => el.isDirectory() && filterableDirs.has(el.name)) - .map(el => path.join(DEST_DIR, el.parentPath, el.name)); - - filteredDirs.forEach(dir => { - fs.removeSync(dir); - }) + .map(el => path.join(DEST_DIR, el.parentPath, el.name)) + .forEach(dir => fs.removeSync(dir)); } From 6749d8084bb6f8b56aa330ef6d7d0d0790f3a29c Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 02:15:17 +0100 Subject: [PATCH 10/28] build(copy-dist): add further cleanupNodeModules functionality deleting of ts and map files from node_modules folder, adapted from copy-trilium.sh. --- bin/copy-dist.ts | 13 +++++++++++++ bin/copy-trilium.sh | 2 -- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 38413b1b9..9fb520907 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -87,5 +87,18 @@ function cleanupNodeModules() { .map(el => path.join(DEST_DIR, el.parentPath, el.name)) .forEach(dir => fs.removeSync(dir)); + + // Delete unnecessary files based on file extension + const filterableFileExt = new Set([ + "ts", + "map" + ]) + + nodeDir + // TriliumNextTODO: check if we can improve this naive file ext matching + .filter(el => el.isFile() && filterableFileExt.has(el.name.split(".").at(-1) || "")) + .map(file => path.join(DEST_DIR, file.parentPath, file.name)) + .forEach(file => fs.removeSync(file)); + } diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index e99bf08b9..6aea1175c 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -22,7 +22,5 @@ if [[ -d "$BUILD_DIR"/node_modules ]]; then fi find $BUILD_DIR/libraries -name "*.map" -type f -delete -find $BUILD_DIR/node_modules -name "*.map" -type f -delete -find $BUILD_DIR -name "*.ts" -type f -delete unset f d BUILD_DIR From cd8401089d19532d1fa2dc5ebdea79200ec34630 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 16 Mar 2025 02:33:27 +0100 Subject: [PATCH 11/28] build(copy-trilium): update list of useless deps paths * image-q/demo -> doesn't exist anymore (and even if it did - previous cleanup step, would've removed this anyways) * @excalidraw/excalidraw/dist/* -> updated to point to the dev folder * boxicons -> only fonts and css folders are used, so remove the other ones * jimp -> updated paths and removed non-existent path fixing here for historical reasons, next step is to move these over to copy-dist.ts --- bin/copy-trilium.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index 6aea1175c..f6030a6ec 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -12,11 +12,11 @@ fi if [[ -d "$BUILD_DIR"/node_modules ]]; then # cleanup of useless files in dependencies - for d in 'image-q/demo' \ - '@excalidraw/excalidraw/dist/excalidraw-assets-dev' '@excalidraw/excalidraw/dist/excalidraw.development.js' '@excalidraw/excalidraw/dist/excalidraw-with-preact.development.js' \ + for d in \ + '@excalidraw/excalidraw/dist/dev' \ 'mermaid/dist/mermaid.js' \ - 'boxicons/svg' 'boxicons/node_modules/react'/* \ - '@jimp/plugin-print/fonts' 'jimp/browser' 'jimp/fonts'; do + 'boxicons/svg' 'boxicons/node_modules' 'boxicons/src' 'boxicons/iconjar' \ + '@jimp/plugin-print/fonts' 'jimp/dist/browser'; do [[ -e "$BUILD_DIR"/node_modules/"$d" ]] && rm -r "$BUILD_DIR"/node_modules/"$d" done fi From 1ceaafa1e88323eb106f00a451515f34d1e62bb2 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 25 Mar 2025 09:02:03 +0100 Subject: [PATCH 12/28] 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 --- Dockerfile | 1 + Dockerfile.alpine | 1 + bin/cleanupNodeModules.ts | 87 +++++++++++++++++++++++++++++++++++++++ bin/copy-dist.ts | 41 ++---------------- forge.config.cjs | 19 ++++++++- 5 files changed, 110 insertions(+), 39 deletions(-) create mode 100644 bin/cleanupNodeModules.ts diff --git a/Dockerfile b/Dockerfile index 4aac3160f..538f3e58f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ RUN npm ci && \ /usr/src/app/build \ /tmp/node-compile-cache +#TODO: run cleanupNodeModules script #TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work # currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down), # as we install necessary dependencies in runtime buildstage anyways diff --git a/Dockerfile.alpine b/Dockerfile.alpine index f83789399..595d21561 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -18,6 +18,7 @@ RUN npm ci && \ /usr/src/app/build \ /tmp/node-compile-cache +#TODO: run cleanupNodeModules script #TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work # currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down), # as we install necessary dependencies in runtime buildstage anyways diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts new file mode 100644 index 000000000..2daf7c01b --- /dev/null +++ b/bin/cleanupNodeModules.ts @@ -0,0 +1,87 @@ +import fs from "fs-extra"; +import path from "path"; + +function main() { + if (process.argv.length !== 3) { + console.error("More than one path was supplied as argument. Aborting."); + process.exit(1); + } + + const basePath = process.argv[2]; + + if (!fs.existsSync(basePath)) { + console.error(`Supplied path '${basePath}' does not exist. Aborting.`) + process.exit(1); + } + + cleanupNodeModules(basePath); +} + +function cleanupNodeModules(basePath: string) { + const nodeDir = fs.readdirSync(path.join(basePath, "./node_modules"), { recursive: true, withFileTypes: true }); + //const libDir = fs.readdirSync(path.join(basePath, "./libraries"), { recursive: true, withFileTypes: true }); + + /** + * Delete unnecessary folders + */ + const filterableDirs = new Set([ + "demo", + "demos", + "doc", + "docs", + "example", + "examples", + "test", + "tests" + ]); + + nodeDir + .filter(el => el.isDirectory() && filterableDirs.has(el.name)) + .forEach(dir => fs.removeSync(path.join(dir.parentPath, dir.name))); + + + /** + * Delete unnecessary files based on file extension + * TODO filter out useless (README).md files + */ + const filterableFileExt = new Set([ + "ts", + "map" + ]); + + nodeDir + // TriliumNextTODO: check if we can improve this naive file ext matching, without introducing any additional dependency + .filter(el => el.isFile() && filterableFileExt.has(el.name.split(".").at(-1) || "")) + .forEach(file => fs.removeSync(path.join(file.parentPath, file.name))); + + + /** + * Delete specific unnecessary folders + * TODO: use basePath + * TODO: check if we want removeSync to throw an error, if path does not exist anymore -> currently it will silently fail + */ + const extraFoldersDelete = new Set([ + 'build/node_modules/@excalidraw/excalidraw/dist/dev', + 'build/node_modules/boxicons/svg', + 'build/node_modules/boxicons/node_modules', + 'build/node_modules/boxicons/src', + 'build/node_modules/boxicons/iconjar', + 'build/node_modules/@jimp/plugin-print/fonts', + 'build/node_modules/jimp/dist/browser' + // "node_modules/@excalidraw/excalidraw/dist/dev", + // "node_modules/jimp/browser", + // "node_modules/@jimp/plugin-print/fonts", + // "node_modules/jimp/dist/browser", + // "node_modules/jimp/fonts", + // "node_modules/boxicons/svg", + // "node_modules/boxicons/node_modules/react", + // "node_modules/mermaid/dist/mermaid.js" + ]); + + nodeDir + .filter(el => el.isDirectory() && extraFoldersDelete.has(path.join(el.parentPath, el.name))) + .forEach(dir => fs.removeSync(path.join(dir.parentPath, dir.name))) + +} + +main() \ No newline at end of file diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 9fb520907..e04edee0c 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -28,6 +28,7 @@ try { "./README.md", "./forge.config.cjs", "./bin/tpl/", + "./bin/cleanupNodeModules.ts", "./bin/electron-forge/desktop.ejs", "./bin/electron-forge/sign-windows.cjs", "./src/views/", @@ -59,46 +60,12 @@ try { console.log("Copying complete!") // TriliumNextTODO: for Docker this needs to run separately *after* build-stage - console.log("Pruning npm packages...") - execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`); - - cleanupNodeModules(); + // Disable for now, because this messes with electron-forge as well + //console.log("Pruning npm packages...") + //execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`); } catch(err) { console.error("Error during copy:", err) process.exit(1) } -function cleanupNodeModules() { - const nodeDir = fs.readdirSync(path.join(DEST_DIR, "./node_modules"), { recursive: true, withFileTypes: true }); - - const filterableDirs = new Set([ - "demo", - "demos", - "doc", - "docs", - "example", - "examples", - "test", - "tests" - ]); - - nodeDir - .filter(el => el.isDirectory() && filterableDirs.has(el.name)) - .map(el => path.join(DEST_DIR, el.parentPath, el.name)) - .forEach(dir => fs.removeSync(dir)); - - - // Delete unnecessary files based on file extension - const filterableFileExt = new Set([ - "ts", - "map" - ]) - - nodeDir - // TriliumNextTODO: check if we can improve this naive file ext matching - .filter(el => el.isFile() && filterableFileExt.has(el.name.split(".").at(-1) || "")) - .map(file => path.join(DEST_DIR, file.parentPath, file.name)) - .forEach(file => fs.removeSync(file)); - -} diff --git a/forge.config.cjs b/forge.config.cjs index 763cb80e8..1a7e5a3c6 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -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 From 3e3344b3294a6ba70460ee94474a3083d7c130d1 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 25 Mar 2025 09:03:54 +0100 Subject: [PATCH 13/28] chore(scripts): remove now unneeded electron-forge:prepare --- package.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ec931d8bb..7d998ee90 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,9 @@ "electron:switch": "electron-rebuild", "docs:edit": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_ENV=dev TRILIUM_PORT=37741 electron ./electron-docs-main.ts .", "docs:edit-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_PORT=37741 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-docs-main.ts .\"", - "electron-forge:prepare": "npm run build:prepare-dist", - "electron-forge:start": "npm run electron-forge:prepare && cd ./build && electron-forge start", - "electron-forge:make": "npm run electron-forge:prepare && cross-env DEBUG=electron-windows-installer:* electron-forge make ./build", - "electron-forge:package": "npm run electron-forge:prepare && cd ./build && electron-forge package", + "electron-forge:start": "npm run build:prepare-dist && cd ./build && electron-forge start", + "electron-forge:make": "npm run build:prepare-dist && cross-env DEBUG=electron-windows-installer:* electron-forge make ./build", + "electron-forge:package": "npm run build:prepare-dist && cd ./build && electron-forge package", "docs:build-backend": "rimraf ./docs/backend_api && typedoc ./docs/backend_api src/becca/entities/*.ts src/services/backend_script_api.ts src/services/sql.ts", "docs:build-frontend": "rimraf ./docs/frontend_api && jsdoc -c jsdoc-conf.json -d ./docs/frontend_api src/public/app/entities/*.js src/public/app/services/frontend_script_api.js src/public/app/widgets/basic_widget.js src/public/app/widgets/note_context_aware_widget.js src/public/app/widgets/right_panel_widget.js", "docs:build": "npm run docs:build-backend && npm run docs:build-frontend", @@ -232,7 +231,6 @@ "lorem-ipsum": "2.0.8", "mind-elixir": "4.4.3", "mini-css-extract-plugin": "2.9.2", - "node-abi": "4.2.0", "nodemon": "3.1.9", "postcss-loader": "8.1.1", "prettier": "3.5.3", From f79b925e490c962296a6521ba0fda09d404471f1 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 25 Mar 2025 09:18:41 +0100 Subject: [PATCH 14/28] build(server): use cleanupNodeModules script --- bin/build-server.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/build-server.sh b/bin/build-server.sh index fc1807ee0..26dc19ad3 100755 --- a/bin/build-server.sh +++ b/bin/build-server.sh @@ -25,6 +25,7 @@ NODE_VERSION=22.14.0 BUILD_DIR="./build" DIST_DIR="./dist" +CLEANUP_SCRIPT="./bin/cleanupNodeModules.ts" # Trigger the build @@ -32,7 +33,7 @@ echo "Build start" npm run build:prepare-dist echo "Build finished" -./bin/copy-trilium.sh +node --experimental-strip-types $CLEANUP_SCRIPT $BUILD_DIR NODE_FILENAME=node-v${NODE_VERSION}-linux-${ARCH} From 57ee61938d2abb5f40dd22aa902fcd2bda633fd5 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 25 Mar 2025 09:19:48 +0100 Subject: [PATCH 15/28] build(copy-trilium): delete now unused script all of its functionality has been "absorbed" by the cross-platform copy-dist and cleanupNodeModules scripts, that can be used for all of our builds now --- bin/copy-trilium.sh | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100755 bin/copy-trilium.sh diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh deleted file mode 100755 index f6030a6ec..000000000 --- a/bin/copy-trilium.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -e # Fail on any command error -shopt -s globstar - -BUILD_DIR="./build" - -if ! [[ $(which npm) ]]; then - echo "Missing npm" - exit 1 -fi - -if [[ -d "$BUILD_DIR"/node_modules ]]; then - # cleanup of useless files in dependencies - for d in \ - '@excalidraw/excalidraw/dist/dev' \ - 'mermaid/dist/mermaid.js' \ - 'boxicons/svg' 'boxicons/node_modules' 'boxicons/src' 'boxicons/iconjar' \ - '@jimp/plugin-print/fonts' 'jimp/dist/browser'; do - [[ -e "$BUILD_DIR"/node_modules/"$d" ]] && rm -r "$BUILD_DIR"/node_modules/"$d" - done -fi - -find $BUILD_DIR/libraries -name "*.map" -type f -delete - -unset f d BUILD_DIR From 83da24b38d8a23d78ff8f607264390bbb1cd80ae Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 25 Mar 2025 09:21:40 +0100 Subject: [PATCH 16/28] build(dockerignore): add cleanupNodeModules as exception --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 2ceb847c9..32795ae0a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -35,6 +35,7 @@ npm-debug.log # exceptions !/bin/copy-dist.ts !/bin/electron-forge/sign-windows.cjs +!/bin/cleanupNodeModules.ts # temporary exception to make copy-dist inside Docker build not fail # TriliumNextTODO: make copy-dist *not* requiring to copy this file for builds other than electron-forge From b457fa2e874fafd65e1c539092f8c239c19a74f7 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 26 Mar 2025 09:12:22 +0100 Subject: [PATCH 17/28] chore(cleanupNodeModules): rename nodeDir to nodeModulesContent --- bin/cleanupNodeModules.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts index 2daf7c01b..072214ce9 100644 --- a/bin/cleanupNodeModules.ts +++ b/bin/cleanupNodeModules.ts @@ -18,7 +18,7 @@ function main() { } function cleanupNodeModules(basePath: string) { - const nodeDir = fs.readdirSync(path.join(basePath, "./node_modules"), { recursive: true, withFileTypes: true }); + const nodeModulesContent = fs.readdirSync(path.join(basePath, "./node_modules"), { recursive: true, withFileTypes: true }); //const libDir = fs.readdirSync(path.join(basePath, "./libraries"), { recursive: true, withFileTypes: true }); /** @@ -35,7 +35,7 @@ function cleanupNodeModules(basePath: string) { "tests" ]); - nodeDir + nodeModulesContent .filter(el => el.isDirectory() && filterableDirs.has(el.name)) .forEach(dir => fs.removeSync(path.join(dir.parentPath, dir.name))); @@ -49,7 +49,7 @@ function cleanupNodeModules(basePath: string) { "map" ]); - nodeDir + nodeModulesContent // TriliumNextTODO: check if we can improve this naive file ext matching, without introducing any additional dependency .filter(el => el.isFile() && filterableFileExt.has(el.name.split(".").at(-1) || "")) .forEach(file => fs.removeSync(path.join(file.parentPath, file.name))); @@ -78,7 +78,7 @@ function cleanupNodeModules(basePath: string) { // "node_modules/mermaid/dist/mermaid.js" ]); - nodeDir + nodeModulesContent .filter(el => el.isDirectory() && extraFoldersDelete.has(path.join(el.parentPath, el.name))) .forEach(dir => fs.removeSync(path.join(dir.parentPath, dir.name))) From 6fe23f9a136713f10c0b0bff541bb173b60cf579 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 26 Mar 2025 09:15:33 +0100 Subject: [PATCH 18/28] chore(cleanupNodeModules): remove commented out paths extra note on mermaid: that should be packed by webpack now, so we just need to move it to devDeps and and we should be good --- bin/cleanupNodeModules.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts index 072214ce9..975b83af3 100644 --- a/bin/cleanupNodeModules.ts +++ b/bin/cleanupNodeModules.ts @@ -68,14 +68,6 @@ function cleanupNodeModules(basePath: string) { 'build/node_modules/boxicons/iconjar', 'build/node_modules/@jimp/plugin-print/fonts', 'build/node_modules/jimp/dist/browser' - // "node_modules/@excalidraw/excalidraw/dist/dev", - // "node_modules/jimp/browser", - // "node_modules/@jimp/plugin-print/fonts", - // "node_modules/jimp/dist/browser", - // "node_modules/jimp/fonts", - // "node_modules/boxicons/svg", - // "node_modules/boxicons/node_modules/react", - // "node_modules/mermaid/dist/mermaid.js" ]); nodeModulesContent From 1150f78b158b93ac1329b9d35c82ad3537c5facd Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 26 Mar 2025 09:18:16 +0100 Subject: [PATCH 19/28] build(cleanupNodeModules): use path.join and basePath for extraFoldersDelete --- bin/cleanupNodeModules.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts index 975b83af3..2885f1484 100644 --- a/bin/cleanupNodeModules.ts +++ b/bin/cleanupNodeModules.ts @@ -18,7 +18,8 @@ function main() { } function cleanupNodeModules(basePath: string) { - const nodeModulesContent = fs.readdirSync(path.join(basePath, "./node_modules"), { recursive: true, withFileTypes: true }); + const nodeModulesDirPath = path.join(basePath, "node_modules"); + const nodeModulesContent = fs.readdirSync(nodeModulesDirPath, { recursive: true, withFileTypes: true }); //const libDir = fs.readdirSync(path.join(basePath, "./libraries"), { recursive: true, withFileTypes: true }); /** @@ -39,7 +40,6 @@ function cleanupNodeModules(basePath: string) { .filter(el => el.isDirectory() && filterableDirs.has(el.name)) .forEach(dir => fs.removeSync(path.join(dir.parentPath, dir.name))); - /** * Delete unnecessary files based on file extension * TODO filter out useless (README).md files @@ -57,17 +57,16 @@ function cleanupNodeModules(basePath: string) { /** * Delete specific unnecessary folders - * TODO: use basePath * TODO: check if we want removeSync to throw an error, if path does not exist anymore -> currently it will silently fail */ const extraFoldersDelete = new Set([ - 'build/node_modules/@excalidraw/excalidraw/dist/dev', - 'build/node_modules/boxicons/svg', - 'build/node_modules/boxicons/node_modules', - 'build/node_modules/boxicons/src', - 'build/node_modules/boxicons/iconjar', - 'build/node_modules/@jimp/plugin-print/fonts', - 'build/node_modules/jimp/dist/browser' + path.join(nodeModulesDirPath, "@excalidraw", "excalidraw", "dist", "dev"), + path.join(nodeModulesDirPath, "boxicons", "svg"), + path.join(nodeModulesDirPath, "boxicons", "node_modules"), + path.join(nodeModulesDirPath, "boxicons", "src"), + path.join(nodeModulesDirPath, "boxicons", "iconjar"), + path.join(nodeModulesDirPath, "@jimp", "plugin-print", "fonts"), + path.join(nodeModulesDirPath, "jimp", "dist", "browser") // missing "@" in front of jimp is not a typo here ]); nodeModulesContent From 1528703ed98a7ce8ab6c259eb9bd0cec8911b84f Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 26 Mar 2025 09:26:22 +0100 Subject: [PATCH 20/28] build(cleanupNodeModules): add some minimalistic logging --- bin/cleanupNodeModules.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts index 2885f1484..e20004747 100644 --- a/bin/cleanupNodeModules.ts +++ b/bin/cleanupNodeModules.ts @@ -1,6 +1,12 @@ import fs from "fs-extra"; import path from "path"; +/** + * Example usage with node >= v22: + * node --experimental-strip-types bin/cleanupNodeModules.ts /path/to/build/folder + * Example usage with tsx: + * tsx bin/cleanupNodeModules.ts /path/to/build/folder + */ function main() { if (process.argv.length !== 3) { console.error("More than one path was supplied as argument. Aborting."); @@ -13,8 +19,9 @@ function main() { console.error(`Supplied path '${basePath}' does not exist. Aborting.`) process.exit(1); } - + console.log(`Starting node_modules pruning in '${basePath}'...`) cleanupNodeModules(basePath); + console.log("Successfully pruned node_modules.") } function cleanupNodeModules(basePath: string) { From 51f2e23c2f88631a2465de143500d1bbb7367cec Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 26 Mar 2025 09:28:50 +0100 Subject: [PATCH 21/28] build(cleanupNodeModules): delete .bin folder this is only needed for executing package scripts -> which we don't do in production fixes #1499 --- bin/cleanupNodeModules.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts index e20004747..c5df07da9 100644 --- a/bin/cleanupNodeModules.ts +++ b/bin/cleanupNodeModules.ts @@ -67,6 +67,7 @@ function cleanupNodeModules(basePath: string) { * TODO: check if we want removeSync to throw an error, if path does not exist anymore -> currently it will silently fail */ const extraFoldersDelete = new Set([ + path.join(nodeModulesDirPath, ".bin"), path.join(nodeModulesDirPath, "@excalidraw", "excalidraw", "dist", "dev"), path.join(nodeModulesDirPath, "boxicons", "svg"), path.join(nodeModulesDirPath, "boxicons", "node_modules"), From 0b428035ae0254642b101d0fc402f3e03aa9534a Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 26 Mar 2025 09:47:06 +0100 Subject: [PATCH 22/28] build(cleanupNodeModules): move removal of elements to its own function also added a logging function for debugging purposes --- bin/cleanupNodeModules.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts index c5df07da9..d811c95a1 100644 --- a/bin/cleanupNodeModules.ts +++ b/bin/cleanupNodeModules.ts @@ -45,7 +45,7 @@ function cleanupNodeModules(basePath: string) { nodeModulesContent .filter(el => el.isDirectory() && filterableDirs.has(el.name)) - .forEach(dir => fs.removeSync(path.join(dir.parentPath, dir.name))); + .forEach(dir => removeDirent(dir)); /** * Delete unnecessary files based on file extension @@ -59,7 +59,7 @@ function cleanupNodeModules(basePath: string) { nodeModulesContent // TriliumNextTODO: check if we can improve this naive file ext matching, without introducing any additional dependency .filter(el => el.isFile() && filterableFileExt.has(el.name.split(".").at(-1) || "")) - .forEach(file => fs.removeSync(path.join(file.parentPath, file.name))); + .forEach(dir => removeDirent(dir)); /** @@ -79,7 +79,17 @@ function cleanupNodeModules(basePath: string) { nodeModulesContent .filter(el => el.isDirectory() && extraFoldersDelete.has(path.join(el.parentPath, el.name))) - .forEach(dir => fs.removeSync(path.join(dir.parentPath, dir.name))) + .forEach(dir => removeDirent(dir)) +} + +function removeDirent(el: Dirent) { + const elementToDelete = path.join(el.parentPath, el.name); + fs.removeSync(elementToDelete); + + if (process.env.VERBOSE) { + console.log(`Deleted ${elementToDelete}`); + } + } From 75431ca634860d6b0af15b434b209cc47e81f521 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 27 Mar 2025 00:00:41 +0100 Subject: [PATCH 23/28] build: make running of npm ci in build scripts configurable * moved the running of npm ci from copy-dist to cleanupNodeModules * added flag to disable it (necessary for electron-forge) --- Dockerfile | 1 + Dockerfile.alpine | 5 ++++- bin/build-server.sh | 1 + bin/cleanupNodeModules.ts | 33 +++++++++++++++++++++++---------- bin/copy-dist.ts | 6 ------ forge.config.cjs | 2 +- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 538f3e58f..0ee13f25d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,6 +40,7 @@ COPY --from=builder /usr/src/app ./ RUN sed -i "/electron/d" package.json && \ npm ci --omit=dev && \ + node --experimental-strip-types ./bin/cleanupNodeModules.ts . --skip-prune-dev-deps && \ npm cache clean --force && \ rm -rf /tmp/node-compile-cache diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 595d21561..943030943 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -35,8 +35,11 @@ COPY --from=builder /usr/src/app ./ RUN sed -i "/electron/d" package.json && \ npm ci --omit=dev && \ + node --experimental-strip-types ./bin/cleanupNodeModules.ts . --skip-prune-dev-deps && \ npm cache clean --force && \ - rm -rf /tmp/node-compile-cache + rm -rf \ + /tmp/node-compile-cache \ + ./bin/cleanupNodeModules.ts # Add application user RUN adduser -s /bin/false node; exit 0 diff --git a/bin/build-server.sh b/bin/build-server.sh index 26dc19ad3..6677d7c19 100755 --- a/bin/build-server.sh +++ b/bin/build-server.sh @@ -33,6 +33,7 @@ echo "Build start" npm run build:prepare-dist echo "Build finished" +# pruning of unnecessary files and devDeps in node_modules node --experimental-strip-types $CLEANUP_SCRIPT $BUILD_DIR NODE_FILENAME=node-v${NODE_VERSION}-linux-${ARCH} diff --git a/bin/cleanupNodeModules.ts b/bin/cleanupNodeModules.ts index d811c95a1..bb3e90331 100644 --- a/bin/cleanupNodeModules.ts +++ b/bin/cleanupNodeModules.ts @@ -1,30 +1,43 @@ import fs from "fs-extra"; import path from "path"; +import type { Dirent } from "fs-extra"; +import { execSync } from "node:child_process"; /** * Example usage with node >= v22: - * node --experimental-strip-types bin/cleanupNodeModules.ts /path/to/build/folder + * node --experimental-strip-types bin/cleanupNodeModules.ts /path/to/build/folder [--skip-prune-dev-deps] * Example usage with tsx: - * tsx bin/cleanupNodeModules.ts /path/to/build/folder + * tsx bin/cleanupNodeModules.ts /path/to/build/folder [--skip-prune-dev-deps] */ function main() { - if (process.argv.length !== 3) { - console.error("More than one path was supplied as argument. Aborting."); + + if (process.argv.length > 4 || process.argv.length < 3) { + console.error("Usage: cleanupNodeModules.ts [path-to-build-folder] [--skip-prune-dev-deps]"); process.exit(1); } const basePath = process.argv[2]; + const pruneDevDeps = process.argv[3] !== "--skip-prune-dev-deps"; if (!fs.existsSync(basePath)) { - console.error(`Supplied path '${basePath}' does not exist. Aborting.`) + console.error(`Supplied path '${basePath}' does not exist. Aborting.`); process.exit(1); } - console.log(`Starting node_modules pruning in '${basePath}'...`) - cleanupNodeModules(basePath); - console.log("Successfully pruned node_modules.") + + console.log(`Starting pruning of node_modules ${!pruneDevDeps ? '(skipping npm pruning)' : ''} in '${basePath}'...`); + cleanupNodeModules(basePath, pruneDevDeps); + console.log("Successfully pruned node_modules."); } -function cleanupNodeModules(basePath: string) { +function cleanupNodeModules(basePath: string, pruneDevDeps: boolean = true) { + + // This needs to run for the server and Docker build, + // but needs to be skipped for electron-forge: its + // built-in pruning takes care of it already + if (pruneDevDeps) { + execSync(`npm ci --omit=dev --prefix ${basePath}`); + } + const nodeModulesDirPath = path.join(basePath, "node_modules"); const nodeModulesContent = fs.readdirSync(nodeModulesDirPath, { recursive: true, withFileTypes: true }); //const libDir = fs.readdirSync(path.join(basePath, "./libraries"), { recursive: true, withFileTypes: true }); @@ -82,6 +95,7 @@ function cleanupNodeModules(basePath: string) { .forEach(dir => removeDirent(dir)) } + function removeDirent(el: Dirent) { const elementToDelete = path.join(el.parentPath, el.name); fs.removeSync(elementToDelete); @@ -90,7 +104,6 @@ function removeDirent(el: Dirent) { console.log(`Deleted ${elementToDelete}`); } - } main() \ No newline at end of file diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index e04edee0c..404cf0991 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -1,6 +1,5 @@ import fs from "fs-extra"; import path from "path"; -import { execSync } from "node:child_process"; const DEST_DIR = "./build"; @@ -59,11 +58,6 @@ try { console.log("Copying complete!") - // TriliumNextTODO: for Docker this needs to run separately *after* build-stage - // Disable for now, because this messes with electron-forge as well - //console.log("Pruning npm packages...") - //execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`); - } catch(err) { console.error("Error during copy:", err) process.exit(1) diff --git a/forge.config.cjs b/forge.config.cjs index 1a7e5a3c6..b94b2756e 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -47,7 +47,7 @@ module.exports = { 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}'`; + const command = `node --experimental-strip-types ${cleanupNodeModulesScript} '${buildPath}' --skip-prune-dev-deps`; // execSync throws, if above returns any non-zero exit code execSync(command); callback() From e9fa37c4eeecdc2fc6fb65d6fdd02774262300cc Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 27 Mar 2025 09:04:10 +0100 Subject: [PATCH 24/28] chore(docker): remove TODO --- Dockerfile | 1 - Dockerfile.alpine | 1 - 2 files changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0ee13f25d..abf8b0920 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,6 @@ RUN npm ci && \ /usr/src/app/build \ /tmp/node-compile-cache -#TODO: run cleanupNodeModules script #TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work # currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down), # as we install necessary dependencies in runtime buildstage anyways diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 943030943..40b00c48f 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -18,7 +18,6 @@ RUN npm ci && \ /usr/src/app/build \ /tmp/node-compile-cache -#TODO: run cleanupNodeModules script #TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work # currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down), # as we install necessary dependencies in runtime buildstage anyways From d5bc9841e3e9bc76521221638dfa309f93b9ed7a Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 27 Mar 2025 09:05:17 +0100 Subject: [PATCH 25/28] build(docker): use absolute path to stay consistent --- Dockerfile.alpine | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 40b00c48f..88a450723 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -36,9 +36,9 @@ RUN sed -i "/electron/d" package.json && \ npm ci --omit=dev && \ node --experimental-strip-types ./bin/cleanupNodeModules.ts . --skip-prune-dev-deps && \ npm cache clean --force && \ - rm -rf \ + rm -rf \ /tmp/node-compile-cache \ - ./bin/cleanupNodeModules.ts + /usr/src/app/bin/cleanupNodeModules.ts # Add application user RUN adduser -s /bin/false node; exit 0 From fa0358662a39716eb69178602c1419bb018798d6 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 27 Mar 2025 09:06:09 +0100 Subject: [PATCH 26/28] build(docker): add missing cleanupNodeModules removal to Dockerfile previously forgot to add this here as well -> had it only in the Dockerfile.alpine --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index abf8b0920..635a44d3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,7 +41,9 @@ RUN sed -i "/electron/d" package.json && \ npm ci --omit=dev && \ node --experimental-strip-types ./bin/cleanupNodeModules.ts . --skip-prune-dev-deps && \ npm cache clean --force && \ - rm -rf /tmp/node-compile-cache + rm -rf \ + /tmp/node-compile-cache \ + /usr/src/app/bin/cleanupNodeModules.ts # Configure container EXPOSE 8080 From 6218ae6cd7a8919db248061a6ead505f2acd72b3 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 27 Mar 2025 09:07:29 +0100 Subject: [PATCH 27/28] chore(docker): move exception below TODO comment --- .dockerignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index 32795ae0a..1ca391a43 100644 --- a/.dockerignore +++ b/.dockerignore @@ -34,11 +34,11 @@ npm-debug.log # exceptions !/bin/copy-dist.ts -!/bin/electron-forge/sign-windows.cjs !/bin/cleanupNodeModules.ts # temporary exception to make copy-dist inside Docker build not fail -# TriliumNextTODO: make copy-dist *not* requiring to copy this file for builds other than electron-forge +# TriliumNextTODO: make copy-dist *not* requiring to copy these file for builds other than electron-forge !forge.config.cjs !/bin/tpl -!/bin/electron-forge/desktop.ejs \ No newline at end of file +!/bin/electron-forge/desktop.ejs +!/bin/electron-forge/sign-windows.cjs \ No newline at end of file From 9fe37465c73ef9675b3e3168f0e53d22116d2fb3 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 27 Mar 2025 09:35:48 +0100 Subject: [PATCH 28/28] build(electron-forge): use double quotes for the buildPath in afterPrune attempt to fix failing Windows build in CI, which uses cmd shell, which apparently treats single apostrophes differently --- forge.config.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge.config.cjs b/forge.config.cjs index b94b2756e..8d5b5d22e 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -47,7 +47,7 @@ module.exports = { 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}' --skip-prune-dev-deps`; + const command = `node --experimental-strip-types ${cleanupNodeModulesScript} "${buildPath}" --skip-prune-dev-deps`; // execSync throws, if above returns any non-zero exit code execSync(command); callback()