@stacksjs/browser-extension 0.70.68 → 0.70.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +75 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,77 @@
1
1
  # @stacksjs/browser-extension
2
2
 
3
- Build MV3 browser extensions (Chrome + Firefox) the Stacks way — manifest, content/background scripts, DNR rules, and packaging, all driven by a single `config/extension.ts`.
3
+ Build MV3 browser extensions (Chrome + Firefox) the Stacks way — the manifest,
4
+ content/background scripts, stx pages, `declarativeNetRequest` rulesets, and
5
+ store-ready packaging are all derived from a single `config/extension.ts`. No
6
+ hand-written `manifest.json`, no per-project build script.
7
+
8
+ ## Quick start
9
+
10
+ ```sh
11
+ buddy extension:init # scaffold config/extension.ts + starter files
12
+ buddy extension:build # build all targets → dist/ (+ dist-firefox/)
13
+ buddy extension:build --target chrome
14
+ buddy extension:package # build + zip store-ready archives
15
+ ```
16
+
17
+ ## Configure
18
+
19
+ ```ts
20
+ // config/extension.ts
21
+ import { defineExtension } from '@stacksjs/browser-extension'
22
+
23
+ export default defineExtension({
24
+ name: 'My Extension',
25
+ description: 'Does something useful.',
26
+ geckoId: 'my-ext@example.com', // required to ship on Firefox
27
+ targets: ['chrome', 'firefox'],
28
+
29
+ background: 'src/background/index.ts',
30
+ content: [
31
+ { entry: 'src/content/index.ts', matches: ['<all_urls>'], runAt: 'document_start' },
32
+ // world: 'MAIN' runs in the page's own JS context (patch page globals)
33
+ { entry: 'src/content/inpage.ts', matches: ['*://example.com/*'], world: 'MAIN' },
34
+ ],
35
+ pages: {
36
+ popup: { template: 'pages/popup.stx', script: 'src/ui/popup.ts' },
37
+ options: { template: 'pages/options.stx', script: 'src/ui/options.ts' },
38
+ },
39
+ icons: { 16: 'icons/icon-16.png', 48: 'icons/icon-48.png', 128: 'icons/icon-128.png' },
40
+ public: 'public', // copied verbatim into the build
41
+ assets: { 'styles.css': 'src/ui/styles.css' }, // extra file copies
42
+
43
+ // declarativeNetRequest — compiled from a module whose default export
44
+ // returns the rules array, written to rules/<id>.json:
45
+ rules: [{ id: 'static_rules', source: 'src/rules/static.ts' }],
46
+
47
+ manifest: {
48
+ permissions: ['declarativeNetRequest', 'storage', 'tabs'],
49
+ hostPermissions: ['http://*/*', 'https://*/*'],
50
+ minimumChromeVersion: '111',
51
+ firefoxMinVersion: '140.0',
52
+ webAccessibleResources: [{ resources: ['stubs/*.js'], matches: ['<all_urls>'] }],
53
+ },
54
+
55
+ // App-specific post-processing the generic build can't express:
56
+ hooks: {
57
+ async postBuild({ outdir, target }) { /* … */ },
58
+ },
59
+ })
60
+ ```
61
+
62
+ ## What the build does
63
+
64
+ Per target it: copies `public/**` + `assets`, bundles page scripts, builds the
65
+ stx pages to HTML (**sanitized for the extension CSP** — inline scripts/styles
66
+ stripped, asset paths made relative, stx dev-chunks removed), bundles
67
+ content/background scripts as classic **IIFE** bundles (esm would leak
68
+ top-level vars as page globals), compiles each ruleset's `source` to
69
+ `rules/<id>.json`, writes `manifest.json` (per-target: Chrome `service_worker`
70
+ vs Firefox event-page + `browser_specific_settings.gecko`), and runs your
71
+ `hooks.postBuild`.
72
+
73
+ ## Programmatic API
74
+
75
+ ```ts
76
+ import { buildExtension, buildAllTargets, packageExtension, generateManifest } from '@stacksjs/browser-extension'
77
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/browser-extension",
3
3
  "type": "module",
4
- "version": "0.70.68",
4
+ "version": "0.70.69",
5
5
  "description": "Build MV3 browser extensions (Chrome + Firefox) the Stacks way — manifest, content/background scripts, DNR rules, packaging, all config-driven.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [