Lines 271-311javascript
273 * Read a manifest from disk and validate it. Two formats, one recommendation:
274 * • `.json` — THE convention (every shipped DS uses it): an inert declaration, re-read fresh on every
275 * projection, statically reviewable (the diff IS the declaration), `$schema`-validated in editors,
276 * and readable by tools that must never execute the DS. The conformance gate's declaration-keyed
277 * behavior (e.g. the `kind:"asset"` exemption) rests on these bytes being deliberate and inert.
278 * • `.ts`/`.js` — the composition escape hatch (a module's `default` or `manifest` export) for a DS
279 * that legitimately computes/composes its declaration. EXECUTED to read; same Zod validation.
281export async function loadManifestFile(absPath) {
282 if (!existsSync(absPath)) {
283 return invalid([{ field: "(file)", message: `manifest not found at ${absPath}` }]);
287 if (absPath.endsWith(".json")) {
288 raw = JSON.parse(readFileSync(absPath, "utf8"));
291 // Bust the ESM module cache with the file's mtime so an EDITED module manifest is re-read live —
292 // "re-derivation is registration" must hold for both formats (a plain `import(absPath)` freezes
293 // the first read for the life of the process). An unchanged file re-uses its cached module, so
MediumDynamic Require
Package source references dynamic require/import behavior.
dist/ds/manifest.jsView on unpkg · L291 294 // module instances stay bounded by edit count. `pathToFileURL` keeps the specifier a real URL
295 // (a raw absolute path cannot carry a query and breaks on drive-letter platforms). The param is
296 // `t` — Vite's own HMR cache-bust convention, which its transform pipeline strips; an arbitrary
297 // query name is misread as a loader hint under a Vite-driven runtime (vitest), a plain opaque
298 // query under bare node either way.
299 // (Truncated to integer ms: a fractional mtime puts a `.` in the URL tail, which an esbuild-backed
300 // transform then misreads as the file extension → "Invalid loader value".)
301 const url = pathToFileURL(absPath);
302 url.searchParams.set("t", String(Math.trunc(statSync(absPath).mtimeMs)));
303 const mod = (await import(__rewriteRelativeImportExtension(url.href)));
304 raw = mod.default ?? mod.manifest;
308 return invalid([{ field: "(file)", message: `could not read manifest: ${e.message}` }]);
310 return loadManifest(raw);