addfox 0.1.1-beta.1

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.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ [中文](README-zh_CN.md) | English
2
+
3
+ ---
4
+
5
+ <p align="center">
6
+ <img width="230" src="addmo.png">
7
+ </p>
8
+
9
+ <h1 align="center">
10
+ Addmo
11
+ </h1>
12
+ <p align="center">
13
+ Browser extension development framework built on Rsbuild
14
+ </p>
15
+
16
+ Browser extension development involves more complex debugging, so we use **full-bundle mode** to minimize the gap between dev and production. Thanks to **Rsbuild’s performance**, addmo uses **build watch** for hot reload—same bundled output in dev and production, without sacrificing build speed.
17
+
18
+ ## Quick start
19
+
20
+ ### Option 1: Scaffold a new project
21
+
22
+ ```bash
23
+ pnpm create addmo-app
24
+ # or
25
+ npx create-addmo-app
26
+ ```
27
+
28
+ Follow the prompts: (1) framework (Vanilla / Vue / React / Preact / Svelte / Solid), (2) language (TypeScript / JavaScript), (3) package manager (pnpm / npm / yarn / bun), (4) entries to include, (5) whether to install addmo skills. A full project layout and `addmo.config` will be generated.
29
+
30
+ ### Option 2: Add to an existing project
31
+
32
+ Install the main package **addmo** as a **dev dependency** (build tool; one install gives you the CLI and all build tooling; internally it uses `@addmo/cli` and `@rsbuild/core`):
33
+
34
+ ```bash
35
+ pnpm add -D addmo
36
+ # or
37
+ npm install -D addmo
38
+ # or
39
+ yarn add -D addmo
40
+ ```
41
+
42
+ Create `addmo.config.ts` (or `addmo.config.js` / `addmo.config.mjs`) in the project root and configure it as below. Your layout must include entries such as `background`, `content`, `popup`, `options`, `sidepanel` (under `app/` by default or under a dir set via `appDir`).
43
+
44
+ ### Packages and imports
45
+
46
+ - **Core** (`defineConfig`, types, discovery, manifest, etc.) is exported from **addmo**. In config use: `import { defineConfig } from "addmo"`.
47
+ - **Content UI** is in **`@addmo/utils`**: `import { defineContentUI, mountContentUI } from "@addmo/utils"`. For the `browser` API, install [webextension-polyfill](https://github.com/mozilla/webextension-polyfill) and use `import browser from "webextension-polyfill"`.
48
+
49
+ ## Config
50
+
51
+ Config file: `addmo.config.ts`, `addmo.config.js`, or `addmo.config.mjs`.
52
+
53
+ Return a config object from `defineConfig`. Supported fields:
54
+
55
+ | Field | Description |
56
+ |-------|-------------|
57
+ | **manifest** | Extension manifest. Single object or split as `chromium` / `firefox` |
58
+ | **plugins** | Rsbuild plugins array (like Vite). Use function calls, e.g. `plugins: [vue()]` (from `@addmo/rsbuild-plugin-vue`) or `plugins: [pluginReact()]` (from `@rsbuild/plugin-react`) |
59
+ | **rsbuild** | Override or extend Rsbuild config (like Vite’s build options). **Object**: deep-merged with base. **Function**: `(base, helpers) => config` for full control; use `helpers.merge(base, overrides)` for deep-merge |
60
+ | **entry** | Custom entries: object, key = entry name (reserved: popup, options, sidepanel, background, devtools, content; others custom), value = path string relative to baseDir (e.g. `'content/index.ts'`). Omit to use default discovery from appDir |
61
+ | **appDir** | App directory; default is `app/`. Also the base for **entry** paths |
62
+ | **outDir** | Output directory name under `.addmo`; default `"extension"` (output at `.addmo/extension`) |
63
+ | **browserPath** | Dev browser executable paths. `browserPath.chrome`, `browserPath.firefox`, etc.; used when running `addmo dev`. If unset, uses OS default install paths |
64
+ | **hooks** | Lifecycle hooks at “parse CLI → load config → build Rsbuild config → run build”. See “Lifecycle hooks” below |
65
+
66
+ ### Lifecycle hooks
67
+
68
+ Configure `hooks` in `defineConfig`. Each hook receives `PipelineContext` (root, command, browser, config, entries, rsbuild, etc.):
69
+
70
+ | Hook | When |
71
+ |------|------|
72
+ | **afterCliParsed** | After CLI args (command, -b) are parsed |
73
+ | **afterConfigLoaded** | After config and entries are resolved |
74
+ | **beforeRsbuildConfig** | After manifest and entries are fixed, before Rsbuild config is built |
75
+ | **beforeBuild** | After Rsbuild config is ready, before build runs |
76
+ | **afterBuild** | After build finishes (only for `addmo build`; dev runs watch and does not exit) |
77
+
78
+ ### Errors and exit codes
79
+
80
+ On missing config, no entries, invalid command or invalid `-b`, the CLI throws **AddmoError** (with `code`, `details`, `hint`), prints a clear message to stderr and exits with a non-zero code. Error codes are exported from `addmo` as `ADDMO_ERROR_CODES`.
81
+
82
+ ### Config example
83
+
84
+ ```ts
85
+ import { defineConfig } from "addmo";
86
+ import vue from "@addmo/rsbuild-plugin-vue";
87
+
88
+ export default defineConfig({
89
+ appDir: "app",
90
+ outDir: "extension",
91
+ manifest: {
92
+ name: "My Extension",
93
+ version: "1.0.0",
94
+ manifest_version: 3,
95
+ permissions: ["storage", "activeTab"],
96
+ },
97
+ plugins: [vue()],
98
+ // browserPath: { chrome: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", firefox: "..." },
99
+ // rsbuild: (base, helpers) => helpers.merge(base, { ... }),
100
+ // entry: { background: "background/index.ts", content: "content/index.ts", popup: "popup/index.ts" },
101
+ // hooks: { beforeBuild: (ctx) => console.log("Building for", ctx.browser) },
102
+ });
103
+ ```
104
+
105
+ ## Directory and entry convention
106
+
107
+ - By default, entries are discovered under **app/** or **appDir** (baseDir). You can override with **entry**:
108
+ - **background**, **content**: script only
109
+ - **popup**, **options**, **sidepanel**, **devtools**: require `index.html` + entry script in the same dir
110
+ - Reserved names (fixed): popup, options, sidepanel, background, devtools, content; other names are custom
111
+ - **entry** values are paths relative to baseDir, e.g. `'content/index.ts'`, `'src/popup/index.ts'`
112
+
113
+ ## Commands
114
+
115
+ In a project that has addmo installed:
116
+
117
+ - `addmo dev` or `pnpm dev` (if `"dev": "addmo dev"` in package.json): dev mode with watch and HMR (Reload Manager extension + local WebSocket)
118
+ - `addmo build`: production build to `.addmo/<outDir>` (default `outDir` is `"extension"`); optionally zips to `.addmo/<outDir>.zip`
119
+
120
+ **Terminal output**: When running `addmo dev` or `addmo build`, each line is prefixed with **`[addmo]`** so you can tell addmo’s output from Rsbuild’s; full Rsbuild logs and errors are unchanged.
121
+
122
+ Use **`-b, --browser <browser>`** to choose the target browser (and thus manifest branch and dev browser): `chromium`, `firefox`, `chrome`, `edge`, `brave`, etc.
123
+
124
+ - `addmo dev -b chrome` / `addmo dev -b firefox`
125
+ - `addmo build -b chrome` / `addmo build -b firefox`
126
+
127
+ Default is Chrome if `-b` is omitted. The target is determined only by `-b`, not by env vars.
128
+
129
+ ## Dependencies
130
+
131
+ The framework follows common practice: **recommended dev dependencies** are checked before build and **installed automatically** when missing (using the project’s package manager: pnpm / npm / yarn / bun).
132
+
133
+ - **Extension development**: `@types/chrome` (Chrome extension API types) is installed as a dev dependency if not already in the project.
134
+ - **Plugins**: If you use `plugins: [vue()]`, the CLI ensures `vue` is installed. For React, use `@rsbuild/plugin-react` and add `react` and `react-dom` (and `@rsbuild/plugin-react`) to your project.
135
+
136
+ To skip auto-install (e.g. in CI or when you manage deps yourself), set **`ADDMO_SKIP_DEPS=1`**.
137
+
138
+ - **addmo** brings in `@addmo/cli`, `@rsbuild/core`, and the framework plugins; you only need to add **addmo** to your project. Use `addmo dev` and `addmo build` in your scripts.
139
+
140
+ ## Dev HMR
141
+
142
+ In dev, a WebSocket server is started and the extension is reloaded after each build. The Rsbuild plugin opens the browser and loads the extension after the first build; later rebuilds trigger a reload via WebSocket.
143
+
144
+ Browser paths: set **browserPath** in config to override; otherwise the framework tries OS default paths (Windows / macOS / Linux).
145
+
146
+ ## Repo structure
147
+
148
+ - `packages/addmo`: **addmo** – main package users install; provides the `addmo` binary and delegates to `@addmo/cli` (same idea as installing `parcel` while internals live in `@parcel/*`)
149
+ - `packages/cli`: **@addmo/cli** – CLI entry and **Pipeline** (parse → config → Rsbuild config → hooks; injects ConfigLoader / CliParser)
150
+ - `packages/core`: Core modules; filenames match class names (camelCase): **ConfigLoader** (configLoader.ts), **CliParser** (cliParser.ts), **EntryDiscoverer** (entryDiscoverer.ts), **EntryResolver** (entryResolver.ts), **ManifestBuilder** (manifestBuilder.ts); constants, AddmoError, mergeRsbuildConfig, defineConfig, types
151
+ - `packages/utils`: Utilities (webextension-polyfill etc.); use `@addmo/utils` as needed
152
+ - `packages/plugins/rsbuild-plugin-extension-entry`: **Internal** – resolves dirs and entries, sets entry/html/output (package: `@addmo/rsbuild-plugin-extension-entry`)
153
+ - `packages/plugins/rsbuild-plugin-extension-manifest`: **Internal** – writes manifest.json (package: `@addmo/rsbuild-plugin-extension-manifest`)
154
+ - `packages/plugins/rsbuild-plugin-extension-hmr**: **Internal** – dev HMR and browser launch
155
+ - `packages/plugins/rsbuild-plugin-vue`: Vue 3 + Vue JSX + Less + Babel; use `plugins: [vue()]`
156
+ - `packages/create-addmo-app`: Scaffold CLI; generates project with `plugins: [vue()]` or `plugins: [pluginReact()]` (use `@rsbuild/plugin-react` for React)
157
+
158
+ The framework runs rsbuild-plugin-extension-entry, rsbuild-plugin-extension-manifest and rsbuild-plugin-extension-hmr by default. Users add framework plugins via `plugins: [vue()]` etc. and override Rsbuild via `rsbuild`.
package/bin/addmo.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ // Delegates to @addmo/cli — users install "addmo", internals stay @addmo/*
3
+ import "@addmo/cli/dist/cli.js";
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "@addmo/core";
2
+ export { setupAddmoMonitor } from "@addmo/rsbuild-plugin-extension-monitor/runtime";
package/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from "@addmo/core";
2
+ export { setupAddmoMonitor } from "@addmo/rsbuild-plugin-extension-monitor/runtime";
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "addfox",
3
+ "version": "0.1.1-beta.1",
4
+ "description": "Build tool for browser extensions — one install, addmo dev / build",
5
+ "type": "module",
6
+ "bin": {
7
+ "addmo": "./bin/addmo.mjs"
8
+ },
9
+ "main": "./index.mjs",
10
+ "module": "./index.mjs",
11
+ "types": "./index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./index.d.ts",
15
+ "import": "./index.mjs",
16
+ "default": "./index.mjs"
17
+ },
18
+ "./monitor": {
19
+ "types": "./monitor.d.ts",
20
+ "import": "./monitor.mjs",
21
+ "default": "./monitor.mjs"
22
+ }
23
+ },
24
+ "files": [
25
+ "bin",
26
+ "index.mjs",
27
+ "index.d.ts"
28
+ ],
29
+ "scripts": {
30
+ "build": "echo 'No build step'",
31
+ "test": "node -e \"process.exit(0)\"",
32
+ "test:coverage": "node -e \"process.exit(0)\""
33
+ },
34
+ "dependencies": {
35
+ "@addmo/cli": "workspace:*",
36
+ "@addmo/core": "workspace:*",
37
+ "@addmo/rsbuild-plugin-extension-monitor": "workspace:*"
38
+ }
39
+ }