@apex-stack/core 0.7.1 → 0.7.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.
@@ -7,7 +7,7 @@ import {
7
7
  renderPage,
8
8
  resolveApexConfig,
9
9
  scanPages
10
- } from "./chunk-7CBGVRBB.js";
10
+ } from "./chunk-EVFABT7B.js";
11
11
  import "./chunk-PMLGY6Z3.js";
12
12
 
13
13
  // src/commands/build.ts
@@ -19,10 +19,22 @@ import { createServer as createViteServer } from "vite";
19
19
 
20
20
  // src/build/buildClient.ts
21
21
  import { existsSync, readdirSync, readFileSync } from "fs";
22
+ import { createRequire } from "module";
22
23
  import { join } from "path";
24
+ import { pathToFileURL } from "url";
23
25
  import { apex } from "@apex-stack/vite";
24
26
  import { build } from "vite";
25
27
  var VIRT = "virtual:apex-client:";
28
+ async function tailwindPlugin(root) {
29
+ try {
30
+ const req = createRequire(join(root, "package.json"));
31
+ const mod = await import(pathToFileURL(req.resolve("@tailwindcss/vite")).href);
32
+ const tw = mod.default ?? mod;
33
+ return tw();
34
+ } catch {
35
+ return null;
36
+ }
37
+ }
26
38
  function entryName(pageId) {
27
39
  return pageId.replace(/^\/pages\//, "").replace(/\.alpine$/, "").replace(/[^a-zA-Z0-9]+/g, "_");
28
40
  }
@@ -31,6 +43,9 @@ async function buildClient(root, routes, outDir, base = "/") {
31
43
  for (const r of routes) input[entryName(r.pageId)] = `${VIRT}${r.pageId}`;
32
44
  const storesDir = join(root, "stores");
33
45
  const storeIds = existsSync(storesDir) ? readdirSync(storesDir).filter((f) => f.endsWith(".ts") || f.endsWith(".js")).map((f) => `/stores/${f}`) : [];
46
+ const appCssRel = ["app.css", "styles/app.css", "src/app.css"].find(
47
+ (f) => existsSync(join(root, f))
48
+ );
34
49
  const entryPlugin = {
35
50
  name: "apex:client-entries",
36
51
  resolveId(id) {
@@ -40,6 +55,7 @@ async function buildClient(root, routes, outDir, base = "/") {
40
55
  if (id.startsWith(`\0${VIRT}`)) {
41
56
  const pageId = id.slice(`\0${VIRT}`.length);
42
57
  return [
58
+ ...appCssRel ? [`import ${JSON.stringify(`/${appCssRel}`)}`] : [],
43
59
  `import Alpine from 'alpinejs'`,
44
60
  ...storeIds.map((sid, i) => `import __s${i} from ${JSON.stringify(sid)}`),
45
61
  `import ${JSON.stringify(pageId)}`,
@@ -50,11 +66,12 @@ async function buildClient(root, routes, outDir, base = "/") {
50
66
  }
51
67
  }
52
68
  };
69
+ const tw = await tailwindPlugin(root);
53
70
  await build({
54
71
  root,
55
72
  base,
56
73
  logLevel: "warn",
57
- plugins: [apex({ clientRuntime: "@apex-stack/core/client" }), entryPlugin],
74
+ plugins: [...tw ? [tw] : [], apex({ clientRuntime: "@apex-stack/core/client" }), entryPlugin],
58
75
  build: {
59
76
  outDir,
60
77
  emptyOutDir: false,
@@ -65,14 +82,28 @@ async function buildClient(root, routes, outDir, base = "/") {
65
82
  const manifest = JSON.parse(
66
83
  readFileSync(join(outDir, ".vite", "manifest.json"), "utf8")
67
84
  );
85
+ const collectCss = (key, seen) => {
86
+ const m = manifest[key];
87
+ if (!m || seen.has(key)) return [];
88
+ seen.add(key);
89
+ const out = [...m.css ?? []];
90
+ for (const imp of m.imports ?? []) out.push(...collectCss(imp, seen));
91
+ return out;
92
+ };
68
93
  const prefix = base.endsWith("/") ? base : `${base}/`;
69
94
  const hrefs = /* @__PURE__ */ new Map();
70
95
  for (const r of routes) {
71
96
  const virt = `${VIRT}${r.pageId}`;
72
- const entry = Object.values(manifest).find(
73
- (m) => m.isEntry && typeof m.src === "string" && (m.src === virt || m.src.endsWith(virt))
74
- );
75
- if (entry) hrefs.set(r.pageId, `${prefix}${entry.file}`);
97
+ const key = Object.keys(manifest).find((k) => {
98
+ const m = manifest[k];
99
+ return m?.isEntry && typeof m.src === "string" && (m.src === virt || m.src.endsWith(virt));
100
+ });
101
+ if (!key) continue;
102
+ const css = [...new Set(collectCss(key, /* @__PURE__ */ new Set()))];
103
+ hrefs.set(r.pageId, {
104
+ js: `${prefix}${manifest[key]?.file}`,
105
+ css: css.map((c) => `${prefix}${c}`)
106
+ });
76
107
  }
77
108
  return hrefs;
78
109
  }
@@ -209,7 +240,8 @@ var buildCommand = defineCommand({
209
240
  runtimeConfig,
210
241
  publicConfig
211
242
  };
212
- const html = args.islands ? await renderIslandsPage(common) : await renderPage({ ...common, clientHref: hrefs.get(route.pageId) });
243
+ const assets = hrefs.get(route.pageId);
244
+ const html = args.islands ? await renderIslandsPage(common) : await renderPage({ ...common, clientHref: assets?.js, clientCss: assets?.css });
213
245
  const dest = join3(outDir, outFile(route.pattern));
214
246
  mkdirSync(dirname(dest), { recursive: true });
215
247
  writeFileSync(dest, html);
@@ -278,7 +310,8 @@ async function buildServerTarget(root, outDir, outLabel, routes) {
278
310
  routes: routes.map((r) => ({
279
311
  ...r,
280
312
  serverFile: server.modules[r.pageId],
281
- clientHref: clientHrefs.get(r.pageId)
313
+ clientHref: clientHrefs.get(r.pageId)?.js,
314
+ clientCss: clientHrefs.get(r.pageId)?.css
282
315
  })),
283
316
  components,
284
317
  api,
@@ -205,6 +205,7 @@ async function renderPage(opts) {
205
205
  clientHref: opts.clientHref,
206
206
  storeIds: stores.map((s) => s.id),
207
207
  appCss: opts.appCss,
208
+ clientCss: opts.clientCss,
208
209
  headTags: renderHead(head),
209
210
  configScript: clientConfigScript(opts.publicConfig ?? {})
210
211
  });
@@ -218,27 +219,29 @@ function shell({
218
219
  clientHref,
219
220
  storeIds = [],
220
221
  appCss,
222
+ clientCss = [],
221
223
  headTags = "<title>Apex JS</title>",
222
224
  configScript = ""
223
225
  }) {
224
226
  const storeImports = storeIds.map((id, i) => ` import __s${i} from ${JSON.stringify(id)}`).join("\n");
225
227
  const storeRegs = storeIds.map((_, i) => ` Alpine.store(__s${i}.name, __s${i}.factory())`).join("\n");
226
228
  const clientScript = clientHref ? `<script type="module" src="${clientHref}"></script>` : `<script type="module">
227
- ${appCss ? ` import ${JSON.stringify(appCss)}
228
- ` : ""} import Alpine from 'alpinejs'
229
+ import Alpine from 'alpinejs'
229
230
  ${storeImports ? `${storeImports}
230
231
  ` : ""} import ${JSON.stringify(pageId)}
231
232
  window.Alpine = Alpine
232
233
  ${storeRegs ? `${storeRegs}
233
234
  ` : ""} Alpine.start()
234
235
  </script>`;
236
+ const cssLinks = [...appCss ? [appCss] : [], ...clientCss].map((href) => `<link rel="stylesheet" href="${href}" />`).join("\n ");
235
237
  return `<!DOCTYPE html>
236
238
  <html lang="en">
237
239
  <head>
238
240
  <meta charset="utf-8" />
239
241
  <meta name="viewport" content="width=device-width, initial-scale=1" />
240
242
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
241
- ${headTags}
243
+ ${cssLinks ? `${cssLinks}
244
+ ` : ""}${headTags}
242
245
  <style>${css}</style>
243
246
  </head>
244
247
  <body>
package/dist/cli.js CHANGED
@@ -147,9 +147,9 @@ var main = defineCommand2({
147
147
  },
148
148
  subCommands: {
149
149
  new: newCommand,
150
- dev: () => import("./dev-XQN7XBZ4.js").then((m) => m.devCommand),
151
- build: () => import("./build-NA6JEP3F.js").then((m) => m.buildCommand),
152
- start: () => import("./start-7HSIYO6C.js").then((m) => m.startCommand),
150
+ dev: () => import("./dev-SXOWAX4N.js").then((m) => m.devCommand),
151
+ build: () => import("./build-C3FW7BTM.js").then((m) => m.buildCommand),
152
+ start: () => import("./start-VBGP3HFC.js").then((m) => m.startCommand),
153
153
  make: () => import("./make-VAYO5GWA.js").then((m) => m.makeCommand),
154
154
  add: () => import("./add-M3YLIFF5.js").then((m) => m.addCommand),
155
155
  theme: () => import("./theme-UUOIV44V.js").then((m) => m.themeCommand),
@@ -24,7 +24,7 @@ var devCommand = defineCommand({
24
24
  process.stdout.write(banner());
25
25
  const sp = spinner(`Starting dev server${args.islands ? " (islands mode)" : ""}\u2026`);
26
26
  try {
27
- const { startDevServer } = await import("./server-2FN6GV3M.js");
27
+ const { startDevServer } = await import("./server-AV533LKD.js");
28
28
  const { port: actual } = await startDevServer({ root, port, islands: Boolean(args.islands) });
29
29
  sp.succeed("Dev server ready");
30
30
  ready([
@@ -19,7 +19,7 @@ import {
19
19
  renderPage,
20
20
  resolveApexConfig,
21
21
  scanPages
22
- } from "./chunk-7CBGVRBB.js";
22
+ } from "./chunk-EVFABT7B.js";
23
23
  import "./chunk-PMLGY6Z3.js";
24
24
 
25
25
  // src/dev/server.ts
@@ -150,9 +150,8 @@ function fileTree(root, errorFile) {
150
150
  if (++count > 600) break;
151
151
  const childRel = rel ? `${rel}/${e.name}` : e.name;
152
152
  if (e.isDirectory()) {
153
- const onPath = errRel === childRel || errRel.startsWith(`${childRel}/`);
154
153
  items.push(
155
- `<details class="tdir"${onPath ? " open" : ""}><summary>${FOLDER_ICON}<span>${esc(e.name)}</span></summary>${walk(join(dir, e.name), childRel, depth + 1)}</details>`
154
+ `<details class="tdir" open><summary>${FOLDER_ICON}<span>${esc(e.name)}</span></summary>${walk(join(dir, e.name), childRel, depth + 1)}</details>`
156
155
  );
157
156
  } else {
158
157
  const isErr = childRel === errRel;
@@ -244,7 +243,7 @@ var tabs = document.querySelectorAll('.tabs button');
244
243
  tabs.forEach(function (b) {
245
244
  b.addEventListener('click', function () {
246
245
  tabs.forEach(function (x) { x.classList.toggle('active', x === b); });
247
- ['frames','raw','tree'].forEach(function (v) {
246
+ ['frames','raw'].forEach(function (v) {
248
247
  var el = document.getElementById('view-' + v);
249
248
  if (el) el.hidden = v !== b.dataset.view;
250
249
  });
@@ -260,8 +259,22 @@ function renderErrorPage(error, opts) {
260
259
  const message = error.message || String(error);
261
260
  const stack = error.stack || "";
262
261
  const frames = parseFrames(stack, opts.root);
263
- const origin = frames.find((f) => f.app) ?? frames[0];
264
- const framesHtml = frames.length ? frames.map((f) => frameCard(f, opts.root)).join("") : '<p class="sub">No stack frames available.</p>';
262
+ const v = error;
263
+ const rawFile = v.loc?.file ?? v.id ?? v.file;
264
+ const locFile = typeof rawFile === "string" ? rawFile.replace(/\?.*$/, "").replace(/[\\/]/g, sep) : "";
265
+ let synthetic;
266
+ if (locFile && existsSync(locFile) && locFile.startsWith(opts.root) && !frames.some((f) => f.file === locFile)) {
267
+ synthetic = {
268
+ func: "compile error",
269
+ file: locFile,
270
+ line: v.loc?.line ?? 1,
271
+ col: v.loc?.column ?? 1,
272
+ app: true
273
+ };
274
+ }
275
+ const allFrames = synthetic ? [synthetic, ...frames] : frames;
276
+ const origin = synthetic ?? frames.find((f) => f.app) ?? frames[0];
277
+ const framesHtml = allFrames.length ? allFrames.map((f) => frameCard(f, opts.root)).join("") : '<p class="sub">No stack frames available.</p>';
265
278
  const body = `
266
279
  <div class="brand">${MARK} Apex JS <span class="pill err">Dev error</span></div>
267
280
  <p class="kind">${esc(kind)}</p>
@@ -11,7 +11,7 @@ import {
11
11
  matchRoute,
12
12
  renderIslandsPage,
13
13
  renderPage
14
- } from "./chunk-7CBGVRBB.js";
14
+ } from "./chunk-EVFABT7B.js";
15
15
  import "./chunk-PMLGY6Z3.js";
16
16
 
17
17
  // src/commands/start.ts
@@ -130,6 +130,7 @@ async function startProdServer(options) {
130
130
  registry,
131
131
  componentCss,
132
132
  clientHref: route?.clientHref,
133
+ clientCss: route?.clientCss,
133
134
  runtimeConfig,
134
135
  publicConfig,
135
136
  locals: event.context.apexLocals ?? {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apex-stack/core",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "The full-stack meta-framework for Alpine.js — CLI and runtime",
5
5
  "type": "module",
6
6
  "license": "MIT",
Binary file
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4