@powerhousedao/devtools 0.0.0-stage → 6.4.0-next.3
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/LICENSE +661 -0
- package/README.md +116 -2
- package/dist/build-FMqn8eub.mjs +693 -0
- package/dist/build-FMqn8eub.mjs.map +1 -0
- package/dist/client-connect.js +44 -0
- package/dist/client-page.js +4 -0
- package/dist/connect.d.mts +14 -0
- package/dist/connect.d.mts.map +1 -0
- package/dist/connect.mjs +21 -0
- package/dist/connect.mjs.map +1 -0
- package/dist/es-BgJ5sfYg.js +3 -0
- package/dist/input-group-Ce9ByF9k.js +155 -0
- package/dist/mount.d.ts +97 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/mount.js +264 -0
- package/dist/schema-diagram-CdVGWeZX.js +109 -0
- package/dist/server.d.mts +360 -0
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +25 -0
- package/dist/server.mjs.map +1 -0
- package/dist/vite-INmnb9pz.mjs +604 -0
- package/dist/vite-INmnb9pz.mjs.map +1 -0
- package/package.json +93 -3
package/README.md
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @powerhousedao/devtools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DevTools for Powerhouse projects: a dock over the running app that shows the project's document
|
|
4
|
+
models, editors, drive apps, subgraphs and processors, as its code has them.
|
|
5
|
+
|
|
6
|
+
DevTools is for development only. It is a dev-server plugin: only a dev server loads it, and
|
|
7
|
+
nothing a build resolves refers to it. The design is in
|
|
8
|
+
[ADR 0010](../../docs/adr/0010-devtools.md).
|
|
9
|
+
|
|
10
|
+
## Connect dev servers
|
|
11
|
+
|
|
12
|
+
`ph vetra`, `ph connect studio` and `ph run <host> dev` load DevTools as a default dev-server
|
|
13
|
+
plugin. A project changes nothing.
|
|
14
|
+
|
|
15
|
+
To turn it off for one run, set `PH_DEVTOOLS=0`. It is also off under `NODE_ENV=production`. To
|
|
16
|
+
turn it off for a host, add this to its `host.js`:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
runner: {
|
|
20
|
+
devPlugins: [{ module: "@powerhousedao/devtools/connect", enabled: false }],
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## A Connect project with its own Vite config
|
|
25
|
+
|
|
26
|
+
Add DevTools' Vite plugin. It applies to the dev server only.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { getConnectBaseViteConfig } from "@powerhousedao/builder-tools";
|
|
30
|
+
import { devtoolsVitePlugin } from "@powerhousedao/devtools/server";
|
|
31
|
+
import { defineConfig, mergeConfig } from "vite";
|
|
32
|
+
|
|
33
|
+
export default defineConfig(({ mode }) =>
|
|
34
|
+
mergeConfig(getConnectBaseViteConfig({ mode, dirname: import.meta.dirname }), {
|
|
35
|
+
plugins: [devtoolsVitePlugin({ client: "connect" })],
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Any other dev server
|
|
41
|
+
|
|
42
|
+
The server answers the API and puts a tag in the page. The page mounts DevTools.
|
|
43
|
+
|
|
44
|
+
On the server, in development only:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createDevtoolsServer } from "@powerhousedao/devtools/server";
|
|
48
|
+
|
|
49
|
+
const { handler, tokenTag } = createDevtoolsServer({ projectRoot: process.cwd() });
|
|
50
|
+
// 1. Run `handler(req, res, next)` ahead of the app's own routes.
|
|
51
|
+
// 2. Put `tokenTag` in the <head> of every page.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
DevTools reads the project itself. A server that knows more of the run passes it: `appUrl` for
|
|
55
|
+
where the app answers, and `run` for the tool that started it and the addresses of its other
|
|
56
|
+
services.
|
|
57
|
+
|
|
58
|
+
In the page:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
if (import.meta.env.DEV) {
|
|
62
|
+
const { mountDevtools } = await import("@powerhousedao/devtools/mount");
|
|
63
|
+
mountDevtools();
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
A Vite app that is not Connect uses `devtoolsVitePlugin()` from
|
|
68
|
+
`@powerhousedao/devtools/server` in place of both steps. The plugin's own module mounts DevTools
|
|
69
|
+
before the app's code runs.
|
|
70
|
+
|
|
71
|
+
A page has one DevTools. A second `mountDevtools(options)` lays its options over the one that is
|
|
72
|
+
mounted and returns the same handle, so an app passes its `target`, `appSource` or `app` whenever
|
|
73
|
+
its code runs.
|
|
74
|
+
|
|
75
|
+
`mountDevtools` renders in a shadow root with its own stylesheet and its own React, so the page
|
|
76
|
+
needs neither React nor Tailwind, and the two sides' styles do not mix. It does nothing on a page
|
|
77
|
+
without the tag.
|
|
78
|
+
|
|
79
|
+
On a page of a Powerhouse app, DevTools reads what the app knows from `window.ph`: the modules it
|
|
80
|
+
has loaded, its notifications and its router. Another kind of app gives its own `appSource`, or
|
|
81
|
+
passes `app` and later changes through the `update` of the handle.
|
|
82
|
+
|
|
83
|
+
The API answers only a browser on the same machine, on the origin that served the page. Behind a
|
|
84
|
+
forwarded port, a proxy or a tunnel, in a container, or on a page loaded from `file://`, DevTools
|
|
85
|
+
shows without project data. A page the Vite plugin sends to another machine has no DevTools.
|
|
86
|
+
|
|
87
|
+
## Writing another dev-server plugin
|
|
88
|
+
|
|
89
|
+
A dev-server plugin is a module that default-exports a host plugin with a `devServer` hook. The
|
|
90
|
+
hook gets the project's folder and what the CLI knows of the run, and returns Vite plugins.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import type { ConnectDevPlugin } from "@powerhousedao/host-core";
|
|
94
|
+
import type { Plugin } from "vite";
|
|
95
|
+
|
|
96
|
+
const inspector: ConnectDevPlugin<Plugin> = {
|
|
97
|
+
name: "inspector",
|
|
98
|
+
appliesTo: "connect",
|
|
99
|
+
hooks: {
|
|
100
|
+
devServer: ({ projectRoot, run }) => [inspectorVitePlugin({ projectRoot, run })],
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export default inspector;
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A host lists it in `runner.devPlugins`. The CLI keeps every Vite plugin the hook returns to a dev
|
|
108
|
+
server, so nothing it adds reaches a build. This package's own plugin, in `src/connect/`, is the
|
|
109
|
+
example to follow.
|
|
110
|
+
|
|
111
|
+
## Entries
|
|
112
|
+
|
|
113
|
+
| Entry | For |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| `./connect` | The dev-server plugin of a Connect host |
|
|
116
|
+
| `./server` | `devtoolsVitePlugin`, `createDevtoolsServer`, `createDevtoolsApiHandler`, `createProjectReader` and the API's types |
|
|
117
|
+
| `./mount` | `mountDevtools`, self-contained |
|