@withl5e/l5e 0.3.2 → 0.3.3-alpha.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.
@@ -1,10 +1,11 @@
1
- import { transform as z } from "esbuild";
2
- import { existsSync as w, mkdirSync as J, writeFileSync as D, rmSync as N, statSync as O, readFileSync as T, readdirSync as G } from "fs";
1
+ import { transform as J } from "esbuild";
2
+ import { existsSync as w, mkdirSync as D, writeFileSync as N, rmSync as G, statSync as O, readFileSync as T, readdirSync as H } from "fs";
3
3
  import { join as b, relative as S, resolve as y, dirname as K } from "path";
4
- const j = "virtual:l5e-views", v = "virtual:l5e-route", _ = "virtual:l5e-ssr-entry", E = "virtual:l5e-global-loader", R = "virtual:l5e-island-strategies", P = "virtual:l5e-islands", $ = "virtual:l5e-actions", I = "virtual:l5e-middleware", F = /* @__PURE__ */ new Set(["MODE", "BASE_URL", "PROD", "DEV", "SSR", "LEGACY"]);
4
+ import { f as B } from "./global-style-DFvaBcuR.js";
5
+ const j = "virtual:l5e-views", v = "virtual:l5e-route", _ = "virtual:l5e-ssr-entry", E = "virtual:l5e-global-loader", R = "virtual:l5e-island-strategies", I = "virtual:l5e-islands", $ = "virtual:l5e-actions", P = "virtual:l5e-middleware", F = /* @__PURE__ */ new Set(["MODE", "BASE_URL", "PROD", "DEV", "SSR", "LEGACY"]);
5
6
  function k(s, o = []) {
6
- const l = G(s);
7
- for (const i of l) {
7
+ const a = H(s);
8
+ for (const i of a) {
8
9
  const t = b(s, i);
9
10
  if (O(t).isDirectory()) {
10
11
  if (i === "node_modules" || i === "dist" || i === ".git")
@@ -16,166 +17,170 @@ function k(s, o = []) {
16
17
  }
17
18
  function A(s) {
18
19
  let o = 0;
19
- for (let l = 0; l < s.length; l++)
20
- o = (o << 5) - o + s.charCodeAt(l), o = o & o;
20
+ for (let a = 0; a < s.length; a++)
21
+ o = (o << 5) - o + s.charCodeAt(a), o = o & o;
21
22
  return Math.abs(o).toString(16).slice(0, 4);
22
23
  }
23
24
  function V(s) {
24
25
  const o = s.split("/");
25
- let l = o[o.length - 1];
26
- return l = l.replace(/\.(tsx?|jsx?)$/, ""), l;
26
+ let a = o[o.length - 1];
27
+ return a = a.replace(/\.(tsx?|jsx?)$/, ""), a;
27
28
  }
28
- function H(s) {
29
+ function q(s) {
29
30
  return `${V(s)}_${A(s)}`;
30
31
  }
31
- function B(s, o) {
32
- const l = s.replace(/^\//, ""), i = y(o, l);
32
+ function Y(s, o) {
33
+ const a = s.replace(/^\//, ""), i = y(o, a);
33
34
  for (const t of [".tsx", ".ts", ".jsx", ".js"])
34
35
  if (w(i + t))
35
- return l + t;
36
- return w(i) ? l : null;
36
+ return a + t;
37
+ return w(i) ? a : null;
37
38
  }
38
- function Y(s, o) {
39
- const l = T(s, "utf-8"), i = [], t = /<ClientIsland\s[^>]*?from\s*=\s*"([^"]+)"/g, n = /* @__PURE__ */ new Set();
39
+ function Z(s, o) {
40
+ const a = T(s, "utf-8"), i = [], t = /<ClientIsland\s[^>]*?from\s*=\s*"([^"]+)"/g, n = /* @__PURE__ */ new Set();
40
41
  let c;
41
- for (; (c = t.exec(l)) !== null; ) {
42
- const a = c[1];
42
+ for (; (c = t.exec(a)) !== null; ) {
43
+ const l = c[1];
43
44
  let e;
44
- if (a.startsWith("~/"))
45
- e = "/src/" + a.substring(2);
46
- else if (a.startsWith("/src/"))
47
- e = a;
48
- else if (a.startsWith("./") || a.startsWith("../")) {
49
- const r = y(s, "..", a);
50
- e = "/" + S(o, r).replace(/\\/g, "/");
45
+ if (l.startsWith("~/"))
46
+ e = "/src/" + l.substring(2);
47
+ else if (l.startsWith("/src/"))
48
+ e = l;
49
+ else if (l.startsWith("./") || l.startsWith("../")) {
50
+ const m = y(s, "..", l);
51
+ e = "/" + S(o, m).replace(/\\/g, "/");
51
52
  } else
52
- e = a;
53
- const d = B(e, o);
53
+ e = l;
54
+ const d = Y(e, o);
54
55
  if (!d) {
55
56
  console.warn(
56
- `[l5e] Island component not found: ${e} (from ${a} in ${s})`
57
+ `[l5e] Island component not found: ${e} (from ${l} in ${s})`
57
58
  );
58
59
  continue;
59
60
  }
60
- const f = H(e);
61
- n.has(f) || (n.add(f), i.push({
61
+ const u = q(e);
62
+ n.has(u) || (n.add(u), i.push({
62
63
  component: V(e),
63
64
  resolvedPath: e,
64
65
  src: d,
65
66
  // "src/views/.../Counter.tsx" — matches manifest key format
66
- key: f
67
+ key: u
67
68
  }));
68
69
  }
69
70
  return i;
70
71
  }
71
- function Z(s, o) {
72
- const l = T(s, "utf-8"), i = [], t = [], n = /useCss\s*\(\s*['"]([^'"]+)['"]\s*,?\s*\)/g, c = /useClientJs\s*\(\s*['"]([^'"]+)['"]\s*,?\s*\)/g;
73
- let a;
74
- for (; (a = n.exec(l)) !== null; ) {
75
- const e = a[1];
72
+ function X(s, o) {
73
+ const a = T(s, "utf-8"), i = [], t = [], n = /useCss\s*\(\s*['"]([^'"]+)['"]\s*,?\s*\)/g, c = /useClientJs\s*\(\s*['"]([^'"]+)['"]\s*,?\s*\)/g;
74
+ let l;
75
+ for (; (l = n.exec(a)) !== null; ) {
76
+ const e = l[1];
76
77
  if (e.startsWith("/src/"))
77
78
  i.push(e);
78
79
  else if (e.startsWith("./") || e.startsWith("../")) {
79
- const d = y(s, "..", e), f = "/" + S(o, d).replace(/\\/g, "/");
80
- i.push(f);
80
+ const d = y(s, "..", e), u = "/" + S(o, d).replace(/\\/g, "/");
81
+ i.push(u);
81
82
  } else
82
83
  i.push(e);
83
84
  }
84
- for (; (a = c.exec(l)) !== null; ) {
85
- const e = a[1];
85
+ for (; (l = c.exec(a)) !== null; ) {
86
+ const e = l[1];
86
87
  if (e.startsWith("/src/"))
87
88
  t.push(e);
88
89
  else if (e.startsWith("./") || e.startsWith("../")) {
89
- const d = y(s, "..", e), f = "/" + S(o, d).replace(/\\/g, "/");
90
- t.push(f);
90
+ const d = y(s, "..", e), u = "/" + S(o, d).replace(/\\/g, "/");
91
+ t.push(u);
91
92
  } else
92
93
  t.push(e);
93
94
  }
94
95
  return { css: i, js: t };
95
96
  }
96
97
  function C(s) {
97
- const o = {}, l = b(s, "src"), i = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
98
+ const o = {}, a = b(s, "src"), i = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
98
99
  try {
99
- if (!O(l).isDirectory())
100
+ if (!O(a).isDirectory())
100
101
  return { input: o, islandRegistry: i, pathToKey: t, keyToSrc: n, actionRegistry: c };
101
- const a = b(s, "src", "client.global.ts");
102
- w(a) && (o.global = a, console.log("[l5e] Detected src/client.global.ts and added as entry"));
103
- const e = k(l), d = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
104
- for (const r of e) {
105
- const { css: u, js: p } = Z(r, s);
106
- u.forEach((h) => d.add(h)), p.forEach((h) => f.add(h));
107
- const m = Y(r, s);
108
- for (const h of m)
102
+ const l = b(s, "src", "client.global.ts");
103
+ w(l) && (o.global = l, console.log("[l5e] Detected src/client.global.ts and added as entry"));
104
+ const e = B(s);
105
+ e && (o["global-style"] = e, console.log("[l5e] Detected src/global.css and added as global stylesheet"));
106
+ const d = k(a), u = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Set();
107
+ for (const r of d) {
108
+ const { css: f, js: p } = X(r, s);
109
+ f.forEach((h) => u.add(h)), p.forEach((h) => m.add(h));
110
+ const g = Z(r, s);
111
+ for (const h of g)
109
112
  i.set(h.key, h.resolvedPath), t.set(h.resolvedPath, h.key), n.set(h.key, h.src);
110
- const g = r.replace(/\\/g, "/");
111
- if (/\/actions\.(ts|tsx)$/.test(g)) {
112
- const h = T(r, "utf-8"), x = /export\s+const\s+(\w+)\s*=\s*defineAction\s*\(/g;
113
+ const x = r.replace(/\\/g, "/");
114
+ if (/\/actions\.(ts|tsx)$/.test(x)) {
115
+ const h = T(r, "utf-8"), U = /export\s+const\s+(\w+)\s*=\s*defineAction\s*\(/g;
113
116
  let W;
114
- const L = S(l, K(r)).replace(/\\/g, "/") || ".";
115
- for (; (W = x.exec(h)) !== null; ) {
116
- const M = W[1], U = `${M}_${A(L)}`;
117
- c.set(U, { modulePath: L, actionName: M });
117
+ const L = S(a, K(r)).replace(/\\/g, "/") || ".";
118
+ for (; (W = U.exec(h)) !== null; ) {
119
+ const M = W[1], z = `${M}_${A(L)}`;
120
+ c.set(z, { modulePath: L, actionName: M });
118
121
  }
119
122
  }
120
123
  }
121
- for (const r of d) {
122
- const u = r.startsWith("/src/") || r.startsWith("/") ? r.substring(1) : r, p = y(s, u);
124
+ for (const r of u) {
125
+ const f = r.startsWith("/src/") || r.startsWith("/") ? r.substring(1) : r, p = y(s, f);
126
+ if (e && y(p) === y(e))
127
+ continue;
123
128
  if (!w(p)) {
124
129
  console.warn(`[l5e] CSS file not found: ${p} (from ${r})`);
125
130
  continue;
126
131
  }
127
- const m = u.replace(/^src\//, "").replace(/\.css$/, "").replace(/\//g, "-").replace(/\\/g, "-");
128
- o[m] = p;
132
+ const g = f.replace(/^src\//, "").replace(/\.css$/, "").replace(/\//g, "-").replace(/\\/g, "-");
133
+ o[g] = p;
129
134
  }
130
- for (const r of f) {
131
- const u = r.startsWith("/src/") || r.startsWith("/") ? r.substring(1) : r, p = y(s, u);
135
+ for (const r of m) {
136
+ const f = r.startsWith("/src/") || r.startsWith("/") ? r.substring(1) : r, p = y(s, f);
132
137
  if (!w(p)) {
133
138
  console.warn(`[l5e] JS/TS file not found: ${p} (from ${r})`);
134
139
  continue;
135
140
  }
136
- const m = u.replace(/^src\//, "").replace(/\.(ts|tsx|js|jsx)$/, "").replace(/\//g, "-").replace(/\\/g, "-");
137
- o[m] = p;
141
+ const g = f.replace(/^src\//, "").replace(/\.(ts|tsx|js|jsx)$/, "").replace(/\//g, "-").replace(/\\/g, "-");
142
+ o[g] = p;
138
143
  }
139
- for (const [r, u] of n) {
140
- const p = y(s, u);
144
+ for (const [r, f] of n) {
145
+ const p = y(s, f);
141
146
  o[`island-${r}`] = p;
142
147
  }
143
148
  i.size > 0 && console.log(`[l5e] Detected ${i.size} island(s)`), c.size > 0 && console.log(`[l5e] Detected ${c.size} action(s)`);
144
- } catch (a) {
145
- console.warn("[l5e] Failed to discover rollup input:", a);
149
+ } catch (l) {
150
+ console.warn("[l5e] Failed to discover rollup input:", l);
146
151
  }
147
152
  return { input: o, islandRegistry: i, pathToKey: t, keyToSrc: n, actionRegistry: c };
148
153
  }
149
- function X(s, o, l, i, t) {
154
+ function Q(s, o, a, i, t) {
150
155
  const n = [];
151
156
  let c = 0;
152
- const a = /ClientIsland\s*,\s*\{/g;
157
+ const l = /ClientIsland\s*,\s*\{/g;
153
158
  let e;
154
- for (; (e = a.exec(s)) !== null; ) {
155
- const d = e.index + e[0].length, f = s.substring(d, d + 500), r = /from:\s*"([^"]+)"/.exec(f);
156
- if (!r) continue;
157
- const u = r[1];
158
- let p;
159
- if (u.startsWith("~/"))
160
- p = "/src/" + u.substring(2);
161
- else if (u.startsWith("/src/"))
162
- p = u;
163
- else if (u.startsWith("./") || u.startsWith("../")) {
164
- const x = y(o, "..", u);
165
- p = "/" + S(l, x).replace(/\\/g, "/");
166
- } else
167
- p = u;
168
- const m = i.get(p);
159
+ for (; (e = l.exec(s)) !== null; ) {
160
+ const d = e.index + e[0].length, u = s.substring(d, d + 500), m = /from:\s*"([^"]+)"/.exec(u);
169
161
  if (!m) continue;
170
- const g = t.get(m);
162
+ const r = m[1];
163
+ let f;
164
+ if (r.startsWith("~/"))
165
+ f = "/src/" + r.substring(2);
166
+ else if (r.startsWith("/src/"))
167
+ f = r;
168
+ else if (r.startsWith("./") || r.startsWith("../")) {
169
+ const h = y(o, "..", r);
170
+ f = "/" + S(a, h).replace(/\\/g, "/");
171
+ } else
172
+ f = r;
173
+ const p = i.get(f);
174
+ if (!p) continue;
175
+ const g = t.get(p);
171
176
  if (!g) continue;
172
- const h = d + r.index + r[0].length;
173
- n.push(s.substring(c, h)), n.push(`, __key: "${m}", __src: "${g}"`), c = h;
177
+ const x = d + m.index + m[0].length;
178
+ n.push(s.substring(c, x)), n.push(`, __key: "${p}", __src: "${g}"`), c = x;
174
179
  }
175
180
  return n.push(s.substring(c)), n.join("");
176
181
  }
177
- function st() {
178
- let s = process.cwd(), o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
182
+ function ot() {
183
+ let s = process.cwd(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
179
184
  return {
180
185
  name: "l5e-jsx-classic",
181
186
  enforce: "pre",
@@ -209,7 +214,7 @@ function st() {
209
214
  const t = b(s, ".l5e-temp");
210
215
  if (w(t))
211
216
  try {
212
- N(t, { recursive: !0, force: !0 }), console.log("[l5e] Cleaned up temporary files");
217
+ G(t, { recursive: !0, force: !0 }), console.log("[l5e] Cleaned up temporary files");
213
218
  } catch (n) {
214
219
  console.warn("[l5e] Failed to cleanup temporary files:", n);
215
220
  }
@@ -217,15 +222,15 @@ function st() {
217
222
  writeBundle(t, n) {
218
223
  if (i.size > 0) {
219
224
  const c = b(s, "dist", "server");
220
- w(c) || J(c, { recursive: !0 });
221
- const a = Object.fromEntries(i);
222
- D(b(c, "action-registry.json"), JSON.stringify(a), "utf-8"), console.log(`[l5e] Wrote action-registry.json (${i.size} actions)`);
225
+ w(c) || D(c, { recursive: !0 });
226
+ const l = Object.fromEntries(i);
227
+ N(b(c, "action-registry.json"), JSON.stringify(l), "utf-8"), console.log(`[l5e] Wrote action-registry.json (${i.size} actions)`);
223
228
  }
224
229
  },
225
230
  config(t) {
226
231
  const n = t.root || process.cwd(), c = C(n);
227
- c.islandRegistry, o = c.pathToKey, l = c.keyToSrc, i = c.actionRegistry;
228
- const a = t.build?.rollupOptions?.input || {}, e = typeof a == "object" && !Array.isArray(a) ? { ...c.input, ...a } : c.input;
232
+ c.islandRegistry, o = c.pathToKey, a = c.keyToSrc, i = c.actionRegistry;
233
+ const l = t.build?.rollupOptions?.input || {}, e = typeof l == "object" && !Array.isArray(l) ? { ...c.input, ...l } : c.input;
229
234
  return {
230
235
  build: {
231
236
  ...t.build,
@@ -241,7 +246,7 @@ function st() {
241
246
  };
242
247
  },
243
248
  resolveId(t) {
244
- return t === j ? "\0" + j : t === v ? "\0" + v : t === _ ? "\0" + _ : t === E ? "\0" + E : t === R ? "\0" + R : t === P ? "\0" + P : t === $ ? "\0" + $ : t === I ? "\0" + I : null;
249
+ return t === j ? "\0" + j : t === v ? "\0" + v : t === _ ? "\0" + _ : t === E ? "\0" + E : t === R ? "\0" + R : t === I ? "\0" + I : t === $ ? "\0" + $ : t === P ? "\0" + P : null;
245
250
  },
246
251
  async transform(t, n, c) {
247
252
  if (n.replace(/\\/g, "/").endsWith("src/client.global.ts") && !c?.ssr)
@@ -253,23 +258,23 @@ ${t}`,
253
258
  if (!c?.ssr) {
254
259
  const d = n.replace(/\\/g, "/").match(/\/src\/(.+)\/actions\.(ts|tsx)$/);
255
260
  if (d) {
256
- const f = d[1], r = /export\s+const\s+(\w+)\s*=\s*defineAction\s*\(/g, u = [];
257
- let p;
258
- for (; (p = r.exec(t)) !== null; ) {
259
- const m = p[1], h = t.substring(p.index, p.index + 500).match(/method:\s*['"](\w+)['"]/), x = h ? h[1].toUpperCase() : "GET";
260
- u.push({ name: m, method: x });
261
+ const u = d[1], m = /export\s+const\s+(\w+)\s*=\s*defineAction\s*\(/g, r = [];
262
+ let f;
263
+ for (; (f = m.exec(t)) !== null; ) {
264
+ const p = f[1], x = t.substring(f.index, f.index + 500).match(/method:\s*['"](\w+)['"]/), h = x ? x[1].toUpperCase() : "GET";
265
+ r.push({ name: p, method: h });
261
266
  }
262
- if (u.length > 0)
267
+ if (r.length > 0)
263
268
  return {
264
- code: u.map(({ name: g, method: h }) => {
265
- const x = `${g}_${A(f)}`;
266
- return h === "GET" ? `export async function ${g}(params) {
267
- const res = await fetch('/_l5e/action/${x}?' + new URLSearchParams(params));
269
+ code: r.map(({ name: g, method: x }) => {
270
+ const h = `${g}_${A(u)}`;
271
+ return x === "GET" ? `export async function ${g}(params) {
272
+ const res = await fetch('/_l5e/action/${h}?' + new URLSearchParams(params));
268
273
  if (!res.ok) throw Object.assign(new Error('HTTP ' + res.status), { status: res.status });
269
274
  return res;
270
275
  }` : `export async function ${g}(body) {
271
- const res = await fetch('/_l5e/action/${x}', {
272
- method: '${h}',
276
+ const res = await fetch('/_l5e/action/${h}', {
277
+ method: '${x}',
273
278
  headers: { 'Content-Type': 'application/json' },
274
279
  body: JSON.stringify(body),
275
280
  });
@@ -288,7 +293,7 @@ ${t}`,
288
293
  if (/\.(tsx|jsx)$/.test(n))
289
294
  try {
290
295
  const e = `import { Fragment as __Fragment, jsxFactory } from "@withl5e/l5e/jsx-runtime"
291
- ${t}`, d = await z(e, {
296
+ ${t}`, d = await J(e, {
292
297
  loader: n.endsWith(".tsx") ? "tsx" : "jsx",
293
298
  jsx: "transform",
294
299
  jsxFactory: "jsxFactory",
@@ -297,9 +302,9 @@ ${t}`, d = await z(e, {
297
302
  sourcefile: n,
298
303
  target: "es2020"
299
304
  });
300
- let f = d.code;
301
- return f.includes("ClientIsland") && (f = X(f, n, s, o, l)), {
302
- code: f,
305
+ let u = d.code;
306
+ return u.includes("ClientIsland") && (u = Q(u, n, s, o, a)), {
307
+ code: u,
303
308
  map: d.map || null
304
309
  };
305
310
  } catch (e) {
@@ -309,10 +314,10 @@ ${t}`, d = await z(e, {
309
314
  let e = t, d = !1;
310
315
  if (e = e.replace(
311
316
  /import\.meta\.env\.([a-zA-Z_][a-zA-Z0-9_]*)/g,
312
- (f, r) => F.has(r) ? f : (d = !0, `process.env.${r}`)
317
+ (u, m) => F.has(m) ? u : (d = !0, `process.env.${m}`)
313
318
  ), e = e.replace(
314
319
  /import\.meta\.env\[(['"`])([^'"`]+)\1\]/g,
315
- (f, r, u) => F.has(u) ? f : (d = !0, `process.env[${r}${u}${r}]`)
320
+ (u, m, r) => F.has(r) ? u : (d = !0, `process.env[${m}${r}${m}]`)
316
321
  ), d)
317
322
  return {
318
323
  code: e,
@@ -329,7 +334,9 @@ export const viewLoaders = import.meta.glob('/src/views/*/loader.{ts,tsx}');
329
334
  export const viewComponents = import.meta.glob('/src/views/*/index.tsx');
330
335
  `;
331
336
  if (t === "\0" + v)
332
- return "export { default } from '/src/route.ts';";
337
+ return `export default function routeHandler(requestInfo) {
338
+ return import('/src/route.ts').then((mod) => mod.default(requestInfo));
339
+ }`;
333
340
  if (t === "\0" + _)
334
341
  return `export { render } from '@withl5e/l5e/entry-server';
335
342
  export { viewActions } from 'virtual:l5e-actions';`;
@@ -340,7 +347,7 @@ export { viewActions } from 'virtual:l5e-actions';`;
340
347
  return `export const viewActions = import.meta.glob('/src/**/actions.{ts,tsx}');
341
348
  export const actionRegistry = ${JSON.stringify(n)};`;
342
349
  }
343
- if (t === "\0" + I)
350
+ if (t === "\0" + P)
344
351
  return `
345
352
  const middlewareModules = import.meta.glob([
346
353
  '/src/middleware.{ts,tsx,js,jsx}',
@@ -366,7 +373,7 @@ export async function loadMiddleware() {
366
373
  return mod.onRequest;
367
374
  }
368
375
  `;
369
- if (t === "\0" + P)
376
+ if (t === "\0" + I)
370
377
  return "export const islandModules = import.meta.glob('/src/**/react/*.{tsx,jsx}');";
371
378
  if (t === "\0" + R) {
372
379
  const n = b(s, "src", "island-strategies.ts");
@@ -377,7 +384,7 @@ export async function loadMiddleware() {
377
384
  };
378
385
  }
379
386
  export {
380
- st as coreVite,
381
- st as default
387
+ ot as coreVite,
388
+ ot as default
382
389
  };
383
390
  //# sourceMappingURL=vite-plugin.js.map