From cd075b7c009f065d9e79ce4a078b5bac1b74258d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Fri, 18 Oct 2024 13:50:33 +0200 Subject: [PATCH] fix: hotfix manifest.json to work --- package-lock.json | 42 +++++++++++++++++++++--------------------- package.json | 2 +- vite.config.ts | 40 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index ff8130a..43eaf09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@crxjs/vite-plugin": "^2.0.0-beta.21", + "@crxjs/vite-plugin": "2.0.0-beta.25", "@semantic-release/changelog": "^5.0.1", "@semantic-release/exec": "^5.0.0", "@semantic-release/git": "^9.0.0", @@ -500,9 +500,9 @@ } }, "node_modules/@crxjs/vite-plugin": { - "version": "2.0.0-beta.21", - "resolved": "https://registry.npmjs.org/@crxjs/vite-plugin/-/vite-plugin-2.0.0-beta.21.tgz", - "integrity": "sha512-kSXgHHqCXASqJ8NmY94+KLGVwdtkJ0E7KsRQ+vbMpRliJ5ze0xnSk0l41p4txlUysmEoqaeo4Xb7rEFdcU2zjQ==", + "version": "2.0.0-beta.25", + "resolved": "https://registry.npmjs.org/@crxjs/vite-plugin/-/vite-plugin-2.0.0-beta.25.tgz", + "integrity": "sha512-g5ytTNiFpFCi+T0trSDJLohVz5PufLBLh6OGljyGTHkQCKiApuEgZ1bAjgPXluMDhMUvbPfZT10LYl5ROefXog==", "dev": true, "dependencies": { "@rollup/pluginutils": "^4.1.2", @@ -8346,9 +8346,9 @@ } }, "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", "dev": true }, "node_modules/picomatch": { @@ -8444,9 +8444,9 @@ } }, "node_modules/postcss": { - "version": "8.4.32", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.32.tgz", - "integrity": "sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==", + "version": "8.4.47", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.47.tgz", + "integrity": "sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==", "dev": true, "funding": [ { @@ -8464,8 +8464,8 @@ ], "dependencies": { "nanoid": "^3.3.7", - "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" + "picocolors": "^1.1.0", + "source-map-js": "^1.2.1" }, "engines": { "node": "^10 || ^12 || >=14" @@ -9220,9 +9220,9 @@ } }, "node_modules/source-map-js": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", - "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -9778,9 +9778,9 @@ } }, "node_modules/vite": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/vite/-/vite-3.2.7.tgz", - "integrity": "sha512-29pdXjk49xAP0QBr0xXqu2s5jiQIXNvE/xwd0vUizYT2Hzqe4BksNNoWllFVXJf4eLZ+UlVQmXfB4lWrc+t18g==", + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/vite/-/vite-3.2.11.tgz", + "integrity": "sha512-K/jGKL/PgbIgKCiJo5QbASQhFiV02X9Jh+Qq0AKCRCRKZtOTVi4t6wh75FDpGf2N9rYOnzH87OEFQNaFy6pdxQ==", "dev": true, "dependencies": { "esbuild": "^0.15.9", @@ -9839,9 +9839,9 @@ } }, "node_modules/vite/node_modules/rollup": { - "version": "2.79.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", - "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", + "version": "2.79.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.2.tgz", + "integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==", "dev": true, "bin": { "rollup": "dist/bin/rollup" diff --git a/package.json b/package.json index b0856e3..66140b1 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@crxjs/vite-plugin": "^2.0.0-beta.21", + "@crxjs/vite-plugin": "2.0.0-beta.25", "@semantic-release/changelog": "^5.0.1", "@semantic-release/exec": "^5.0.0", "@semantic-release/git": "^9.0.0", diff --git a/vite.config.ts b/vite.config.ts index 6981ebc..fb53021 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,47 @@ -import { defineConfig } from 'vite'; +import { defineConfig, Plugin } from 'vite'; import react from '@vitejs/plugin-react'; import { crx } from '@crxjs/vite-plugin'; import zipPack from 'vite-plugin-zip-pack'; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-expect-error +import fs from 'node:fs'; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-expect-error +import path from 'node:path'; import manifest from './manifest.json'; +function myPlugin(): Plugin { + function updateManifest() { + const absolutePath = path.resolve('./dist/manifest.json'); + + const content = fs.readFileSync(absolutePath); + const test = JSON.parse(content); + test.web_accessible_resources = test.web_accessible_resources.map((i) => ({ + ...i, + use_dynamic_url: false, + })); + fs.writeFile(absolutePath, JSON.stringify(test, null, 2), (err) => { + if (err) { + console.error(err); + } else { + console.log('manifest.json updated'); + } + }); + } + + return { + name: 'my-plugin', + generateBundle(options, bundle) { + console.log(bundle); + }, + writeBundle() { + updateManifest(); + }, + }; +} + // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react(), crx({ manifest: manifest as any }), zipPack()], + plugins: [react(), crx({ manifest: manifest as any }), myPlugin(), zipPack()], });