Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .bumpy/_config.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 0 additions & 2 deletions .bumpy/empty-ci-setup.md

This file was deleted.

5 changes: 5 additions & 0 deletions .bumpy/jsonc-config-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@varlock/bumpy': patch
---

Support JSONC in config file — allows // line comments, block comments, and trailing commas in .bumpy/\_config.json
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions packages/bumpy/src/core/config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function loadConfig(rootDir: string): Promise<BumpyConfig> {
const configPath = resolve(rootDir, BUMPY_DIR, CONFIG_FILE);
let userConfig: Partial<BumpyConfig> = {};
if (await exists(configPath)) {
userConfig = await readJson<Partial<BumpyConfig>>(configPath);
userConfig = await readJsonc<Partial<BumpyConfig>>(configPath);
}
return mergeConfig(DEFAULT_CONFIG, userConfig);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/bumpy/src/utils/fs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { readFile, writeFile, readdir, unlink, mkdir, access } from 'node:fs/promises';
import { join } from 'node:path';
import { parseJsonc } from './jsonc.ts';

export async function readJson<T = Record<string, unknown>>(filePath: string): Promise<T> {
const content = await readFile(filePath, 'utf-8');
return JSON.parse(content) as T;
}

export async function readJsonc<T = Record<string, unknown>>(filePath: string): Promise<T> {
const content = await readFile(filePath, 'utf-8');
return parseJsonc(content) as T;
}

export async function writeJson(filePath: string, data: unknown, indent = 2): Promise<void> {
await writeFile(filePath, JSON.stringify(data, null, indent) + '\n', 'utf-8');
}
Expand Down
11 changes: 11 additions & 0 deletions packages/bumpy/src/utils/jsonc.ts
Original file line number Diff line number Diff line change
@@ -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'));
}
}
42 changes: 42 additions & 0 deletions packages/bumpy/test/utils/jsonc.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});