@takazudo/zudo-sg 0.5.1 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,46 @@ All notable changes to `@takazudo/zudo-sg` are documented in this file.
4
4
 
5
5
  The format is based on Keep a Changelog, and release notes are generated from the changelog MDX pages.
6
6
 
7
+ ## [0.5.3] - 2026-10-13
8
+
9
+ This maintenance release fixes catalog-root resolution beneath a symlinked
10
+ directory and raises the first-party peer floors to the versions the engine is
11
+ built and tested against. The public API is unchanged.
12
+
13
+ ### Bug Fixes
14
+
15
+ - A configured catalog root can now sit beneath a symlinked ancestor directory,
16
+ such as a checkout reached through a symlink. A symlink at the root itself,
17
+ including a dangling one, and any symlink below the root are still rejected.
18
+ Missing output directories are created only after a successful capture, and
19
+ component walks use the platform path root so a Windows drive prefix is not
20
+ skipped.
21
+
22
+ ### Other Changes
23
+
24
+ - Peer floors now follow the newest first-party releases: `@takazudo/zfb`
25
+ ^4.3.3 (was ^4.3.1) and `@takazudo/zudo-doc` ^6.1.1 (was ^6.0.0).
26
+ `@takazudo/zdtp` stays at ^0.8.6. Hosts on older zfb or zudo-doc versions
27
+ need to upgrade those together with the engine.
28
+
29
+ ## [0.5.2] - 2026-10-12
30
+
31
+ This maintenance release raises the minimum versions of the engine's CodeMirror
32
+ and Lezer runtime dependencies and documents how hosts recover from a stale
33
+ Lezer lockfile. The public API is unchanged.
34
+
35
+ ### Other Changes
36
+
37
+ - Raise the runtime dependency minimums to `@codemirror/view` ^6.43.14 and
38
+ `@lezer/highlight` ^1.2.5, so fresh installs resolve the versions the code
39
+ panel is tested against.
40
+ - The README now explains how a host lockfile that keeps an older
41
+ `@lezer/common` breaks code-panel highlighting, and how `pnpm dedupe`
42
+ fixes it.
43
+ - Development tooling only: TypeScript checks now run on the native
44
+ TypeScript 7 compiler through the TypeScript 6 API, and test dependencies
45
+ were updated (`@testing-library/jest-dom` 7, `@types/node` 22.20.5).
46
+
7
47
  ## [0.5.1] - 2026-10-12
8
48
 
9
49
  This release adds an opt-in, same-origin external preview runtime contract with
package/README.md CHANGED
@@ -132,10 +132,10 @@ output as drift and never writes it.
132
132
  ## Installation
133
133
 
134
134
  ```sh
135
- pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^4.3.1 @takazudo/zfb-md-wasm@^4.3.1 @takazudo/zfb-runtime@^4.3.1 @takazudo/zudo-doc@^6.0.0 @takazudo/zdtp@^0.8.6 diff@^8.0.4 katex@^0.16.38 zod@^4.3.6
135
+ pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^4.3.3 @takazudo/zfb-md-wasm@^4.3.3 @takazudo/zfb-runtime@^4.3.3 @takazudo/zudo-doc@^6.1.1 @takazudo/zdtp@^0.8.6 diff@^8.0.4 katex@^0.16.38 zod@^4.3.6
136
136
  ```
137
137
 
138
- The engine peers are `@takazudo/zfb ^4.3.1`, `@takazudo/zudo-doc ^6.0.0`,
138
+ The engine peers are `@takazudo/zfb ^4.3.3`, `@takazudo/zudo-doc ^6.1.1`,
139
139
  and `@takazudo/zdtp ^0.8.6`. `@takazudo/zdtp` is required:
140
140
  the injected `/tokens` route loads its dashboard through the engine-owned
141
141
  opaque Preact adapter. Preact is a regular engine dependency, not a host peer. The
@@ -153,6 +153,39 @@ and `manifestOut` to populate the `/tokens` dashboards. Manual adopters should
153
153
  also retain `@takazudo/zdtp`, `diff`, and `katex`; they are required host
154
154
  dependencies, not optional extras.
155
155
 
