fix(legacy-json): preserve source subdirectories in output paths#841
fix(legacy-json): preserve source subdirectories in output paths#841shivxmsharma wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview Output paths are built from each head node’s
Reviewed by Cursor Bugbot for commit 1c64086. Bugbot is set up for automated code reviews on this repo. Configure here. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #841 +/- ##
==========================================
- Coverage 84.60% 84.56% -0.04%
==========================================
Files 176 176
Lines 15802 15809 +7
Branches 1411 1411
==========================================
Hits 13369 13369
- Misses 2423 2430 +7
Partials 10 10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Right now
legacy-jsonwrites every file straight into the output root and names it after the generatedapislug, so a doc likepath/to/file.mdends up aspath-to-file.jsoninstead ofpath/to/file.json. The folder structure of the source docs gets flattened.There were two reasons for this in
src/generators/legacy-json/generate.mjs:The output filename was built from
section.api. That value is a slug (created inmetadata/utils/parse.mjs) that deliberately turns path separators into dashes, which is exactly why the subfolders disappear. The real relative path is already available on the head node ashead.path( the same fieldlegacy-htmluses ) so I now build a smallapi → pathlookup from the head nodes and use that for the filename.The file was written with
writeFilefromnode:fs/promises, which doesn't create missing folders, so writing into a subfolder would fail even with the right path. I switched to the project's ownwriteFilefromutils/file.mjs, which creates the parent directories first (again, the helperlegacy-htmlalready uses).The change is contained to the write path:
processChunkand the yielded sections are untouched, so nothing downstream (likelegacy-json-all) is affected.Validation
Running the generator on a few docs that live in subfolders:
node bin/cli.mjs generate -i "docs/**/*.md" -t legacy-json -o out -v 18.0.0Before:
After:
The subfolders are preserved and created automatically, and the generated JSON is unchanged otherwise.
If you're reviewing, the thing to check is that the output path now comes from
path(viawithExt(path, 'json')) instead ofsection.api, and thatwriteFileis imported fromutils/file.mjs.node --run testpasses for me. The only suites that fail (api-links,jsx-ast,web) fail the exact same way on a cleanmain, so they're unrelated to this change.node --run lintandnode --run formatare clean.One related thing I noticed but left out on purpose:
buildSection.mjsbuilds itssourcefield asdoc/api/${head.api}.md(you can see it in the output above asdoc/api/sub-deepgamma.md), which has the same slug-vs-path problem for files in subfolders. I kept this PR focused on the output path since that's what the issue is about. Happy to fixsourcehere too or in a follow-up, whichever you'd prefer.Related Issues
Fixes #838
Check List
node --run testand all tests passed.node --run format&node --run lint.