wxt.config.ts now builds for the target browser (docs/08 §1, §9): - `manifestVersion: 3` for every target — WXT built Firefox as MV2; - Firefox gets browser_specific_settings.gecko — the permanent id bookmarkmagic@poli0981.dev, strict_min_version 140.0 (the first that accepts data_collection_permissions, which AMO requires of new add-ons), and data_collection_permissions { required: ["none"] } — and no minimum_chrome_version; Chrome keeps its floor of 136; - Vite targets firefox140 for that package; - the sources archive AMO reviews leaves out coverage, captures, store copy, docs, tests and tools. Permissions, CSP, pages and icons are identical in both packages. check-manifest.mjs takes --browser chrome|firefox, mapped through a fixed table to .output/<target>-mv3 (still no path from the command line), and pins each package's exact key set and floor; the gecko block is compared key order aside. New npm scripts: build:firefox, zip:firefox; verify:full builds and checks both packages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
186 lines
7.5 KiB
TypeScript
186 lines
7.5 KiB
TypeScript
import { defineConfig } from 'wxt';
|
|
import { CREDITED_PACKAGES } from './scripts/credited-packages.mjs';
|
|
|
|
/**
|
|
* WXT configuration.
|
|
*
|
|
* Hard constraints encoded here (docs/08 §1, CLAUDE.md hard rules):
|
|
* - Permissions are exactly ["bookmarks", "storage"] — forever, for v1.
|
|
* No host_permissions, no content_scripts, no background service worker.
|
|
* - No remote code: everything ships in the package. The extension-page CSP
|
|
* below only ever TIGHTENS the MV3 default; it never loosens it.
|
|
* - srcDir: 'src' so entrypoints/, public/ and lib/ all live under src/ and
|
|
* the `@` alias resolves there (docs/02 §2).
|
|
* - One runtime floor, stated three times on purpose: `minimum_chrome_version`
|
|
* below, Vite's `build.target`, and tsconfig's `ES2025` lib. Chrome 136 is
|
|
* the first release with every ES2025 built-in (RegExp.escape landed in 136,
|
|
* Float16Array in 135), so the types the compiler allows are exactly the
|
|
* APIs the oldest supported browser has (docs/01 §1, docs/08 §7).
|
|
*/
|
|
const CHROME_FLOOR = 136;
|
|
|
|
/**
|
|
* Firefox's floor (docs/08 §9): the first Firefox that accepts
|
|
* `data_collection_permissions`, which AMO requires of every new extension;
|
|
* every ES2025 built-in is older (`RegExp.escape` and `Promise.try`, 134).
|
|
*/
|
|
const FIREFOX_FLOOR = 140;
|
|
|
|
/**
|
|
* Firefox's block — docs/08 §9. The id is permanent once the add-on is on AMO;
|
|
* "none" is Firefox's own declaration that nothing is collected, the same
|
|
* answer as the Chrome Web Store privacy tab. `check:manifest --browser
|
|
* firefox` pins all of it in the built package.
|
|
*/
|
|
const FIREFOX_SETTINGS = {
|
|
gecko: {
|
|
id: 'bookmarkmagic@poli0981.dev',
|
|
strict_min_version: `${FIREFOX_FLOOR}.0`,
|
|
data_collection_permissions: { required: ['none'] },
|
|
},
|
|
};
|
|
|
|
/**
|
|
* The zero-network promise, enforced by the browser — docs/08 §3.
|
|
*
|
|
* MV3's default extension-page CSP restricts code execution only; it has no
|
|
* connect-src or img-src at all, so until v1.1.0 a grep gate was the only
|
|
* thing between the product and its "no network" claim. `connect-src 'none'`
|
|
* makes Chrome itself refuse every fetch, XHR, WebSocket, EventSource and
|
|
* beacon; the other directives close remote images, fonts, media, frames and
|
|
* form posts, and `default-src 'none'` closes whatever is left unlisted (web
|
|
* app manifests, prefetches). Every directive the pages use is listed, so it
|
|
* changes nothing for them — styles included. `scripts/check-manifest.mjs`
|
|
* pins this exact string in the built manifest.
|
|
*
|
|
* Production builds only: the dev server (`wxt`, command "serve") reloads the
|
|
* extension over a localhost websocket that `connect-src 'none'` would block.
|
|
*/
|
|
const EXTENSION_PAGE_CSP = [
|
|
"default-src 'none'",
|
|
"script-src 'self'",
|
|
"object-src 'none'",
|
|
"connect-src 'none'",
|
|
"img-src 'self' data: blob:",
|
|
// Inline styles stay allowed (Svelte sets style attributes); remote
|
|
// stylesheets do not.
|
|
"style-src 'self' 'unsafe-inline'",
|
|
"font-src 'self'",
|
|
"media-src 'none'",
|
|
"frame-src 'none'",
|
|
"worker-src 'self'",
|
|
"form-action 'none'",
|
|
"base-uri 'none'",
|
|
].join('; ');
|
|
|
|
/** The npm package a module id lives in, or undefined for our own code. */
|
|
function packageOf(id: string): string | undefined {
|
|
const at = id.lastIndexOf('node_modules');
|
|
if (at === -1) return undefined;
|
|
const parts = id.slice(at + 'node_modules'.length + 1).split('/');
|
|
return parts[0]?.startsWith('@') === true ? `${parts[0]}/${parts[1] ?? ''}` : parts[0];
|
|
}
|
|
|
|
/** The slice of Rollup's output-bundle shape the gate reads. */
|
|
interface BundleLike {
|
|
[file: string]: { type: string; modules?: Record<string, { renderedLength: number }> };
|
|
}
|
|
|
|
/**
|
|
* Fail the build when code from an uncredited package ships. Only modules that
|
|
* actually render count — a package imported and then tree-shaken away is not
|
|
* in the extension and needs no notice. The list is `CREDITED_PACKAGES` in
|
|
* `scripts/credited-packages.mjs`, shared with the notices test and the licence
|
|
* gate (docs/14 §5). Until v1.1.0 the notices said "none" while Svelte's
|
|
* runtime, its `clsx` dependency and WXT's browser shim all shipped.
|
|
*/
|
|
const thirdPartyGate = {
|
|
name: 'bookmarkmagic:third-party-gate',
|
|
apply: 'build' as const,
|
|
generateBundle(
|
|
this: { error: (message: string) => never },
|
|
_options: unknown,
|
|
bundle: BundleLike,
|
|
) {
|
|
const shipped = new Set<string>();
|
|
for (const output of Object.values(bundle)) {
|
|
for (const [id, module] of Object.entries(output.modules ?? {})) {
|
|
const name = packageOf(id);
|
|
if (name !== undefined && module.renderedLength > 0) shipped.add(name);
|
|
}
|
|
}
|
|
const uncredited = [...shipped].filter((name) => !CREDITED_PACKAGES.includes(name));
|
|
if (uncredited.length > 0) {
|
|
this.error(
|
|
`third-party code ships without a notice: ${uncredited.join(', ')} — add it to ` +
|
|
'CREDITED_PACKAGES (scripts/credited-packages.mjs), legal/THIRD_PARTY_NOTICES.md ' +
|
|
'and src/public/THIRD_PARTY_NOTICES.txt',
|
|
);
|
|
}
|
|
},
|
|
};
|
|
|
|
export default defineConfig({
|
|
srcDir: 'src',
|
|
// MV3 for every target. WXT builds Firefox as MV2 unless told otherwise, and
|
|
// this project's manifest, CSP and review story are MV3 (docs/08 §1).
|
|
manifestVersion: 3,
|
|
vite: (env) => ({
|
|
plugins: [thirdPartyGate],
|
|
build: {
|
|
// The floor the package states, so the compiler never emits syntax the
|
|
// oldest allowed browser cannot run.
|
|
target: env.browser === 'firefox' ? `firefox${FIREFOX_FLOOR}` : `chrome${CHROME_FLOOR}`,
|
|
// Vite's modulepreload polyfill is a network call (it fetches each chunk
|
|
// ahead of time) for browsers without native `<link rel=modulepreload>`.
|
|
// Every Chrome at or above the floor has it, so the polyfill is dead code
|
|
// that would leave the one network API in the shipped bundle.
|
|
modulePreload: { polyfill: false },
|
|
},
|
|
}),
|
|
// publicDir is resolved against the project ROOT, not srcDir — WXT's default
|
|
// is `<root>/public`, so this line is required to keep _locales/ and icon/
|
|
// under src/. Without it they are silently omitted from the build and Chrome
|
|
// refuses to load the extension (missing __MSG_appName__ and icons).
|
|
publicDir: 'src/public',
|
|
modules: ['@wxt-dev/module-svelte'],
|
|
manifest: ({ browser, command }) => ({
|
|
name: '__MSG_appName__',
|
|
description: '__MSG_appDesc__',
|
|
default_locale: 'en',
|
|
// The one key that differs between the two packages (docs/08 §1).
|
|
...(browser === 'firefox'
|
|
? { browser_specific_settings: FIREFOX_SETTINGS }
|
|
: { minimum_chrome_version: String(CHROME_FLOOR) }),
|
|
permissions: ['bookmarks', 'storage'],
|
|
// Deep-link lands on #settings only when no Manager tab is open — with
|
|
// open_in_tab Chrome matches the singleton tab ignoring the fragment,
|
|
// so route.svelte.ts must react to hashchange (docs/02 §5).
|
|
options_ui: { page: 'manager.html#settings', open_in_tab: true },
|
|
icons: {
|
|
16: '/icon/16.png',
|
|
32: '/icon/32.png',
|
|
48: '/icon/48.png',
|
|
128: '/icon/128.png',
|
|
},
|
|
homepage_url: 'https://github.com/poli0981/bookmarkmagic',
|
|
...(command === 'build' && {
|
|
content_security_policy: { extension_pages: EXTENSION_PAGE_CSP },
|
|
}),
|
|
}),
|
|
// The sources archive `wxt zip -b firefox` writes for AMO's reviewers
|
|
// (docs/08 §9): what rebuilds the package — the source, the configs, the
|
|
// lockfile, the scripts the build imports — and nothing that is not.
|
|
zip: {
|
|
excludeSources: [
|
|
'coverage/**',
|
|
'capture/**',
|
|
'store/**',
|
|
'docs/**',
|
|
'tests/**',
|
|
'tools/**',
|
|
'stats.html',
|
|
],
|
|
},
|
|
});
|