Skip to content

refactor(migration): simplify JSON config merging by using direct file content#378

Merged
fengmk2 merged 2 commits intomainfrom
merge-json-config-support-jsonc-format
Jan 6, 2026
Merged

refactor(migration): simplify JSON config merging by using direct file content#378
fengmk2 merged 2 commits intomainfrom
merge-json-config-support-jsonc-format

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Dec 26, 2025

Improves the Vite config migration process by directly using JSON/JSONC content in JavaScript context instead of parsing and converting it. Since JSON is valid JavaScript, this approach:

  1. Preserves comments in JSONC files (both // and /* */ style)
  2. Maintains the original formatting and structure of config files
  3. Removes ~130 lines of complex JSON-to-JS conversion code
  4. Fixes the TODO for handling JSONC files in the migrator

The PR includes tests to verify that comments in JSONC files are properly preserved during migration.

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Copy link
Member Author

fengmk2 commented Dec 26, 2025

@fengmk2 fengmk2 self-assigned this Dec 26, 2025
@fengmk2 fengmk2 changed the title feat(migration): add JSONC format support to merge_json_config refactor(migration): simplify JSON config merging by using direct file content Dec 27, 2025
@fengmk2 fengmk2 force-pushed the merge-json-config-support-jsonc-format branch from 5dd3d8a to 1dfdbcc Compare December 27, 2025 01:41
@fengmk2 fengmk2 changed the base branch from main to graphite-base/378 January 4, 2026 12:06
@fengmk2 fengmk2 force-pushed the merge-json-config-support-jsonc-format branch from 1dfdbcc to 157a975 Compare January 4, 2026 12:06
@fengmk2 fengmk2 changed the base branch from graphite-base/378 to 01-04-test_e2e_skip_rollipop_lint_check January 4, 2026 12:06
@fengmk2 fengmk2 marked this pull request as ready for review January 4, 2026 12:07
@fengmk2 fengmk2 requested a review from Brooooooklyn January 4, 2026 12:07
This was referenced Jan 4, 2026
@fengmk2 fengmk2 changed the base branch from 01-04-test_e2e_skip_rollipop_lint_check to graphite-base/378 January 4, 2026 12:39
@fengmk2 fengmk2 force-pushed the graphite-base/378 branch from 402e5df to 0971535 Compare January 4, 2026 12:42
@fengmk2 fengmk2 force-pushed the merge-json-config-support-jsonc-format branch from 157a975 to 587ea35 Compare January 4, 2026 12:42
@graphite-app graphite-app bot changed the base branch from graphite-base/378 to main January 4, 2026 12:43
@fengmk2 fengmk2 force-pushed the merge-json-config-support-jsonc-format branch from 587ea35 to 070a557 Compare January 4, 2026 12:43
Copilot AI review requested due to automatic review settings January 5, 2026 11:14
@fengmk2 fengmk2 force-pushed the merge-json-config-support-jsonc-format branch from 070a557 to 4a5de30 Compare January 5, 2026 11:14
fengmk2 and others added 2 commits January 5, 2026 19:20
Use json-strip-comments crate to strip comments before parsing,
enabling support for .jsonc config files with // and /* */ comments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Simplify implementation by using JSON/JSONC content directly as valid JS.
No parsing or conversion needed - just read file and merge.

- Remove json-strip-comments dependency (not needed)
- Remove json_to_js_object_literal and helper functions
- Comments in JSONC files are preserved in output

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@fengmk2 fengmk2 force-pushed the merge-json-config-support-jsonc-format branch from 4a5de30 to 65ceee6 Compare January 5, 2026 11:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Vite configuration migration process by treating JSON/JSONC content as valid JavaScript instead of parsing and converting it. The approach leverages the fact that JSON is valid JavaScript syntax, and comments (from JSONC) are also valid in JavaScript contexts.

  • Removes ~130 lines of JSON-to-JavaScript conversion code including helper functions for escaping, identifier validation, and reserved word checking
  • Adds comprehensive test coverage for JSONC comment preservation (single-line, block, and inline comments)
  • Removes the TODO comment about handling JSONC files, as the new approach naturally supports them

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/global/src/migration/migrator.ts Removes TODO comment about JSONC handling since the refactored approach now handles it
packages/global/snap-tests/migration-monorepo-yarn4/snap.txt Updates test snapshot to reflect double-quoted JSON style in merged config
packages/global/snap-tests/migration-monorepo-pnpm/snap.txt Updates test snapshots for both root and package configs with double-quoted JSON style
packages/global/snap-tests/migration-merge-vite-config-ts/snap.txt Updates test snapshot to show merged config with JSON-style double quotes
packages/global/snap-tests/migration-merge-vite-config-js/snap.txt Updates test snapshot for JavaScript config with double-quoted merged content
packages/global/snap-tests/migration-from-tsdown-json-config/snap.txt Updates snapshots to show tsdown config merges using double-quoted JSON style
packages/global/snap-tests/migration-auto-create-vite-config/snap.txt Updates snapshot for auto-created config with double-quoted merged JSON content
crates/vite_migration/src/vite_config.rs Simplifies JSON merging by using raw file content, removes conversion logic, adds JSONC tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fengmk2 fengmk2 merged commit 6e4eef6 into main Jan 6, 2026
12 of 13 checks passed
Copy link
Member Author

fengmk2 commented Jan 6, 2026

Merge activity

@fengmk2 fengmk2 deleted the merge-json-config-support-jsonc-format branch January 6, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants