From 3ed952849500077bd151ccb0efad1ca389faa083 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 26 Jan 2025 20:54:30 +0100 Subject: [PATCH 1/3] chore(app/share): port to TypeScript --- src/public/app/{share.js => share.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/public/app/{share.js => share.ts} (92%) diff --git a/src/public/app/share.js b/src/public/app/share.ts similarity index 92% rename from src/public/app/share.js rename to src/public/app/share.ts index 3c3282497..844d621a1 100644 --- a/src/public/app/share.js +++ b/src/public/app/share.ts @@ -3,7 +3,7 @@ * * @param noteId of the given note to be fetched. If false, fetches current note. */ -async function fetchNote(noteId = null) { +async function fetchNote(noteId: string | null = null) { if (!noteId) { noteId = document.body.getAttribute("data-note-id"); } From 74f6ad46ae627ae70ba1f25de11d2b9dc520a7c7 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 26 Jan 2025 21:23:08 +0100 Subject: [PATCH 2/3] chore(app/share): add workaround for dead code eliminination by webpack since fetchNote function is not used anywhere, webpack will treat it as "dead code" and remove it from the final output I did not have any success with using webpack config flags like "sideEffects", so I've reverted to this workaround for now --- src/public/app/share.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/public/app/share.ts b/src/public/app/share.ts index 844d621a1..912154986 100644 --- a/src/public/app/share.ts +++ b/src/public/app/share.ts @@ -25,3 +25,9 @@ document.addEventListener( }, false ); + +// workaround to prevent webpack from removing "fetchNote" as dead code: +// add fetchNote as property to the window object +Object.defineProperty(window, "fetchNote", { + value: fetchNote +}); \ No newline at end of file From ad02b86719775aa98a4c34e7fe3ff38c28886bff Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 26 Jan 2025 21:39:34 +0100 Subject: [PATCH 3/3] chore: remove now unnecessary manual copying of share.js this is now correctly handled by the webpack build --- Dockerfile | 1 - Dockerfile.alpine | 1 - bin/copy-trilium.sh | 1 - 3 files changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index a032ac665..959c244a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,6 @@ RUN cp -R build/src/* src/. && \ npm run webpack && \ npm prune --omit=dev && \ npm cache clean --force && \ - cp src/public/app/share.js src/public/app-dist/. && \ cp -r src/public/app/doc_notes src/public/app-dist/. && \ rm -rf src/public/app/* && \ mkdir -p src/public/app/services && \ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 77b0012d6..f7b49b94c 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -27,7 +27,6 @@ RUN cp -R build/src/* src/. && \ npm run webpack && \ npm prune --omit=dev && \ npm cache clean --force && \ - cp src/public/app/share.js src/public/app-dist/. && \ cp -r src/public/app/doc_notes src/public/app-dist/. && \ rm -rf src/public/app && \ mkdir -p src/public/app/services && \ diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index a9961847e..221e8a0ea 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -68,7 +68,6 @@ find $DIR -name "*.ts" -type f -delete d="$DIR"/src/public [[ -d "$d"/app-dist ]] || mkdir -pv "$d"/app-dist -cp "$d"/app/share.js "$d"/app-dist/ cp -r "$d"/app/doc_notes "$d"/app-dist/ rm -rf "$d"/app