From 7f42b508934a0241cb3ae380105c8567ba9c786f Mon Sep 17 00:00:00 2001 From: Jones Jankovic Date: Mon, 2 Nov 2026 18:15:09 +1030 Subject: [PATCH] build: ship each asset once and fix ineffective dynamic imports --- lib/dedupePublicAssets.ts | 53 ------------------- lib/inlineWorker.ts | 1 + lib/publish.js | 23 +++----- package-lock.json | 1 - package.json | 3 +- src/manifests/manifest.json | 3 -- .../globalSearch/src/utils/versionCheck.ts | 4 +- src/seqta/utils/setupSettingsButton.ts | 3 +- vite.config.ts | 12 ++--- 9 files changed, 15 insertions(+), 88 deletions(-) delete mode 100644 lib/dedupePublicAssets.ts diff --git a/lib/dedupePublicAssets.ts b/lib/dedupePublicAssets.ts deleted file mode 100644 index d3c5c9dd..00000000 --- a/lib/dedupePublicAssets.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { createHash } from "node:crypto"; -import { readFileSync, unlinkSync, writeFileSync } from "node:fs"; -import { resolve } from "node:path"; -import { dirname, relative } from "node:path/posix"; -import { globSync } from "glob"; -import type { Plugin } from "rollup"; - -const hash = (path: string) => - createHash("sha256").update(readFileSync(path)).digest("hex"); - -/** Reuse identical files already copied to stable extension paths. */ -export default (): Plugin => ({ - name: "dedupe-public-assets", - writeBundle({ dir }) { - if (!dir) return; - const files = globSync("**/*", { cwd: dir, nodir: true }); - const stable = new Map(); - const duplicates = new Map(); - for (const file of files) { - if (file.startsWith("resources/")) - stable.set(hash(resolve(dir, file)), file); - } - for (const file of files) { - const match = file.startsWith("assets/") - ? stable.get(hash(resolve(dir, file))) - : undefined; - if (match) duplicates.set(file, match); - } - for (const file of files.filter((file) => - /\.(?:css|html|js)$/.test(file), - )) { - const path = resolve(dir, file); - let output = readFileSync(path, "utf8"); - for (const [asset, canonical] of duplicates) { - output = output.replaceAll( - relative(dirname(file), asset), - relative(dirname(file), canonical), - ); - } - writeFileSync(path, output); - } - for (const file of duplicates.keys()) unlinkSync(resolve(dir, file)); - - const manifestPath = resolve(dir, "manifest.json"); - const manifest = JSON.parse(readFileSync(manifestPath, "utf8")); - for (const entry of manifest.web_accessible_resources ?? []) { - entry.resources = entry.resources.filter( - (file: string) => !duplicates.has(file), - ); - } - writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`); - }, -}); diff --git a/lib/inlineWorker.ts b/lib/inlineWorker.ts index 91c9d96b..621a687a 100644 --- a/lib/inlineWorker.ts +++ b/lib/inlineWorker.ts @@ -18,6 +18,7 @@ export default function InlineWorkerDevPlugin(): Plugin { format: "iife", target: "esnext", minify: true, + conditions: ["onnxruntime-web-use-extern-wasm"], alias: { "@huggingface/transformers": resolve( "node_modules/@huggingface/transformers/dist/transformers.web.js", diff --git a/lib/publish.js b/lib/publish.js index 94a227d2..f96a04d6 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -11,7 +11,7 @@ * or `node lib/publish.js --b firefox` */ -import { globSync } from "glob"; +import { globSync } from "node:fs"; import semver from "semver"; import { execSync } from "node:child_process"; @@ -20,13 +20,8 @@ function getLatestVersion(files) { const versions = files .map((file) => { - const match = file.match(/@([\d\.]+)-/); - console.log( - "Matching file:", - file, - "Version found:", - match ? match[1] : "None", - ); + const match = file.match(/@([\d.]+)-/); + console.log("Matching file:", file, "Version found:", match ? match[1] : "None"); if (!match) return null; @@ -61,9 +56,7 @@ function getLatestVersion(files) { } // Get the original full version string that matches the identified latest SemVer version - const latestVersionData = versions.find( - (v) => v.semverVersion === latestSemver, - ); + const latestVersionData = versions.find((v) => v.semverVersion === latestSemver); const latestFullVersion = latestVersionData ? latestVersionData.fullVersion : null; console.log("Final selected latest version:", latestFullVersion); @@ -121,12 +114,8 @@ function zipSources() { } function runPublishCommand(browsers) { - const chromeZip = browsers.includes("chrome") - ? getLatestFiles("chrome") - : null; - const firefoxZip = browsers.includes("firefox") - ? getLatestFiles("firefox") - : null; + const chromeZip = browsers.includes("chrome") ? getLatestFiles("chrome") : null; + const firefoxZip = browsers.includes("firefox") ? getLatestFiles("firefox") : null; // Sources are typically only needed for Firefox submissions const firefoxSourcesZip = browsers.includes("firefox") ? zipSources() : null; diff --git a/package-lock.json b/package-lock.json index a8f2575b..da15b4af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -66,7 +66,6 @@ "cross-env": "^10.1.0", "esbuild": "^0.28.2", "eslint": "^10.14.0", - "glob": "^14.0.3", "globals": "^17.14.0", "jest": "^30.5.2", "jest-environment-jsdom": "^30.5.2", diff --git a/package.json b/package.json index 1adf20d1..0cfdd417 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "cross-env": "^10.1.0", "esbuild": "^0.28.2", "eslint": "^10.14.0", - "glob": "^14.0.3", "globals": "^17.14.0", "jest": "^30.5.2", "jest-environment-jsdom": "^30.5.2", @@ -108,7 +107,7 @@ "webextension-polyfill": "^0.12.0" }, "overrides": { - "glob": "$glob" + "glob": "^14.0.3" }, "allowScripts": { "@parcel/watcher": false, diff --git a/src/manifests/manifest.json b/src/manifests/manifest.json index 27c97b6f..179d5ea4 100644 --- a/src/manifests/manifest.json +++ b/src/manifests/manifest.json @@ -46,13 +46,10 @@ "web_accessible_resources": [ { "resources": [ - "resources/error-page/*", - "resources/icons/*", "resources/pdfjs/pdf.worker.min.mjs", "resources/pdfjs/pdf.legacy.min.mjs", "resources/themeToggleSurprisePage.js", "resources/ort/*", - "assets/*.css", "assets/*" ], "matches": ["*://*/*"] diff --git a/src/plugins/built-in/globalSearch/src/utils/versionCheck.ts b/src/plugins/built-in/globalSearch/src/utils/versionCheck.ts index 6bef9dba..1c592aa2 100644 --- a/src/plugins/built-in/globalSearch/src/utils/versionCheck.ts +++ b/src/plugins/built-in/globalSearch/src/utils/versionCheck.ts @@ -1,5 +1,6 @@ import browser from "webextension-polyfill"; import { resetSearchIndexes } from "../indexing/resetIndexes"; +import { clearSearchCache } from "../search/searchUtils"; import { verboseDebug, verboseLog } from "@/utils/verboseLog"; const VERSION_STORAGE_KEY = "betterseqta-global-search-version"; @@ -79,10 +80,9 @@ export async function clearAllCaches(): Promise { setTimeout(async () => { try { - const { clearSearchCache } = await import("../search/searchUtils"); clearSearchCache(); } catch (e) { - if (!isAssetLoadError(e)) verboseDebug("[Version Check] Could not clear search cache:", e); + verboseDebug("[Version Check] Could not clear search cache:", e); } try { diff --git a/src/seqta/utils/setupSettingsButton.ts b/src/seqta/utils/setupSettingsButton.ts index d389e68b..9bb64d28 100644 --- a/src/seqta/utils/setupSettingsButton.ts +++ b/src/seqta/utils/setupSettingsButton.ts @@ -1,6 +1,6 @@ import { closeExtensionPopup, getSettingsOpenGeneration } from "./closers/closeExtensionPopup"; import { animateSettingsOpen, isExtensionSettingsOpen, prefetchSettingsShell } from "./settingsPopupAnimation"; -import { renderSettingsIfNeeded } from "./adders/AddExtensionSettings"; +import { addExtensionSettings, renderSettingsIfNeeded } from "./adders/AddExtensionSettings"; export function setupSettingsButton() { const AddedSettings = document.getElementById("AddedSettings"); @@ -33,7 +33,6 @@ export async function openSettingsPopup(): Promise { try { let host = document.getElementById("ExtensionPopup"); if (!host) { - const { addExtensionSettings } = await import("./adders/AddExtensionSettings"); addExtensionSettings(); host = document.getElementById("ExtensionPopup"); } diff --git a/vite.config.ts b/vite.config.ts index 5136c8f3..cd77f40e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, loadEnv } from "vite"; +import { defaultClientConditions, defineConfig, loadEnv } from "vite"; import { join, resolve } from "node:path"; import touchGlobalCSSPlugin from "./lib/touchGlobalCSS.ts"; @@ -9,7 +9,7 @@ import fixCrxWorkerLiveReload from "./lib/fixCrxWorkerLiveReload.ts"; import stabilizeCrxDevHmr from "./lib/stabilizeCrxDevHmr.ts"; import { firefoxStripFunctionProbe } from "./lib/firefoxStripFunctionProbe.ts"; import { extensionChunkUrls } from "./lib/extensionChunkUrls.ts"; -import dedupePublicAssets from "./lib/dedupePublicAssets.ts"; + import { svelte } from "@sveltejs/vite-plugin-svelte"; @@ -96,18 +96,14 @@ export default defineConfig(({ command, mode: viteMode }) => { fixCrxWorkerLiveReload(), stabilizeCrxDevHmr(), touchGlobalCSSPlugin(), - ...(command === "build" - ? [ - dedupePublicAssets(), - firefoxStripFunctionProbe(), - ] - : []), + ...(command === "build" ? [firefoxStripFunctionProbe()] : []), ], root: resolve(repoRoot, "./src"), resolve: { alias: { "@": resolve(repoRoot, "./src"), }, + conditions: ["onnxruntime-web-use-extern-wasm", ...defaultClientConditions], dedupe: [ "@huggingface/transformers", "onnxruntime-common",