@jogak/core 0.1.0-alpha.0 → 0.1.0-alpha.10.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/CHANGELOG.md +118 -0
- package/dist/actions-BvvUNlgo.js +69 -0
- package/dist/actions-D9bnuJ1b.cjs +1 -0
- package/dist/adapter.d.ts +80 -0
- package/dist/adapters/next/index.cjs +73 -0
- package/dist/adapters/next/index.d.ts +5 -0
- package/dist/adapters/next/index.mjs +222 -0
- package/dist/adapters/next/scaffold.d.ts +23 -0
- package/dist/adapters/next/spawn-dev.d.ts +2 -0
- package/dist/adapters/standalone/index.cjs +1 -0
- package/dist/adapters/standalone/index.d.ts +3 -0
- package/dist/adapters/standalone/index.mjs +21 -0
- package/dist/adapters/vite/build.d.ts +2 -0
- package/dist/adapters/vite/index.cjs +22 -0
- package/dist/adapters/vite/index.d.ts +5 -0
- package/dist/adapters/vite/index.mjs +134 -0
- package/dist/adapters/vite/preview-frame-plugin.d.ts +6 -0
- package/dist/adapters/vite/spawn-dev.d.ts +2 -0
- package/dist/adapters/webpack/index.cjs +74 -0
- package/dist/adapters/webpack/index.d.ts +5 -0
- package/dist/adapters/webpack/index.mjs +214 -0
- package/dist/adapters/webpack/scaffold.d.ts +18 -0
- package/dist/adapters/webpack/spawn-dev.d.ts +2 -0
- package/dist/builder-detect.d.ts +9 -0
- package/dist/config.d.ts +71 -0
- package/dist/detect-global-css-CDcuUAYE.cjs +1 -0
- package/dist/detect-global-css-CIVMmgzy.js +33 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +13 -413
- package/dist/plugin-DhT-PH1R.js +354 -0
- package/dist/plugin-Wtlz0hae.cjs +50 -0
- package/dist/preview-entry/protocol.d.ts +29 -0
- package/dist/preview-entry/source.d.ts +30 -0
- package/dist/registry-CnBX6XxF.js +397 -0
- package/dist/registry-DRRMxvoz.cjs +1 -0
- package/dist/registry.d.ts +3 -0
- package/dist/renderers/next/client/Preview.d.ts +27 -0
- package/dist/renderers/next/client/index.d.ts +2 -0
- package/dist/renderers/next/index.cjs +1 -0
- package/dist/renderers/next/index.d.ts +4 -0
- package/dist/renderers/next/index.mjs +53 -0
- package/dist/renderers/next/server/JogakLayout.d.ts +28 -0
- package/dist/renderers/next/server/index.d.ts +2 -0
- package/dist/renderers/react/JogakProvider.d.ts +8 -0
- package/dist/renderers/react/adapter.d.ts +2 -0
- package/dist/renderers/react/index.cjs +1 -0
- package/dist/renderers/react/index.d.ts +7 -0
- package/dist/renderers/react/index.mjs +101 -0
- package/dist/renderers/react/useEntry.d.ts +40 -0
- package/dist/renderers/react/useRegistryMeta.d.ts +27 -0
- package/dist/renderers/web-components/define.d.ts +11 -0
- package/dist/renderers/web-components/index.cjs +1 -0
- package/dist/renderers/web-components/index.d.ts +1 -0
- package/dist/renderers/web-components/index.mjs +48 -0
- package/dist/server.cjs +1 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.mjs +45 -0
- package/dist/source-9OiU8x_y.cjs +43 -0
- package/dist/source-D44KTQPu.js +50 -0
- package/dist/types.d.ts +161 -0
- package/dist/vite/index.cjs +1 -0
- package/dist/vite/index.mjs +2 -275
- package/dist/vite-plugin/detect-global-css.d.ts +33 -0
- package/dist/vite-plugin/index.cjs +1 -0
- package/dist/vite-plugin/index.d.ts +12 -0
- package/dist/vite-plugin/index.mjs +4 -0
- package/dist/vite-plugin/resolve-paths.d.ts +32 -0
- package/dist/{vite → vite-plugin}/virtual-ids.d.ts +17 -0
- package/package.json +101 -10
- package/dist/index.js +0 -1
- package/dist/vite/index.js +0 -41
- /package/dist/build/{index.js → index.cjs} +0 -0
- /package/dist/meta/{extractor-child.js → extractor-child.cjs} +0 -0
- /package/dist/{vite → vite-plugin}/cache-validate.d.ts +0 -0
- /package/dist/{vite → vite-plugin}/plugin.d.ts +0 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { resolve as j, join as V, dirname as q } from "node:path";
|
|
2
|
+
import { existsSync as E, readFileSync as H } from "node:fs";
|
|
3
|
+
import { stat as P, rm as z, readdir as Q, readFile as L } from "node:fs/promises";
|
|
4
|
+
import { r as Z } from "./detect-global-css-CIVMmgzy.js";
|
|
5
|
+
import { c as U } from "./extractor-client-CReBed7x.js";
|
|
6
|
+
const tt = [
|
|
7
|
+
"@jogak/core",
|
|
8
|
+
"@jogak/react",
|
|
9
|
+
"@jogak/web-components",
|
|
10
|
+
"@jogak/next"
|
|
11
|
+
];
|
|
12
|
+
async function J(t) {
|
|
13
|
+
try {
|
|
14
|
+
const c = await P(t);
|
|
15
|
+
if (!c.isDirectory())
|
|
16
|
+
return c.mtimeMs;
|
|
17
|
+
} catch {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
let r = 0, u;
|
|
21
|
+
try {
|
|
22
|
+
u = await Q(t);
|
|
23
|
+
} catch {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
for (const c of u) {
|
|
27
|
+
const m = V(t, c);
|
|
28
|
+
try {
|
|
29
|
+
const s = await P(m);
|
|
30
|
+
if (s.isDirectory()) {
|
|
31
|
+
const p = await J(m);
|
|
32
|
+
p > r && (r = p);
|
|
33
|
+
} else s.mtimeMs > r && (r = s.mtimeMs);
|
|
34
|
+
} catch {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return r;
|
|
39
|
+
}
|
|
40
|
+
async function et(t) {
|
|
41
|
+
const r = j(t.root, "node_modules/.vite/deps");
|
|
42
|
+
if (!E(r))
|
|
43
|
+
return { purged: !1 };
|
|
44
|
+
const u = V(r, "_metadata.json");
|
|
45
|
+
if (!E(u))
|
|
46
|
+
return { purged: !1 };
|
|
47
|
+
let c;
|
|
48
|
+
try {
|
|
49
|
+
c = (await P(u)).mtimeMs;
|
|
50
|
+
} catch (s) {
|
|
51
|
+
return t.logger.warn(
|
|
52
|
+
`[jogak] cache validation: failed to stat _metadata.json (${s.message})`
|
|
53
|
+
), { purged: !1 };
|
|
54
|
+
}
|
|
55
|
+
const m = t.packages ?? tt;
|
|
56
|
+
for (const s of m) {
|
|
57
|
+
const p = j(t.root, "node_modules", s, "dist");
|
|
58
|
+
if (!E(p)) continue;
|
|
59
|
+
let y;
|
|
60
|
+
try {
|
|
61
|
+
y = await J(p);
|
|
62
|
+
} catch (h) {
|
|
63
|
+
t.logger.warn(
|
|
64
|
+
`[jogak] cache validation: failed to walk ${s}/dist (${h.message})`
|
|
65
|
+
);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (y > c + 1e3)
|
|
69
|
+
try {
|
|
70
|
+
return await z(r, { recursive: !0, force: !0 }), t.logger.info(
|
|
71
|
+
`[jogak] vite deps cache invalidated (stale): ${s} dist newer than cache`
|
|
72
|
+
), { purged: !0, reason: s };
|
|
73
|
+
} catch (h) {
|
|
74
|
+
return t.logger.warn(
|
|
75
|
+
`[jogak] cache validation: failed to purge ${r} (${h.message})`
|
|
76
|
+
), { purged: !1 };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { purged: !1 };
|
|
80
|
+
}
|
|
81
|
+
function rt(t) {
|
|
82
|
+
return t.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
83
|
+
}
|
|
84
|
+
function ot(t) {
|
|
85
|
+
if (E(t))
|
|
86
|
+
try {
|
|
87
|
+
const r = H(t, "utf8");
|
|
88
|
+
return JSON.parse(rt(r));
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function at(t, r, u) {
|
|
94
|
+
if (!t.endsWith("/*") || !r.endsWith("/*")) return;
|
|
95
|
+
const c = t.slice(0, -2), m = j(u, r.slice(0, -2));
|
|
96
|
+
return [c, m];
|
|
97
|
+
}
|
|
98
|
+
function nt(t, r) {
|
|
99
|
+
var m, s;
|
|
100
|
+
const u = {}, c = /* @__PURE__ */ new Set([
|
|
101
|
+
t,
|
|
102
|
+
j(r, "tsconfig.app.json")
|
|
103
|
+
]);
|
|
104
|
+
for (const p of c) {
|
|
105
|
+
const y = ot(p);
|
|
106
|
+
if (y === void 0) continue;
|
|
107
|
+
const h = (m = y.compilerOptions) == null ? void 0 : m.paths;
|
|
108
|
+
if (h === void 0) continue;
|
|
109
|
+
const b = ((s = y.compilerOptions) == null ? void 0 : s.baseUrl) ?? ".", T = j(q(p), b);
|
|
110
|
+
for (const [C, l] of Object.entries(h)) {
|
|
111
|
+
const d = l[0];
|
|
112
|
+
if (d === void 0) continue;
|
|
113
|
+
const _ = at(C, d, T);
|
|
114
|
+
if (_ === void 0) continue;
|
|
115
|
+
const [k, x] = _;
|
|
116
|
+
u[k] === void 0 && (u[k] = x);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return u;
|
|
120
|
+
}
|
|
121
|
+
const G = "virtual:jogak", M = "\0" + G, B = "virtual:jogak/entry/", N = "\0" + B, K = "virtual:jogak/global-css", D = "\0" + K;
|
|
122
|
+
function st(t) {
|
|
123
|
+
return Buffer.from(t, "utf8").toString("base64url");
|
|
124
|
+
}
|
|
125
|
+
function it(t) {
|
|
126
|
+
return Buffer.from(t, "base64url").toString("utf8");
|
|
127
|
+
}
|
|
128
|
+
function F(t) {
|
|
129
|
+
return {
|
|
130
|
+
title: t.title,
|
|
131
|
+
jogakNamesKey: [...t.jogakNames].sort().join("|")
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function ct(t, r) {
|
|
135
|
+
return t !== void 0 && t.title === r.title && t.jogakNamesKey === r.jogakNamesKey;
|
|
136
|
+
}
|
|
137
|
+
function pt(t = {}) {
|
|
138
|
+
const {
|
|
139
|
+
patterns: r = ["src/**/*.jogak.ts", "src/**/*.jogak.tsx"],
|
|
140
|
+
codeTheme: u = "vsDark"
|
|
141
|
+
} = t, c = t.cwd, m = t.tsConfigFilePath, s = t.disableCacheValidation === !0, p = t.resolveAlias, y = t.globalCss, h = t.previewIsolation ?? "iframe", b = t.previewFrame === !0, T = t.userPreviewUrl ?? t.userViteUrl ?? "", C = t.previewEntryPath ?? "/__jogak_preview__/index.html";
|
|
142
|
+
let l, d, _;
|
|
143
|
+
const k = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map();
|
|
144
|
+
async function R() {
|
|
145
|
+
const { glob: e } = await import("glob"), f = _ ?? process.cwd(), o = (await e(r, { cwd: f, absolute: !0 })).sort(), i = [];
|
|
146
|
+
k.clear(), x.clear();
|
|
147
|
+
for (const a of o) {
|
|
148
|
+
let v = "";
|
|
149
|
+
try {
|
|
150
|
+
v = await L(a, "utf8");
|
|
151
|
+
} catch {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
let w = {}, n = null;
|
|
155
|
+
if (d !== void 0) {
|
|
156
|
+
try {
|
|
157
|
+
w = await d.extract(a);
|
|
158
|
+
} catch {
|
|
159
|
+
w = {};
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
n = await d.extractMeta(a);
|
|
163
|
+
} catch {
|
|
164
|
+
n = null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (n === null) continue;
|
|
168
|
+
const g = n.title;
|
|
169
|
+
k.set(g, a), x.set(a, g);
|
|
170
|
+
const S = {
|
|
171
|
+
id: g,
|
|
172
|
+
title: n.title,
|
|
173
|
+
jogakNames: n.jogakNames,
|
|
174
|
+
autoArgTypes: w,
|
|
175
|
+
userArgTypes: n.userArgTypes,
|
|
176
|
+
source: v,
|
|
177
|
+
filePath: a,
|
|
178
|
+
metaExtras: n.metaExtras
|
|
179
|
+
};
|
|
180
|
+
I.set(a, F(S)), i.push({ id: g, filePath: a, meta: S });
|
|
181
|
+
}
|
|
182
|
+
return i;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
name: "vite-plugin-jogak",
|
|
186
|
+
/**
|
|
187
|
+
* 사용자 path alias 주입.
|
|
188
|
+
*
|
|
189
|
+
* `runHost`는 vite root를 `@jogak/ui` 패키지로 두고 사용자 `vite.config.ts`를
|
|
190
|
+
* 무시하므로(`configFile: false`), 사용자가 컴포넌트 안에서 쓰는 `@/lib/utils`
|
|
191
|
+
* 같은 alias가 그냥은 적용되지 않는다. 본 hook이 사용자 tsconfig의
|
|
192
|
+
* `compilerOptions.paths`를 vite `resolve.alias`로 자동 변환해 주입한다.
|
|
193
|
+
*
|
|
194
|
+
* 우선순위: `options.resolveAlias` (명시) > tsconfig 자동 추출.
|
|
195
|
+
*/
|
|
196
|
+
config() {
|
|
197
|
+
const e = c ?? process.cwd(), f = m ?? j(e, "tsconfig.json"), o = nt(f, e), i = {};
|
|
198
|
+
if (p !== void 0)
|
|
199
|
+
for (const [v, w] of Object.entries(p))
|
|
200
|
+
i[v] = j(e, w);
|
|
201
|
+
const a = { ...o, ...i };
|
|
202
|
+
if (Object.keys(a).length !== 0)
|
|
203
|
+
return {
|
|
204
|
+
resolve: { alias: a }
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
async configResolved(e) {
|
|
208
|
+
_ = c ?? e.root, e.command === "serve" && !s && await et({
|
|
209
|
+
root: e.root,
|
|
210
|
+
logger: {
|
|
211
|
+
info: (o) => e.logger.info(o),
|
|
212
|
+
warn: (o) => e.logger.warn(o)
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const f = m ?? j(_, "tsconfig.json");
|
|
216
|
+
d = E(f) ? U({ tsConfigFilePath: f }) : U();
|
|
217
|
+
},
|
|
218
|
+
configureServer(e) {
|
|
219
|
+
l = e;
|
|
220
|
+
},
|
|
221
|
+
buildEnd() {
|
|
222
|
+
d == null || d.releaseCache();
|
|
223
|
+
},
|
|
224
|
+
resolveId(e) {
|
|
225
|
+
if (e === G)
|
|
226
|
+
return M;
|
|
227
|
+
if (e === K)
|
|
228
|
+
return D;
|
|
229
|
+
if (e.startsWith(B))
|
|
230
|
+
return "\0" + e;
|
|
231
|
+
},
|
|
232
|
+
async load(e) {
|
|
233
|
+
if (e === D) {
|
|
234
|
+
const f = _ ?? process.cwd(), o = Z(y, f);
|
|
235
|
+
return o.length === 0 ? `// [jogak] globalCss not configured or no candidates found.
|
|
236
|
+
export {}
|
|
237
|
+
` : `${o.map((a) => `import ${JSON.stringify(a)}`).join(`
|
|
238
|
+
`)}
|
|
239
|
+
export {}
|
|
240
|
+
`;
|
|
241
|
+
}
|
|
242
|
+
if (e === M) {
|
|
243
|
+
const o = (await R()).map((a) => a.meta), i = b ? "" : `
|
|
244
|
+
export const _jogakCodeTheme = ${JSON.stringify(u)}
|
|
245
|
+
export const _jogakPreviewIsolation = ${JSON.stringify(h)}
|
|
246
|
+
export const _jogakUserPreviewUrl = ${JSON.stringify(T)}
|
|
247
|
+
export const _jogakPreviewEntryPath = ${JSON.stringify(C)}
|
|
248
|
+
export const _jogakUserViteUrl = ${JSON.stringify(T)}
|
|
249
|
+
export const _jogakMetas = _metas
|
|
250
|
+
`;
|
|
251
|
+
return `import { defaultRegistry } from '@jogak/core'
|
|
252
|
+
|
|
253
|
+
const _entryLoader = (slug) =>
|
|
254
|
+
import(/* @vite-ignore */ '/@id/__x00__virtual:jogak/entry/' + slug)
|
|
255
|
+
defaultRegistry.setEntryLoader((id) => {
|
|
256
|
+
const slug = ${lt()}
|
|
257
|
+
return _entryLoader(slug(id))
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
const _metas = ${JSON.stringify(o)}
|
|
261
|
+
|
|
262
|
+
for (const m of _metas) defaultRegistry.registerMeta(m)
|
|
263
|
+
${i}`;
|
|
264
|
+
}
|
|
265
|
+
if (e.startsWith(N)) {
|
|
266
|
+
const f = e.slice(N.length), o = it(f);
|
|
267
|
+
let i = k.get(o);
|
|
268
|
+
return i === void 0 && (await R(), i = k.get(o)), i === void 0 ? `// [jogak] unknown entry id: ${JSON.stringify(o)}
|
|
269
|
+
export {}
|
|
270
|
+
` : `import * as _user from ${JSON.stringify(i)}
|
|
271
|
+
import { defaultRegistry } from '@jogak/core'
|
|
272
|
+
|
|
273
|
+
const _meta = _user.default
|
|
274
|
+
const _named = { ..._user }
|
|
275
|
+
delete _named.default
|
|
276
|
+
const _jogaks = Object.values(_named).filter(
|
|
277
|
+
(v) => v !== null && typeof v === 'object' && typeof v.name === 'string'
|
|
278
|
+
)
|
|
279
|
+
defaultRegistry.hydrateEntry(${JSON.stringify(o)}, _jogaks, _meta?.component)
|
|
280
|
+
|
|
281
|
+
if (import.meta.hot) {
|
|
282
|
+
import.meta.hot.accept()
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export {}
|
|
286
|
+
`;
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
async handleHotUpdate({ file: e, modules: f }) {
|
|
290
|
+
const o = /\.jogak\.(tsx?|jsx?)$/.test(e), i = /\.(tsx?|jsx?)$/.test(e) && !o;
|
|
291
|
+
if (!o && !i || l === void 0 || !o) return;
|
|
292
|
+
const a = l.moduleGraph.getModuleById(
|
|
293
|
+
M
|
|
294
|
+
), v = x.get(e), w = v !== void 0 ? N + st(v) : void 0, n = w !== void 0 ? l.moduleGraph.getModuleById(w) : void 0;
|
|
295
|
+
let g = null, S = {}, O = "";
|
|
296
|
+
if (d !== void 0) {
|
|
297
|
+
try {
|
|
298
|
+
g = await d.extractMeta(e);
|
|
299
|
+
} catch {
|
|
300
|
+
g = null;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
S = await d.extract(e);
|
|
304
|
+
} catch {
|
|
305
|
+
S = {};
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
O = await L(e, "utf8");
|
|
309
|
+
} catch {
|
|
310
|
+
O = "";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (g === null) {
|
|
314
|
+
a !== void 0 && l.moduleGraph.invalidateModule(a), n !== void 0 && l.moduleGraph.invalidateModule(n), l.ws.send({ type: "full-reload" });
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const $ = F(g), W = I.get(e), X = ct(W, $);
|
|
318
|
+
if (I.set(e, $), !X || v === void 0) {
|
|
319
|
+
a !== void 0 && l.moduleGraph.invalidateModule(a), n !== void 0 && l.moduleGraph.invalidateModule(n), l.ws.send({ type: "full-reload" });
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const Y = {
|
|
323
|
+
id: v,
|
|
324
|
+
title: g.title,
|
|
325
|
+
jogakNames: g.jogakNames,
|
|
326
|
+
autoArgTypes: S,
|
|
327
|
+
userArgTypes: g.userArgTypes,
|
|
328
|
+
source: O,
|
|
329
|
+
filePath: e,
|
|
330
|
+
metaExtras: g.metaExtras
|
|
331
|
+
};
|
|
332
|
+
n !== void 0 && l.moduleGraph.invalidateModule(n), l.ws.send({
|
|
333
|
+
type: "custom",
|
|
334
|
+
event: "jogak:meta-update",
|
|
335
|
+
data: { id: v, meta: Y }
|
|
336
|
+
});
|
|
337
|
+
const A = [...f];
|
|
338
|
+
return n !== void 0 && !A.includes(n) && A.push(n), A;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function lt() {
|
|
343
|
+
return `(rawId) => {
|
|
344
|
+
if (typeof Buffer !== 'undefined') return Buffer.from(rawId, 'utf8').toString('base64url')
|
|
345
|
+
// 브라우저 폴백: btoa는 binary string 기준이라 UTF-8을 한번 인코딩해야 한다.
|
|
346
|
+
const enc = new TextEncoder().encode(rawId)
|
|
347
|
+
let bin = ''
|
|
348
|
+
for (let i = 0; i < enc.length; i++) bin += String.fromCharCode(enc[i])
|
|
349
|
+
return btoa(bin).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')
|
|
350
|
+
}`;
|
|
351
|
+
}
|
|
352
|
+
export {
|
|
353
|
+
pt as j
|
|
354
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";var X=Object.create;var L=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var Z=(e,r,s,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of H(r))!Q.call(e,n)&&n!==s&&L(e,n,{get:()=>r[n],enumerable:!(c=Y(r,n))||c.enumerable});return e};var ee=(e,r,s)=>(s=e!=null?X(z(e)):{},Z(r||!e||!e.__esModule?L(s,"default",{value:e,enumerable:!0}):s,e));const v=require("node:path"),E=require("node:fs"),S=require("node:fs/promises"),te=require("./detect-global-css-CDcuUAYE.cjs"),U=require("./extractor-client-CiWszHel.cjs"),re=["@jogak/core","@jogak/react","@jogak/web-components","@jogak/next"];async function V(e){try{const c=await S.stat(e);if(!c.isDirectory())return c.mtimeMs}catch{return 0}let r=0,s;try{s=await S.readdir(e)}catch{return 0}for(const c of s){const n=v.join(e,c);try{const l=await S.stat(n);if(l.isDirectory()){const p=await V(n);p>r&&(r=p)}else l.mtimeMs>r&&(r=l.mtimeMs)}catch{continue}}return r}async function oe(e){const r=v.resolve(e.root,"node_modules/.vite/deps");if(!E.existsSync(r))return{purged:!1};const s=v.join(r,"_metadata.json");if(!E.existsSync(s))return{purged:!1};let c;try{c=(await S.stat(s)).mtimeMs}catch(l){return e.logger.warn(`[jogak] cache validation: failed to stat _metadata.json (${l.message})`),{purged:!1}}const n=e.packages??re;for(const l of n){const p=v.resolve(e.root,"node_modules",l,"dist");if(!E.existsSync(p))continue;let h;try{h=await V(p)}catch(w){e.logger.warn(`[jogak] cache validation: failed to walk ${l}/dist (${w.message})`);continue}if(h>c+1e3)try{return await S.rm(r,{recursive:!0,force:!0}),e.logger.info(`[jogak] vite deps cache invalidated (stale): ${l} dist newer than cache`),{purged:!0,reason:l}}catch(w){return e.logger.warn(`[jogak] cache validation: failed to purge ${r} (${w.message})`),{purged:!1}}}return{purged:!1}}function ae(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"")}function se(e){if(E.existsSync(e))try{const r=E.readFileSync(e,"utf8");return JSON.parse(ae(r))}catch{return}}function ne(e,r,s){if(!e.endsWith("/*")||!r.endsWith("/*"))return;const c=e.slice(0,-2),n=v.resolve(s,r.slice(0,-2));return[c,n]}function ie(e,r){var n,l;const s={},c=new Set([e,v.resolve(r,"tsconfig.app.json")]);for(const p of c){const h=se(p);if(h===void 0)continue;const w=(n=h.compilerOptions)==null?void 0:n.paths;if(w===void 0)continue;const T=((l=h.compilerOptions)==null?void 0:l.baseUrl)??".",b=v.resolve(v.dirname(p),T);for(const[I,d]of Object.entries(w)){const f=d[0];if(f===void 0)continue;const _=ne(I,f,b);if(_===void 0)continue;const[k,C]=_;s[k]===void 0&&(s[k]=C)}}return s}const J="virtual:jogak",N="\0"+J,G="virtual:jogak/entry/",P="\0"+G,B="virtual:jogak/global-css",D="\0"+B;function ce(e){return Buffer.from(e,"utf8").toString("base64url")}function le(e){return Buffer.from(e,"base64url").toString("utf8")}function F(e){return{title:e.title,jogakNamesKey:[...e.jogakNames].sort().join("|")}}function ue(e,r){return e!==void 0&&e.title===r.title&&e.jogakNamesKey===r.jogakNamesKey}function de(e={}){const{patterns:r=["src/**/*.jogak.ts","src/**/*.jogak.tsx"],codeTheme:s="vsDark"}=e,c=e.cwd,n=e.tsConfigFilePath,l=e.disableCacheValidation===!0,p=e.resolveAlias,h=e.globalCss,w=e.previewIsolation??"iframe",T=e.previewFrame===!0,b=e.userPreviewUrl??e.userViteUrl??"",I=e.previewEntryPath??"/__jogak_preview__/index.html";let d,f,_;const k=new Map,C=new Map,O=new Map;async function R(){const{glob:t}=await import("glob"),g=_??process.cwd(),o=(await t(r,{cwd:g,absolute:!0})).sort(),u=[];k.clear(),C.clear();for(const a of o){let y="";try{y=await S.readFile(a,"utf8")}catch{continue}let j={},i=null;if(f!==void 0){try{j=await f.extract(a)}catch{j={}}try{i=await f.extractMeta(a)}catch{i=null}}if(i===null)continue;const m=i.title;k.set(m,a),C.set(a,m);const x={id:m,title:i.title,jogakNames:i.jogakNames,autoArgTypes:j,userArgTypes:i.userArgTypes,source:y,filePath:a,metaExtras:i.metaExtras};O.set(a,F(x)),u.push({id:m,filePath:a,meta:x})}return u}return{name:"vite-plugin-jogak",config(){const t=c??process.cwd(),g=n??v.resolve(t,"tsconfig.json"),o=ie(g,t),u={};if(p!==void 0)for(const[y,j]of Object.entries(p))u[y]=v.resolve(t,j);const a={...o,...u};if(Object.keys(a).length!==0)return{resolve:{alias:a}}},async configResolved(t){_=c??t.root,t.command==="serve"&&!l&&await oe({root:t.root,logger:{info:o=>t.logger.info(o),warn:o=>t.logger.warn(o)}});const g=n??v.resolve(_,"tsconfig.json");f=E.existsSync(g)?U.createPropsExtractor({tsConfigFilePath:g}):U.createPropsExtractor()},configureServer(t){d=t},buildEnd(){f==null||f.releaseCache()},resolveId(t){if(t===J)return N;if(t===B)return D;if(t.startsWith(G))return"\0"+t},async load(t){if(t===D){const g=_??process.cwd(),o=te.resolveGlobalCssPaths(h,g);return o.length===0?`// [jogak] globalCss not configured or no candidates found.
|
|
2
|
+
export {}
|
|
3
|
+
`:`${o.map(a=>`import ${JSON.stringify(a)}`).join(`
|
|
4
|
+
`)}
|
|
5
|
+
export {}
|
|
6
|
+
`}if(t===N){const o=(await R()).map(a=>a.meta),u=T?"":`
|
|
7
|
+
export const _jogakCodeTheme = ${JSON.stringify(s)}
|
|
8
|
+
export const _jogakPreviewIsolation = ${JSON.stringify(w)}
|
|
9
|
+
export const _jogakUserPreviewUrl = ${JSON.stringify(b)}
|
|
10
|
+
export const _jogakPreviewEntryPath = ${JSON.stringify(I)}
|
|
11
|
+
export const _jogakUserViteUrl = ${JSON.stringify(b)}
|
|
12
|
+
export const _jogakMetas = _metas
|
|
13
|
+
`;return`import { defaultRegistry } from '@jogak/core'
|
|
14
|
+
|
|
15
|
+
const _entryLoader = (slug) =>
|
|
16
|
+
import(/* @vite-ignore */ '/@id/__x00__virtual:jogak/entry/' + slug)
|
|
17
|
+
defaultRegistry.setEntryLoader((id) => {
|
|
18
|
+
const slug = ${fe()}
|
|
19
|
+
return _entryLoader(slug(id))
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const _metas = ${JSON.stringify(o)}
|
|
23
|
+
|
|
24
|
+
for (const m of _metas) defaultRegistry.registerMeta(m)
|
|
25
|
+
${u}`}if(t.startsWith(P)){const g=t.slice(P.length),o=le(g);let u=k.get(o);return u===void 0&&(await R(),u=k.get(o)),u===void 0?`// [jogak] unknown entry id: ${JSON.stringify(o)}
|
|
26
|
+
export {}
|
|
27
|
+
`:`import * as _user from ${JSON.stringify(u)}
|
|
28
|
+
import { defaultRegistry } from '@jogak/core'
|
|
29
|
+
|
|
30
|
+
const _meta = _user.default
|
|
31
|
+
const _named = { ..._user }
|
|
32
|
+
delete _named.default
|
|
33
|
+
const _jogaks = Object.values(_named).filter(
|
|
34
|
+
(v) => v !== null && typeof v === 'object' && typeof v.name === 'string'
|
|
35
|
+
)
|
|
36
|
+
defaultRegistry.hydrateEntry(${JSON.stringify(o)}, _jogaks, _meta?.component)
|
|
37
|
+
|
|
38
|
+
if (import.meta.hot) {
|
|
39
|
+
import.meta.hot.accept()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {}
|
|
43
|
+
`}},async handleHotUpdate({file:t,modules:g}){const o=/\.jogak\.(tsx?|jsx?)$/.test(t),u=/\.(tsx?|jsx?)$/.test(t)&&!o;if(!o&&!u||d===void 0||!o)return;const a=d.moduleGraph.getModuleById(N),y=C.get(t),j=y!==void 0?P+ce(y):void 0,i=j!==void 0?d.moduleGraph.getModuleById(j):void 0;let m=null,x={},A="";if(f!==void 0){try{m=await f.extractMeta(t)}catch{m=null}try{x=await f.extract(t)}catch{x={}}try{A=await S.readFile(t,"utf8")}catch{A=""}}if(m===null){a!==void 0&&d.moduleGraph.invalidateModule(a),i!==void 0&&d.moduleGraph.invalidateModule(i),d.ws.send({type:"full-reload"});return}const $=F(m),q=O.get(t),K=ue(q,$);if(O.set(t,$),!K||y===void 0){a!==void 0&&d.moduleGraph.invalidateModule(a),i!==void 0&&d.moduleGraph.invalidateModule(i),d.ws.send({type:"full-reload"});return}const W={id:y,title:m.title,jogakNames:m.jogakNames,autoArgTypes:x,userArgTypes:m.userArgTypes,source:A,filePath:t,metaExtras:m.metaExtras};i!==void 0&&d.moduleGraph.invalidateModule(i),d.ws.send({type:"custom",event:"jogak:meta-update",data:{id:y,meta:W}});const M=[...g];return i!==void 0&&!M.includes(i)&&M.push(i),M}}}function fe(){return`(rawId) => {
|
|
44
|
+
if (typeof Buffer !== 'undefined') return Buffer.from(rawId, 'utf8').toString('base64url')
|
|
45
|
+
// 브라우저 폴백: btoa는 binary string 기준이라 UTF-8을 한번 인코딩해야 한다.
|
|
46
|
+
const enc = new TextEncoder().encode(rawId)
|
|
47
|
+
let bin = ''
|
|
48
|
+
for (let i = 0; i < enc.length; i++) bin += String.fromCharCode(enc[i])
|
|
49
|
+
return btoa(bin).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')
|
|
50
|
+
}`}exports.jogak=de;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 알파.9: jogak chrome ↔ preview iframe 간 postMessage 통신 프로토콜.
|
|
3
|
+
*
|
|
4
|
+
* 모든 어댑터(vite/next/webpack/standalone)가 동일 프로토콜 사용. iframe 안 entry source는
|
|
5
|
+
* cross-origin 환경에서도 작동하도록 `targetOrigin: '*'`. preview는 사용자 본인 컴포넌트만
|
|
6
|
+
* mount하는 신뢰 환경이므로 origin 검증은 README 명시 후 생략.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 부모(jogak SPA) → iframe (preview entry).
|
|
10
|
+
*/
|
|
11
|
+
export type JogakMessageToFrame = {
|
|
12
|
+
readonly type: 'jogak:setProps';
|
|
13
|
+
readonly entryId: string;
|
|
14
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: 'jogak:unmount';
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* iframe (preview entry) → 부모(jogak SPA).
|
|
20
|
+
*/
|
|
21
|
+
export type JogakMessageFromFrame = {
|
|
22
|
+
readonly type: 'jogak:ready';
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: 'jogak:rendered';
|
|
25
|
+
readonly entryId: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: 'jogak:error';
|
|
28
|
+
readonly message: string;
|
|
29
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 알파.9: 모든 빌더 어댑터가 공통으로 사용하는 preview entry source.
|
|
3
|
+
*
|
|
4
|
+
* 빌더에 무관하게 다음 책임:
|
|
5
|
+
* 1. `defaultRegistry.requestEntry(entryId)`로 사용자 컴포넌트 dynamic import
|
|
6
|
+
* 2. `reactAdapter.render`로 mount
|
|
7
|
+
* 3. postMessage 프로토콜 (`@jogak/core/preview-entry/protocol`)로 부모와 통신
|
|
8
|
+
*
|
|
9
|
+
* 어댑터별 차이는 `extraImports` 배열뿐:
|
|
10
|
+
* - vite-adapter: `['virtual:jogak/preview-global-css']`
|
|
11
|
+
* - next-adapter: 사용자 globalCss 절대 경로 직접 inject
|
|
12
|
+
* - webpack-adapter: 사용자 globalCss 절대 경로
|
|
13
|
+
* - standalone-adapter: 사용자 사전 빌드 css 절대 경로
|
|
14
|
+
*/
|
|
15
|
+
export interface RenderPreviewEntryOptions {
|
|
16
|
+
/**
|
|
17
|
+
* 어댑터별 추가 import 라인. 라인 순서대로 emit되어 cascade order 결정.
|
|
18
|
+
*
|
|
19
|
+
* @example vite-adapter
|
|
20
|
+
* ['virtual:jogak/preview-global-css']
|
|
21
|
+
*
|
|
22
|
+
* @example next-adapter
|
|
23
|
+
* ['/abs/path/src/index.css']
|
|
24
|
+
*/
|
|
25
|
+
readonly extraImports?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 어댑터가 호출 — 자기 scope에 맞는 추가 import 라인 주입.
|
|
29
|
+
*/
|
|
30
|
+
export declare function renderPreviewEntrySource(opts?: RenderPreviewEntryOptions): string;
|