fix: migrate JSON helpers to jsonc-parser for format-preserving in-place edits

- Replace hand-rolled `JSON.parse`/`JSON.stringify` round-trips in `json.ts` with `jsonc-parser` `modify` + `applyEdits` so comments, trailing commas, indentation, and key ordering are preserved across all `setJsonPath`, `unsetJsonPath`, `mergeJson`, and `addPackageDependency` calls
- Add `setJsonPathSegments` / `unsetJsonPathSegments` for callers whose keys contain `.` (tsconfig `paths` aliases like `"@acme/ui.foo/*"` would be mis-split by the dot-path API); export both from `packages/codemods/src/index.ts`
- Refactor `set-tsconfig-paths` to use the new segment-aware helpers and drop its local `parseJsonc` + `applyEdits` usage — the builtin no longer performs raw `fs.readFileSync`/`writeFileSync` itself
- Add `jsonc-parser` to `apps/cli/package.json` (was already a transitive dep; now explicit)
- Add `"format preservation (JSONC)"` test suite covering comment/trailing-comma survival, key-ordering stability under `addPackageDependency`, dotted-key segment addressing, and no-op behavior when a parent key is absent
This commit is contained in:
jake committed 2026-05-26 22:34:18 -04:00
1 parent cf233f8275
commit e3f5b977ba
6 files changed
+200 -97

No files matched your search

+3
View File
@@ -49,6 +49,9 @@ importers:
handlebars:
specifier: ^4.7.9
version: 4.7.9
jsonc-parser:
specifier: ^3.3.1
version: 3.3.1
picocolors:
specifier: ^1.1.1
version: 1.1.1