From 69b6b116a0af7edc862eeffa404fe01aa024fd18 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Sun, 4 May 2025 07:20:45 +1000 Subject: [PATCH] feat: update crxjs and remove extra included files --- lib/patchPackage.ts | 79 ------------------------------------- package.json | 2 +- src/manifests/manifest.json | 2 +- vite.config.ts | 5 --- 4 files changed, 2 insertions(+), 86 deletions(-) delete mode 100644 lib/patchPackage.ts diff --git a/lib/patchPackage.ts b/lib/patchPackage.ts deleted file mode 100644 index 08dec9bb..00000000 --- a/lib/patchPackage.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* - TEMPORARY FIX FOR CHROME 130+ builds -*/ - -import path from 'node:path'; -import fs from 'fs'; -import { PluginOption } from 'vite'; -import { ManifestV3Export } from '@crxjs/vite-plugin'; - -const manifestPath = path.resolve('dist/chrome/manifest.json'); - -export function updateManifestPlugin(): PluginOption { - return { - name: 'update-manifest-plugin', - enforce: 'post', - closeBundle() { - forceDisableUseDynamicUrl(); - }, - - configureServer(server) { - server.httpServer?.once('listening', () => { - const updated = forceDisableUseDynamicUrl(); - if (updated) { - server.ws.send({ type: 'full-reload' }); - console.log('** updated **'); - } - - // Implement retry mechanism for file watching - const watchWithRetry = () => { - if (!fs.existsSync(manifestPath)) { - console.log('Manifest not found, retrying in 1 second...'); - setTimeout(watchWithRetry, 1000); - return; - } - - fs.watchFile(manifestPath, () => { - try { - const manifestContents = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); - if (manifestContents.web_accessible_resources?.some((resource: any) => resource.use_dynamic_url)) { - const updated = forceDisableUseDynamicUrl(); - if (updated) { - server.ws.send({ type: 'full-reload' }); - console.log('** updated **'); - } - } - } catch (error) { - console.log('Error reading manifest, will retry on next change:', error.message); - } - }); - }; - - watchWithRetry(); - }); - }, - - writeBundle() { - console.log('### writeBundle ##'); - forceDisableUseDynamicUrl(); - }, - }; -} - -function forceDisableUseDynamicUrl() { - if (!fs.existsSync(manifestPath)) { - return false; - } - - const manifestContents = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Awaited; - - if (typeof manifestContents === 'function' || !manifestContents.web_accessible_resources) return false; - if (manifestContents.web_accessible_resources.every((resource) => !resource.use_dynamic_url)) return false; - - manifestContents.web_accessible_resources.forEach((resource) => { - if (resource.use_dynamic_url) resource.use_dynamic_url = false; - }); - - fs.writeFileSync(manifestPath, JSON.stringify(manifestContents, null, 2)); - return true; -} diff --git a/package.json b/package.json index b8f7262d..1f41338d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@babel/plugin-transform-runtime": "^7.26.9", "@babel/runtime": "^7.26.9", "@bedframe/cli": "^0.0.91", - "@crxjs/vite-plugin": "2.0.0-beta.25", + "@crxjs/vite-plugin": "2.0.0-beta.32", "@types/mime-types": "^2.1.4", "@types/react": "^19.0.10", "@types/react-dom": "^19.0.4", diff --git a/src/manifests/manifest.json b/src/manifests/manifest.json index 9ccf3f2f..06bd6669 100644 --- a/src/manifests/manifest.json +++ b/src/manifests/manifest.json @@ -32,7 +32,7 @@ ], "web_accessible_resources": [ { - "resources": ["*/*", "resources/*", "seqta/utils/migration/migrate.html", "plugins/built-in/globalSearch/*"], + "resources": ["resources/icons/*", "seqta/utils/migration/migrate.html"], "matches": ["*://*/*"] } ] diff --git a/vite.config.ts b/vite.config.ts index 2cdac04c..d807e3f5 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,6 @@ import { defineConfig } from 'vite'; import { join, resolve } from 'path'; -import { updateManifestPlugin } from './lib/patchPackage'; import touchGlobalCSSPlugin from './lib/touchGlobalCSS'; import InlineWorkerPlugin from './lib/inlineWorker'; import { base64Loader } from './lib/base64loader'; @@ -9,7 +8,6 @@ import type { BuildTarget } from './lib/types'; import ClosePlugin from './lib/closePlugin'; import million from "million/compiler"; -//import MillionLint from '@million/lint'; import { svelte } from '@sveltejs/vite-plugin-svelte' @@ -27,7 +25,6 @@ const targets: BuildTarget[] = [ const mode = process.env.MODE || 'chrome'; // Check the environment variable to determine which build type to use. //const sourcemap = (process.env.SOURCEMAP === "true") || false; // Check whether we want sourcemaps. - export default defineConfig(({ command }) => ({ plugins: [ base64Loader, @@ -36,12 +33,10 @@ export default defineConfig(({ command }) => ({ emitCss: false }), million.vite({ auto: true }), - //MillionLint.vite(), /* enable for testing and debugging performance */ crx({ manifest: targets.find(t => t.browser === mode.toLowerCase())?.manifest ?? chrome.manifest, browser: mode.toLowerCase() === "firefox" ? "firefox" : "chrome" }), - updateManifestPlugin(), touchGlobalCSSPlugin(), ...(command === 'build' ? [ClosePlugin()] : []) ],