@constela/start 1.2.3 → 1.2.4

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.
@@ -1492,7 +1492,7 @@ function normalizeDataSourcePatterns(projectRoot, pageDir, dataSources) {
1492
1492
  }
1493
1493
  return result;
1494
1494
  }
1495
- async function loadJsonPage(baseDir, pagePath) {
1495
+ async function loadJsonPage(baseDir, pagePath, options) {
1496
1496
  const filePath = join6(baseDir, pagePath);
1497
1497
  const resolvedBase = resolve3(baseDir);
1498
1498
  const resolvedPath = resolve3(filePath);
@@ -1523,7 +1523,8 @@ async function loadJsonPage(baseDir, pagePath) {
1523
1523
  validateVersion(page.version);
1524
1524
  const pageDir = dirname2(filePath);
1525
1525
  const resolvedImports = await resolveImports(pageDir, page.imports, baseDir);
1526
- const normalizedData = normalizeDataSourcePatterns(baseDir, pageDir, page.data);
1526
+ const patternBaseDir = options?.routesDir ?? pageDir;
1527
+ const normalizedData = normalizeDataSourcePatterns(baseDir, patternBaseDir, page.data);
1527
1528
  const loadedData = await loadPageData(baseDir, normalizedData, { imports: resolvedImports });
1528
1529
  const widgets = await loadWidgets(pageDir, page.widgets, baseDir);
1529
1530
  return {
@@ -1831,9 +1832,11 @@ async function convertToCompiledProgram(pageInfo) {
1831
1832
  }
1832
1833
  var JsonPageLoader = class {
1833
1834
  projectRoot;
1835
+ routesDir;
1834
1836
  cache = /* @__PURE__ */ new Map();
1835
- constructor(projectRoot) {
1837
+ constructor(projectRoot, options) {
1836
1838
  this.projectRoot = projectRoot;
1839
+ this.routesDir = options?.routesDir;
1837
1840
  }
1838
1841
  /**
1839
1842
  * Load a JSON page with full resolution
@@ -1842,7 +1845,9 @@ var JsonPageLoader = class {
1842
1845
  if (this.cache.has(pagePath)) {
1843
1846
  return this.cache.get(pagePath);
1844
1847
  }
1845
- const pageInfo = await loadJsonPage(this.projectRoot, pagePath);
1848
+ const pageInfo = await loadJsonPage(this.projectRoot, pagePath, {
1849
+ routesDir: this.routesDir
1850
+ });
1846
1851
  this.cache.set(pagePath, pageInfo);
1847
1852
  return pageInfo;
1848
1853
  }
@@ -2168,14 +2173,15 @@ h1 { color: #666; }
2168
2173
  }
2169
2174
 
2170
2175
  // src/build/index.ts
2171
- import { existsSync as existsSync7, readFileSync as readFileSync5 } from "fs";
2176
+ import { existsSync as existsSync8, readFileSync as readFileSync5 } from "fs";
2172
2177
  import { mkdir as mkdir2, writeFile, cp, readdir } from "fs/promises";
2173
- import { join as join9, dirname as dirname5, relative as relative2, basename as basename4, isAbsolute as isAbsolute2, resolve as resolve4 } from "path";
2178
+ import { join as join9, dirname as dirname5, relative as relative2, basename as basename4, isAbsolute as isAbsolute3, resolve as resolve4 } from "path";
2174
2179
 
2175
2180
  // src/build/bundler.ts
2176
2181
  import * as esbuild from "esbuild";
2182
+ import { existsSync as existsSync7 } from "fs";
2177
2183
  import { mkdir } from "fs/promises";
2178
- import { join as join8, dirname as dirname4 } from "path";
2184
+ import { join as join8, dirname as dirname4, isAbsolute as isAbsolute2 } from "path";
2179
2185
  import { fileURLToPath } from "url";
2180
2186
  var __dirname = dirname4(fileURLToPath(import.meta.url));
2181
2187
  async function bundleRuntime(options) {
@@ -2205,6 +2211,44 @@ async function bundleRuntime(options) {
2205
2211
  }
2206
2212
  return "/_constela/runtime.js";
2207
2213
  }
2214
+ async function bundleCSS(options) {
2215
+ const cssFiles = Array.isArray(options.css) ? options.css : [options.css];
2216
+ const outFile = join8(options.outDir, "_constela", "styles.css");
2217
+ await mkdir(dirname4(outFile), { recursive: true });
2218
+ const resolvedCssFiles = cssFiles.map((f) => isAbsolute2(f) ? f : join8(process.cwd(), f));
2219
+ for (const fullPath of resolvedCssFiles) {
2220
+ if (!existsSync7(fullPath)) {
2221
+ throw new Error(`CSS file not found: ${fullPath}`);
2222
+ }
2223
+ }
2224
+ try {
2225
+ if (resolvedCssFiles.length === 1) {
2226
+ await esbuild.build({
2227
+ entryPoints: resolvedCssFiles,
2228
+ bundle: true,
2229
+ outfile: outFile,
2230
+ minify: options.minify ?? true,
2231
+ loader: { ".css": "css" }
2232
+ });
2233
+ } else {
2234
+ const virtualEntry = resolvedCssFiles.map((f) => `@import "${f}";`).join("\n");
2235
+ await esbuild.build({
2236
+ stdin: {
2237
+ contents: virtualEntry,
2238
+ loader: "css",
2239
+ resolveDir: process.cwd()
2240
+ },
2241
+ bundle: true,
2242
+ outfile: outFile,
2243
+ minify: options.minify ?? true
2244
+ });
2245
+ }
2246
+ } catch (error) {
2247
+ const message = error instanceof Error ? error.message : String(error);
2248
+ throw new Error(`Failed to bundle CSS to ${outFile}: ${message}`);
2249
+ }
2250
+ return "/_constela/styles.css";
2251
+ }
2208
2252
 
2209
2253
  // src/build/index.ts
2210
2254
  var DEFAULT_PUBLIC_DIR2 = "public";
@@ -2234,7 +2278,7 @@ async function loadGetStaticPaths(pageFile) {
2234
2278
  const dir = dirname5(pageFile);
2235
2279
  const baseName = basename4(pageFile, ".json");
2236
2280
  const pathsFile = join9(dir, `${baseName}.paths.ts`);
2237
- if (!existsSync7(pathsFile)) {
2281
+ if (!existsSync8(pathsFile)) {
2238
2282
  return null;
2239
2283
  }
2240
2284
  try {
@@ -2275,7 +2319,7 @@ async function loadGetStaticPaths(pageFile) {
2275
2319
  }
2276
2320
  async function loadLayout2(layoutName, layoutsDir) {
2277
2321
  const layoutPath = join9(layoutsDir, `${layoutName}.json`);
2278
- if (!existsSync7(layoutPath)) {
2322
+ if (!existsSync8(layoutPath)) {
2279
2323
  throw new Error(`Layout "${layoutName}" not found at ${layoutPath}`);
2280
2324
  }
2281
2325
  try {
@@ -2383,7 +2427,7 @@ async function processLayouts(pageInfo, layoutsDir) {
2383
2427
  }
2384
2428
  return updatedPageInfo;
2385
2429
  }
2386
- async function renderPageToHtml(program, params, runtimePath) {
2430
+ async function renderPageToHtml(program, params, runtimePath, cssPath) {
2387
2431
  const normalizedProgram = {
2388
2432
  ...program,
2389
2433
  view: normalizeViewNode(structuredClone(program.view))
@@ -2399,11 +2443,12 @@ async function renderPageToHtml(program, params, runtimePath) {
2399
2443
  query: {},
2400
2444
  path: "/"
2401
2445
  };
2446
+ const cssLinkTag = cssPath ? `<link rel="stylesheet" href="${cssPath}">` : void 0;
2402
2447
  const hydrationScript = generateHydrationScript(normalizedProgram, void 0, routeContext);
2403
- return wrapHtml(content, hydrationScript, void 0, runtimePath ? { runtimePath } : void 0);
2448
+ return wrapHtml(content, hydrationScript, cssLinkTag, runtimePath ? { runtimePath } : void 0);
2404
2449
  }
2405
2450
  async function copyPublicDir(publicDir, outDir, generatedFiles) {
2406
- if (!existsSync7(publicDir)) {
2451
+ if (!existsSync8(publicDir)) {
2407
2452
  return;
2408
2453
  }
2409
2454
  await copyDirRecursive(publicDir, outDir, generatedFiles);
@@ -2471,7 +2516,14 @@ async function build2(options) {
2471
2516
  };
2472
2517
  }
2473
2518
  const runtimePath = await bundleRuntime({ outDir });
2474
- const absoluteRoutesDir = isAbsolute2(routesDir) ? routesDir : resolve4(routesDir);
2519
+ let cssPath;
2520
+ if (options?.css) {
2521
+ cssPath = await bundleCSS({
2522
+ outDir,
2523
+ css: options.css
2524
+ });
2525
+ }
2526
+ const absoluteRoutesDir = isAbsolute3(routesDir) ? routesDir : resolve4(routesDir);
2475
2527
  const projectRoot = dirname5(dirname5(absoluteRoutesDir));
2476
2528
  for (const route of jsonPages) {
2477
2529
  const relPathFromRoutesDir = relative2(absoluteRoutesDir, route.file);
@@ -2479,23 +2531,31 @@ async function build2(options) {
2479
2531
  const content = readFileSync5(route.file, "utf-8");
2480
2532
  const page = validateJsonPage(content, route.file);
2481
2533
  if (isDynamicRoute(route.pattern)) {
2482
- const staticPaths = await loadGetStaticPaths(route.file);
2483
- if (!staticPaths) {
2534
+ const loader = new JsonPageLoader(projectRoot, { routesDir: absoluteRoutesDir });
2535
+ let pageInfo = await loader.loadPage(relPathFromProjectRoot);
2536
+ let staticPathsResult = null;
2537
+ if (pageInfo.page.getStaticPaths) {
2538
+ staticPathsResult = await generateStaticPathsFromPage(
2539
+ pageInfo.page,
2540
+ pageInfo.loadedData
2541
+ );
2542
+ } else {
2543
+ const externalPaths = await loadGetStaticPaths(route.file);
2544
+ if (externalPaths) {
2545
+ staticPathsResult = externalPaths.paths.map((p) => ({ params: p.params }));
2546
+ }
2547
+ }
2548
+ if (!staticPathsResult || staticPathsResult.length === 0) {
2484
2549
  continue;
2485
2550
  }
2486
- if (!staticPaths.paths || !Array.isArray(staticPaths.paths)) {
2487
- throw new Error(`Invalid getStaticPaths format in ${route.file}`);
2551
+ if (layoutsDir) {
2552
+ pageInfo = await processLayouts(pageInfo, layoutsDir);
2488
2553
  }
2489
- for (const pathEntry of staticPaths.paths) {
2554
+ for (const pathEntry of staticPathsResult) {
2490
2555
  const params = pathEntry.params;
2491
2556
  const outputPath = paramsToOutputPath(route.pattern, params, outDir);
2492
- const loader = new JsonPageLoader(projectRoot);
2493
- let pageInfo = await loader.loadPage(relPathFromProjectRoot);
2494
- if (layoutsDir) {
2495
- pageInfo = await processLayouts(pageInfo, layoutsDir);
2496
- }
2497
2557
  const program = await convertToCompiledProgram(pageInfo);
2498
- const html = await renderPageToHtml(program, params, runtimePath);
2558
+ const html = await renderPageToHtml(program, params, runtimePath, cssPath);
2499
2559
  await mkdir2(dirname5(outputPath), { recursive: true });
2500
2560
  await writeFile(outputPath, html, "utf-8");
2501
2561
  generatedFiles.push(outputPath);
@@ -2508,13 +2568,13 @@ async function build2(options) {
2508
2568
  }
2509
2569
  } else {
2510
2570
  const outputPath = getOutputPath(relPathFromRoutesDir, outDir);
2511
- const loader = new JsonPageLoader(projectRoot);
2571
+ const loader = new JsonPageLoader(projectRoot, { routesDir: absoluteRoutesDir });
2512
2572
  let pageInfo = await loader.loadPage(relPathFromProjectRoot);
2513
2573
  if (layoutsDir) {
2514
2574
  pageInfo = await processLayouts(pageInfo, layoutsDir);
2515
2575
  }
2516
2576
  const program = await convertToCompiledProgram(pageInfo);
2517
- const html = await renderPageToHtml(program, {}, runtimePath);
2577
+ const html = await renderPageToHtml(program, {}, runtimePath, cssPath);
2518
2578
  await mkdir2(dirname5(outputPath), { recursive: true });
2519
2579
  await writeFile(outputPath, html, "utf-8");
2520
2580
  generatedFiles.push(outputPath);
@@ -2532,12 +2592,12 @@ async function build2(options) {
2532
2592
  }
2533
2593
 
2534
2594
  // src/config/config-loader.ts
2535
- import { existsSync as existsSync8, readFileSync as readFileSync6 } from "fs";
2595
+ import { existsSync as existsSync9, readFileSync as readFileSync6 } from "fs";
2536
2596
  import { join as join10 } from "path";
2537
2597
  var CONFIG_FILENAME = "constela.config.json";
2538
2598
  async function loadConfig(projectRoot) {
2539
2599
  const configPath = join10(projectRoot, CONFIG_FILENAME);
2540
- if (!existsSync8(configPath)) {
2600
+ if (!existsSync9(configPath)) {
2541
2601
  return {};
2542
2602
  }
2543
2603
  let content;
package/dist/cli/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  createDevServer,
4
4
  loadConfig,
5
5
  resolveConfig
6
- } from "../chunk-U6CTMEFX.js";
6
+ } from "../chunk-MP2KUHWS.js";
7
7
  import "../chunk-PUTC5BCP.js";
8
8
 
9
9
  // src/cli/index.ts
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  transformCsv,
24
24
  transformMdx,
25
25
  transformYaml
26
- } from "./chunk-U6CTMEFX.js";
26
+ } from "./chunk-MP2KUHWS.js";
27
27
  import {
28
28
  generateHydrationScript,
29
29
  renderPage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/start",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Meta-framework for Constela applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,9 +42,9 @@
42
42
  "vite": "^6.0.0",
43
43
  "@constela/compiler": "0.7.0",
44
44
  "@constela/core": "0.7.0",
45
- "@constela/server": "3.0.0",
45
+ "@constela/runtime": "0.10.1",
46
46
  "@constela/router": "8.0.0",
47
- "@constela/runtime": "0.10.1"
47
+ "@constela/server": "3.0.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/mdast": "^4.0.4",