moi-computer 0.0.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/LICENSE +95 -0
- package/README.md +71 -0
- package/bin/moi.mjs +25 -0
- package/bunfig.toml +3 -0
- package/client/CLAUDE.md +12 -0
- package/client/api/workspaces.ts +158 -0
- package/client/assets/claude.svg +3 -0
- package/client/assets/favicon.png +0 -0
- package/client/assets/hermes-nous.png +0 -0
- package/client/assets/mcp/.gitkeep +0 -0
- package/client/assets/mcp/atlassian.png +0 -0
- package/client/assets/mcp/discord.png +0 -0
- package/client/assets/mcp/figma.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.png +0 -0
- package/client/assets/mcp/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.png +0 -0
- package/client/assets/mcp/sentry.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/moi-logo.svg +11 -0
- package/client/assets/openclaw.svg +22 -0
- package/client/components/App.tsx +35 -0
- package/client/components/BottomPanel.tsx +33 -0
- package/client/components/ChatInput.tsx +62 -0
- package/client/components/ChatPanel.tsx +206 -0
- package/client/components/ChatPopup.tsx +60 -0
- package/client/components/CustomizePanel.tsx +117 -0
- package/client/components/HiddenPanel.tsx +79 -0
- package/client/components/HomePage.tsx +17 -0
- package/client/components/MarkdownContent.tsx +41 -0
- package/client/components/ThreadSelector.tsx +88 -0
- package/client/components/TurnView.tsx +618 -0
- package/client/components/WidgetErrorBoundary.tsx +46 -0
- package/client/components/WidgetFrame.tsx +66 -0
- package/client/components/WidgetGrid.tsx +113 -0
- package/client/components/WidgetShell.tsx +44 -0
- package/client/components/Widgets.tsx +132 -0
- package/client/components/WorkspacePreview.tsx +48 -0
- package/client/components/WorkspacesPage.tsx +237 -0
- package/client/components/layout/SidebarLayout.tsx +260 -0
- package/client/components/playground/LedLogo.tsx +181 -0
- package/client/components/playground/PixelPainter.tsx +105 -0
- package/client/components/playground/PlaygroundPage.tsx +71 -0
- package/client/components/routes/workspace/[id].tsx +282 -0
- package/client/components/ui/button.tsx +48 -0
- package/client/components/ui/dropdown-menu.tsx +257 -0
- package/client/components/ui/input.tsx +21 -0
- package/client/components/ui/popover.tsx +79 -0
- package/client/components/ui/textarea.tsx +18 -0
- package/client/externalize-react.ts +29 -0
- package/client/hooks/useChat.ts +88 -0
- package/client/hooks/useFitsSidebar.ts +34 -0
- package/client/hooks/useGridReconcile.ts +73 -0
- package/client/hooks/useMeiEvents.ts +66 -0
- package/client/hooks/useScrollFade.ts +38 -0
- package/client/hooks/useWidget.ts +72 -0
- package/client/hooks/useWidgetList.ts +30 -0
- package/client/hooks/useWorkspaceTheme.ts +76 -0
- package/client/index.css +182 -0
- package/client/index.html +43 -0
- package/client/index.tsx +19 -0
- package/client/lib/WorkspaceContext.tsx +24 -0
- package/client/lib/WorkspaceLayoutContext.tsx +92 -0
- package/client/lib/cn.ts +6 -0
- package/client/lib/grid-pack.ts +35 -0
- package/client/lib/group-turns.ts +44 -0
- package/client/lib/mcp-icons.ts +53 -0
- package/client/lib/ws.ts +129 -0
- package/client/main.tsx +23 -0
- package/client/store/chat.tsx +162 -0
- package/client/store/ui.ts +21 -0
- package/client/theme.css +66 -0
- package/lib/claude-adapter.ts +602 -0
- package/lib/format.ts +212 -0
- package/lib/themes.ts +89 -0
- package/lib/types.ts +144 -0
- package/package.json +117 -0
- package/server/CLAUDE.md +6 -0
- package/server/agent.ts +132 -0
- package/server/build-widget.ts +343 -0
- package/server/cli.ts +632 -0
- package/server/constants.ts +3 -0
- package/server/control.ts +98 -0
- package/server/functions-worker.ts +89 -0
- package/server/functions.ts +171 -0
- package/server/layout.ts +83 -0
- package/server/openclaw-adapter.ts +242 -0
- package/server/openclaw-gateway.ts +255 -0
- package/server/openclaw-session.ts +485 -0
- package/server/openclaw-strip.ts +134 -0
- package/server/openclaw.ts +206 -0
- package/server/registry.ts +150 -0
- package/server/skills-template.ts +21 -0
- package/server/state.ts +87 -0
- package/server/theme.ts +55 -0
- package/server/web.ts +321 -0
- package/server/widgets.ts +254 -0
- package/tsconfig.json +21 -0
- package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
- package/workspace/.claude/skills/widgets/SKILL.md +176 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExportNamedDeclaration,
|
|
3
|
+
VariableDeclarator
|
|
4
|
+
} from '@typescript-eslint/types/dist/generated/ast-spec'
|
|
5
|
+
import { parse } from '@typescript-eslint/typescript-estree'
|
|
6
|
+
import type { BunPlugin } from 'bun'
|
|
7
|
+
import tailwind from 'bun-plugin-tailwind'
|
|
8
|
+
import { basename, dirname, join } from 'path'
|
|
9
|
+
|
|
10
|
+
import type { WidgetConfig } from '@/lib/types'
|
|
11
|
+
|
|
12
|
+
const EXTERNAL_MODULES = [
|
|
13
|
+
'react',
|
|
14
|
+
'react/jsx-runtime',
|
|
15
|
+
'react/jsx-dev-runtime',
|
|
16
|
+
'react-dom',
|
|
17
|
+
'react-dom/client'
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
type ServerModule = {
|
|
21
|
+
name: string
|
|
22
|
+
exports: string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type WidgetArtifact = {
|
|
26
|
+
js: string
|
|
27
|
+
serverModules: ServerModule[]
|
|
28
|
+
config: WidgetConfig | null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const DEFAULT_CONFIG: WidgetConfig = { rowSpan: 1, colSpan: 2 }
|
|
32
|
+
const VALID_SPANS = [1, 2, 3, 4] as const
|
|
33
|
+
|
|
34
|
+
export async function extractWidgetConfig(srcPath: string): Promise<WidgetConfig | null> {
|
|
35
|
+
const source = await Bun.file(srcPath).text()
|
|
36
|
+
const widgetName = basename(srcPath).replace(/\.tsx?$/, '')
|
|
37
|
+
|
|
38
|
+
const ast = parse(source, { jsx: true, errorOnUnknownASTType: false })
|
|
39
|
+
|
|
40
|
+
const exportDecl = ast.body.find(
|
|
41
|
+
node =>
|
|
42
|
+
node.type === 'ExportNamedDeclaration' &&
|
|
43
|
+
node.declaration?.type === 'VariableDeclaration' &&
|
|
44
|
+
node.declaration.declarations.some(d => d.id.type === 'Identifier' && d.id.name === 'config')
|
|
45
|
+
) as ExportNamedDeclaration | undefined
|
|
46
|
+
if (!exportDecl) return null
|
|
47
|
+
|
|
48
|
+
const varDecl = exportDecl.declaration
|
|
49
|
+
if (varDecl?.type !== 'VariableDeclaration') return null
|
|
50
|
+
|
|
51
|
+
const decl = varDecl.declarations.find(
|
|
52
|
+
(d): d is VariableDeclarator & { id: { type: 'Identifier'; name: string } } =>
|
|
53
|
+
d.id.type === 'Identifier' && d.id.name === 'config'
|
|
54
|
+
)
|
|
55
|
+
const rawInit = decl?.init
|
|
56
|
+
// Unwrap `as const` — AST wraps the object in TSAsExpression
|
|
57
|
+
const init = rawInit?.type === 'TSAsExpression' ? rawInit.expression : rawInit
|
|
58
|
+
if (init?.type !== 'ObjectExpression') return null
|
|
59
|
+
|
|
60
|
+
const result: Partial<WidgetConfig> = {}
|
|
61
|
+
|
|
62
|
+
for (const prop of init.properties) {
|
|
63
|
+
if (prop.type !== 'Property' || prop.key?.type !== 'Identifier') continue
|
|
64
|
+
const key = prop.key.name as string
|
|
65
|
+
if (key !== 'rowSpan' && key !== 'colSpan') continue
|
|
66
|
+
if (prop.value?.type !== 'Literal' || typeof prop.value.value !== 'number') continue
|
|
67
|
+
|
|
68
|
+
const val = prop.value.value
|
|
69
|
+
if (!(VALID_SPANS as readonly number[]).includes(val)) {
|
|
70
|
+
console.warn(`[mei] "${widgetName}": config.${key}=${val} is out of 1–4 range, using default`)
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
73
|
+
result[key] = val as 1 | 2 | 3 | 4
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { ...DEFAULT_CONFIG, ...result }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function escapeRegex(s: string): string {
|
|
80
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function validateServerExports(filePath: string): Promise<string[]> {
|
|
84
|
+
const source = await Bun.file(filePath).text()
|
|
85
|
+
const transpiler = new Bun.Transpiler({ loader: 'ts' })
|
|
86
|
+
const { exports } = transpiler.scan(source)
|
|
87
|
+
|
|
88
|
+
const runtimeExports = exports.filter(name => {
|
|
89
|
+
const escaped = escapeRegex(name)
|
|
90
|
+
const typePattern = new RegExp(`export\\s+(type|interface)\\s+${escaped}\\b`)
|
|
91
|
+
return !typePattern.test(source)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
for (const name of runtimeExports) {
|
|
95
|
+
const escaped = escapeRegex(name)
|
|
96
|
+
const asyncFnPattern = new RegExp(
|
|
97
|
+
`export\\s+async\\s+function\\*?\\s+${escaped}\\b` +
|
|
98
|
+
'|' +
|
|
99
|
+
`export\\s+const\\s+${escaped}\\s*=\\s*async\\s*[\\(]`
|
|
100
|
+
)
|
|
101
|
+
if (!asyncFnPattern.test(source)) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`"${name}" in ${basename(filePath)} is not an async function. ` +
|
|
104
|
+
`.server.ts files can only export async functions.`
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return runtimeExports
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// The mei:rpc virtual module — contains the RPC call logic with devalue serialization.
|
|
113
|
+
// Bundled into the widget output once, shared by all server function stubs.
|
|
114
|
+
const RPC_MODULE_SOURCE = `
|
|
115
|
+
import { stringify, parse } from "devalue";
|
|
116
|
+
|
|
117
|
+
export function rpc(module, name) {
|
|
118
|
+
return async (...args) => {
|
|
119
|
+
const ws = window.__MEI_WS__ || "default";
|
|
120
|
+
const res = await fetch("/_rpc/" + ws + "/fn/" + module + "/" + name, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers: { "Content-Type": "application/json" },
|
|
123
|
+
body: stringify(args),
|
|
124
|
+
});
|
|
125
|
+
if (!res.ok) throw new Error(await res.text());
|
|
126
|
+
return parse(await res.text());
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
`
|
|
130
|
+
|
|
131
|
+
function serverProxyPlugin(sourceDir: string): {
|
|
132
|
+
plugin: BunPlugin
|
|
133
|
+
serverModules: ServerModule[]
|
|
134
|
+
} {
|
|
135
|
+
const serverModules: ServerModule[] = []
|
|
136
|
+
|
|
137
|
+
const plugin: BunPlugin = {
|
|
138
|
+
name: 'server-proxy',
|
|
139
|
+
setup(build) {
|
|
140
|
+
// Resolve mei:rpc virtual module
|
|
141
|
+
build.onResolve({ filter: /^mei:rpc$/ }, () => ({
|
|
142
|
+
path: 'mei:rpc',
|
|
143
|
+
namespace: 'mei-rpc'
|
|
144
|
+
}))
|
|
145
|
+
|
|
146
|
+
build.onLoad({ filter: /.*/, namespace: 'mei-rpc' }, () => ({
|
|
147
|
+
contents: RPC_MODULE_SOURCE,
|
|
148
|
+
loader: 'js'
|
|
149
|
+
}))
|
|
150
|
+
|
|
151
|
+
// Intercept .server imports
|
|
152
|
+
build.onResolve({ filter: /\.server(\.ts)?$/ }, args => {
|
|
153
|
+
if (!args.path.startsWith('.')) return
|
|
154
|
+
return {
|
|
155
|
+
path: join(sourceDir, args.path.replace(/\.server(\.ts)?$/, '.server.ts')),
|
|
156
|
+
namespace: 'server-proxy'
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
// Generate proxy stubs using mei:rpc
|
|
161
|
+
build.onLoad({ filter: /.*/, namespace: 'server-proxy' }, async args => {
|
|
162
|
+
const exports = await validateServerExports(args.path)
|
|
163
|
+
const moduleName = basename(args.path, '.server.ts')
|
|
164
|
+
|
|
165
|
+
serverModules.push({ name: moduleName, exports })
|
|
166
|
+
|
|
167
|
+
const lines = [
|
|
168
|
+
`import { rpc } from "mei:rpc";`,
|
|
169
|
+
...exports.map(
|
|
170
|
+
name =>
|
|
171
|
+
`export const ${name} = rpc(${JSON.stringify(moduleName)}, ${JSON.stringify(name)});`
|
|
172
|
+
)
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
return { contents: lines.join('\n'), loader: 'js' }
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return { plugin, serverModules }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Path to the host's `@theme inline` block — shared with `client/index.css`.
|
|
184
|
+
// Inlined into the widget's synthetic CSS at build time so Tailwind sees the
|
|
185
|
+
// theme tokens.
|
|
186
|
+
const HOST_THEME_PATH = join(import.meta.dir, '..', 'client', 'theme.css')
|
|
187
|
+
|
|
188
|
+
// Three things matter for widget styling:
|
|
189
|
+
// 1. The umbrella `@import 'tailwindcss'` brings in @layer theme + base +
|
|
190
|
+
// utilities — which is what spacing/color utilities like `left-2.5`,
|
|
191
|
+
// `gap-1.5`, `text-amber-500` need to resolve. The split
|
|
192
|
+
// `theme`/`utilities` imports skip the `@layer theme` wrapper and theme
|
|
193
|
+
// variables aren't in scope at compile time.
|
|
194
|
+
// 2. The host's `@theme inline` block (inlined from theme.css) teaches
|
|
195
|
+
// Tailwind about host-owned tokens (`--color-background`,
|
|
196
|
+
// `--color-foreground`, etc.) so widgets compile classes like
|
|
197
|
+
// `bg-foreground/20`, `text-muted`, `rounded-xl`. The `inline` keyword
|
|
198
|
+
// means the widget's CSS does NOT redefine the underlying
|
|
199
|
+
// `--background`/`--foreground` variables — those stay host-owned and
|
|
200
|
+
// the widget picks them up from `:root` at runtime.
|
|
201
|
+
// 3. Tailwind's auto-detection treats `.widgets/` as a hidden directory
|
|
202
|
+
// and skips it. An explicit `@source` bypasses the dot-dir + gitignore
|
|
203
|
+
// filters.
|
|
204
|
+
//
|
|
205
|
+
// Important: the synthetic CSS must live on disk in the `file` namespace
|
|
206
|
+
// because `bun-plugin-tailwind`'s `onLoad` only matches that namespace —
|
|
207
|
+
// custom-namespace CSS is treated as raw text and our `@theme inline` block
|
|
208
|
+
// is left unprocessed. We materialize it inside `<sourceDir>/.build/` and
|
|
209
|
+
// have the entry import it by absolute path.
|
|
210
|
+
async function writeSyntheticTailwindCss(widgetPath: string): Promise<string> {
|
|
211
|
+
const sourceDir = dirname(widgetPath)
|
|
212
|
+
const buildDir = join(sourceDir, '.build')
|
|
213
|
+
const cssPath = join(buildDir, 'widget-tailwind.css')
|
|
214
|
+
const contents = [
|
|
215
|
+
`@import 'tailwindcss';`,
|
|
216
|
+
await Bun.file(HOST_THEME_PATH).text(),
|
|
217
|
+
`@source "${sourceDir}";`
|
|
218
|
+
].join('\n')
|
|
219
|
+
await Bun.write(cssPath, contents)
|
|
220
|
+
return cssPath
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function widgetEntryPlugin(widgetPath: string, syntheticCssPath: string): BunPlugin {
|
|
224
|
+
return {
|
|
225
|
+
name: 'widget-entry',
|
|
226
|
+
setup(build) {
|
|
227
|
+
build.onResolve({ filter: /^__widget-entry$/ }, () => ({
|
|
228
|
+
path: '__widget-entry',
|
|
229
|
+
namespace: 'widget-entry'
|
|
230
|
+
}))
|
|
231
|
+
|
|
232
|
+
build.onLoad({ filter: /.*/, namespace: 'widget-entry' }, () => ({
|
|
233
|
+
contents: [
|
|
234
|
+
`import ${JSON.stringify(syntheticCssPath)};`,
|
|
235
|
+
`export { default } from ${JSON.stringify(widgetPath)};`
|
|
236
|
+
].join('\n'),
|
|
237
|
+
loader: 'js'
|
|
238
|
+
}))
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function injectCss(js: string, css: string, widgetName: string): string {
|
|
244
|
+
if (!css.trim()) return js
|
|
245
|
+
|
|
246
|
+
// After `moi bundle` rebuilds the widget, the new JS module re-runs in the
|
|
247
|
+
// browser. Always replace any prior <style data-widget="<id>"> tag so the
|
|
248
|
+
// freshly-built CSS takes effect; the previous "skip if already present"
|
|
249
|
+
// guard left stale rules in place after edits.
|
|
250
|
+
const injection = [
|
|
251
|
+
`((css, id) => {`,
|
|
252
|
+
` document.querySelector(\`style[data-widget="\${id}"]\`)?.remove();`,
|
|
253
|
+
` const s = document.createElement("style");`,
|
|
254
|
+
` s.dataset.widget = id;`,
|
|
255
|
+
` s.textContent = css;`,
|
|
256
|
+
` document.head.appendChild(s);`,
|
|
257
|
+
`})(${JSON.stringify(css)}, ${JSON.stringify(widgetName)});`
|
|
258
|
+
].join('\n')
|
|
259
|
+
|
|
260
|
+
return injection + '\n' + js
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function formatBuildLog(log: BuildMessage | ResolveMessage): string {
|
|
264
|
+
const prefix = log.level === 'error' ? 'error' : log.level
|
|
265
|
+
const loc = log.position
|
|
266
|
+
? `${log.position.file}:${log.position.line}:${log.position.column}: `
|
|
267
|
+
: ''
|
|
268
|
+
const lineText = log.position?.lineText ? `\n ${log.position.lineText.trim()}` : ''
|
|
269
|
+
return `${loc}${prefix}: ${log.message}${lineText}`
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function prevalidateServerFiles(entrypoint: string): Promise<void> {
|
|
273
|
+
const sourceDir = dirname(entrypoint)
|
|
274
|
+
const source = await Bun.file(entrypoint).text()
|
|
275
|
+
|
|
276
|
+
const importPattern = /from\s+['"]\.\/([^'"]+)\.server(?:\.ts)?['"]/g
|
|
277
|
+
let match
|
|
278
|
+
while ((match = importPattern.exec(source)) !== null) {
|
|
279
|
+
const serverPath = join(sourceDir, `${match[1]}.server.ts`)
|
|
280
|
+
if (await Bun.file(serverPath).exists()) {
|
|
281
|
+
await validateServerExports(serverPath)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export async function buildWidget(entrypoint: string): Promise<WidgetArtifact> {
|
|
287
|
+
const sourceDir = dirname(entrypoint)
|
|
288
|
+
const widgetName = basename(entrypoint).replace(/\.tsx?$/, '')
|
|
289
|
+
|
|
290
|
+
await prevalidateServerFiles(entrypoint)
|
|
291
|
+
|
|
292
|
+
const { plugin: serverProxy, serverModules } = serverProxyPlugin(sourceDir)
|
|
293
|
+
const syntheticCssPath = await writeSyntheticTailwindCss(entrypoint)
|
|
294
|
+
|
|
295
|
+
let result: Awaited<ReturnType<typeof Bun.build>>
|
|
296
|
+
try {
|
|
297
|
+
result = await Bun.build({
|
|
298
|
+
entrypoints: ['__widget-entry'],
|
|
299
|
+
format: 'esm',
|
|
300
|
+
target: 'browser',
|
|
301
|
+
sourcemap: 'inline',
|
|
302
|
+
external: EXTERNAL_MODULES,
|
|
303
|
+
// bun-plugin-tailwind uses `build.config.root` as the auto-detect
|
|
304
|
+
// project root (`projectRoot = build.config?.root ?? process.cwd()`).
|
|
305
|
+
// Without this, oxide scans `none-computer/` (the parent server's
|
|
306
|
+
// cwd) instead of the workspace's `.widgets/`.
|
|
307
|
+
root: sourceDir,
|
|
308
|
+
plugins: [widgetEntryPlugin(entrypoint, syntheticCssPath), serverProxy, tailwind]
|
|
309
|
+
})
|
|
310
|
+
} catch (err) {
|
|
311
|
+
// Bun.build throws AggregateError on failure (default throw: true).
|
|
312
|
+
// The message is a generic "Bundle failed"; the real diagnostics live on `.errors`.
|
|
313
|
+
const logs = (err as { errors?: (BuildMessage | ResolveMessage)[] }).errors ?? []
|
|
314
|
+
const formatted = logs.length
|
|
315
|
+
? logs.map(formatBuildLog).join('\n')
|
|
316
|
+
: err instanceof Error
|
|
317
|
+
? err.message
|
|
318
|
+
: String(err)
|
|
319
|
+
throw new Error(`Build failed for "${widgetName}":\n${formatted}`)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (!result.success) {
|
|
323
|
+
const errors = result.logs.map(formatBuildLog).join('\n')
|
|
324
|
+
throw new Error(`Build failed for "${widgetName}":\n${errors}`)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const jsOutput = result.outputs.find(o => o.path.endsWith('.js'))
|
|
328
|
+
const cssOutput = result.outputs.find(o => o.path.endsWith('.css'))
|
|
329
|
+
|
|
330
|
+
if (!jsOutput) {
|
|
331
|
+
throw new Error(`Build produced no JS output for "${widgetName}"`)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
let js = await jsOutput.text()
|
|
335
|
+
|
|
336
|
+
if (cssOutput) {
|
|
337
|
+
const css = await cssOutput.text()
|
|
338
|
+
js = injectCss(js, css, widgetName)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const config = await extractWidgetConfig(entrypoint)
|
|
342
|
+
return { js, serverModules, config }
|
|
343
|
+
}
|