From 0108a018100506bba9543abba863c63b8630cdeb Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Tue, 21 Apr 2026 18:30:06 -0700 Subject: [PATCH 1/2] Support JSONC (comments) in config file Add jsonc-parser dependency and readJsonc utility so that .bumpy/_config.json can contain // and /* */ comments. Co-Authored-By: Claude Opus 4.6 (1M context) --- bun.lock | 3 +++ packages/bumpy/package.json | 1 + packages/bumpy/src/core/config.ts | 4 ++-- packages/bumpy/src/utils/fs.ts | 6 ++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bun.lock b/bun.lock index 14ab283..56d7c5e 100644 --- a/bun.lock +++ b/bun.lock @@ -25,6 +25,7 @@ "@types/picomatch": "^4.0.3", "@types/semver": "^7.7.0", "js-yaml": "^4.1.0", + "jsonc-parser": "^3.3.1", "picocolors": "^1.1.1", "picomatch": "^4.0.4", "semver": "^7.7.2", @@ -241,6 +242,8 @@ "jsesc": ["jsesc@3.1.0", "", { "bin": { "jsesc": "bin/jsesc" } }, "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA=="], + "jsonc-parser": ["jsonc-parser@3.3.1", "", {}, "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ=="], + "lefthook": ["lefthook@2.1.5", "", { "optionalDependencies": { "lefthook-darwin-arm64": "2.1.5", "lefthook-darwin-x64": "2.1.5", "lefthook-freebsd-arm64": "2.1.5", "lefthook-freebsd-x64": "2.1.5", "lefthook-linux-arm64": "2.1.5", "lefthook-linux-x64": "2.1.5", "lefthook-openbsd-arm64": "2.1.5", "lefthook-openbsd-x64": "2.1.5", "lefthook-windows-arm64": "2.1.5", "lefthook-windows-x64": "2.1.5" }, "bin": { "lefthook": "bin/index.js" } }, "sha512-yB9IFWurFllusbPZqvG0EavTmpNXPya2MuO7Li7YT78xAj3uCQ3AgmW9TVUbTTsSMhsegbiAMRpwfEk2TP1P0A=="], "lefthook-darwin-arm64": ["lefthook-darwin-arm64@2.1.5", "", { "os": "darwin", "cpu": "arm64" }, "sha512-VITTaw8PxxyE26gkZ8UcwIa5ZrWnKNRGLeeSrqri40cQdXvLTEoMq2tjjw7eiL9UcB0waRReDdzydevy9GOPUQ=="], diff --git a/packages/bumpy/package.json b/packages/bumpy/package.json index e97e2a4..5c5204f 100644 --- a/packages/bumpy/package.json +++ b/packages/bumpy/package.json @@ -47,6 +47,7 @@ "@types/picomatch": "^4.0.3", "@types/semver": "^7.7.0", "js-yaml": "^4.1.0", + "jsonc-parser": "^3.3.1", "picocolors": "^1.1.1", "picomatch": "^4.0.4", "semver": "^7.7.2", diff --git a/packages/bumpy/src/core/config.ts b/packages/bumpy/src/core/config.ts index 662e98f..cb89d64 100644 --- a/packages/bumpy/src/core/config.ts +++ b/packages/bumpy/src/core/config.ts @@ -1,5 +1,5 @@ import { resolve } from 'node:path'; -import { readJson, exists } from '../utils/fs.ts'; +import { readJson, readJsonc, exists } from '../utils/fs.ts'; import { type BumpyConfig, type PackageConfig, DEFAULT_CONFIG } from '../types.ts'; const BUMPY_DIR = '.bumpy'; @@ -32,7 +32,7 @@ export async function loadConfig(rootDir: string): Promise { const configPath = resolve(rootDir, BUMPY_DIR, CONFIG_FILE); let userConfig: Partial = {}; if (await exists(configPath)) { - userConfig = await readJson>(configPath); + userConfig = await readJsonc>(configPath); } return mergeConfig(DEFAULT_CONFIG, userConfig); } diff --git a/packages/bumpy/src/utils/fs.ts b/packages/bumpy/src/utils/fs.ts index a05a7d2..e332009 100644 --- a/packages/bumpy/src/utils/fs.ts +++ b/packages/bumpy/src/utils/fs.ts @@ -1,11 +1,17 @@ import { readFile, writeFile, readdir, unlink, mkdir, access } from 'node:fs/promises'; import { join } from 'node:path'; +import { parse as parseJsonc } from 'jsonc-parser'; export async function readJson>(filePath: string): Promise { const content = await readFile(filePath, 'utf-8'); return JSON.parse(content) as T; } +export async function readJsonc>(filePath: string): Promise { + const content = await readFile(filePath, 'utf-8'); + return parseJsonc(content) as T; +} + export async function writeJson(filePath: string, data: unknown, indent = 2): Promise { await writeFile(filePath, JSON.stringify(data, null, indent) + '\n', 'utf-8'); } From 1625ee840495f6dac08b7091a871b2acf5d966c2 Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Tue, 21 Apr 2026 18:36:02 -0700 Subject: [PATCH 2/2] Support JSONC (comments) in config file Add a lightweight JSONC parser (strips comments and trailing commas) so that .bumpy/_config.json can contain // and block comments. Adapted from https://github.com/fabiospampinato/tiny-jsonc Co-Authored-By: Claude Opus 4.6 (1M context) --- .bumpy/_config.json | 6 ++++ .bumpy/empty-ci-setup.md | 2 -- .bumpy/jsonc-config-support.md | 5 +++ .vscode/settings.json | 10 ++++++ bun.lock | 3 -- docs/configuration.md | 2 ++ packages/bumpy/package.json | 1 - packages/bumpy/src/utils/fs.ts | 2 +- packages/bumpy/src/utils/jsonc.ts | 11 +++++++ packages/bumpy/test/utils/jsonc.test.ts | 42 +++++++++++++++++++++++++ 10 files changed, 77 insertions(+), 7 deletions(-) delete mode 100644 .bumpy/empty-ci-setup.md create mode 100644 .bumpy/jsonc-config-support.md create mode 100644 .vscode/settings.json create mode 100644 packages/bumpy/src/utils/jsonc.ts create mode 100644 packages/bumpy/test/utils/jsonc.test.ts diff --git a/.bumpy/_config.json b/.bumpy/_config.json index 6c359c0..02c50b5 100644 --- a/.bumpy/_config.json +++ b/.bumpy/_config.json @@ -1,6 +1,12 @@ { + // we use the local version, but normally you'd use + // "$schema": "../node_modules/@varlock/bumpy/config-schema.json", "$schema": "../packages/bumpy/config-schema.json", + + // main is already default, but no harm in being explicit "baseBranch": "main", + // only thank external contributors "changelog": ["github", { "internalAuthors": ["theoephraim", "philmillman"] }], + // narrows down which files are considered changes "changedFilePatterns": ["src/**", "skills/**", "package.json", "tsconfig.json", "tsdown.config.ts"] } diff --git a/.bumpy/empty-ci-setup.md b/.bumpy/empty-ci-setup.md deleted file mode 100644 index a845151..0000000 --- a/.bumpy/empty-ci-setup.md +++ /dev/null @@ -1,2 +0,0 @@ ---- ---- diff --git a/.bumpy/jsonc-config-support.md b/.bumpy/jsonc-config-support.md new file mode 100644 index 0000000..45717fa --- /dev/null +++ b/.bumpy/jsonc-config-support.md @@ -0,0 +1,5 @@ +--- +'@varlock/bumpy': patch +--- + +Support JSONC in config file — allows // line comments, block comments, and trailing commas in .bumpy/\_config.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..eb5d60d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + // use the project's TS version rather than the VSCode's built-in one + "typescript.tsdk": "./node_modules/typescript/lib", + "typescript.enablePromptUseWorkspaceTsdk": true, + "files.associations": { + // package.json needs to be "json" rather than "json with comments" so that the "version lens" plugin works + "package.json": "json", + "**/.bumpy/_config.json": "jsonc" + } +} diff --git a/bun.lock b/bun.lock index 56d7c5e..14ab283 100644 --- a/bun.lock +++ b/bun.lock @@ -25,7 +25,6 @@ "@types/picomatch": "^4.0.3", "@types/semver": "^7.7.0", "js-yaml": "^4.1.0", - "jsonc-parser": "^3.3.1", "picocolors": "^1.1.1", "picomatch": "^4.0.4", "semver": "^7.7.2", @@ -242,8 +241,6 @@ "jsesc": ["jsesc@3.1.0", "", { "bin": { "jsesc": "bin/jsesc" } }, "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA=="], - "jsonc-parser": ["jsonc-parser@3.3.1", "", {}, "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ=="], - "lefthook": ["lefthook@2.1.5", "", { "optionalDependencies": { "lefthook-darwin-arm64": "2.1.5", "lefthook-darwin-x64": "2.1.5", "lefthook-freebsd-arm64": "2.1.5", "lefthook-freebsd-x64": "2.1.5", "lefthook-linux-arm64": "2.1.5", "lefthook-linux-x64": "2.1.5", "lefthook-openbsd-arm64": "2.1.5", "lefthook-openbsd-x64": "2.1.5", "lefthook-windows-arm64": "2.1.5", "lefthook-windows-x64": "2.1.5" }, "bin": { "lefthook": "bin/index.js" } }, "sha512-yB9IFWurFllusbPZqvG0EavTmpNXPya2MuO7Li7YT78xAj3uCQ3AgmW9TVUbTTsSMhsegbiAMRpwfEk2TP1P0A=="], "lefthook-darwin-arm64": ["lefthook-darwin-arm64@2.1.5", "", { "os": "darwin", "cpu": "arm64" }, "sha512-VITTaw8PxxyE26gkZ8UcwIa5ZrWnKNRGLeeSrqri40cQdXvLTEoMq2tjjw7eiL9UcB0waRReDdzydevy9GOPUQ=="], diff --git a/docs/configuration.md b/docs/configuration.md index 22e2c8d..2a20684 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2,6 +2,8 @@ Bumpy is configured via `.bumpy/_config.json`, created by `bumpy init`. Per-package config can also be set in each `package.json` under the `"bumpy"` key. +> **Tip:** The config file supports JSONC — you can use `//` line comments, `/* */` block comments, and trailing commas. + ## Global config (`.bumpy/_config.json`) | Option | Type | Default | Description | diff --git a/packages/bumpy/package.json b/packages/bumpy/package.json index 5c5204f..e97e2a4 100644 --- a/packages/bumpy/package.json +++ b/packages/bumpy/package.json @@ -47,7 +47,6 @@ "@types/picomatch": "^4.0.3", "@types/semver": "^7.7.0", "js-yaml": "^4.1.0", - "jsonc-parser": "^3.3.1", "picocolors": "^1.1.1", "picomatch": "^4.0.4", "semver": "^7.7.2", diff --git a/packages/bumpy/src/utils/fs.ts b/packages/bumpy/src/utils/fs.ts index e332009..519eb88 100644 --- a/packages/bumpy/src/utils/fs.ts +++ b/packages/bumpy/src/utils/fs.ts @@ -1,6 +1,6 @@ import { readFile, writeFile, readdir, unlink, mkdir, access } from 'node:fs/promises'; import { join } from 'node:path'; -import { parse as parseJsonc } from 'jsonc-parser'; +import { parseJsonc } from './jsonc.ts'; export async function readJson>(filePath: string): Promise { const content = await readFile(filePath, 'utf-8'); diff --git a/packages/bumpy/src/utils/jsonc.ts b/packages/bumpy/src/utils/jsonc.ts new file mode 100644 index 0000000..e76b80d --- /dev/null +++ b/packages/bumpy/src/utils/jsonc.ts @@ -0,0 +1,11 @@ +// JSONC parsing adapted from https://github.com/fabiospampinato/tiny-jsonc +const stringOrCommentRe = /("(?:\\?[^])*?")|(\/\/.*)|(\/\*[^]*?\*\/)/g; +const stringOrTrailingCommaRe = /("(?:\\?[^])*?")|(,\s*)(?=]|})/g; + +export function parseJsonc(text: string): unknown { + try { + return JSON.parse(text); + } catch { + return JSON.parse(text.replace(stringOrCommentRe, '$1').replace(stringOrTrailingCommaRe, '$1')); + } +} diff --git a/packages/bumpy/test/utils/jsonc.test.ts b/packages/bumpy/test/utils/jsonc.test.ts new file mode 100644 index 0000000..6f10094 --- /dev/null +++ b/packages/bumpy/test/utils/jsonc.test.ts @@ -0,0 +1,42 @@ +import { test, expect, describe } from 'bun:test'; +import { parseJsonc } from '../../src/utils/jsonc.ts'; + +describe('parseJsonc', () => { + test('parses plain JSON', () => { + expect(parseJsonc('{"a": 1}')).toEqual({ a: 1 }); + }); + + test('strips line comments', () => { + const input = `{ + // this is a comment + "a": 1 + }`; + expect(parseJsonc(input)).toEqual({ a: 1 }); + }); + + test('strips block comments', () => { + const input = `{ + /* block comment */ + "a": 1 + }`; + expect(parseJsonc(input)).toEqual({ a: 1 }); + }); + + test('handles trailing commas', () => { + const input = `{ "a": 1, "b": 2, }`; + expect(parseJsonc(input)).toEqual({ a: 1, b: 2 }); + }); + + test('preserves comment-like strings in values', () => { + const input = `{ "url": "https://example.com // not a comment" }`; + expect(parseJsonc(input)).toEqual({ url: 'https://example.com // not a comment' }); + }); + + test('throws on invalid JSON', () => { + expect(() => parseJsonc('{ bad }')).toThrow(); + }); + + test('throws on empty input', () => { + expect(() => parseJsonc('')).toThrow(); + }); +});