|
| 1 | +/* eslint-disable camelcase */ |
| 2 | +import {existsSync, readFileSync, writeFileSync} from 'node:fs'; |
| 3 | +import {join} from 'node:path'; |
| 4 | + |
| 5 | +const [extensionPath, manifestVersion] = process.argv.slice(2); |
| 6 | + |
| 7 | +if (!extensionPath || !manifestVersion) { |
| 8 | + throw new Error('Please provide a path to the extension and a manifest version, like: npm run manifest distribution 2'); |
| 9 | +} |
| 10 | + |
| 11 | +const manifestPath = join(extensionPath, 'manifest.json'); |
| 12 | + |
| 13 | +if (!existsSync(manifestPath)) { |
| 14 | + throw new Error(`No manifest found in: ${extensionPath}`); |
| 15 | +} |
| 16 | + |
| 17 | +const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')); |
| 18 | + |
| 19 | +if (manifestVersion === '2') { |
| 20 | + // Avoid bad Firefox UX with manifest v3 |
| 21 | + // TODO: Drop after https://bugzilla.mozilla.org/show_bug.cgi?id=1851083 |
| 22 | + manifest.manifest_version = 2; |
| 23 | + manifest.web_accessible_resources = ['assets/resolve-conflicts.js']; |
| 24 | + delete manifest.background.service_worker; |
| 25 | + |
| 26 | + manifest.permissions.push(...manifest.host_permissions); |
| 27 | + delete manifest.host_permissions; |
| 28 | + delete manifest.optional_host_permissions; |
| 29 | + |
| 30 | + manifest.browser_action = manifest.action; |
| 31 | + delete manifest.action; |
| 32 | +} else { |
| 33 | + // Kiwi browser support |
| 34 | + // TODO: Drop after https://github.com/kiwibrowser/src.next/issues/1138 |
| 35 | + delete manifest.background.scripts; |
| 36 | +} |
| 37 | + |
| 38 | +writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)); |
0 commit comments