mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
fix: add patchPackage to fix Chrome 130+ compatability
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
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 **');
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.watchFile(manifestPath, () => {
|
||||||
|
console.log('** watchFile ** ');
|
||||||
|
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 **');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
writeBundle() {
|
||||||
|
console.log('### writeBundle ##');
|
||||||
|
forceDisableUseDynamicUrl();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function forceDisableUseDynamicUrl() {
|
||||||
|
if (!fs.existsSync(manifestPath)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifestContents = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Awaited<ManifestV3Export>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
+3
-1
@@ -1,6 +1,7 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import { join, resolve } from 'path';
|
import { join, resolve } from 'path';
|
||||||
|
|
||||||
|
import { updateManifestPlugin } from './lib/patchPackage';
|
||||||
import { base64Loader } from './lib/base64loader';
|
import { base64Loader } from './lib/base64loader';
|
||||||
import type { BuildTarget } from './lib/types';
|
import type { BuildTarget } from './lib/types';
|
||||||
|
|
||||||
@@ -31,7 +32,8 @@ export default defineConfig({
|
|||||||
crx({
|
crx({
|
||||||
manifest: targets.find(t => t.browser === mode.toLowerCase())?.manifest ?? chrome.manifest,
|
manifest: targets.find(t => t.browser === mode.toLowerCase())?.manifest ?? chrome.manifest,
|
||||||
browser: mode.toLowerCase() === "firefox" ? "firefox" : "chrome"
|
browser: mode.toLowerCase() === "firefox" ? "firefox" : "chrome"
|
||||||
})
|
}),
|
||||||
|
updateManifestPlugin()
|
||||||
],
|
],
|
||||||
root: resolve(__dirname, './src'),
|
root: resolve(__dirname, './src'),
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
Reference in New Issue
Block a user