mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
build: ship each asset once and fix ineffective dynamic imports
This commit is contained in:
9 files changed
+15
-88
No files matched your search
@@ -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<string, string>();
|
||||
const duplicates = new Map<string, string>();
|
||||
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`);
|
||||
},
|
||||
});
|
||||
@@ -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",
|
||||
|
||||
+6
-17
@@ -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;
|
||||
|
||||
|
||||
Generated
-1
@@ -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",
|
||||
|
||||
+1
-2
@@ -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,
|
||||
|
||||
@@ -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": ["*://*/*"]
|
||||
|
||||
@@ -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<void> {
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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<void> {
|
||||
try {
|
||||
let host = document.getElementById("ExtensionPopup");
|
||||
if (!host) {
|
||||
const { addExtensionSettings } = await import("./adders/AddExtensionSettings");
|
||||
addExtensionSettings();
|
||||
host = document.getElementById("ExtensionPopup");
|
||||
}
|
||||
|
||||
+4
-8
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user