@contentbit/studio 2.0.0-next.1 → 2.0.0-next.3

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.
Files changed (30) hide show
  1. package/dist/client/assets/{api-aCc2x-IO.js → api-D5joupdU.js} +1 -1
  2. package/dist/client/assets/{arrow-right-tp4VknZo.js → arrow-right-DgVH2ckT.js} +1 -1
  3. package/dist/client/assets/{document-DIh3ZPXr.js → document-C9j7At_d.js} +1 -1
  4. package/dist/client/assets/{documents-CjBZYbQ4.js → documents-IFM8-M_m.js} +1 -1
  5. package/dist/client/assets/{file-code-corner-Fzc5liO9.js → file-code-corner-Ea1mVVN3.js} +1 -1
  6. package/dist/client/assets/{file-text-B8O46COn.js → file-text-JyAIocHS.js} +1 -1
  7. package/dist/client/assets/index-0pGRBfyx.js +12 -0
  8. package/dist/client/assets/{page-BMU8eIrR.js → page-B3xqvv7Z.js} +1 -1
  9. package/dist/client/assets/{routes-WndCJoku.js → routes-DCV_quef.js} +1 -1
  10. package/dist/client/assets/{search-BnUPH8AI.js → search-Dh1jm8QA.js} +1 -1
  11. package/dist/client/assets/{target-BMSXP2fU.js → target-BIrWK4A2.js} +1 -1
  12. package/dist/client/assets/{templates-IJid1Zwh.js → templates-CyNCDlsk.js} +1 -1
  13. package/dist/server/api.d.ts.map +1 -1
  14. package/dist/server/assets/{_tanstack-start-manifest_v-WfZ3uz_l.js → _tanstack-start-manifest_v-BuI4pWk7.js} +23 -23
  15. package/dist/server/assets/{document-BjPXZ9gS.js → document-DOP_63d9.js} +1 -1
  16. package/dist/server/assets/{documents-jT4KnSkA.js → documents-DFgsCsBO.js} +1 -1
  17. package/dist/server/assets/{empty-plugin-adapters-Ctp1ZmyT.js → empty-plugin-adapters-CViywP8O.js} +1 -1
  18. package/dist/server/assets/{page--xw7NmtK.js → page-aNwYcZ_l.js} +1 -1
  19. package/dist/server/assets/{router-xI8HUWRI.js → router-CtNxhc0G.js} +38 -42
  20. package/dist/server/assets/{routes-CfwU-Ww2.js → routes-C77LqfqF.js} +1 -1
  21. package/dist/server/assets/start-BrmB4H5W.js +3 -0
  22. package/dist/server/index.js +73 -39
  23. package/dist/server/server.js +2790 -2344
  24. package/package.json +7 -7
  25. package/src/routeTree.gen.ts +36 -36
  26. package/src/server/api.ts +16 -13
  27. package/src/server/scan.ts +4 -4
  28. package/src/server/site.test.ts +32 -3
  29. package/dist/client/assets/index-Cd04OFZT.js +0 -11
  30. package/dist/server/assets/start-Dk-BJfGT.js +0 -3
@@ -1809,16 +1809,10 @@ import { spawn } from "node:child_process";
1809
1809
  import { existsSync as existsSync4 } from "node:fs";
1810
1810
  import { createRequire } from "node:module";
1811
1811
  import { createServer as createNetServer } from "node:net";
1812
- import { dirname, isAbsolute as isAbsolute3, join as join5, resolve as resolvePath } from "node:path";
1812
+ import { dirname as dirname2, isAbsolute as isAbsolute3, join as join5, resolve as resolvePath } from "node:path";
1813
1813
  import { fileURLToPath } from "node:url";
1814
1814
  import { createServer } from "vite";
1815
1815
 
1816
- // src/server/scan.ts
1817
- import {
1818
- createSeoBrief as createSeoBrief2,
1819
- readContentPageFacts as readContentPageFacts2
1820
- } from "@contentbit/core";
1821
-
1822
1816
  // ../built-site/dist/findings.js
