@@ -246,6 +246,25 @@ async function init() {
246246 ) ;
247247 }
248248
249+ if ( framework === "svelte" ) {
250+ preOrderDirectoryTraverse (
251+ root ,
252+ ( ) => { } ,
253+ ( filepath ) => {
254+ // update manifest html files
255+ if ( path . basename ( filepath ) . startsWith ( "manifest" ) ) {
256+ const content = fs . readFileSync ( filepath , "utf8" ) . replace (
257+ `import pkg from '../package.json';` ,
258+ `import { readFileSync } from "fs";
259+ const pkg = JSON.parse(readFileSync(new URL("./../package.json", import.meta.url).pathname, "utf-8"));`
260+ ) ;
261+
262+ fs . writeFileSync ( filepath , content ) ;
263+ }
264+ }
265+ ) ;
266+ }
267+
249268 if ( manifestVersion === "2+3" ) {
250269 preOrderDirectoryTraverse (
251270 root ,
@@ -254,25 +273,19 @@ async function init() {
254273 if ( path . basename ( filepath ) . startsWith ( "vite.config" ) ) {
255274 const content = fs
256275 . readFileSync ( filepath , "utf8" )
276+ . replace (
277+ `import { defineConfig } from "vite";` ,
278+ `import { defineConfig, loadEnv } from "vite";`
279+ )
257280 . replace (
258281 "export default defineConfig(() => {" ,
259282 `export default defineConfig(({ mode }) => {
260- const configEnv = loadEnv(mode, process.cwd(), "");
261-
262- const manifest = configEnv.MANIFEST_VERSION === "3" ? ManifestV3 : ManifestV2;
283+ const env = loadEnv(mode, process.cwd(), "");
263284`
264285 )
265286 . replace (
266- `import manifest from "./src/manifest";` ,
267- `import { ManifestV2, ManifestV3 } from "./src/manifest";`
268- )
269- . replace (
270- `import manifest from "./src/manifest.js";` ,
271- `import { ManifestV2, ManifestV3 } from "./src/manifest.js";`
272- )
273- . replace (
274- `import { defineConfig } from "vite";` ,
275- `import { defineConfig, loadEnv } from "vite";`
287+ `getManifest()` ,
288+ `getManifest(Number(env.MANIFEST_VERSION))`
276289 ) ;
277290
278291 fs . writeFileSync ( filepath , content ) ;
@@ -304,7 +317,20 @@ async function init() {
304317 if ( path . basename ( filepath ) . startsWith ( "manifest" ) ) {
305318 const content = fs
306319 . readFileSync ( filepath , "utf8" )
307- . replace ( / \. j s / g, `.ts` ) ;
320+ . replace ( / \. j s " / g, `.ts"` )
321+ . replace ( / \. j s x " / g, `.tsx"` )
322+ . replace (
323+ `getManifest() {` ,
324+ `getManifest(): ${
325+ manifestVersion === "2"
326+ ? "chrome.runtime.ManifestV2"
327+ : "chrome.runtime.ManifestV3"
328+ } {`
329+ )
330+ . replace (
331+ `getManifest(manifestVersion) {` ,
332+ `getManifest(manifestVersion: number): chrome.runtime.ManifestV2 | chrome.runtime.ManifestV3 {`
333+ ) ;
308334
309335 fs . writeFileSync ( filepath , content ) ;
310336 }
0 commit comments