@takazudo/zudo-sg 0.5.2 → 0.5.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.
- package/CHANGELOG.md +36 -0
- package/README.md +10 -5
- package/dist/registry/catalog-path.d.ts +7 -0
- package/dist/registry/catalog-path.js +16 -0
- package/dist/registry/external-catalog-node.js +77 -25
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,42 @@ 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.4] - 2026-10-13
|
|
8
|
+
|
|
9
|
+
This maintenance release raises the zfb peer floor to the version the engine is
|
|
10
|
+
built and tested against. The public API is unchanged.
|
|
11
|
+
|
|
12
|
+
### Other Changes
|
|
13
|
+
|
|
14
|
+
- The `@takazudo/zfb` peer floor is now ^4.4.0 (was ^4.3.3).
|
|
15
|
+
`@takazudo/zudo-doc` stays at ^6.1.1 and `@takazudo/zdtp` at ^0.8.6. Hosts on
|
|
16
|
+
an older zfb need to upgrade it together with the engine.
|
|
17
|
+
- Fragment-history navigation is covered end to end under zfb 4.4.0: Back
|
|
18
|
+
restores the page behind a browser-created hash entry, and the following
|
|
19
|
+
Forward is reported as a forward navigation.
|
|
20
|
+
|
|
21
|
+
## [0.5.3] - 2026-10-13
|
|
22
|
+
|
|
23
|
+
This maintenance release fixes catalog-root resolution beneath a symlinked
|
|
24
|
+
directory and raises the first-party peer floors to the versions the engine is
|
|
25
|
+
built and tested against. The public API is unchanged.
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
- A configured catalog root can now sit beneath a symlinked ancestor directory,
|
|
30
|
+
such as a checkout reached through a symlink. A symlink at the root itself,
|
|
31
|
+
including a dangling one, and any symlink below the root are still rejected.
|
|
32
|
+
Missing output directories are created only after a successful capture, and
|
|
33
|
+
component walks use the platform path root so a Windows drive prefix is not
|
|
34
|
+
skipped.
|
|
35
|
+
|
|
36
|
+
### Other Changes
|
|
37
|
+
|
|
38
|
+
- Peer floors now follow the newest first-party releases: `@takazudo/zfb`
|
|
39
|
+
^4.3.3 (was ^4.3.1) and `@takazudo/zudo-doc` ^6.1.1 (was ^6.0.0).
|
|
40
|
+
`@takazudo/zdtp` stays at ^0.8.6. Hosts on older zfb or zudo-doc versions
|
|
41
|
+
need to upgrade those together with the engine.
|
|
42
|
+
|
|
7
43
|
## [0.5.2] - 2026-10-12
|
|
8
44
|
|
|
9
45
|
This maintenance release raises the minimum versions of the engine's CodeMirror
|
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.
|
|
135
|
+
pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^4.4.0 @takazudo/zfb-md-wasm@^4.4.0 @takazudo/zfb-runtime@^4.4.0 @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.
|
|
138
|
+
The engine peers are `@takazudo/zfb ^4.4.0`, `@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
|
|
@@ -215,7 +215,7 @@ control. Any non-empty host navigation stays authoritative; set
|
|
|
215
215
|
`chromeDefaults: false` in the second argument to keep an intentionally empty
|
|
216
216
|
header. The engine requires `packageOwnedRoutes: true` on the host (its
|
|
217
217
|
routes import zudo-doc's route-context virtual modules). On the engine's zfb
|
|
218
|
-
peer floor (4.
|
|
218
|
+
peer floor (4.4.0) nothing else is needed: `zfb dev` seeds its island
|
|
219
219
|
scanner from the injected routes. `@takazudo/zudo-sg/islands` remains
|
|
220
220
|
exported as a side-effect module that statically imports every engine
|
|
221
221
|
island — importing it once from a host `pages/` file is optional and
|
|
@@ -505,8 +505,13 @@ the browser bundle. The engine does not install a browser or import React.
|
|
|
505
505
|
- `validateExternalCatalogAssets({manifest, projectRoot, assetRoot, captures})`
|
|
506
506
|
checks capture receipts against files. Missing images, stale loader/source
|
|
507
507
|
hashes, wrong image hash/dimensions/fixture identity, and `failed` dispositions
|
|
508
|
-
throw. Intentional placeholders remain labelled.
|
|
509
|
-
|
|
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,
|
|
510
515
|
noninterlaced 8-bit PNGs of at most 16,777,216 pixels, matching the declared
|
|
511
516
|
viewport dimensions. Only IHDR/IDAT/IEND critical chunks are supported;
|
|
512
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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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)
|
|
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
|
-
|
|
81
|
-
|
|
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(
|
|
129
|
+
if (lstatSync(cursor).isSymbolicLink()) fail(`symlink is not allowed: ${cursor}`);
|
|
84
130
|
} catch (error) {
|
|
85
|
-
if (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
|
|
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(
|
|
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(
|
|
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(
|
|
175
|
-
if (row.capture.kind === "image") containedPath(
|
|
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(
|
|
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(
|
|
197
|
-
const path = containedPath(
|
|
198
|
-
containedPath(
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.5.4",
|
|
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",
|
|
@@ -158,14 +158,14 @@
|
|
|
158
158
|
"preact": "^10.29.1"
|
|
159
159
|
},
|
|
160
160
|
"peerDependencies": {
|
|
161
|
-
"@takazudo/zfb": "^4.
|
|
161
|
+
"@takazudo/zfb": "^4.4.0",
|
|
162
162
|
"@takazudo/zdtp": "^0.8.6",
|
|
163
|
-
"@takazudo/zudo-doc": "^6.
|
|
163
|
+
"@takazudo/zudo-doc": "^6.1.1"
|
|
164
164
|
},
|
|
165
165
|
"devDependencies": {
|
|
166
166
|
"@takazudo/zdtp": "0.8.6",
|
|
167
|
-
"@takazudo/zfb": "4.
|
|
168
|
-
"@takazudo/zudo-doc": "6.
|
|
167
|
+
"@takazudo/zfb": "4.4.0",
|
|
168
|
+
"@takazudo/zudo-doc": "6.1.1",
|
|
169
169
|
"@testing-library/jest-dom": "^7.0.1",
|
|
170
170
|
"@types/culori": "^4.0.1",
|
|
171
171
|
"@types/node": "^22.20.5",
|