@glasshome/widget-sdk 1.1.0 → 1.1.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/dist/index.js +1 -1
- package/dist/vite/index.js +138 -115
- package/package.json +1 -1
package/dist/index.js
CHANGED
package/dist/vite/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { createHash as
|
|
2
|
-
import { existsSync as l, rmSync as
|
|
1
|
+
import { createHash as R } from "node:crypto";
|
|
2
|
+
import { existsSync as l, rmSync as T, mkdirSync as D, readdirSync as I, statSync as P, readFileSync as g, writeFileSync as w } from "node:fs";
|
|
3
3
|
import { createRequire as F } from "node:module";
|
|
4
|
-
import { resolve as
|
|
5
|
-
import { fileURLToPath as
|
|
6
|
-
import { widgetManifestSchema as U, formatSchemaError as
|
|
7
|
-
import
|
|
4
|
+
import { resolve as c, join as u, dirname as y, sep as x } from "node:path";
|
|
5
|
+
import { fileURLToPath as H } from "node:url";
|
|
6
|
+
import { widgetManifestSchema as U, formatSchemaError as A } from "@glasshome/widget-contract";
|
|
7
|
+
import C from "@tailwindcss/vite";
|
|
8
8
|
function L(e) {
|
|
9
9
|
const t = JSON.stringify(e, Object.keys(e).sort());
|
|
10
|
-
return
|
|
10
|
+
return R("sha256").update(t).digest("hex").slice(0, 16);
|
|
11
11
|
}
|
|
12
|
-
const
|
|
13
|
-
function
|
|
12
|
+
const V = "virtual:glasshome-widget", E = "\0virtual:glasshome-widget", B = "/@glasshome/preview";
|
|
13
|
+
function p(e) {
|
|
14
14
|
return x === "\\" ? e.split(x).join("/") : e;
|
|
15
15
|
}
|
|
16
16
|
function S() {
|
|
17
|
-
const e =
|
|
18
|
-
return
|
|
17
|
+
const e = H(import.meta.url);
|
|
18
|
+
return c(y(e), "../../preview");
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function k(e) {
|
|
21
21
|
return e === "solid-js" || e.startsWith("solid-js/") || e === "@glasshome/widget-sdk" || e.startsWith("@glasshome/widget-sdk/") || e === "@glasshome/ui" || e.startsWith("@glasshome/ui/");
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function O() {
|
|
24
24
|
return {
|
|
25
25
|
name: "glasshome-widget:sync-layer-guard",
|
|
26
26
|
apply: "build",
|
|
@@ -33,35 +33,57 @@ function j() {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
function
|
|
36
|
+
const J = "node_modules/.cache/glasshome-widgets";
|
|
37
|
+
function $(e) {
|
|
38
38
|
try {
|
|
39
|
-
return F(
|
|
39
|
+
return F(u(process.cwd(), "package.json")).resolve(e);
|
|
40
40
|
} catch {
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
const G = [
|
|
45
|
+
"--radius",
|
|
46
|
+
"--background",
|
|
47
|
+
"--foreground",
|
|
48
|
+
"--card",
|
|
49
|
+
"--primary",
|
|
50
|
+
"--border",
|
|
51
|
+
"--muted",
|
|
52
|
+
"--accent"
|
|
53
|
+
];
|
|
54
|
+
function j(e, t) {
|
|
55
|
+
const i = u(e, `${t}.css`);
|
|
56
|
+
if (!l(i)) return;
|
|
57
|
+
const n = g(i, "utf-8");
|
|
58
|
+
for (const o of n.matchAll(/:host[^{]*\{([^}]*)\}/g)) {
|
|
59
|
+
const s = o[1] ?? "", r = G.find((a) => s.includes(`${a}:`));
|
|
60
|
+
if (r)
|
|
61
|
+
throw new Error(
|
|
62
|
+
`[glasshome-widget] "${t}.css" defines theme variable "${r}" on :host. Theme variables must inherit from the document so widgets follow the household theme — never re-scope them into the widget's shadow root.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function N(e, t, i) {
|
|
67
|
+
const n = c(e, J);
|
|
68
|
+
D(n, { recursive: !0 });
|
|
69
|
+
const o = $("@glasshome/ui/styles");
|
|
70
|
+
if (!o)
|
|
49
71
|
throw new Error(
|
|
50
72
|
"[widget-sdk] @glasshome/ui is required to build widgets (it provides the theme every GlassHome widget ships with). Add it to your widget's dependencies."
|
|
51
73
|
);
|
|
52
|
-
const s =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
...
|
|
56
|
-
y(
|
|
57
|
-
].filter((
|
|
58
|
-
|
|
74
|
+
const s = c(y(o), "../.."), r = $("@glasshome/widget-sdk/tailwind-sources"), a = r ? y(r) : null, h = [
|
|
75
|
+
u(s, "src"),
|
|
76
|
+
u(s, "dist"),
|
|
77
|
+
...a ? [u(a, "src"), u(a, "dist")] : [],
|
|
78
|
+
y(i)
|
|
79
|
+
].filter((d) => l(d)), m = c(n, `${t}.tailwind.css`);
|
|
80
|
+
w(
|
|
59
81
|
m,
|
|
60
82
|
[
|
|
61
83
|
'@import "tailwindcss" source(none);',
|
|
62
84
|
'@import "tw-animate-css";',
|
|
63
85
|
'@import "@glasshome/ui/styles/theme";',
|
|
64
|
-
...
|
|
86
|
+
...h.map((d) => `@source "${p(d)}";`),
|
|
65
87
|
"@custom-variant dark {",
|
|
66
88
|
" &:is(.dark *) { @slot }",
|
|
67
89
|
" :host(.dark) & { @slot }",
|
|
@@ -70,84 +92,84 @@ function O(e, t, n) {
|
|
|
70
92
|
].join(`
|
|
71
93
|
`)
|
|
72
94
|
);
|
|
73
|
-
const f =
|
|
74
|
-
return
|
|
95
|
+
const f = c(n, `${t}.entry.ts`);
|
|
96
|
+
return w(
|
|
75
97
|
f,
|
|
76
98
|
[
|
|
77
|
-
`import "${
|
|
78
|
-
`export { default } from "${
|
|
99
|
+
`import "${p(m)}";`,
|
|
100
|
+
`export { default } from "${p(i)}";`,
|
|
79
101
|
""
|
|
80
102
|
].join(`
|
|
81
103
|
`)
|
|
82
104
|
), f;
|
|
83
105
|
}
|
|
84
|
-
function
|
|
85
|
-
const e =
|
|
106
|
+
function _() {
|
|
107
|
+
const e = C();
|
|
86
108
|
for (const t of e)
|
|
87
109
|
t.apply ??= "build";
|
|
88
110
|
return e;
|
|
89
111
|
}
|
|
90
|
-
function
|
|
112
|
+
function q(e) {
|
|
91
113
|
const t = [];
|
|
92
114
|
if (!l(e)) return t;
|
|
93
|
-
for (const
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
96
|
-
const
|
|
97
|
-
l(
|
|
115
|
+
for (const i of I(e)) {
|
|
116
|
+
const n = c(e, i);
|
|
117
|
+
if (!P(n).isDirectory()) continue;
|
|
118
|
+
const o = c(n, "index.tsx"), s = c(n, "manifest.json");
|
|
119
|
+
l(o) && l(s) && t.push({ name: i, entry: o });
|
|
98
120
|
}
|
|
99
121
|
return t;
|
|
100
122
|
}
|
|
101
|
-
function
|
|
102
|
-
const
|
|
123
|
+
function z(e, t) {
|
|
124
|
+
const i = [];
|
|
103
125
|
if (l(e))
|
|
104
|
-
for (const
|
|
105
|
-
if (!
|
|
106
|
-
const s =
|
|
126
|
+
for (const o of I(e)) {
|
|
127
|
+
if (!P(u(e, o)).isDirectory()) continue;
|
|
128
|
+
const s = u(e, o, "manifest.json");
|
|
107
129
|
if (!l(s)) continue;
|
|
108
130
|
const r = U.safeParse(
|
|
109
|
-
JSON.parse(
|
|
131
|
+
JSON.parse(g(s, "utf-8"))
|
|
110
132
|
);
|
|
111
133
|
if (!r.success)
|
|
112
134
|
throw new Error(
|
|
113
|
-
`[registry] Invalid manifest for "${
|
|
135
|
+
`[registry] Invalid manifest for "${o}": ${A(r.error)}`
|
|
114
136
|
);
|
|
115
|
-
const
|
|
116
|
-
|
|
137
|
+
const a = l(u(t, `${o}.css`));
|
|
138
|
+
i.push({
|
|
117
139
|
...r.data,
|
|
118
|
-
bundleUrl: `./${
|
|
119
|
-
...
|
|
140
|
+
bundleUrl: `./${o}.js`,
|
|
141
|
+
...a ? { cssUrl: `./${o}.css` } : {}
|
|
120
142
|
});
|
|
121
143
|
}
|
|
122
|
-
const
|
|
144
|
+
const n = {
|
|
123
145
|
version: 1,
|
|
124
146
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
125
147
|
baseUrl: "./",
|
|
126
|
-
widgets:
|
|
148
|
+
widgets: i
|
|
127
149
|
};
|
|
128
|
-
l(t) || D(t, { recursive: !0 }),
|
|
150
|
+
l(t) || D(t, { recursive: !0 }), w(u(t, "registry.json"), JSON.stringify(n, null, 2)), console.log(`[registry] Generated registry.json with ${i.length} widget(s)`);
|
|
129
151
|
}
|
|
130
|
-
async function
|
|
131
|
-
const { build: t } = await import("vite"),
|
|
132
|
-
let s =
|
|
152
|
+
async function M(e) {
|
|
153
|
+
const { build: t } = await import("vite"), i = process.cwd(), n = c(i, e?.srcDir ?? "src"), o = c(i, e?.outDir ?? "dist");
|
|
154
|
+
let s = q(n);
|
|
133
155
|
if (s.length === 0) {
|
|
134
|
-
console.warn("[glasshome-widgets] No widgets found in",
|
|
156
|
+
console.warn("[glasshome-widgets] No widgets found in", n);
|
|
135
157
|
return;
|
|
136
158
|
}
|
|
137
159
|
if (e?.only) {
|
|
138
160
|
const r = new Set(e.only);
|
|
139
|
-
s = s.filter((
|
|
161
|
+
s = s.filter((a) => r.has(a.name));
|
|
140
162
|
}
|
|
141
|
-
e?.only || l(
|
|
163
|
+
e?.only || l(o) && T(o, { recursive: !0 }), l(o) || D(o, { recursive: !0 });
|
|
142
164
|
for (const r of s)
|
|
143
165
|
await t({
|
|
144
166
|
configFile: !1,
|
|
145
|
-
root:
|
|
146
|
-
plugins: [...
|
|
167
|
+
root: i,
|
|
168
|
+
plugins: [..._(), ...e?.plugins ?? [], O()],
|
|
147
169
|
...e?.viteConfig,
|
|
148
170
|
build: {
|
|
149
171
|
lib: {
|
|
150
|
-
entry:
|
|
172
|
+
entry: N(i, r.name, r.entry),
|
|
151
173
|
formats: ["es"],
|
|
152
174
|
fileName: r.name,
|
|
153
175
|
// Widget CSS ships as a separate asset (adopted by the host's
|
|
@@ -155,19 +177,19 @@ async function q(e) {
|
|
|
155
177
|
cssFileName: r.name
|
|
156
178
|
},
|
|
157
179
|
rollupOptions: {
|
|
158
|
-
external:
|
|
180
|
+
external: k
|
|
159
181
|
},
|
|
160
|
-
outDir:
|
|
182
|
+
outDir: o,
|
|
161
183
|
emptyOutDir: !1,
|
|
162
184
|
copyPublicDir: !1,
|
|
163
185
|
...e?.viteConfig?.build
|
|
164
186
|
},
|
|
165
187
|
logLevel: "warn"
|
|
166
|
-
});
|
|
167
|
-
|
|
188
|
+
}), j(o, r.name);
|
|
189
|
+
z(n, o);
|
|
168
190
|
}
|
|
169
|
-
function
|
|
170
|
-
const t = e?.entry ?? "src/index.tsx",
|
|
191
|
+
function te(e) {
|
|
192
|
+
const t = e?.entry ?? "src/index.tsx", i = {
|
|
171
193
|
name: "glasshome-widget:build",
|
|
172
194
|
apply: "build",
|
|
173
195
|
config() {
|
|
@@ -175,100 +197,101 @@ function ee(e) {
|
|
|
175
197
|
return {
|
|
176
198
|
build: {
|
|
177
199
|
lib: {
|
|
178
|
-
entry:
|
|
200
|
+
entry: N(s, "index", c(s, t)),
|
|
179
201
|
formats: ["es"],
|
|
180
202
|
fileName: "index",
|
|
181
203
|
cssFileName: "index"
|
|
182
204
|
},
|
|
183
205
|
rollupOptions: {
|
|
184
|
-
external:
|
|
206
|
+
external: k
|
|
185
207
|
}
|
|
186
208
|
}
|
|
187
209
|
};
|
|
188
210
|
}
|
|
189
|
-
},
|
|
211
|
+
}, n = {
|
|
190
212
|
name: "glasshome-widget:dev",
|
|
191
213
|
apply: "serve",
|
|
192
214
|
enforce: "pre",
|
|
193
215
|
config() {
|
|
194
|
-
const s = S(), r = process.cwd(),
|
|
216
|
+
const s = S(), r = process.cwd(), a = c(r, "..", "..");
|
|
195
217
|
return {
|
|
196
218
|
server: {
|
|
197
219
|
fs: {
|
|
198
|
-
allow: [s, r,
|
|
220
|
+
allow: [s, r, a]
|
|
199
221
|
}
|
|
200
222
|
}
|
|
201
223
|
};
|
|
202
224
|
},
|
|
203
225
|
configureServer(s) {
|
|
204
|
-
const r = S(),
|
|
205
|
-
s.middlewares.use(async (
|
|
206
|
-
if (
|
|
226
|
+
const r = S(), a = u(r, "preview.html");
|
|
227
|
+
s.middlewares.use(async (h, m, f) => {
|
|
228
|
+
if (h.url === "/" || h.url === "/index.html")
|
|
207
229
|
try {
|
|
208
|
-
let
|
|
209
|
-
|
|
210
|
-
} catch (
|
|
211
|
-
f(
|
|
230
|
+
let d = g(a, "utf-8");
|
|
231
|
+
d = await s.transformIndexHtml(h.url, d), m.setHeader("Content-Type", "text/html"), m.statusCode = 200, m.end(d);
|
|
232
|
+
} catch (d) {
|
|
233
|
+
f(d);
|
|
212
234
|
}
|
|
213
235
|
else
|
|
214
236
|
f();
|
|
215
237
|
});
|
|
216
238
|
},
|
|
217
239
|
resolveId(s) {
|
|
218
|
-
if (s ===
|
|
240
|
+
if (s === B) {
|
|
219
241
|
const r = S();
|
|
220
|
-
return
|
|
242
|
+
return p(u(r, "host.tsx"));
|
|
221
243
|
}
|
|
222
|
-
if (s ===
|
|
223
|
-
return
|
|
244
|
+
if (s === V)
|
|
245
|
+
return E;
|
|
224
246
|
},
|
|
225
247
|
load(s) {
|
|
226
|
-
if (s ===
|
|
227
|
-
return `export { default } from "${
|
|
248
|
+
if (s === E)
|
|
249
|
+
return `export { default } from "${p(c(process.cwd(), t))}";`;
|
|
228
250
|
}
|
|
229
|
-
},
|
|
251
|
+
}, o = {
|
|
230
252
|
name: "glasshome-widget:schema",
|
|
231
253
|
apply: "build",
|
|
232
254
|
async closeBundle() {
|
|
233
|
-
|
|
255
|
+
j(c(process.cwd(), "dist"), "index");
|
|
256
|
+
const s = c(process.cwd(), "dist", "index.js");
|
|
234
257
|
if (l(s))
|
|
235
258
|
try {
|
|
236
|
-
const
|
|
237
|
-
if (!
|
|
238
|
-
const { z:
|
|
259
|
+
const a = (await import(`${s}?t=${Date.now()}`)).default;
|
|
260
|
+
if (!a?.configSchema) return;
|
|
261
|
+
const { z: h } = await import("zod"), m = h.toJSONSchema(a.configSchema, { unrepresentable: "any" }), f = c(process.cwd(), "manifest.json");
|
|
239
262
|
if (l(f)) {
|
|
240
|
-
const b = JSON.parse(
|
|
241
|
-
b.schema = m,
|
|
263
|
+
const b = JSON.parse(g(f, "utf-8"));
|
|
264
|
+
b.schema = m, w(f, JSON.stringify(b, null, 2));
|
|
242
265
|
}
|
|
243
|
-
const
|
|
244
|
-
if (l(v) &&
|
|
245
|
-
const
|
|
266
|
+
const d = L(m), v = c(process.cwd(), ".schema-hash");
|
|
267
|
+
if (l(v) && g(v, "utf-8").trim() !== d) {
|
|
268
|
+
const W = a.manifest?.name ?? "unknown";
|
|
246
269
|
console.warn(
|
|
247
|
-
`[widget-sdk] Schema shape changed for "${
|
|
270
|
+
`[widget-sdk] Schema shape changed for "${W}" — verify configVersion was bumped`
|
|
248
271
|
);
|
|
249
272
|
}
|
|
250
|
-
|
|
273
|
+
w(v, d);
|
|
251
274
|
} catch {
|
|
252
275
|
}
|
|
253
276
|
}
|
|
254
277
|
};
|
|
255
|
-
return [...
|
|
278
|
+
return [..._(), i, O(), o, n];
|
|
256
279
|
}
|
|
257
|
-
function
|
|
258
|
-
const t = e?.srcDir ?? "src",
|
|
259
|
-
let
|
|
280
|
+
function re(e) {
|
|
281
|
+
const t = e?.srcDir ?? "src", i = e?.outDir ?? "dist";
|
|
282
|
+
let n = [];
|
|
260
283
|
return [{
|
|
261
284
|
name: "glasshome-widgets:build",
|
|
262
285
|
apply: "build",
|
|
263
286
|
config(s) {
|
|
264
|
-
return
|
|
287
|
+
return n = (s.plugins ?? []).flat().filter(Boolean).filter(
|
|
265
288
|
(r) => !r.name?.startsWith("glasshome-widgets:")
|
|
266
289
|
), {
|
|
267
290
|
build: {
|
|
268
291
|
rollupOptions: {
|
|
269
292
|
input: { __glasshome_noop: "\0glasshome-noop" }
|
|
270
293
|
},
|
|
271
|
-
outDir:
|
|
294
|
+
outDir: i,
|
|
272
295
|
copyPublicDir: !1
|
|
273
296
|
}
|
|
274
297
|
};
|
|
@@ -280,19 +303,19 @@ function se(e) {
|
|
|
280
303
|
if (s === "\0glasshome-noop") return "export {}";
|
|
281
304
|
},
|
|
282
305
|
async closeBundle() {
|
|
283
|
-
await
|
|
306
|
+
await M({
|
|
284
307
|
srcDir: t,
|
|
285
|
-
outDir:
|
|
286
|
-
plugins:
|
|
308
|
+
outDir: i,
|
|
309
|
+
plugins: n
|
|
287
310
|
});
|
|
288
311
|
}
|
|
289
312
|
}];
|
|
290
313
|
}
|
|
291
314
|
export {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
315
|
+
M as buildWidgets,
|
|
316
|
+
q as discoverWidgets,
|
|
317
|
+
z as generateRegistry,
|
|
318
|
+
te as glasshomeWidget,
|
|
319
|
+
re as glasshomeWidgets,
|
|
320
|
+
k as isWidgetExternal
|
|
298
321
|
};
|