@jogak/core 0.1.0-alpha.4 → 0.1.0-alpha.6

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.
@@ -1,8 +1,8 @@
1
- import { resolve as h, join as $, dirname as G } from "node:path";
2
- import { existsSync as S, readFileSync as J } from "node:fs";
3
- import { stat as C, rm as B, readdir as K, readFile as N } from "node:fs/promises";
4
- import { c as R } from "../extractor-client-CReBed7x.js";
5
- const W = [
1
+ import { resolve as y, join as $, dirname as K } from "node:path";
2
+ import { existsSync as b, readFileSync as W } from "node:fs";
3
+ import { stat as M, rm as X, readdir as Y, readFile as L } from "node:fs/promises";
4
+ import { c as N } from "../extractor-client-CReBed7x.js";
5
+ const q = [
6
6
  "@jogak/core",
7
7
  "@jogak/react",
8
8
  "@jogak/web-components",
@@ -10,175 +10,202 @@ const W = [
10
10
  ];
11
11
  async function P(t) {
12
12
  try {
13
- const l = await C(t);
14
- if (!l.isDirectory())
15
- return l.mtimeMs;
13
+ const n = await M(t);
14
+ if (!n.isDirectory())
15
+ return n.mtimeMs;
16
16
  } catch {
17
17
  return 0;
18
18
  }
19
- let o = 0, f;
19
+ let r = 0, s;
20
20
  try {
21
- f = await K(t);
21
+ s = await Y(t);
22
22
  } catch {
23
23
  return 0;
24
24
  }
25
- for (const l of f) {
26
- const m = $(t, l);
25
+ for (const n of s) {
26
+ const g = $(t, n);
27
27
  try {
28
- const c = await C(m);
29
- if (c.isDirectory()) {
30
- const p = await P(m);
31
- p > o && (o = p);
32
- } else c.mtimeMs > o && (o = c.mtimeMs);
28
+ const l = await M(g);
29
+ if (l.isDirectory()) {
30
+ const p = await P(g);
31
+ p > r && (r = p);
32
+ } else l.mtimeMs > r && (r = l.mtimeMs);
33
33
  } catch {
34
34
  continue;
35
35
  }
36
36
  }
37
- return o;
37
+ return r;
38
38
  }
39
- async function X(t) {
40
- const o = h(t.root, "node_modules/.vite/deps");
41
- if (!S(o))
39
+ async function H(t) {
40
+ const r = y(t.root, "node_modules/.vite/deps");
41
+ if (!b(r))
42
42
  return { purged: !1 };
43
- const f = $(o, "_metadata.json");
44
- if (!S(f))
43
+ const s = $(r, "_metadata.json");
44
+ if (!b(s))
45
45
  return { purged: !1 };
46
- let l;
46
+ let n;
47
47
  try {
48
- l = (await C(f)).mtimeMs;
49
- } catch (c) {
48
+ n = (await M(s)).mtimeMs;
49
+ } catch (l) {
50
50
  return t.logger.warn(
51
- `[jogak] cache validation: failed to stat _metadata.json (${c.message})`
51
+ `[jogak] cache validation: failed to stat _metadata.json (${l.message})`
52
52
  ), { purged: !1 };
53
53
  }
54
- const m = t.packages ?? W;
55
- for (const c of m) {
56
- const p = h(t.root, "node_modules", c, "dist");
57
- if (!S(p)) continue;
58
- let r;
54
+ const g = t.packages ?? q;
55
+ for (const l of g) {
56
+ const p = y(t.root, "node_modules", l, "dist");
57
+ if (!b(p)) continue;
58
+ let h;
59
59
  try {
60
- r = await P(p);
61
- } catch (i) {
60
+ h = await P(p);
61
+ } catch (a) {
62
62
  t.logger.warn(
63
- `[jogak] cache validation: failed to walk ${c}/dist (${i.message})`
63
+ `[jogak] cache validation: failed to walk ${l}/dist (${a.message})`
64
64
  );
65
65
  continue;
66
66
  }
67
- if (r > l + 1e3)
67
+ if (h > n + 1e3)
68
68
  try {
69
- return await B(o, { recursive: !0, force: !0 }), t.logger.info(
70
- `[jogak] vite deps cache invalidated (stale): ${c} dist newer than cache`
71
- ), { purged: !0, reason: c };
72
- } catch (i) {
69
+ return await X(r, { recursive: !0, force: !0 }), t.logger.info(
70
+ `[jogak] vite deps cache invalidated (stale): ${l} dist newer than cache`
71
+ ), { purged: !0, reason: l };
72
+ } catch (a) {
73
73
  return t.logger.warn(
74
- `[jogak] cache validation: failed to purge ${o} (${i.message})`
74
+ `[jogak] cache validation: failed to purge ${r} (${a.message})`
75
75
  ), { purged: !1 };
76
76
  }
77
77
  }
78
78
  return { purged: !1 };
79
79
  }
80
- function Y(t) {
80
+ const z = [
81
+ "src/index.css",
82
+ "src/main.css",
83
+ "src/styles.css",
84
+ "src/styles/globals.css",
85
+ "src/styles/index.css",
86
+ "src/app/globals.css",
87
+ "src/global.css",
88
+ "src/app.css"
89
+ ];
90
+ function Q(t) {
91
+ for (const r of z) {
92
+ const s = y(t, r);
93
+ if (b(s)) return [s];
94
+ }
95
+ return [];
96
+ }
97
+ function Z(t, r) {
98
+ if (t === void 0 || t === !1) return [];
99
+ if (t === !0) return Q(r);
100
+ if (typeof t == "string")
101
+ return t.length > 0 ? [y(r, t)] : [];
102
+ const s = [];
103
+ for (const n of t)
104
+ typeof n == "string" && n.length > 0 && s.push(y(r, n));
105
+ return s;
106
+ }
107
+ function tt(t) {
81
108
  return t.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
82
109
  }
83
- function q(t) {
84
- if (S(t))
110
+ function et(t) {
111
+ if (b(t))
85
112
  try {
86
- const o = J(t, "utf8");
87
- return JSON.parse(Y(o));
113
+ const r = W(t, "utf8");
114
+ return JSON.parse(tt(r));
88
115
  } catch {
89
116
  return;
90
117
  }
91
118
  }
92
- function H(t, o, f) {
93
- if (!t.endsWith("/*") || !o.endsWith("/*")) return;
94
- const l = t.slice(0, -2), m = h(f, o.slice(0, -2));
95
- return [l, m];
119
+ function rt(t, r, s) {
120
+ if (!t.endsWith("/*") || !r.endsWith("/*")) return;
121
+ const n = t.slice(0, -2), g = y(s, r.slice(0, -2));
122
+ return [n, g];
96
123
  }
97
- function z(t, o) {
98
- var m, c;
99
- const f = {}, l = /* @__PURE__ */ new Set([
124
+ function ot(t, r) {
125
+ var g, l;
126
+ const s = {}, n = /* @__PURE__ */ new Set([
100
127
  t,
101
- h(o, "tsconfig.app.json")
128
+ y(r, "tsconfig.app.json")
102
129
  ]);
103
- for (const p of l) {
104
- const r = q(p);
105
- if (r === void 0) continue;
106
- const i = (m = r.compilerOptions) == null ? void 0 : m.paths;
107
- if (i === void 0) continue;
108
- const k = ((c = r.compilerOptions) == null ? void 0 : c.baseUrl) ?? ".", w = h(G(p), k);
109
- for (const [_, T] of Object.entries(i)) {
110
- const M = T[0];
111
- if (M === void 0) continue;
112
- const e = H(_, M, w);
113
- if (e === void 0) continue;
114
- const [d, a] = e;
115
- f[d] === void 0 && (f[d] = a);
130
+ for (const p of n) {
131
+ const h = et(p);
132
+ if (h === void 0) continue;
133
+ const a = (g = h.compilerOptions) == null ? void 0 : g.paths;
134
+ if (a === void 0) continue;
135
+ const m = ((l = h.compilerOptions) == null ? void 0 : l.baseUrl) ?? ".", j = y(K(p), m);
136
+ for (const [_, C] of Object.entries(a)) {
137
+ const k = C[0];
138
+ if (k === void 0) continue;
139
+ const T = rt(_, k, j);
140
+ if (T === void 0) continue;
141
+ const [e, u] = T;
142
+ s[e] === void 0 && (s[e] = u);
116
143
  }
117
144
  }
118
- return f;
145
+ return s;
119
146
  }
120
- const D = "virtual:jogak", x = "\0" + D, F = "virtual:jogak/entry/", A = "\0" + F;
121
- function Q(t) {
147
+ const F = "virtual:jogak", x = "\0" + F, G = "virtual:jogak/entry/", I = "\0" + G, U = "virtual:jogak/global-css", R = "\0" + U;
148
+ function st(t) {
122
149
  return Buffer.from(t, "utf8").toString("base64url");
123
150
  }
124
- function Z(t) {
151
+ function at(t) {
125
152
  return Buffer.from(t, "base64url").toString("utf8");
126
153
  }
127
- function O(t) {
154
+ function D(t) {
128
155
  return {
129
156
  title: t.title,
130
157
  jogakNamesKey: [...t.jogakNames].sort().join("|")
131
158
  };
132
159
  }
133
- function tt(t, o) {
134
- return t !== void 0 && t.title === o.title && t.jogakNamesKey === o.jogakNamesKey;
160
+ function nt(t, r) {
161
+ return t !== void 0 && t.title === r.title && t.jogakNamesKey === r.jogakNamesKey;
135
162
  }
136
- function it(t = {}) {
163
+ function ft(t = {}) {
137
164
  const {
138
- patterns: o = ["src/**/*.jogak.ts", "src/**/*.jogak.tsx"],
139
- codeTheme: f = "vsDark"
140
- } = t, l = t.cwd, m = t.tsConfigFilePath, c = t.disableCacheValidation === !0, p = t.resolveAlias;
141
- let r, i, k;
142
- const w = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
143
- async function M() {
144
- const { glob: e } = await import("glob"), d = k ?? process.cwd(), a = await e(o, { cwd: d, absolute: !0 }), u = [];
145
- w.clear(), _.clear();
146
- for (const s of a) {
147
- let y = "";
165
+ patterns: r = ["src/**/*.jogak.ts", "src/**/*.jogak.tsx"],
166
+ codeTheme: s = "vsDark"
167
+ } = t, n = t.cwd, g = t.tsConfigFilePath, l = t.disableCacheValidation === !0, p = t.resolveAlias, h = t.globalCss;
168
+ let a, m, j;
169
+ const _ = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map();
170
+ async function T() {
171
+ const { glob: e } = await import("glob"), u = j ?? process.cwd(), o = (await e(r, { cwd: u, absolute: !0 })).sort(), d = [];
172
+ _.clear(), C.clear();
173
+ for (const i of o) {
174
+ let v = "";
148
175
  try {
149
- y = await N(s, "utf8");
176
+ v = await L(i, "utf8");
150
177
  } catch {
151
178
  continue;
152
179
  }
153
- let v = {}, n = null;
154
- if (i !== void 0) {
180
+ let w = {}, c = null;
181
+ if (m !== void 0) {
155
182
  try {
156
- v = await i.extract(s);
183
+ w = await m.extract(i);
157
184
  } catch {
158
- v = {};
185
+ w = {};
159
186
  }
160
187
  try {
161
- n = await i.extractMeta(s);
188
+ c = await m.extractMeta(i);
162
189
  } catch {
163
- n = null;
190
+ c = null;
164
191
  }
165
192
  }
166
- if (n === null) continue;
167
- const g = n.title;
168
- w.set(g, s), _.set(s, g);
169
- const j = {
170
- id: g,
171
- title: n.title,
172
- jogakNames: n.jogakNames,
173
- autoArgTypes: v,
174
- userArgTypes: n.userArgTypes,
175
- source: y,
176
- filePath: s,
177
- metaExtras: n.metaExtras
193
+ if (c === null) continue;
194
+ const f = c.title;
195
+ _.set(f, i), C.set(i, f);
196
+ const S = {
197
+ id: f,
198
+ title: c.title,
199
+ jogakNames: c.jogakNames,
200
+ autoArgTypes: w,
201
+ userArgTypes: c.userArgTypes,
202
+ source: v,
203
+ filePath: i,
204
+ metaExtras: c.metaExtras
178
205
  };
179
- T.set(s, O(j)), u.push({ id: g, filePath: s, meta: j });
206
+ k.set(i, D(S)), d.push({ id: f, filePath: i, meta: S });
180
207
  }
181
- return u;
208
+ return d;
182
209
  }
183
210
  return {
184
211
  name: "vite-plugin-jogak",
@@ -193,65 +220,76 @@ function it(t = {}) {
193
220
  * 우선순위: `options.resolveAlias` (명시) > tsconfig 자동 추출.
194
221
  */
195
222
  config() {
196
- const e = l ?? process.cwd(), d = m ?? h(e, "tsconfig.json"), a = z(d, e), u = {};
223
+ const e = n ?? process.cwd(), u = g ?? y(e, "tsconfig.json"), o = ot(u, e), d = {};
197
224
  if (p !== void 0)
198
- for (const [y, v] of Object.entries(p))
199
- u[y] = h(e, v);
200
- const s = { ...a, ...u };
201
- if (Object.keys(s).length !== 0)
225
+ for (const [v, w] of Object.entries(p))
226
+ d[v] = y(e, w);
227
+ const i = { ...o, ...d };
228
+ if (Object.keys(i).length !== 0)
202
229
  return {
203
- resolve: { alias: s }
230
+ resolve: { alias: i }
204
231
  };
205
232
  },
206
233
  async configResolved(e) {
207
- k = l ?? e.root, e.command === "serve" && !c && await X({
234
+ j = n ?? e.root, e.command === "serve" && !l && await H({
208
235
  root: e.root,
209
236
  logger: {
210
- info: (a) => e.logger.info(a),
211
- warn: (a) => e.logger.warn(a)
237
+ info: (o) => e.logger.info(o),
238
+ warn: (o) => e.logger.warn(o)
212
239
  }
213
240
  });
214
- const d = m ?? h(k, "tsconfig.json");
215
- i = S(d) ? R({ tsConfigFilePath: d }) : R();
241
+ const u = g ?? y(j, "tsconfig.json");
242
+ m = b(u) ? N({ tsConfigFilePath: u }) : N();
216
243
  },
217
244
  configureServer(e) {
218
- r = e;
245
+ a = e;
219
246
  },
220
247
  buildEnd() {
221
- i == null || i.releaseCache();
248
+ m == null || m.releaseCache();
222
249
  },
223
250
  resolveId(e) {
224
- if (e === D)
251
+ if (e === F)
225
252
  return x;
226
- if (e.startsWith(F))
253
+ if (e === U)
254
+ return R;
255
+ if (e.startsWith(G))
227
256
  return "\0" + e;
228
257
  },
229
258
  async load(e) {
259
+ if (e === R) {
260
+ const u = j ?? process.cwd(), o = Z(h, u);
261
+ return o.length === 0 ? `// [jogak] globalCss not configured or no candidates found.
262
+ export {}
263
+ ` : `${o.map((i) => `import ${JSON.stringify(i)}`).join(`
264
+ `)}
265
+ export {}
266
+ `;
267
+ }
230
268
  if (e === x) {
231
- const a = (await M()).map((u) => u.meta);
269
+ const o = (await T()).map((d) => d.meta);
232
270
  return `import { defaultRegistry } from '@jogak/core'
233
271
 
234
272
  const _entryLoader = (slug) =>
235
273
  import(/* @vite-ignore */ '/@id/__x00__virtual:jogak/entry/' + slug)
236
274
  defaultRegistry.setEntryLoader((id) => {
237
- const slug = ${et()}
275
+ const slug = ${it()}
238
276
  return _entryLoader(slug(id))
239
277
  })
240
278
 
241
- const _metas = ${JSON.stringify(a)}
279
+ const _metas = ${JSON.stringify(o)}
242
280
 
243
281
  for (const m of _metas) defaultRegistry.registerMeta(m)
244
282
 
245
- export const _jogakCodeTheme = ${JSON.stringify(f)}
283
+ export const _jogakCodeTheme = ${JSON.stringify(s)}
246
284
  export const _jogakMetas = _metas
247
285
  `;
248
286
  }
249
- if (e.startsWith(A)) {
250
- const d = e.slice(A.length), a = Z(d);
251
- let u = w.get(a);
252
- return u === void 0 && (await M(), u = w.get(a)), u === void 0 ? `// [jogak] unknown entry id: ${JSON.stringify(a)}
287
+ if (e.startsWith(I)) {
288
+ const u = e.slice(I.length), o = at(u);
289
+ let d = _.get(o);
290
+ return d === void 0 && (await T(), d = _.get(o)), d === void 0 ? `// [jogak] unknown entry id: ${JSON.stringify(o)}
253
291
  export {}
254
- ` : `import * as _user from ${JSON.stringify(u)}
292
+ ` : `import * as _user from ${JSON.stringify(d)}
255
293
  import { defaultRegistry } from '@jogak/core'
256
294
 
257
295
  const _meta = _user.default
@@ -260,7 +298,7 @@ delete _named.default
260
298
  const _jogaks = Object.values(_named).filter(
261
299
  (v) => v !== null && typeof v === 'object' && typeof v.name === 'string'
262
300
  )
263
- defaultRegistry.hydrateEntry(${JSON.stringify(a)}, _jogaks, _meta?.component)
301
+ defaultRegistry.hydrateEntry(${JSON.stringify(o)}, _jogaks, _meta?.component)
264
302
 
265
303
  if (import.meta.hot) {
266
304
  import.meta.hot.accept()
@@ -270,60 +308,60 @@ export {}
270
308
  `;
271
309
  }
272
310
  },
273
- async handleHotUpdate({ file: e, modules: d }) {
274
- const a = /\.jogak\.(tsx?|jsx?)$/.test(e), u = /\.(tsx?|jsx?)$/.test(e) && !a;
275
- if (!a && !u || r === void 0 || !a) return;
276
- const s = r.moduleGraph.getModuleById(
311
+ async handleHotUpdate({ file: e, modules: u }) {
312
+ const o = /\.jogak\.(tsx?|jsx?)$/.test(e), d = /\.(tsx?|jsx?)$/.test(e) && !o;
313
+ if (!o && !d || a === void 0 || !o) return;
314
+ const i = a.moduleGraph.getModuleById(
277
315
  x
278
- ), y = _.get(e), v = y !== void 0 ? A + Q(y) : void 0, n = v !== void 0 ? r.moduleGraph.getModuleById(v) : void 0;
279
- let g = null, j = {}, E = "";
280
- if (i !== void 0) {
316
+ ), v = C.get(e), w = v !== void 0 ? I + st(v) : void 0, c = w !== void 0 ? a.moduleGraph.getModuleById(w) : void 0;
317
+ let f = null, S = {}, A = "";
318
+ if (m !== void 0) {
281
319
  try {
282
- g = await i.extractMeta(e);
320
+ f = await m.extractMeta(e);
283
321
  } catch {
284
- g = null;
322
+ f = null;
285
323
  }
286
324
  try {
287
- j = await i.extract(e);
325
+ S = await m.extract(e);
288
326
  } catch {
289
- j = {};
327
+ S = {};
290
328
  }
291
329
  try {
292
- E = await N(e, "utf8");
330
+ A = await L(e, "utf8");
293
331
  } catch {
294
- E = "";
332
+ A = "";
295
333
  }
296
334
  }
297
- if (g === null) {
298
- s !== void 0 && r.moduleGraph.invalidateModule(s), n !== void 0 && r.moduleGraph.invalidateModule(n), r.ws.send({ type: "full-reload" });
335
+ if (f === null) {
336
+ i !== void 0 && a.moduleGraph.invalidateModule(i), c !== void 0 && a.moduleGraph.invalidateModule(c), a.ws.send({ type: "full-reload" });
299
337
  return;
300
338
  }
301
- const I = O(g), L = T.get(e), U = tt(L, I);
302
- if (T.set(e, I), !U || y === void 0) {
303
- s !== void 0 && r.moduleGraph.invalidateModule(s), n !== void 0 && r.moduleGraph.invalidateModule(n), r.ws.send({ type: "full-reload" });
339
+ const O = D(f), V = k.get(e), B = nt(V, O);
340
+ if (k.set(e, O), !B || v === void 0) {
341
+ i !== void 0 && a.moduleGraph.invalidateModule(i), c !== void 0 && a.moduleGraph.invalidateModule(c), a.ws.send({ type: "full-reload" });
304
342
  return;
305
343
  }
306
- const V = {
307
- id: y,
308
- title: g.title,
309
- jogakNames: g.jogakNames,
310
- autoArgTypes: j,
311
- userArgTypes: g.userArgTypes,
312
- source: E,
344
+ const J = {
345
+ id: v,
346
+ title: f.title,
347
+ jogakNames: f.jogakNames,
348
+ autoArgTypes: S,
349
+ userArgTypes: f.userArgTypes,
350
+ source: A,
313
351
  filePath: e,
314
- metaExtras: g.metaExtras
352
+ metaExtras: f.metaExtras
315
353
  };
316
- n !== void 0 && r.moduleGraph.invalidateModule(n), r.ws.send({
354
+ c !== void 0 && a.moduleGraph.invalidateModule(c), a.ws.send({
317
355
  type: "custom",
318
356
  event: "jogak:meta-update",
319
- data: { id: y, meta: V }
357
+ data: { id: v, meta: J }
320
358
  });
321
- const b = [...d];
322
- return n !== void 0 && !b.includes(n) && b.push(n), b;
359
+ const E = [...u];
360
+ return c !== void 0 && !E.includes(c) && E.push(c), E;
323
361
  }
324
362
  };
325
363
  }
326
- function et() {
364
+ function it() {
327
365
  return `(rawId) => {
328
366
  if (typeof Buffer !== 'undefined') return Buffer.from(rawId, 'utf8').toString('base64url')
329
367
  // 브라우저 폴백: btoa는 binary string 기준이라 UTF-8을 한번 인코딩해야 한다.
@@ -334,5 +372,5 @@ function et() {
334
372
  }`;
335
373
  }
336
374
  export {
337
- it as jogak
375
+ ft as jogak
338
376
  };
@@ -15,5 +15,8 @@ export declare const RESOLVED_VIRTUAL_INDEX_ID: string;
15
15
  /** Entry 모듈 prefix — 뒤에 base64url(id)이 붙는다. */
16
16
  export declare const VIRTUAL_ENTRY_PREFIX = "virtual:jogak/entry/";
17
17
  export declare const RESOLVED_VIRTUAL_ENTRY_PREFIX: string;
18
+ /** Global css 모듈 — 사용자 globalCss를 import한다 (알파.6, opt-in). */
19
+ export declare const VIRTUAL_GLOBAL_CSS_ID = "virtual:jogak/global-css";
20
+ export declare const RESOLVED_VIRTUAL_GLOBAL_CSS_ID: string;
18
21
  export declare function idToSlug(id: string): string;
19
22
  export declare function slugToId(slug: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jogak/core",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "Core types, registry, and Vite plugin for Jogak — a lightweight Storybook alternative.",
5
5
  "keywords": [
6
6
  "jogak",
@@ -63,6 +63,7 @@
63
63
  "devDependencies": {
64
64
  "vite": "^6.0.0",
65
65
  "vite-plugin-dts": "^4.0.0",
66
+ "vitest": "^2.0.0",
66
67
  "typescript": "^5.5.0",
67
68
  "@types/node": "^20.14.0"
68
69
  },
@@ -77,6 +78,8 @@
77
78
  "scripts": {
78
79
  "build": "vite build",
79
80
  "dev": "vite build --watch",
80
- "typecheck": "tsc --noEmit"
81
+ "typecheck": "tsc --noEmit",
82
+ "test": "vitest run",
83
+ "test:watch": "vitest"
81
84
  }
82
85
  }