156
+ ## Recover highlighting in an existing consumer lock
157
+
158
+ An existing lock can retain two `@lezer/common` module identities even after
159
+ installing compatible engine/editor versions. The visible symptom is missing
160
+ TSX or editable CSS highlighting with a CodeMirror plugin error
161
+ `tags is not iterable` (the variable name can differ in a minified bundle);
162
+ successful editor construction or typing does not
163
+ establish that highlighting works.
164
+
165
+ From the affected host, diagnose and deduplicate its own graph:
166
+
167
+ ```sh
168
+ pnpm dedupe --check
169
+ pnpm dedupe --ignore-scripts
170
+ pnpm install --frozen-lockfile
171
+ ```
172
+
173
+ The first command is diagnostic and exits nonzero when deduplication is needed.
174
+ Review the resulting lock diff. Rebuild the host's generated output from scratch
175
+ (the packed proof removes only `dist` and `.zfb-build` before `pnpm exec zfb build`),
176
+ then verify TSX source tokens, editable CSS tokens, Live CSS application and
177
+ clearing, preview isolation, and absence of plugin/browser errors.
178
+ An ordinary or frozen install alone can preserve the split.
179
+
180
+ This recovery is scoped to pnpm **11.5.2**; other package managers need their own
181
+ resolution proof. It is consumer remediation, not a universal package-side fix.
182
+ Published compatible Lezer ranges still admit older common modules; direct
183
+ floors or a root-workspace dedupe check do not guarantee every retained consumer
184
+ lock. The separate packed diagnostic `pnpm verify:retained-lezer-lock` in the
185
+ engine repository preserves a clean control and treats the pre-recovery failure
186
+ as expected evidence. Track the remaining compatibility requirement in
187
+ [zudo-sg#963](https://github.com/Takazudo/zudo-sg/issues/963).
188
+
156
189
  ## Composing it into a host
157
190
 
158
191
  ```ts
@@ -182,7 +215,7 @@ control. Any non-empty host navigation stays authoritative; set
182
215
  `chromeDefaults: false` in the second argument to keep an intentionally empty
183
216
  header. The engine requires `packageOwnedRoutes: true` on the host (its
184
217
  routes import zudo-doc's route-context virtual modules). On the engine's zfb
185
- peer floor (4.3.1) nothing else is needed: `zfb dev` seeds its island
218
+ peer floor (4.3.3) nothing else is needed: `zfb dev` seeds its island
186
219
  scanner from the injected routes. `@takazudo/zudo-sg/islands` remains
187
220
  exported as a side-effect module that statically imports every engine
188
221
  island — importing it once from a host `pages/` file is optional and
@@ -472,8 +505,13 @@ the browser bundle. The engine does not install a browser or import React.
472
505
  - `validateExternalCatalogAssets({manifest, projectRoot, assetRoot, captures})`
473
506
  checks capture receipts against files. Missing images, stale loader/source
474
507
  hashes, wrong image hash/dimensions/fixture identity, and `failed` dispositions
475
- throw. Intentional placeholders remain labelled. Paths reject symlinks,
476
- including parents, before reading/writing. Captures must be complete,
508
+ throw. Intentional placeholders remain labelled. A project or asset root may
509
+ sit below a symlinked ancestor, including macOS `/var` and `/tmp`. The
510
+ configured root itself must be a real directory or absent: a live or dangling
511
+ symlink there is rejected, and so is every symlink beneath that root, even
512
+ one that points back inside it. Missing output directories are created only
513
+ after a successful capture; preflight, validation, and a failed capture do
514
+ not create them. Captures must be complete,
477
515
  noninterlaced 8-bit PNGs of at most 16,777,216 pixels, matching the declared
478
516
  viewport dimensions. Only IHDR/IDAT/IEND critical chunks are supported;
479
517
  palette chunks are outside this browser screenshot format. Legacy descriptor
@@ -0,0 +1,7 @@
1
+ import path from "node:path";
2
+ /**
3
+ * Components of an absolute path, from the first real segment through the leaf.
4
+ * `path.parse().root` keeps a Windows drive or UNC prefix. A prefix built only
5
+ * from `path.sep` becomes `\C:` and the walk then stops.
6
+ */
7
+ export declare function absoluteComponents(candidate: string, pathImpl?: typeof path): string[];
@@ -0,0 +1,16 @@
1
+ import path from "node:path";
2
+ function absoluteComponents(candidate, pathImpl = path) {
3
+ const { root } = pathImpl.parse(candidate);
4
+ if (root === "") return [];
5
+ const cursors = [];
6
+ let cursor = root;
7
+ for (const part of candidate.slice(root.length).split(pathImpl.sep)) {
8
+ if (part === "") continue;
9
+ cursor = pathImpl.join(cursor, part);
10
+ cursors.push(cursor);
11
+ }
12
+ return cursors;
13
+ }
14
+ export {
15
+ absoluteComponents
16
+ };
@@ -1,6 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
- import { lstatSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
2
+ import { lstatSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
4
+ import { absoluteComponents } from "./catalog-path.js";
4
5
  import { inflateSync } from "node:zlib";
5
6
  import { isExternalRuntimeIdentity, isJsonValue, matchesExternalRuntimeIdentity } from "../preview/external-runtime.js";
6
7
  import { validateStoryDescriptors } from "./descriptors.js";
@@ -64,25 +65,71 @@ function validateExternalCatalogOutputs(input) {
64
65
  }
65
66
  return manifest;
66
67
  }
67
- function containedPath(root, path, createParents = false) {
68
- const boundary = resolve(root);
69
- const candidate = resolve(boundary, path);
70
- const rel = relative(boundary, candidate);
71
- if (!rel || isAbsolute(rel) || rel === ".." || rel.startsWith(`..${sep}`)) fail(`path escapes asset/project root: ${path}`);
72
- let cursor = boundary;
73
- const ancestors = [];
68
+ function errno(error) {
69
+ return error.code;
70
+ }
71
+ function canonicalDirectory(path) {
72
+ let canonical;
73
+ try {
74
+ canonical = realpathSync(path);
75
+ } catch (error) {
76
+ if (errno(error) !== "ENOENT") throw error;
77
+ return fail(`catalog root is not a directory: ${path}`);
78
+ }
79
+ try {
80
+ const listed = lstatSync(canonical);
81
+ if (!listed.isSymbolicLink() && listed.isDirectory()) return canonical;
82
+ } catch (error) {
83
+ if (errno(error) !== "ENOENT") throw error;
84
+ }
85
+ return fail(`catalog root is not a directory: ${path}`);
86
+ }
87
+ function resolveCatalogRoot(root) {
88
+ const absolute = resolve(root);
89
+ try {
90
+ const listed = lstatSync(absolute);
91
+ if (listed.isSymbolicLink()) fail(`symlink is not allowed: ${absolute}`);
92
+ if (!listed.isDirectory()) fail(`catalog root is not a directory: ${absolute}`);
93
+ return canonicalDirectory(absolute);
94
+ } catch (error) {
95
+ if (errno(error) !== "ENOENT") throw error;
96
+ }
97
+ const missing = [];
98
+ let cursor = absolute;
74
99
  for (; ; ) {
75
- ancestors.unshift(cursor);
76
100
  const parent = dirname(cursor);
77
- if (parent === cursor) break;
101
+ if (parent === cursor) fail(`catalog root has no existing ancestor: ${absolute}`);
102
+ missing.unshift(basename(cursor));
78
103
  cursor = parent;
104
+ try {
105
+ const listed = lstatSync(cursor);
106
+ if (listed.isSymbolicLink()) {
107
+ let target;
108
+ try {
109
+ target = realpathSync(cursor);
110
+ } catch (error) {
111
+ if (errno(error) !== "ENOENT") throw error;
112
+ return fail(`symlink is not allowed: ${cursor}`);
113
+ }
114
+ return resolve(canonicalDirectory(target), ...missing);
115
+ }
116
+ if (!listed.isDirectory()) fail(`catalog root is not a directory: ${cursor}`);
117
+ return resolve(canonicalDirectory(cursor), ...missing);
118
+ } catch (error) {
119
+ if (errno(error) !== "ENOENT") throw error;
120
+ }
79
121
  }
80
- const paths = [...ancestors, ...rel.split(sep).map((_, i, parts) => resolve(boundary, ...parts.slice(0, i + 1)))];
81
- for (const part of paths) {
122
+ }
123
+ function containedPath(boundary, path, createParents = false) {
124
+ const candidate = resolve(boundary, path);
125
+ const rel = relative(boundary, candidate);
126
+ if (!rel || isAbsolute(rel) || rel === ".." || rel.startsWith(`..${sep}`)) fail(`path escapes asset/project root: ${path}`);
127
+ for (const cursor of absoluteComponents(candidate)) {
82
128
  try {
83
- if (lstatSync(part).isSymbolicLink()) fail(`symlink is not allowed: ${part}`);
129
+ if (lstatSync(cursor).isSymbolicLink()) fail(`symlink is not allowed: ${cursor}`);
84
130
  } catch (error) {
85
- if (error.code !== "ENOENT") throw error;
131
+ if (errno(error) !== "ENOENT") throw error;
132
+ break;
86
133
  }
87
134
  }
88
135
  if (createParents) mkdirSync(dirname(candidate), { recursive: true });
@@ -140,17 +187,17 @@ function pngDimensions(bytes) {
140
187
  for (let y = 0; y < height; y++) if (raw[y * stride] > 4) fail("invalid PNG row filter");
141
188
  return { width, height };
142
189
  }
143
- function validateExternalCatalogAssets(options) {
190
+ function validateResolvedCatalogAssets(options, projectRoot, assetRoot) {
144
191
  const manifest = validateExternalCatalogManifest(options.manifest);
145
192
  const receipts = keyed(options.captures, "capture receipts");
146
193
  sameKeys(manifest.filter((row) => row.capture.kind === "image").map((row) => row.loader.key), receipts, "capture receipts");
147
194
  for (const row of manifest) {
148
195
  thumbnailFromExternalCapture(row.capture);
149
- const currentLoaderHash = loaderHash(options.projectRoot, row);
196
+ const currentLoaderHash = loaderHash(projectRoot, row);
150
197
  if (row.capture.kind !== "image") continue;
151
198
  const capture = row.capture, receipt = receipts.get(capture.key);
152
199
  if (!isExternalRuntimeIdentity(receipt.runtime) || receipt.runtime.slug !== row.slug || receipt.runtime.variant !== row.variant || receipt.stability !== "runtime.whenStable" || receipt.fixture?.module !== row.loader.module || receipt.fixture.exportName !== row.loader.exportName || receipt.src !== capture.src || receipt.width !== capture.width || receipt.height !== capture.height || receipt.loaderSha256 !== currentLoaderHash || receipt.sourceSha256 !== hash(row.source.code)) fail(`stale/mismatched capture receipt for ${capture.key}`);
153
- const path = containedPath(options.assetRoot, `.${capture.src}`);
200
+ const path = containedPath(assetRoot, `.${capture.src}`);
154
201
  let image;
155
202
  try {
156
203
  image = readFileSync(path);
@@ -161,8 +208,13 @@ function validateExternalCatalogAssets(options) {
161
208
  if (dimensions.width !== capture.width || dimensions.height !== capture.height || hash(image) !== receipt.imageSha256) fail(`image bytes/dimensions differ for ${capture.key}`);
162
209
  }
163
210
  }
211
+ function validateExternalCatalogAssets(options) {
212
+ validateResolvedCatalogAssets(options, resolveCatalogRoot(options.projectRoot), resolveCatalogRoot(options.assetRoot));
213
+ }
164
214
  async function captureExternalCatalogImages(options) {
165
215
  const manifest = validateExternalCatalogManifest(options.manifest);
216
+ const projectRoot = resolveCatalogRoot(options.projectRoot);
217
+ const assetRoot = resolveCatalogRoot(options.assetRoot);
166
218
  const origin = new URL(options.origin);
167
219
  if (!["http:", "https:"].includes(origin.protocol) || origin.origin !== options.origin || origin.username || origin.password) fail("origin must be an HTTP(S) origin without path or credentials");
168
220
  const base = options.base ?? "/";
@@ -171,13 +223,13 @@ async function captureExternalCatalogImages(options) {
171
223
  const receipts = [];
172
224
  for (const row of manifest) {
173
225
  thumbnailFromExternalCapture(row.capture);
174
- loaderHash(options.projectRoot, row);
175
- if (row.capture.kind === "image") containedPath(options.assetRoot, `.${row.capture.src}`);
226
+ loaderHash(projectRoot, row);
227
+ if (row.capture.kind === "image") containedPath(assetRoot, `.${row.capture.src}`);
176
228
  }
177
229
  for (const row of manifest) {
178
230
  const capture = row.capture;
179
231
  if (capture.kind !== "image") continue;
180
- const initialLoaderHash = loaderHash(options.projectRoot, row);
232
+ const initialLoaderHash = loaderHash(projectRoot, row);
181
233
  const url = new URL(base.replace(/\/$/, "") + options.previewUrl, origin);
182
234
  url.searchParams.set("slug", row.slug);
183
235
  url.searchParams.set("variant", row.variant);
@@ -193,9 +245,9 @@ async function captureExternalCatalogImages(options) {
193
245
  await check();
194
246
  const dimensions = pngDimensions(image);
195
247
  if (dimensions.width !== capture.width || dimensions.height !== capture.height) fail(`capture dimensions differ for ${capture.key}`);
196
- if (loaderHash(options.projectRoot, row) !== initialLoaderHash) fail(`loader changed during capture: ${capture.key}`);
197
- const path = containedPath(options.assetRoot, `.${capture.src}`, true);
198
- containedPath(options.assetRoot, `.${capture.src}`);
248
+ if (loaderHash(projectRoot, row) !== initialLoaderHash) fail(`loader changed during capture: ${capture.key}`);
249
+ const path = containedPath(assetRoot, `.${capture.src}`, true);
250
+ containedPath(assetRoot, `.${capture.src}`);
199
251
  writeFileSync(path, image, { flag: "w" });
200
252
  receipts.push({
201
253
  key: capture.key,
@@ -209,7 +261,7 @@ async function captureExternalCatalogImages(options) {
209
261
  stability: "runtime.whenStable"
210
262
  });
211
263
  }
212
- validateExternalCatalogAssets({ ...options, captures: receipts });
264
+ validateResolvedCatalogAssets({ ...options, captures: receipts }, projectRoot, assetRoot);
213
265
  return receipts;
214
266
  }
215
267
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takazudo/zudo-sg",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "description": "zudo-sg styleguide engine — story registry, catalog routes and preview machinery for zfb + zudo-doc hosts.",
6
6
  "license": "MIT",
@@ -152,27 +152,28 @@
152
152
  "@codemirror/lang-javascript": "^6.0.0",
153
153
  "@codemirror/language": "^6.13.1",
154
154
  "@codemirror/state": "^6.7.6",
155
- "@codemirror/view": "^6.0.0",
156
- "@lezer/highlight": "^1.0.0",
155
+ "@codemirror/view": "^6.43.14",
156
+ "@lezer/highlight": "^1.2.5",
157
157
  "postcss": "^8.5.28",
158
158
  "preact": "^10.29.1"
159
159
  },
160
160
  "peerDependencies": {
161
- "@takazudo/zfb": "^4.3.1",
161
+ "@takazudo/zfb": "^4.3.3",
162
162
  "@takazudo/zdtp": "^0.8.6",
163
- "@takazudo/zudo-doc": "^6.0.0"
163
+ "@takazudo/zudo-doc": "^6.1.1"
164
164
  },
165
165
  "devDependencies": {
166
166
  "@takazudo/zdtp": "0.8.6",
167
- "@takazudo/zfb": "4.3.1",
168
- "@takazudo/zudo-doc": "6.0.0",
169
- "@testing-library/jest-dom": "^6.9.1",
167
+ "@takazudo/zfb": "4.3.3",
168
+ "@takazudo/zudo-doc": "6.1.1",
169
+ "@testing-library/jest-dom": "^7.0.1",
170
170
  "@types/culori": "^4.0.1",
171
- "@types/node": "^22.0.0",
171
+ "@types/node": "^22.20.5",
172
172
  "culori": "^4.0.2",
173
173
  "happy-dom": "20.14.6",
174
174
  "tsup": "^8.5.0",
175
- "typescript": "^5.9.0",
175
+ "@typescript/native": "npm:typescript@^7.0.2",
176
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
176
177
  "vite": "7.3.5",
177
178
  "vitest": "4.1.11"
178
179
  },