@rainbow-robotics/plugin-ui 1.3.8-dev.4 → 1.10.1-dev.0
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 +246 -246
- package/build-dist.mjs +80 -80
- package/dist/host-ui.js.map +1 -1
- package/dist/manifest.js.map +1 -1
- package/dist/react.d.ts +13 -13
- package/dist/react.js.map +1 -1
- package/dist/sdk.js.map +1 -1
- package/dist/viteHost.js.map +1 -1
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js.map +1 -1
- package/package.json +1 -1
- package/src/host-ui.ts +95 -95
- package/src/host.tsx +277 -277
- package/src/index.d.ts +1 -1
- package/src/manifest.ts +135 -135
- package/src/pluginData.tsx +240 -240
- package/src/react.tsx +13 -13
- package/src/sdk.ts +175 -175
- package/src/viteHost.ts +309 -309
- package/src/ws.ts +256 -256
package/README.md
CHANGED
|
@@ -1,246 +1,246 @@
|
|
|
1
|
-
# @rainbow-robotics/plugin-ui
|
|
2
|
-
|
|
3
|
-
# Muscat plugin UI contract and host mounting architecture
|
|
4
|
-
|
|
5
|
-
A Muscat plugin is a plain React component exported as `export default App`.
|
|
6
|
-
|
|
7
|
-
Plugin mounting works through two paths, both handled by the `./host` package.
|
|
8
|
-
|
|
9
|
-
## Dev environment: `muscat-pk dev`
|
|
10
|
-
|
|
11
|
-
In dev, the plugin's own Vite dev server (using the plugin's `vite.config.ts`) serves a bootstrap module.
|
|
12
|
-
|
|
13
|
-
The host dynamically imports that bootstrap module to run the plugin.
|
|
14
|
-
|
|
15
|
-
Characteristics of this approach:
|
|
16
|
-
|
|
17
|
-
* Full HMR support
|
|
18
|
-
* The plugin runs as its own independent React root
|
|
19
|
-
* The plugin uses its own React instance
|
|
20
|
-
* The host's React tree and the plugin's React tree are separate
|
|
21
|
-
|
|
22
|
-
In other words, in dev the plugin runs inside the host page, but it does not share the React runtime with the host.
|
|
23
|
-
|
|
24
|
-
## Build & robot environment: `muscat-pk build`
|
|
25
|
-
|
|
26
|
-
`muscat-pk build` is not its own bundler — it's a thin wrapper that **runs `vite build` using the plugin project's own `vite.config.ts`**
|
|
27
|
-
(no `--config` is passed; it just sets `cwd` to the plugin root and runs `vite build` — Vite reads that directory's `vite.config.ts` on its own).
|
|
28
|
-
|
|
29
|
-
The scaffolded `vite.config.ts` looks like this:
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
import { defineConfig } from "vite";
|
|
33
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
34
|
-
import { muscat } from "@rainbow-robotics/muscat-plugin-kit/vite";
|
|
35
|
-
export default defineConfig({ plugins: [tailwindcss(), muscat()] });
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
**The external list and rollup config live in `@rainbow-robotics/muscat-plugin-kit`'s `muscat()` preset (`cli/vite.mjs`), not in this package (`@rainbow-robotics/plugin-ui`).** The roles split as follows:
|
|
39
|
-
|
|
40
|
-
| Package | Responsibility |
|
|
41
|
-
|---|---|
|
|
42
|
-
| `@rainbow-robotics/muscat-plugin-kit` | Build time — the `muscat()` preset (external list, entry discovery, rollup config) |
|
|
43
|
-
| `@rainbow-robotics/plugin-ui` (this package) | Runtime — `./host` (mounting), `./vite-host` (import-map injection on the nexus side) |
|
|
44
|
-
|
|
45
|
-
The `muscat()` preset leaves the following dependencies out of the plugin bundle as external bare specifiers:
|
|
46
|
-
|
|
47
|
-
```text
|
|
48
|
-
react
|
|
49
|
-
react-dom
|
|
50
|
-
@rainbow-robotics/plugin-ui/*
|
|
51
|
-
@repo/rb-components
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
The host page includes an import map set up by `./vite-host`.
|
|
55
|
-
|
|
56
|
-
This import map resolves those bare specifiers to the actual module instances the host has already loaded.
|
|
57
|
-
|
|
58
|
-
So a plugin loaded in production behaves as follows:
|
|
59
|
-
|
|
60
|
-
* Uses the same React instance as the host
|
|
61
|
-
* Mounts as a real nested React tree inside the host's React tree
|
|
62
|
-
* Shares `RbContext`
|
|
63
|
-
* Shares the host's UI context
|
|
64
|
-
* Minimizes the plugin bundle size
|
|
65
|
-
|
|
66
|
-
In dev the plugin runs as its own independent React root; in build/robot environments it runs nested inside the host's React tree.
|
|
67
|
-
|
|
68
|
-
### Plugins with no UI skip the vite build entirely
|
|
69
|
-
|
|
70
|
-
`muscat-pk build` collects `contributes[].ui` from `manifest.json` and verifies that a matching `ui/{name}.tsx` (or `.ts`/`.jsx`/`.js`) file actually exists.
|
|
71
|
-
|
|
72
|
-
* If `contributes` declares a `ui` but the file doesn't exist → build fails (clear error)
|
|
73
|
-
* If `contributes` declares no `ui` and the `ui/` directory has no files either (a backend-only plugin) → **the vite build is skipped entirely.** `dist/` only contains manifest.json/assets/backend files.
|
|
74
|
-
|
|
75
|
-
This logic lives in `buildPlugin()` in `libraries/muscat-plugin-kit/cli/src/build.mjs`.
|
|
76
|
-
|
|
77
|
-
### When Node.js isn't available
|
|
78
|
-
|
|
79
|
-
`muscat-pk build` isn't its own bundler — it **spawns `vite build` as a child process**, so a JS runtime must be available to run that child process.
|
|
80
|
-
|
|
81
|
-
* **`muscat-pk` installed via npm** → already running under Node, so this issue never occurs.
|
|
82
|
-
* **`muscat-pk` installed via the S3 self-contained binary (compiled with Bun)** → looks on PATH in order: `bun` → `node` → `nodejs`. If none are found:
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
Node.js 20+ (or Bun) is required to build the plugin UI.
|
|
86
|
-
Install Node.js: https://nodejs.org
|
|
87
|
-
Then run: npm install (inside the plugin directory)
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
is printed and the process exits with `exitCode 1` quietly (no stack trace). This logic lives in `findJsRuntime()` / `runViteBuild()` in `build.mjs`.
|
|
91
|
-
|
|
92
|
-
# Entry points
|
|
93
|
-
|
|
94
|
-
## `./react`
|
|
95
|
-
|
|
96
|
-
Used by:
|
|
97
|
-
|
|
98
|
-
```text
|
|
99
|
-
plugin
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Re-exports every `new-components` export from `@repo/rb-components`, plus the `useRb`, `useRbFormData`, and `useRbSave` hooks from `./sdk`.
|
|
103
|
-
|
|
104
|
-
Plugins should use UI components through this entry point rather than importing `@repo/rb-components` directly.
|
|
105
|
-
|
|
106
|
-
`muscat-pk mcp` parses this package's `dist/react.d.ts` (a self-contained bundle of rb-components' types) to give AI coding agents component lists and prop info.
|
|
107
|
-
|
|
108
|
-
## `./sdk`
|
|
109
|
-
|
|
110
|
-
Used by:
|
|
111
|
-
|
|
112
|
-
```text
|
|
113
|
-
plugin
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Provides `useRb()`.
|
|
117
|
-
|
|
118
|
-
`useRb()` gives access to:
|
|
119
|
-
|
|
120
|
-
* Zenoh-WebSocket-based robot publish
|
|
121
|
-
* subscribe
|
|
122
|
-
* action calls
|
|
123
|
-
* serve
|
|
124
|
-
* toast
|
|
125
|
-
* alert
|
|
126
|
-
* confirm
|
|
127
|
-
* prompt
|
|
128
|
-
|
|
129
|
-
Instead of implementing dialog/toast UI itself, a plugin delegates these requests to the host's real dialog and toast implementation.
|
|
130
|
-
|
|
131
|
-
See `./host-ui` for the actual host UI service implementation.
|
|
132
|
-
|
|
133
|
-
`useRbFormData()` / `useRbSave()` are also provided by `./sdk`. The host passes previously-saved `data` to the plugin, and the plugin registers a payload getter via `onSave` — form save/restore is owned by the host, not the plugin.
|
|
134
|
-
|
|
135
|
-
## `./ws`
|
|
136
|
-
|
|
137
|
-
Used by:
|
|
138
|
-
|
|
139
|
-
```text
|
|
140
|
-
plugin dev bootstrap only
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
Provides `RbWs`.
|
|
144
|
-
|
|
145
|
-
`RbWs` is the WebSocket client `useRb()` uses internally.
|
|
146
|
-
|
|
147
|
-
This entry point isn't used by a plugin's normal production code — it's only used by the dev-environment bootstrap module.
|
|
148
|
-
|
|
149
|
-
## `./manifest`
|
|
150
|
-
|
|
151
|
-
Used by:
|
|
152
|
-
|
|
153
|
-
```text
|
|
154
|
-
nexus
|
|
155
|
-
muscat-pk
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Provides the plugin manifest schema.
|
|
159
|
-
|
|
160
|
-
Acts as the single source of truth for the manifest definition.
|
|
161
|
-
|
|
162
|
-
`contributes[].point` (`CONTRIBUTION_POINTS`) has 4 possible values:
|
|
163
|
-
|
|
164
|
-
| point | Description |
|
|
165
|
-
|---|---|
|
|
166
|
-
| `toolbar` | A live UI panel exposed in the top toolbar |
|
|
167
|
-
| `lnb` | A live UI panel exposed in the left navigation bar (LNB) |
|
|
168
|
-
| `move.panel` | A live UI panel exposed in the Move panel |
|
|
169
|
-
| `program.panel` | A custom command the plugin defines for the Program page's rule-based sequence builder |
|
|
170
|
-
|
|
171
|
-
`toolbar`/`lnb`/`move.panel` back ends use `RBManipulateSDK`/`RBAmrSDK` or `rb.action()` directly. `program.panel` declares `commandInfo` (`funcName: "rb_program_sdk.plugin_execute"`) and its backend runs through `PluginProgramContext` (`on_execute`, `check_stop`, `get_variable`, `set_variable`, `done`).
|
|
172
|
-
|
|
173
|
-
## `./plugin-data`
|
|
174
|
-
|
|
175
|
-
Used by:
|
|
176
|
-
|
|
177
|
-
```text
|
|
178
|
-
nexus only
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
Provides:
|
|
182
|
-
|
|
183
|
-
```text
|
|
184
|
-
PluginDataProvider
|
|
185
|
-
usePluginData()
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
Decides where and how a plugin is loaded from.
|
|
189
|
-
|
|
190
|
-
## `./host`
|
|
191
|
-
|
|
192
|
-
Used by:
|
|
193
|
-
|
|
194
|
-
```text
|
|
195
|
-
nexus only
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
Provides `PluginHost`.
|
|
199
|
-
|
|
200
|
-
`PluginHost` handles both mounting paths described above:
|
|
201
|
-
|
|
202
|
-
* The dev environment's dynamic Vite bootstrap import
|
|
203
|
-
* The build/robot environment's ESM module mount
|
|
204
|
-
|
|
205
|
-
## `./vite-host`
|
|
206
|
-
|
|
207
|
-
Used by:
|
|
208
|
-
|
|
209
|
-
```text
|
|
210
|
-
nexus vite.config.ts
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
Provides Vite plugins.
|
|
214
|
-
|
|
215
|
-
Main responsibilities:
|
|
216
|
-
|
|
217
|
-
* Injecting the import map
|
|
218
|
-
* Supporting the plugin preview dev environment
|
|
219
|
-
|
|
220
|
-
# Plugin production bundle rules
|
|
221
|
-
|
|
222
|
-
A plugin's production bundle should only import these entry points:
|
|
223
|
-
|
|
224
|
-
```text
|
|
225
|
-
./react
|
|
226
|
-
./sdk
|
|
227
|
-
./host-ui
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
`./host-ui` is used optionally, only when needed.
|
|
231
|
-
|
|
232
|
-
The following entry points, on the other hand, are host-only:
|
|
233
|
-
|
|
234
|
-
```text
|
|
235
|
-
./host
|
|
236
|
-
./vite-host
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
These modules include host-only dependencies:
|
|
240
|
-
|
|
241
|
-
```text
|
|
242
|
-
@repo/rb-components
|
|
243
|
-
vite
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
So `./host` and `./vite-host` are never included in a plugin bundle.
|
|
1
|
+
# @rainbow-robotics/plugin-ui
|
|
2
|
+
|
|
3
|
+
# Muscat plugin UI contract and host mounting architecture
|
|
4
|
+
|
|
5
|
+
A Muscat plugin is a plain React component exported as `export default App`.
|
|
6
|
+
|
|
7
|
+
Plugin mounting works through two paths, both handled by the `./host` package.
|
|
8
|
+
|
|
9
|
+
## Dev environment: `muscat-pk dev`
|
|
10
|
+
|
|
11
|
+
In dev, the plugin's own Vite dev server (using the plugin's `vite.config.ts`) serves a bootstrap module.
|
|
12
|
+
|
|
13
|
+
The host dynamically imports that bootstrap module to run the plugin.
|
|
14
|
+
|
|
15
|
+
Characteristics of this approach:
|
|
16
|
+
|
|
17
|
+
* Full HMR support
|
|
18
|
+
* The plugin runs as its own independent React root
|
|
19
|
+
* The plugin uses its own React instance
|
|
20
|
+
* The host's React tree and the plugin's React tree are separate
|
|
21
|
+
|
|
22
|
+
In other words, in dev the plugin runs inside the host page, but it does not share the React runtime with the host.
|
|
23
|
+
|
|
24
|
+
## Build & robot environment: `muscat-pk build`
|
|
25
|
+
|
|
26
|
+
`muscat-pk build` is not its own bundler — it's a thin wrapper that **runs `vite build` using the plugin project's own `vite.config.ts`**
|
|
27
|
+
(no `--config` is passed; it just sets `cwd` to the plugin root and runs `vite build` — Vite reads that directory's `vite.config.ts` on its own).
|
|
28
|
+
|
|
29
|
+
The scaffolded `vite.config.ts` looks like this:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { defineConfig } from "vite";
|
|
33
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
34
|
+
import { muscat } from "@rainbow-robotics/muscat-plugin-kit/vite";
|
|
35
|
+
export default defineConfig({ plugins: [tailwindcss(), muscat()] });
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**The external list and rollup config live in `@rainbow-robotics/muscat-plugin-kit`'s `muscat()` preset (`cli/vite.mjs`), not in this package (`@rainbow-robotics/plugin-ui`).** The roles split as follows:
|
|
39
|
+
|
|
40
|
+
| Package | Responsibility |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `@rainbow-robotics/muscat-plugin-kit` | Build time — the `muscat()` preset (external list, entry discovery, rollup config) |
|
|
43
|
+
| `@rainbow-robotics/plugin-ui` (this package) | Runtime — `./host` (mounting), `./vite-host` (import-map injection on the nexus side) |
|
|
44
|
+
|
|
45
|
+
The `muscat()` preset leaves the following dependencies out of the plugin bundle as external bare specifiers:
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
react
|
|
49
|
+
react-dom
|
|
50
|
+
@rainbow-robotics/plugin-ui/*
|
|
51
|
+
@repo/rb-components
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The host page includes an import map set up by `./vite-host`.
|
|
55
|
+
|
|
56
|
+
This import map resolves those bare specifiers to the actual module instances the host has already loaded.
|
|
57
|
+
|
|
58
|
+
So a plugin loaded in production behaves as follows:
|
|
59
|
+
|
|
60
|
+
* Uses the same React instance as the host
|
|
61
|
+
* Mounts as a real nested React tree inside the host's React tree
|
|
62
|
+
* Shares `RbContext`
|
|
63
|
+
* Shares the host's UI context
|
|
64
|
+
* Minimizes the plugin bundle size
|
|
65
|
+
|
|
66
|
+
In dev the plugin runs as its own independent React root; in build/robot environments it runs nested inside the host's React tree.
|
|
67
|
+
|
|
68
|
+
### Plugins with no UI skip the vite build entirely
|
|
69
|
+
|
|
70
|
+
`muscat-pk build` collects `contributes[].ui` from `manifest.json` and verifies that a matching `ui/{name}.tsx` (or `.ts`/`.jsx`/`.js`) file actually exists.
|
|
71
|
+
|
|
72
|
+
* If `contributes` declares a `ui` but the file doesn't exist → build fails (clear error)
|
|
73
|
+
* If `contributes` declares no `ui` and the `ui/` directory has no files either (a backend-only plugin) → **the vite build is skipped entirely.** `dist/` only contains manifest.json/assets/backend files.
|
|
74
|
+
|
|
75
|
+
This logic lives in `buildPlugin()` in `libraries/muscat-plugin-kit/cli/src/build.mjs`.
|
|
76
|
+
|
|
77
|
+
### When Node.js isn't available
|
|
78
|
+
|
|
79
|
+
`muscat-pk build` isn't its own bundler — it **spawns `vite build` as a child process**, so a JS runtime must be available to run that child process.
|
|
80
|
+
|
|
81
|
+
* **`muscat-pk` installed via npm** → already running under Node, so this issue never occurs.
|
|
82
|
+
* **`muscat-pk` installed via the S3 self-contained binary (compiled with Bun)** → looks on PATH in order: `bun` → `node` → `nodejs`. If none are found:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Node.js 20+ (or Bun) is required to build the plugin UI.
|
|
86
|
+
Install Node.js: https://nodejs.org
|
|
87
|
+
Then run: npm install (inside the plugin directory)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
is printed and the process exits with `exitCode 1` quietly (no stack trace). This logic lives in `findJsRuntime()` / `runViteBuild()` in `build.mjs`.
|
|
91
|
+
|
|
92
|
+
# Entry points
|
|
93
|
+
|
|
94
|
+
## `./react`
|
|
95
|
+
|
|
96
|
+
Used by:
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
plugin
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Re-exports every `new-components` export from `@repo/rb-components`, plus the `useRb`, `useRbFormData`, and `useRbSave` hooks from `./sdk`.
|
|
103
|
+
|
|
104
|
+
Plugins should use UI components through this entry point rather than importing `@repo/rb-components` directly.
|
|
105
|
+
|
|
106
|
+
`muscat-pk mcp` parses this package's `dist/react.d.ts` (a self-contained bundle of rb-components' types) to give AI coding agents component lists and prop info.
|
|
107
|
+
|
|
108
|
+
## `./sdk`
|
|
109
|
+
|
|
110
|
+
Used by:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
plugin
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Provides `useRb()`.
|
|
117
|
+
|
|
118
|
+
`useRb()` gives access to:
|
|
119
|
+
|
|
120
|
+
* Zenoh-WebSocket-based robot publish
|
|
121
|
+
* subscribe
|
|
122
|
+
* action calls
|
|
123
|
+
* serve
|
|
124
|
+
* toast
|
|
125
|
+
* alert
|
|
126
|
+
* confirm
|
|
127
|
+
* prompt
|
|
128
|
+
|
|
129
|
+
Instead of implementing dialog/toast UI itself, a plugin delegates these requests to the host's real dialog and toast implementation.
|
|
130
|
+
|
|
131
|
+
See `./host-ui` for the actual host UI service implementation.
|
|
132
|
+
|
|
133
|
+
`useRbFormData()` / `useRbSave()` are also provided by `./sdk`. The host passes previously-saved `data` to the plugin, and the plugin registers a payload getter via `onSave` — form save/restore is owned by the host, not the plugin.
|
|
134
|
+
|
|
135
|
+
## `./ws`
|
|
136
|
+
|
|
137
|
+
Used by:
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
plugin dev bootstrap only
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Provides `RbWs`.
|
|
144
|
+
|
|
145
|
+
`RbWs` is the WebSocket client `useRb()` uses internally.
|
|
146
|
+
|
|
147
|
+
This entry point isn't used by a plugin's normal production code — it's only used by the dev-environment bootstrap module.
|
|
148
|
+
|
|
149
|
+
## `./manifest`
|
|
150
|
+
|
|
151
|
+
Used by:
|
|
152
|
+
|
|
153
|
+
```text
|
|
154
|
+
nexus
|
|
155
|
+
muscat-pk
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Provides the plugin manifest schema.
|
|
159
|
+
|
|
160
|
+
Acts as the single source of truth for the manifest definition.
|
|
161
|
+
|
|
162
|
+
`contributes[].point` (`CONTRIBUTION_POINTS`) has 4 possible values:
|
|
163
|
+
|
|
164
|
+
| point | Description |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `toolbar` | A live UI panel exposed in the top toolbar |
|
|
167
|
+
| `lnb` | A live UI panel exposed in the left navigation bar (LNB) |
|
|
168
|
+
| `move.panel` | A live UI panel exposed in the Move panel |
|
|
169
|
+
| `program.panel` | A custom command the plugin defines for the Program page's rule-based sequence builder |
|
|
170
|
+
|
|
171
|
+
`toolbar`/`lnb`/`move.panel` back ends use `RBManipulateSDK`/`RBAmrSDK` or `rb.action()` directly. `program.panel` declares `commandInfo` (`funcName: "rb_program_sdk.plugin_execute"`) and its backend runs through `PluginProgramContext` (`on_execute`, `check_stop`, `get_variable`, `set_variable`, `done`).
|
|
172
|
+
|
|
173
|
+
## `./plugin-data`
|
|
174
|
+
|
|
175
|
+
Used by:
|
|
176
|
+
|
|
177
|
+
```text
|
|
178
|
+
nexus only
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Provides:
|
|
182
|
+
|
|
183
|
+
```text
|
|
184
|
+
PluginDataProvider
|
|
185
|
+
usePluginData()
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Decides where and how a plugin is loaded from.
|
|
189
|
+
|
|
190
|
+
## `./host`
|
|
191
|
+
|
|
192
|
+
Used by:
|
|
193
|
+
|
|
194
|
+
```text
|
|
195
|
+
nexus only
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Provides `PluginHost`.
|
|
199
|
+
|
|
200
|
+
`PluginHost` handles both mounting paths described above:
|
|
201
|
+
|
|
202
|
+
* The dev environment's dynamic Vite bootstrap import
|
|
203
|
+
* The build/robot environment's ESM module mount
|
|
204
|
+
|
|
205
|
+
## `./vite-host`
|
|
206
|
+
|
|
207
|
+
Used by:
|
|
208
|
+
|
|
209
|
+
```text
|
|
210
|
+
nexus vite.config.ts
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Provides Vite plugins.
|
|
214
|
+
|
|
215
|
+
Main responsibilities:
|
|
216
|
+
|
|
217
|
+
* Injecting the import map
|
|
218
|
+
* Supporting the plugin preview dev environment
|
|
219
|
+
|
|
220
|
+
# Plugin production bundle rules
|
|
221
|
+
|
|
222
|
+
A plugin's production bundle should only import these entry points:
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
./react
|
|
226
|
+
./sdk
|
|
227
|
+
./host-ui
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
`./host-ui` is used optionally, only when needed.
|
|
231
|
+
|
|
232
|
+
The following entry points, on the other hand, are host-only:
|
|
233
|
+
|
|
234
|
+
```text
|
|
235
|
+
./host
|
|
236
|
+
./vite-host
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
These modules include host-only dependencies:
|
|
240
|
+
|
|
241
|
+
```text
|
|
242
|
+
@repo/rb-components
|
|
243
|
+
vite
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
So `./host` and `./vite-host` are never included in a plugin bundle.
|
package/build-dist.mjs
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import { build } from "esbuild";
|
|
2
|
-
import { rollup } from "rollup";
|
|
3
|
-
import dts from "rollup-plugin-dts";
|
|
4
|
-
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
5
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
-
import { rmSync } from "node:fs";
|
|
7
|
-
import { dirname, resolve } from "node:path";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
|
|
10
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
|
|
12
|
-
rmSync(resolve(here, "dist"), { recursive: true, force: true });
|
|
13
|
-
|
|
14
|
-
// JS: transpile only (no bundling — consumers resolve deps themselves)
|
|
15
|
-
await build({
|
|
16
|
-
entryPoints: {
|
|
17
|
-
react: resolve(here, "src/react.tsx"),
|
|
18
|
-
sdk: resolve(here, "src/sdk.ts"),
|
|
19
|
-
manifest: resolve(here, "src/manifest.ts"),
|
|
20
|
-
viteHost: resolve(here, "src/viteHost.ts"),
|
|
21
|
-
"host-ui": resolve(here, "src/host-ui.ts"),
|
|
22
|
-
// ws is used by the dev bootstrap + host.tsx to build the rb sdk.
|
|
23
|
-
ws: resolve(here, "src/ws.ts"),
|
|
24
|
-
},
|
|
25
|
-
outdir: resolve(here, "dist"),
|
|
26
|
-
format: "esm",
|
|
27
|
-
bundle: false, // each file transpiled independently, deps stay as imports
|
|
28
|
-
platform: "neutral",
|
|
29
|
-
target: "es2022",
|
|
30
|
-
sourcemap: true,
|
|
31
|
-
logLevel: "warning",
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const tsc = spawnSync(
|
|
35
|
-
"node",
|
|
36
|
-
[
|
|
37
|
-
"../../node_modules/typescript/bin/tsc",
|
|
38
|
-
"-p",
|
|
39
|
-
"tsconfig.build.json",
|
|
40
|
-
"--emitDeclarationOnly",
|
|
41
|
-
"--noEmit",
|
|
42
|
-
"false",
|
|
43
|
-
],
|
|
44
|
-
{ cwd: here, stdio: "inherit" },
|
|
45
|
-
);
|
|
46
|
-
if (tsc.status !== 0) {
|
|
47
|
-
console.warn(
|
|
48
|
-
"[plugin-ui] tsc reported errors during declaration emit (likely the known rb-providers/rb-utils " +
|
|
49
|
-
"global.d.ts gap, unrelated to plugin-ui) — .d.ts files were still written; continuing.",
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const reactExternal = (id) =>
|
|
54
|
-
/^react($|\/)/.test(id) || /^react-dom($|\/)/.test(id);
|
|
55
|
-
|
|
56
|
-
const ASSET_RE =
|
|
57
|
-
/\.(css|scss|sass|less|svg|png|jpe?g|gif|webp|woff2?)(\?\w+)?$|^swiper\/css/;
|
|
58
|
-
const stubAssets = {
|
|
59
|
-
name: "stub-assets-for-dts",
|
|
60
|
-
resolveId: (id) => (ASSET_RE.test(id) ? "\0asset-stub" : null),
|
|
61
|
-
load: (id) => (id === "\0asset-stub" ? "export default undefined;" : null),
|
|
62
|
-
};
|
|
63
|
-
const dtsBundle = await rollup({
|
|
64
|
-
input: resolve(here, "src/react.tsx"),
|
|
65
|
-
external: reactExternal,
|
|
66
|
-
plugins: [
|
|
67
|
-
stubAssets,
|
|
68
|
-
nodeResolve({ extensions: [".d.ts", ".ts", ".tsx", ".js", ".jsx"] }),
|
|
69
|
-
dts({ respectExternal: false }),
|
|
70
|
-
],
|
|
71
|
-
onwarn: () => {},
|
|
72
|
-
});
|
|
73
|
-
await dtsBundle.write({
|
|
74
|
-
file: resolve(here, "dist/react.d.ts"),
|
|
75
|
-
format: "es",
|
|
76
|
-
});
|
|
77
|
-
await dtsBundle.close();
|
|
78
|
-
rmSync(resolve(here, "dist/react.d.ts.map"), { force: true });
|
|
79
|
-
|
|
80
|
-
console.log("[plugin-ui] dist/ ready");
|
|
1
|
+
import { build } from "esbuild";
|
|
2
|
+
import { rollup } from "rollup";
|
|
3
|
+
import dts from "rollup-plugin-dts";
|
|
4
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { rmSync } from "node:fs";
|
|
7
|
+
import { dirname, resolve } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
rmSync(resolve(here, "dist"), { recursive: true, force: true });
|
|
13
|
+
|
|
14
|
+
// JS: transpile only (no bundling — consumers resolve deps themselves)
|
|
15
|
+
await build({
|
|
16
|
+
entryPoints: {
|
|
17
|
+
react: resolve(here, "src/react.tsx"),
|
|
18
|
+
sdk: resolve(here, "src/sdk.ts"),
|
|
19
|
+
manifest: resolve(here, "src/manifest.ts"),
|
|
20
|
+
viteHost: resolve(here, "src/viteHost.ts"),
|
|
21
|
+
"host-ui": resolve(here, "src/host-ui.ts"),
|
|
22
|
+
// ws is used by the dev bootstrap + host.tsx to build the rb sdk.
|
|
23
|
+
ws: resolve(here, "src/ws.ts"),
|
|
24
|
+
},
|
|
25
|
+
outdir: resolve(here, "dist"),
|
|
26
|
+
format: "esm",
|
|
27
|
+
bundle: false, // each file transpiled independently, deps stay as imports
|
|
28
|
+
platform: "neutral",
|
|
29
|
+
target: "es2022",
|
|
30
|
+
sourcemap: true,
|
|
31
|
+
logLevel: "warning",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const tsc = spawnSync(
|
|
35
|
+
"node",
|
|
36
|
+
[
|
|
37
|
+
"../../node_modules/typescript/bin/tsc",
|
|
38
|
+
"-p",
|
|
39
|
+
"tsconfig.build.json",
|
|
40
|
+
"--emitDeclarationOnly",
|
|
41
|
+
"--noEmit",
|
|
42
|
+
"false",
|
|
43
|
+
],
|
|
44
|
+
{ cwd: here, stdio: "inherit" },
|
|
45
|
+
);
|
|
46
|
+
if (tsc.status !== 0) {
|
|
47
|
+
console.warn(
|
|
48
|
+
"[plugin-ui] tsc reported errors during declaration emit (likely the known rb-providers/rb-utils " +
|
|
49
|
+
"global.d.ts gap, unrelated to plugin-ui) — .d.ts files were still written; continuing.",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const reactExternal = (id) =>
|
|
54
|
+
/^react($|\/)/.test(id) || /^react-dom($|\/)/.test(id);
|
|
55
|
+
|
|
56
|
+
const ASSET_RE =
|
|
57
|
+
/\.(css|scss|sass|less|svg|png|jpe?g|gif|webp|woff2?)(\?\w+)?$|^swiper\/css/;
|
|
58
|
+
const stubAssets = {
|
|
59
|
+
name: "stub-assets-for-dts",
|
|
60
|
+
resolveId: (id) => (ASSET_RE.test(id) ? "\0asset-stub" : null),
|
|
61
|
+
load: (id) => (id === "\0asset-stub" ? "export default undefined;" : null),
|
|
62
|
+
};
|
|
63
|
+
const dtsBundle = await rollup({
|
|
64
|
+
input: resolve(here, "src/react.tsx"),
|
|
65
|
+
external: reactExternal,
|
|
66
|
+
plugins: [
|
|
67
|
+
stubAssets,
|
|
68
|
+
nodeResolve({ extensions: [".d.ts", ".ts", ".tsx", ".js", ".jsx"] }),
|
|
69
|
+
dts({ respectExternal: false }),
|
|
70
|
+
],
|
|
71
|
+
onwarn: () => {},
|
|
72
|
+
});
|
|
73
|
+
await dtsBundle.write({
|
|
74
|
+
file: resolve(here, "dist/react.d.ts"),
|
|
75
|
+
format: "es",
|
|
76
|
+
});
|
|
77
|
+
await dtsBundle.close();
|
|
78
|
+
rmSync(resolve(here, "dist/react.d.ts.map"), { force: true });
|
|
79
|
+
|
|
80
|
+
console.log("[plugin-ui] dist/ ready");
|