Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(pdfjs): use version-based system for cache busting
Elian Doran971d6ad9e3c3
diff --git a/packages/pdfjs-viewer/scripts/build.ts b/packages/pdfjs-viewer/scripts/build.tsindex 9683b31cc7..ff0cd98051 100644--- a/packages/pdfjs-viewer/scripts/build.ts+++ b/packages/pdfjs-viewer/scripts/build.ts@@ -3,6 +3,8 @@ import BuildHelper from "../../../scripts/build-utils";import { build as esbuild } from "esbuild";import { LOCALES } from "@triliumnext/commons";import { watch } from "chokidar";+import { readFileSync, writeFileSync } from "fs";+import packageJson from "../package.json" with { type: "json "};const build = new BuildHelper("packages/pdfjs-viewer");const watchMode = process.argv.includes("--watch");@@ -16,6 +18,7 @@ async function main() {for (const file of [ "viewer.css", "viewer.html", "viewer.mjs" ]) {build.copy(`viewer/${file}`, `web/${file}`);}+ patchCacheBuster(`${build.outDir}/web/viewer.html`);build.copy(`viewer/images`, `web/images`);// Copy the custom files.@@ -60,6 +63,21 @@ async function rebuildCustomFiles() {build.copy("src/custom.css", "web/custom.css");}+function patchCacheBuster(htmlFilePath: string) {+ const version = packageJson.version;+ console.log(`Versioned URLs: ${version}.`)+ let html = readFileSync(htmlFilePath, "utf-8");+ html = html.replace(+ `<link rel="stylesheet" href="custom.css" />`,+ `<link rel="stylesheet" href="custom.css?v=${version}" />`);+ html = html.replace(+ `<script src="custom.mjs" type="module"></script>` ,+ `<script src="custom.mjs?v=${version}" type="module"></script>`+ );++ writeFileSync(htmlFilePath, html);+}+function watchForChanges() {console.log("Watching for changes in src directory...");const watcher = watch(join(build.projectDir, "src"), {diff --git a/scripts/update-nightly-version.ts b/scripts/update-nightly-version.tsindex 2c0179331e..71f5a96847 100644--- a/scripts/update-nightly-version.ts+++ b/scripts/update-nightly-version.ts@@ -11,9 +11,9 @@**/-import { fileURLToPath } from "url";-import { dirname, join } from "path";import fs from "fs";+import { dirname, join } from "path";+import { fileURLToPath } from "url";function processVersion(version) {// Remove the beta suffix if any.@@ -42,14 +42,19 @@ function patchPackageJson(packageJsonPath) {function main() {const scriptDir = dirname(fileURLToPath(import.meta.url));-+const rootPackageJson = join(scriptDir, "..", "package.json");patchPackageJson(rootPackageJson);-+for (const app of ["server", "client"]) {const appPackageJsonPath = join(scriptDir, "..", "apps", app, "package.json");patchPackageJson(appPackageJsonPath);}++ for (const packageName of [ "pdfjs-viewer" ]) {+ const packageJsonPath = join(scriptDir, "..", "packages", packageName, "package.json");+ patchPackageJson(packageJsonPath);+ }}main();