Repository navigation
Description
Problem
- Dev-mode
requireis broken. Thejson-devcondition on"."mapsrequireto./src/cjs/index.cjs, which doesn't exist onnext(src/has no.cjsfiles). Sorequire("@cldmv/jsonv")with--conditions=json-devfails to resolve. - The condition has the wrong name. It's
json-dev, notjsonv-dev. The fleet namespaces the condition by package name so it can't collide with another package's condition. - The CJS wrappers live in a
cjs/folder.scripts/build-cjs.mjswrites thinrequire(esm)wrappers intodist/cjs/(dist/cjs/index.cjs,dist/cjs/years/*.cjs) instead of beside their ESM files. That gives each entry two parallel trees, and the wrappers can't be tested from source. - The build is a chain of custom scripts:
tsc(build:ts),tscagain for types,scripts/generate-years.mjs,scripts/build-cjs.mjs.
Target layout
The convention is in CLDMV/llm-translator (PR #1): a hand-written src/index.cjs beside the ESM entry, copied verbatim beside its built ESM file.
package.json "." → { "jsonv-dev": { types: ./src/index.mts, import: ./src/index.mts },
types: ./dist/types/index.d.mts, import: ./dist/index.mjs, require: ./dist/index.cjs }
"./parser", "./*" (years) → same pattern, jsonv-dev → src/
src/
index.mts the real exports
index.cjs require_module guard + require("./index.mjs") — copied to dist/index.cjs
dist/
index.mjs, index.cjs (no dist/cjs/)
years/<year>.mjs, years/<year>.cjs
Tasks
-
Rename the condition
json-dev→jsonv-deveverywhere:package.jsonexports, the vitest config, and test/CJS scripts. -
Fix dev-mode
require. The source is TypeScript (.mts), so asrc/index.cjsdoingrequire("./index.mjs")has no sibling to load insrc/. Pick one, and document it in the README's development section:- (a) leave
requireoff thejsonv-devcondition, so CJS consumers in a checkout getdist/(tested bytests/cjs/entry.test.cjs); or - (b) have the CJS wrapper load the
.mtsthrough Node's type stripping (Node ≥ 22.18 / 23.6).
Either way, remove the pointer to the missing
./src/cjs/index.cjs. - (a) leave
-
Move the wrappers next to their ESM files:
dist/index.cjsbesidedist/index.mjs,dist/years/<year>.cjsbesidedist/years/<year>.mjs. Dropdist/cjs/anddist/types/cjs/, and updatemain,exports.requireand the wrappers'requirepaths. Writesrc/index.cjsby hand, as in llm-translator. The per-year wrappers can stay generated, but are written beside each year's.mjs. -
Build: consider replacing the
tsc+ script chain with tsup, which handles.mts; keepgenerate:yearsandbuild:types. -
package.json:engines.node:^20.19.0 || >=22.13.0, because the CJS entry needsrequire(esm)and Node 22.12.x warns whenrequire()loads ESM (today>=18.0.0)
-
Tests: pass
--conditions=jsonv-devto vitest (resolve.conditions,ssr.resolve.conditions,test.nodeOptions) and tonode --test.tests/cjs/entry.test.cjscoversdist/index.cjsand a sampledist/years/<year>.cjs. -
ci.yml:coverage_build_command: "npm run build:ci".bundle-size.yml:dist_paths= the realdist/output.
Compatibility
json-devrename: only affects contributors running from a checkout; published consumers never see it.dist/cjs/→dist/*.cjsmove: invisible to consumers going throughexports.- Deep
requires of@cldmv/jsonv/dist/cjs/...:exportsdoesn't expose these paths, so no consumer can be relying on them.
Activity
Shinrai commentedon Oct 31, 2026
Before this gets picked up: don't use the fire-and-forget async devcheck block from the task list. It doesn't gate anything. Code that imports the package and calls it straight away runs before devcheck exits, from ESM and from CJS. Load it synchronously at the top of
src/index.mtsinstead:Still no top-level await, so the CJS wrappers'
require(esm)keeps working. Keep the../devcheck.mjsspecifier unchanged in the build output (external in tsup, or as-is fromtsc). The dist test should look for the"../devcheck.mjs"specifier indist/index.mjs, not forimport(...).Working copy is fix-headers'
src/index.mjsin CLDMV/fix-headers#165 (ships in 2.2.4).Shinrai commentedon Oct 31, 2026
Correction to my comment above: don't use that block either. The static
import { createRequire } from "node:module"breaks browser bundles (esbuild and webpack fail the build, Vite's bundle throws at load), and jsonv runs in browsers. Use this instead:Same synchronous gate, nothing for a bundler to resolve, and it skips itself in a browser. Checked against esbuild/webpack/Vite (browser and node), headless Chrome loading
src/directly, Node 20.19 / 22.12 / 26, ESM and CJS, and from a.mtsentry under Node's type stripping. Working copy is still CLDMV/fix-headers#165.Shinrai commentedon Nov 1, 2026
One more thing with the sync devcheck load: on Node 22.12.x,
require()ofdevcheck.mjsprints anExperimentalWarning(require of an ES module) on every source-checkout run. 20.19 and 22.13+ don't warn. Consumers of the published package never hit it sincedevcheck.mjsisn't shipped.When you adopt it, set
engines.nodeto^20.19.0 || >=22.13.0(the CJS shim needsrequire(esm)anyway, so anything below 20.19 is already wrong) and keep the CImin_node_versionoff 22.12. fix-headers went to>=22.13.0in CLDMV/fix-headers#165.[-]Adopt the CLDMV library layout: fix the broken dev-mode require, rename json-dev → jsonv-dev, CJS wrappers beside their ESM files, devcheck[/-][+]Adopt the CLDMV library layout: fix the broken dev-mode require, rename json-dev → jsonv-dev, CJS wrappers beside their ESM files[/+]Shinrai commentedon Nov 1, 2026
Dropped the devcheck part, it's being removed from all the packages instead.
cldmv-bot commentedon Nov 1, 2026
Marked
status: implemented— resolved by #112, merged intonext. This issue closes automatically when that work ships to the default branch.release: v1.2.0 - adopt the CLDMV library layout (jsonv-dev condition,…