@cmssy/cli 19.3.0 → 19.3.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.
Files changed (2) hide show
  1. package/dist/index.js +75 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1416,6 +1416,36 @@ import { basename, join as join7, resolve as resolve3 } from "path";
1416
1416
  import { pathToFileURL } from "url";
1417
1417
  import { build } from "esbuild";
1418
1418
  var RUNTIME_ONLY_MODULES = ["server-only", "client-only"];
1419
+ var FRAMEWORK_MODULES = /^(next(\/.*)?|astro:.*)$/;
1420
+ var FRAMEWORK_STUB = `
1421
+ function serve(prop) {
1422
+ if (prop === "__esModule" || prop === "__cmssyFrameworkStub") return true;
1423
+ if (prop === Symbol.toPrimitive) return () => "";
1424
+ if (prop === Symbol.iterator) return () => [][Symbol.iterator]();
1425
+ if (typeof prop === "symbol" || prop === "then") return undefined;
1426
+ return stub;
1427
+ }
1428
+ const names = new Proxy({}, {
1429
+ get(target, prop) {
1430
+ return serve(prop);
1431
+ },
1432
+ });
1433
+ const stub = new Proxy(function Stub() {}, {
1434
+ get(target, prop) {
1435
+ return serve(prop);
1436
+ },
1437
+ getPrototypeOf() {
1438
+ return names;
1439
+ },
1440
+ apply() {
1441
+ return stub;
1442
+ },
1443
+ construct() {
1444
+ return stub;
1445
+ },
1446
+ });
1447
+ module.exports = stub;
1448
+ `;
1419
1449
  var ASSET_EXTENSIONS = [
1420
1450
  ".module.css",
1421
1451
  ".module.scss",
@@ -1441,7 +1471,8 @@ var ASSET_EXTENSIONS = [
1441
1471
  ".webm",
1442
1472
  ".mp3",
1443
1473
  ".md",
1444
- ".mdx"
1474
+ ".mdx",
1475
+ ".astro"
1445
1476
  ];
1446
1477
  var assetLoaders = Object.fromEntries(
1447
1478
  ASSET_EXTENSIONS.map((extension) => [extension, "empty"])
@@ -1460,6 +1491,19 @@ var runtimeOnlyModules = {
1460
1491
  }));
1461
1492
  }
1462
1493
  };
1494
+ var frameworkModules = {
1495
+ name: "cmssy-framework-modules",
1496
+ setup(api) {
1497
+ api.onResolve({ filter: FRAMEWORK_MODULES }, (args) => ({
1498
+ path: args.path,
1499
+ namespace: "cmssy-framework-stub"
1500
+ }));
1501
+ api.onLoad({ filter: /.*/, namespace: "cmssy-framework-stub" }, () => ({
1502
+ contents: FRAMEWORK_STUB,
1503
+ loader: "js"
1504
+ }));
1505
+ }
1506
+ };
1463
1507
  async function loadSiteModule(cwd, entry) {
1464
1508
  const entryPath = resolve3(cwd, entry);
1465
1509
  let code;
@@ -1476,7 +1520,7 @@ async function loadSiteModule(cwd, entry) {
1476
1520
  jsx: "automatic",
1477
1521
  loader: assetLoaders,
1478
1522
  define: { "import.meta.env": "process.env" },
1479
- plugins: [runtimeOnlyModules],
1523
+ plugins: [runtimeOnlyModules, frameworkModules],
1480
1524
  logLevel: "silent"
1481
1525
  });
1482
1526
  code = result.outputFiles[0]?.text ?? "";
@@ -1503,14 +1547,35 @@ async function loadSiteModule(cwd, entry) {
1503
1547
  try {
1504
1548
  return await import(pathToFileURL(file).href);
1505
1549
  } catch (error) {
1550
+ const detail = error instanceof Error ? error.message : String(error);
1551
+ const code2 = error?.code;
1552
+ const fromFramework = (code2 === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code2 === "ERR_MODULE_NOT_FOUND") && /node_modules\/(next|astro)\/|'(next|astro)[/:']/.test(detail);
1506
1553
  throw new CliError(
1507
1554
  `could not load ${entry}`,
1508
- error instanceof Error ? error.message : String(error)
1555
+ fromFramework ? `${detail}
1556
+ a package imported by ${entry} loads a framework module at import time - cmssy stubs framework imports in your own files, not inside node_modules; import that package from app code instead of the files the manifest reads` : detail
1509
1557
  );
1510
1558
  } finally {
1511
1559
  rmSync(file, { force: true });
1512
1560
  }
1513
1561
  }
1562
+ function findFrameworkStubValues(value, path = "") {
1563
+ if (value === null || typeof value !== "object" && typeof value !== "function") {
1564
+ return [];
1565
+ }
1566
+ if (value.__cmssyFrameworkStub === true) {
1567
+ return [path || "<root>"];
1568
+ }
1569
+ if (typeof value === "function") return [];
1570
+ if (Array.isArray(value)) {
1571
+ return value.flatMap(
1572
+ (item, index) => findFrameworkStubValues(item, `${path}[${index}]`)
1573
+ );
1574
+ }
1575
+ return Object.entries(value).flatMap(
1576
+ ([key, item]) => findFrameworkStubValues(item, path ? `${path}.${key}` : key)
1577
+ );
1578
+ }
1514
1579
 
1515
1580
  // src/sync-manifest.ts
1516
1581
  var BLOCKS_CANDIDATES = [
@@ -1723,6 +1788,13 @@ async function collectManifest(options, deps) {
1723
1788
  category,
1724
1789
  regions: config.layout?.regions
1725
1790
  });
1791
+ const stubbedPaths = findFrameworkStubValues(manifest);
1792
+ if (stubbedPaths.length > 0) {
1793
+ throw new CliError(
1794
+ `${blocksPath} feeds framework values into the manifest`,
1795
+ `these entries hold a stubbed next/astro value and would be saved empty: ${stubbedPaths.join(", ")} - the manifest is read without the framework, so compute such values in the component, not in the block schema`
1796
+ );
1797
+ }
1726
1798
  return {
1727
1799
  manifest,
1728
1800
  blocksPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/cli",
3
- "version": "19.3.0",
3
+ "version": "19.3.2",
4
4
  "description": "The cmssy CLI: `cmssy init` wires cmssy into an existing Next.js, Astro or React Router app; `cmssy link` connects it to a workspace and verifies the editor wiring.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "esbuild": "^0.27.7",
31
- "@cmssy/core": "19.3.0"
31
+ "@cmssy/core": "19.3.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^20.0.0",