Skip to content

Commit

Permalink
conditionally build webext manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
arobsn committed Dec 3, 2024
1 parent 524da5d commit 7b611a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/extension/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pkg from "../../package.json";
import { EXT_ENTRY_ROOT } from "../constants/extension";

type Network = "mainnet" | "testnet";
type Browser = "chrome" | "firefox";

const r = (path: string) => `${EXT_ENTRY_ROOT}/${path}`;

Expand Down Expand Up @@ -40,13 +41,12 @@ function buildVersion() {
return label ? `${major}.${minor}.${patch}.${label}` : `${major}.${minor}.${patch}`;
}

export function buildManifest(network: Network, mode: string): Manifest.WebExtensionManifest {
return {
export function buildManifest(network: Network, browser: Browser, mode: string) {
const manifest = {
manifest_version: 3,
name: buildTitle(mode, network),
short_name: "Nautilus",
description: buildDescription(mode, network),
version_name: pkg.version,
version: buildVersion(),
icons: buildIcons(mode, network),
content_security_policy: {
Expand All @@ -64,9 +64,6 @@ export function buildManifest(network: Network, mode: string): Manifest.WebExten
extension_ids: []
}
],
background: {
service_worker: r("background/background.ts")
},
content_scripts: [
{
js: [r("content-scripts/contentScript.ts")],
Expand All @@ -75,5 +72,14 @@ export function buildManifest(network: Network, mode: string): Manifest.WebExten
all_frames: true
}
]
};
} as Manifest.WebExtensionManifest;

if (browser === "chrome") {
manifest.version_name = pkg.version;
manifest.background = { service_worker: r("background/background.ts") };
} else if (browser === "firefox") {
manifest.background = { scripts: [r("background/background.ts")] };
}

return manifest;
}
6 changes: 2 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default defineConfig(({ mode }) => ({
plugins: [
...(mode === "development" ? plugins : []),
webExtension({
manifest: () => buildManifest(env.NETWORK, mode),
manifest: () => buildManifest(env.NETWORK, env.TARGET, mode),
watchFilePaths: [r("src/manifest.ts")],
additionalInputs: [
`${EXT_ENTRY_ROOT}/content-scripts/injected.ts`,
Expand Down Expand Up @@ -95,9 +95,7 @@ export default defineConfig(({ mode }) => ({
}));

function envLoggerPlugin(): PluginOption {
function li(title: string, content: string): string {
return `\x1b[32m➜\x1b[0m ${title} \x1b[36m${content}\x1b[0m`;
}
const li = (t: string, c: string) => `\x1b[32m➜\x1b[0m ${t} \x1b[36m${c}\x1b[0m`;

return {
name: "target-logger",
Expand Down

0 comments on commit 7b611a2

Please sign in to comment.