@bridgebrew/plugin-manager 0.0.1 → 0.0.2
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/browser/browser.tsx +11 -11
- package/browser/screen/harness-profiles.tsx +1348 -0
- package/browser/screen/marketplace-model.ts +356 -0
- package/browser/screen/marketplace.tsx +1173 -0
- package/browser/screen/plugin-dependencies.tsx +139 -0
- package/browser/screen/plugin-docs.tsx +142 -0
- package/browser/screen/plugin-logs.tsx +549 -0
- package/browser/screen/plugin-parts.tsx +257 -0
- package/browser/screen/plugin-readme.tsx +152 -0
- package/browser/screen/plugin-settings.tsx +169 -0
- package/browser/screen/plugins-model.ts +427 -0
- package/browser/screen/plugins.tsx +2593 -0
- package/browser/screen/settings-action.ts +42 -0
- package/browser/screen/settings-fields.ts +414 -0
- package/browser/screen/settings-form.tsx +1669 -0
- package/browser/screen/settings-kinds.tsx +918 -0
- package/browser/screen/settings-page.tsx +72 -0
- package/browser/screen/settings-row.tsx +558 -0
- package/browser/screen/update-all.tsx +175 -0
- package/package.json +12 -2
- package/tsconfig.json +5 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Update all (#491): the workspace's plugins with an update, in one confirmation, then updated one after the other as
|
|
2
|
+
// each one's own Update does; one failure stops nothing else. Each row then says how it went: the dialog is the summary.
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Dialog,
|
|
7
|
+
DialogBody,
|
|
8
|
+
DialogClose,
|
|
9
|
+
DialogContent,
|
|
10
|
+
DialogFooter,
|
|
11
|
+
DialogHeader,
|
|
12
|
+
DialogTitle,
|
|
13
|
+
Icon,
|
|
14
|
+
readJson,
|
|
15
|
+
ScrollArea,
|
|
16
|
+
} from '@bridge/ui';
|
|
17
|
+
import type { CatalogEntry } from './marketplace-model.ts';
|
|
18
|
+
|
|
19
|
+
type Outcome =
|
|
20
|
+
| { state: 'running' }
|
|
21
|
+
| { state: 'updated' }
|
|
22
|
+
| { state: 'waits' }
|
|
23
|
+
| { state: 'failed'; message: string };
|
|
24
|
+
|
|
25
|
+
/** What a row says before it runs: why it asks, or why it stays. */
|
|
26
|
+
const before = (entry: CatalogEntry) =>
|
|
27
|
+
entry.held
|
|
28
|
+
? 'Held by you, not updated'
|
|
29
|
+
: entry.updateAsks === 'external'
|
|
30
|
+
? 'Not tested by Bridge'
|
|
31
|
+
: entry.updateAsks === 'migrates'
|
|
32
|
+
? 'Changes its data, no way back'
|
|
33
|
+
: entry.updateAsks === 'data'
|
|
34
|
+
? 'May change its data'
|
|
35
|
+
: '';
|
|
36
|
+
const after: Record<Outcome['state'], string> = {
|
|
37
|
+
running: 'Updating…',
|
|
38
|
+
updated: 'Updated',
|
|
39
|
+
waits: 'Once the running sessions finish',
|
|
40
|
+
failed: 'Failed, previous version kept',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function UpdateAllDialog({
|
|
44
|
+
entries,
|
|
45
|
+
update,
|
|
46
|
+
onClose,
|
|
47
|
+
}: {
|
|
48
|
+
/** The catalog's entries with an update, and those a hold keeps back. */
|
|
49
|
+
entries: CatalogEntry[];
|
|
50
|
+
/** Installs one entry's update: whether it waits for the running sessions; throws when it failed. */
|
|
51
|
+
update: (entry: CatalogEntry) => Promise<{ waiting: boolean }>;
|
|
52
|
+
onClose: () => void;
|
|
53
|
+
}) {
|
|
54
|
+
// The rows stay those the dialog opened with: a catalog read again while it runs moves none.
|
|
55
|
+
const [rows] = React.useState(entries);
|
|
56
|
+
const [outcomes, setOutcomes] = React.useState<Record<string, Outcome>>({});
|
|
57
|
+
const [phase, setPhase] = React.useState<'asking' | 'running' | 'done'>('asking');
|
|
58
|
+
const todo = rows.filter((entry) => !entry.held);
|
|
59
|
+
const run = async () => {
|
|
60
|
+
setPhase('running');
|
|
61
|
+
for (const entry of todo) {
|
|
62
|
+
setOutcomes((was) => ({ ...was, [entry.key]: { state: 'running' } }));
|
|
63
|
+
let outcome: Outcome;
|
|
64
|
+
try {
|
|
65
|
+
outcome = (await update(entry)).waiting ? { state: 'waits' } : { state: 'updated' };
|
|
66
|
+
} catch (cause) {
|
|
67
|
+
outcome = { state: 'failed', message: (cause as Error).message };
|
|
68
|
+
}
|
|
69
|
+
setOutcomes((was) => ({ ...was, [entry.key]: outcome }));
|
|
70
|
+
}
|
|
71
|
+
setPhase('done');
|
|
72
|
+
};
|
|
73
|
+
const failed = Object.values(outcomes).filter(({ state }) => state === 'failed').length;
|
|
74
|
+
const status =
|
|
75
|
+
phase === 'asking'
|
|
76
|
+
? `${todo.length} ${todo.length === 1 ? 'plugin' : 'plugins'} to update, one after the other`
|
|
77
|
+
: phase === 'running'
|
|
78
|
+
? 'Updating…'
|
|
79
|
+
: failed > 0
|
|
80
|
+
? `${failed} failed, the others went on`
|
|
81
|
+
: 'Done';
|
|
82
|
+
return (
|
|
83
|
+
<Dialog
|
|
84
|
+
open
|
|
85
|
+
onOpenChange={(open) => {
|
|
86
|
+
if (!open && phase !== 'running') onClose();
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<DialogContent aria-label="Update all" className="w-[480px]">
|
|
90
|
+
<DialogHeader className="px-5 pt-4">
|
|
91
|
+
<DialogTitle>Update all</DialogTitle>
|
|
92
|
+
</DialogHeader>
|
|
93
|
+
<DialogBody className="pb-3">
|
|
94
|
+
<ScrollArea className="h-64">
|
|
95
|
+
<ul className="m-0 flex list-none flex-col p-0" aria-label="Updates">
|
|
96
|
+
{rows.map((entry) => {
|
|
97
|
+
const outcome = outcomes[entry.key];
|
|
98
|
+
return (
|
|
99
|
+
<li
|
|
100
|
+
key={entry.key}
|
|
101
|
+
data-update-row={entry.key}
|
|
102
|
+
data-state={outcome?.state ?? (entry.held ? 'held' : 'pending')}
|
|
103
|
+
className="flex h-8 items-center gap-2 text-sm"
|
|
104
|
+
>
|
|
105
|
+
<span className="min-w-0 flex-1 truncate">
|
|
106
|
+
{entry.title}{' '}
|
|
107
|
+
<span className="tabular-nums text-secondary">
|
|
108
|
+
{entry.installed?.version} → {entry.update ?? entry.version}
|
|
109
|
+
</span>
|
|
110
|
+
</span>
|
|
111
|
+
<span
|
|
112
|
+
className={
|
|
113
|
+
outcome?.state === 'failed'
|
|
114
|
+
? 'shrink-0 text-xs text-destructive'
|
|
115
|
+
: 'shrink-0 text-xs text-secondary'
|
|
116
|
+
}
|
|
117
|
+
title={outcome?.state === 'failed' ? outcome.message : undefined}
|
|
118
|
+
>
|
|
119
|
+
{outcome ? after[outcome.state] : before(entry)}
|
|
120
|
+
</span>
|
|
121
|
+
</li>
|
|
122
|
+
);
|
|
123
|
+
})}
|
|
124
|
+
</ul>
|
|
125
|
+
</ScrollArea>
|
|
126
|
+
</DialogBody>
|
|
127
|
+
<DialogFooter className="justify-between gap-2 px-5 py-3">
|
|
128
|
+
<span role="status" className="flex items-center gap-1.5 text-xs text-secondary">
|
|
129
|
+
{phase === 'running' && (
|
|
130
|
+
<Icon
|
|
131
|
+
name="loader-circle"
|
|
132
|
+
size={13}
|
|
133
|
+
className="animate-spin motion-reduce:animate-none"
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
{status}
|
|
137
|
+
</span>
|
|
138
|
+
<div className="flex gap-2">
|
|
139
|
+
{phase === 'asking' ? (
|
|
140
|
+
<>
|
|
141
|
+
<DialogClose render={<Button variant="outline" />}>Cancel</DialogClose>
|
|
142
|
+
<Button variant="primary" disabled={!todo.length} onClick={() => void run()}>
|
|
143
|
+
Update {todo.length} {todo.length === 1 ? 'plugin' : 'plugins'}
|
|
144
|
+
</Button>
|
|
145
|
+
</>
|
|
146
|
+
) : (
|
|
147
|
+
<Button variant="primary" disabled={phase === 'running'} onClick={onClose}>
|
|
148
|
+
Close
|
|
149
|
+
</Button>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
</DialogFooter>
|
|
153
|
+
</DialogContent>
|
|
154
|
+
</Dialog>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Installs `entry`'s update in `slug` as the marketplace's Update does: whether it waits for the running sessions. */
|
|
159
|
+
export const updateOne = async (
|
|
160
|
+
fetch: (url: string, init?: RequestInit) => Promise<Response>,
|
|
161
|
+
slug: string,
|
|
162
|
+
entry: CatalogEntry,
|
|
163
|
+
) => {
|
|
164
|
+
const res = await fetch(`/_bridge/workspaces/${encodeURIComponent(slug)}/plugins/install`, {
|
|
165
|
+
method: 'POST',
|
|
166
|
+
headers: { 'content-type': 'application/json' },
|
|
167
|
+
body: JSON.stringify({
|
|
168
|
+
source: entry.install,
|
|
169
|
+
...(entry.registry !== undefined && { registry: entry.registry }),
|
|
170
|
+
update: true,
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
const done = (await readJson(res)) as { waiting?: true; pendingRestart?: string };
|
|
174
|
+
return { waiting: done.waiting === true || done.pendingRestart !== undefined };
|
|
175
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridgebrew/plugin-manager",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The workspace's plugins (install, enable, reload, remove) and every plugin's settings, for the workspace and for each node.",
|
|
6
6
|
"keywords": [
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
"!**/*.test.ts",
|
|
14
14
|
"!**/*.test.tsx"
|
|
15
15
|
],
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./form": "./browser/screen/settings-form.tsx",
|
|
19
|
+
"./harness-profiles": "./browser/screen/harness-profiles.tsx",
|
|
20
|
+
"./logs": "./browser/screen/plugin-logs.tsx",
|
|
21
|
+
"./model": "./browser/screen/plugins-model.ts"
|
|
22
|
+
},
|
|
16
23
|
"bridge": {
|
|
17
24
|
"kind": "extension",
|
|
18
25
|
"category": "standard",
|
|
@@ -35,9 +42,12 @@
|
|
|
35
42
|
"browser": "./browser/browser.tsx",
|
|
36
43
|
"provenance": "official"
|
|
37
44
|
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"react-markdown": "10.1.0",
|
|
47
|
+
"remark-gfm": "4.0.1"
|
|
48
|
+
},
|
|
38
49
|
"peerDependencies": {
|
|
39
50
|
"@bridge/kernel": ">=0.0.1",
|
|
40
|
-
"@bridge/plugin-manager": ">=0.0.1",
|
|
41
51
|
"@bridge/ui": ">=0.0.1",
|
|
42
52
|
"cordis": "4.0.0-rc.11",
|
|
43
53
|
"react": "19.3.0"
|
package/tsconfig.json
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"extends": "./.bridge/tsconfig.json",
|
|
3
|
+
"//": "jsx: its page tests that are .ts (browser/screen/settings-action.test.ts) import the page, and are typed with the server project (bridge plugin check)",
|
|
4
|
+
"compilerOptions": { "jsx": "react-jsx" }
|
|
5
|
+
}
|