1823
1817
  var DEFAULT_SEVERITY_BY_CODE = {
1824
1818
  CB_PAGE_TITLE_MISSING: "error",
@@ -5721,11 +5715,11 @@ function compileEntry(entry, index) {
5721
5715
  function list(value) {
5722
5716
  return value === void 0 ? [] : [value].flat();
5723
5717
  }
5724
- function globMatcher(globs, normalize = (value) => value) {
5718
+ function globMatcher(globs, normalize2 = (value) => value) {
5725
5719
  if (globs.length === 0)
5726
5720
  return void 0;
5727
- const isMatch = (0, import_picomatch.default)(globs.map(normalize), { dot: true, windows: false });
5728
- return (values) => values.some((value) => isMatch(normalize(value)));
5721
+ const isMatch = (0, import_picomatch.default)(globs.map(normalize2), { dot: true, windows: false });
5722
+ return (values) => values.some((value) => isMatch(normalize2(value)));
5729
5723
  }
5730
5724
  function withoutTrailingSlash(value) {
5731
5725
  return value.length > 1 && value.endsWith("/") ? value.slice(0, -1) : value;
@@ -5737,7 +5731,7 @@ import { createBlockRegistry, scanContentProject } from "@contentbit/core";
5737
5731
  import { createHash } from "node:crypto";
5738
5732
  import { existsSync } from "node:fs";
5739
5733
  import { readFile as readFile2 } from "node:fs/promises";
5740
- import { extname, isAbsolute, join as join2 } from "node:path";
5734
+ import { basename as basename2, dirname, extname, isAbsolute, join as join2 } from "node:path";
5741
5735
  import { pathToFileURL } from "node:url";
5742
5736
  import { glob } from "tinyglobby";
5743
5737
  var ProjectLoadError = class extends Error {
@@ -5789,7 +5783,35 @@ async function loadRegistry(registryPath, options = {}) {
5789
5783
  return registry;
5790
5784
  }
5791
5785
  async function importFresh(path) {
5792
- return import((await versionedUrl(path)).href);
5786
+ const { href } = await versionedUrl(path);
5787
+ try {
5788
+ return await import(href);
5789
+ } catch (err) {
5790
+ if (err instanceof SyntaxError && await isEsmInCommonJsPackage(path)) {
5791
+ const extension = extname(path);
5792
+ throw new ProjectLoadError(2, `${path} uses import or export, but its package.json sets "type": "commonjs", so Node reads it as CommonJS. Rename it to ${basename2(path, extension)}.m${extension.slice(1)}.`);
5793
+ }
5794
+ throw err;
5795
+ }
5796
+ }
5797
+ async function isEsmInCommonJsPackage(path) {
5798
+ if (!/\.[jt]s$/.test(path))
5799
+ return false;
5800
+ const source = await readFile2(path, "utf8").catch(() => "");
5801
+ if (!/^\s*(?:import|export)\s/m.test(source))
5802
+ return false;
5803
+ for (let dir = dirname(path); ; dir = dirname(dir)) {
5804
+ const manifest = await readFile2(join2(dir, "package.json"), "utf8").catch(() => void 0);
5805
+ if (manifest !== void 0) {
5806
+ try {
5807
+ return JSON.parse(manifest).type === "commonjs";
5808
+ } catch {
5809
+ return false;
5810
+ }
5811
+ }
5812
+ if (dirname(dir) === dir)
5813
+ return false;
5814
+ }
5793
5815
  }
5794
5816
  async function versionedUrl(path) {
5795
5817
  const url = pathToFileURL(path);
@@ -5808,6 +5830,7 @@ async function loadContentFiles(files, input) {
5808
5830
  const linkOptions = input.linkOptions ?? {};
5809
5831
  const scan = scanContentProject(sources, registry, {
5810
5832
  linkOptions,
5833
+ root: input.cwd ?? process.cwd(),
5811
5834
  ...input.scan
5812
5835
  });
5813
5836
  return { files, registry, sources, linkOptions, scan };
@@ -5987,15 +6010,15 @@ async function readBuild(cmd, path, root) {
5987
6010
  } catch (error) {
5988
6011
  const code = error.code;
5989
6012
  if (code === "ENOENT") {
5990
- throw new ProjectLoadError(2, `${cmd}: the build folder ${displayPath(path)} does not exist. ${buildAdvice(root)}`);
6013
+ throw new ProjectLoadError(2, `${cmd}: the build folder ${displayPath(path, root)} does not exist. ${buildAdvice(root)}`);
5991
6014
  }
5992
6015
  if (code === "ENOTDIR") {
5993
- throw new ProjectLoadError(2, `${cmd}: ${displayPath(path)} is not a folder.`);
6016
+ throw new ProjectLoadError(2, `${cmd}: ${displayPath(path, root)} is not a folder.`);
5994
6017
  }
5995
6018
  throw error;
5996
6019
  }
5997
6020
  if (site.pages.length === 0) {
5998
- throw new ProjectLoadError(2, `${cmd}: the build folder ${displayPath(path)} holds no HTML page. ${buildAdvice(root)}`);
6021
+ throw new ProjectLoadError(2, `${cmd}: the build folder ${displayPath(path, root)} holds no HTML page. ${buildAdvice(root)}`);
5999
6022
  }
6000
6023
  return site;
6001
6024
  }
@@ -6006,8 +6029,15 @@ function buildAdvice(root) {
6006
6029
  return server;
6007
6030
  return `Build the site with ${buildCommand(root)} first, or set site.build in contentbit.config.ts to the folder its build writes.`;
6008
6031
  }
6009
- function displayPath(file) {
6010
- return relativeInside(process.cwd(), file) ?? file;
6032
+ function displayPath(file, root) {
6033
+ if (relative2(root, file) === "")
6034
+ return ".";
6035
+ return relativeInside(root, file) ?? file;
6036
+ }
6037
+ function pathsFromRoot(root, build) {
6038
+ const folders = build === void 0 ? [root] : [root, build];
6039
+ const isPath = (text) => folders.some((folder) => text === folder || text.startsWith(`${folder}${sep}`));
6040
+ return (_key, value) => typeof value === "string" && isPath(value) ? relative2(root, value).split(sep).join("/") || "." : value;
6011
6041
  }
6012
6042
  function relativeInside(folder, file) {
6013
6043
  const path = relative2(folder, file);
@@ -6088,7 +6118,11 @@ function resolveOrigin(flag, configured, site) {
6088
6118
  }
6089
6119
 
6090
6120
  // src/server/scan.ts
6091
- import { basename as basename2 } from "node:path";
6121
+ import {
6122
+ createSeoBrief as createSeoBrief2,
6123
+ readContentPageFacts as readContentPageFacts2
6124
+ } from "@contentbit/core";
6125
+ import { basename as basename3, normalize } from "node:path";
6092
6126
 
6093
6127
  // src/server/preview.ts
6094
6128
  import { ContentBlocks } from "@contentbit/react";
@@ -6389,7 +6423,7 @@ function fileSummary(file, cwd, frontmatter, stats, findings, options, seoPage)
6389
6423
  };
6390
6424
  }
6391
6425
  function titleFor(file, frontmatter, stats) {
6392
- return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename2(file);
6426
+ return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename3(file);
6393
6427
  }
6394
6428
  function summarize(findings) {
6395
6429
  const count = (severity) => findings.filter((finding) => finding.severity === severity).length;
@@ -6402,9 +6436,8 @@ function statusFor(findings) {
6402
6436
  return "healthy";
6403
6437
  }
6404
6438
  function findAllowedFile(context, cwd, requestedPath) {
6405
- return context.files.find(
6406
- (file) => file === requestedPath || relativePath(cwd, file) === requestedPath
6407
- ) ?? null;
6439
+ const requested = normalize(requestedPath);
6440
+ return context.files.find((file) => file === requested || relativePath(cwd, file) === requested) ?? null;
6408
6441
  }
6409
6442
  function stringValue(value) {
6410
6443
  return typeof value === "string" && value.trim().length > 0 ? value : void 0;
@@ -6418,58 +6451,59 @@ async function handleStudioApiRequest(options, req, res) {
6418
6451
  if (!req.url) return false;
6419
6452
  const url = new URL(req.url, "http://contentbit.local");
6420
6453
  if (!url.pathname.startsWith("/api/")) return false;
6454
+ const root = options.cwd ?? process.cwd();
6421
6455
  try {
6422
6456
  if (req.method !== "GET") {
6423
- sendJson(res, 405, { error: "Studio API is read-only." });
6457
+ sendJson(res, root, 405, { error: "Studio API is read-only." });
6424
6458
  return true;
6425
6459
  }
6426
6460
  if (url.pathname === "/api/project") {
6427
- sendJson(res, 200, await scanProject(options));
6461
+ sendJson(res, root, 200, await scanProject(options));
6428
6462
  return true;
6429
6463
  }
6430
6464
  if (url.pathname === "/api/site") {
6431
- sendJson(res, 200, await scanSite(options));
6465
+ sendJson(res, root, 200, await scanSite(options));
6432
6466
  return true;
6433
6467
  }
6434
6468
  if (url.pathname === "/api/page") {
6435
6469
  const path = url.searchParams.get("path");
6436
6470
  if (!path) {
6437
- sendJson(res, 400, { error: "Missing ?path=" });
6471
+ sendJson(res, root, 400, { error: "Missing ?path=" });
6438
6472
  return true;
6439
6473
  }
6440
6474
  const page = await scanPage(options, path);
6441
6475
  if (!page) {
6442
- sendJson(res, 404, { error: `The build has no page ${path}.` });
6476
+ sendJson(res, root, 404, { error: `The build has no page ${path}.` });
6443
6477
  return true;
6444
6478
  }
6445
- sendJson(res, 200, page);
6479
+ sendJson(res, root, 200, page);
6446
6480
  return true;
6447
6481
  }
6448
6482
  if (url.pathname === "/api/document") {
6449
6483
  const path = url.searchParams.get("path");
6450
6484
  if (!path) {
6451
- sendJson(res, 400, { error: "Missing ?path=" });
6485
+ sendJson(res, root, 400, { error: "Missing ?path=" });
6452
6486
  return true;
6453
6487
  }
6454
6488
  const document = await scanDocument(options, path);
6455
6489
  if (!document) {
6456
- sendJson(res, 404, { error: "Document is not in the configured content set." });
6490
+ sendJson(res, root, 404, { error: "Document is not in the configured content set." });
6457
6491
  return true;
6458
6492
  }
6459
- sendJson(res, 200, document);
6493
+ sendJson(res, root, 200, document);
6460
6494
  return true;
6461
6495
  }
6462
- sendJson(res, 404, { error: "Unknown Studio API route." });
6496
+ sendJson(res, root, 404, { error: "Unknown Studio API route." });
6463
6497
  return true;
6464
6498
  } catch (err) {
6465
- sendJson(res, 500, { error: err instanceof Error ? err.message : String(err) });
6499
+ sendJson(res, root, 500, { error: err instanceof Error ? err.message : String(err) });
6466
6500
  return true;
6467
6501
  }
6468
6502
  }
6469
- function sendJson(res, status, body) {
6503
+ function sendJson(res, root, status, body) {
6470
6504
  res.statusCode = status;
6471
6505
  res.setHeader("content-type", "application/json; charset=utf-8");
6472
- res.end(JSON.stringify(body, null, 2));
6506
+ res.end(JSON.stringify(body, pathsFromRoot(root), 2));
6473
6507
  }
6474
6508
 
6475
6509
  // src/server/index.ts
@@ -6478,7 +6512,7 @@ async function startStudio(options) {
6478
6512
  const host = options.host ?? "127.0.0.1";
6479
6513
  const port = options.port === 0 ? await freePort(host) : options.port ?? 4377;
6480
6514
  const cwd = options.cwd ?? process.cwd();
6481
- const fontRoot = dirname(
6515
+ const fontRoot = dirname2(
6482
6516
  createRequire(join5(root, "package.json")).resolve("@fontsource-variable/inter/package.json")
6483
6517
  );
6484
6518
  const fsAllow = [root, fontRoot];
@@ -6548,7 +6582,7 @@ function componentCandidates(options) {
6548
6582
  const dirs = /* @__PURE__ */ new Set();
6549
6583
  if (options.registryPath) {
6550
6584
  const registryPath = isAbsolute3(options.registryPath) ? options.registryPath : resolvePath(options.cwd, options.registryPath);
6551
- dirs.add(dirname(registryPath));
6585
+ dirs.add(dirname2(registryPath));
6552
6586
  }
6553
6587
  dirs.add(join5(options.cwd, "blocks"));
6554
6588
  const rendererCandidates = [
@@ -6599,10 +6633,10 @@ async function freePort(host) {
6599
6633
  return port;
6600
6634
  }
6601
6635
  function findPackageRoot() {
6602
- let dir = dirname(fileURLToPath(import.meta.url));
6636
+ let dir = dirname2(fileURLToPath(import.meta.url));
6603
6637
  for (; ; ) {
6604
6638
  if (existsSync4(join5(dir, "package.json"))) return dir;
6605
- const next = dirname(dir);
6639
+ const next = dirname2(dir);
6606
6640
  if (next === dir) throw new Error("Could not locate @contentbit/studio package root.");
6607
6641
  dir = next;
6608
6642
  }