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
8 changes: 8 additions & 0 deletions .changeset/crisp-apes-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@jsrepo/migrate": patch
"jsrepo": patch
"@jsrepo/shadcn": patch
---

feat: allow for configuring the indent character in JSON files

2 changes: 1 addition & 1 deletion .github/workflows/build-example-registries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
node-version: 24
cache: pnpm

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bundle-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
node-version: 24
cache: pnpm

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
node-version: 24
cache: pnpm

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cli-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
node-version: 24
cache: pnpm

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-external-projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: 24
cache: pnpm

- name: Install jsrepo dependencies
Expand Down
6 changes: 3 additions & 3 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"fumadocs-ui": "16.0.7",
"gsap": "^3.13.0",
"lucide-react": "^0.575.0",
"next": "16.1.6",
"next": "16.2.6",
"next-themes": "^0.4.6",
"ogl": "^1.0.11",
"react": "19.2.4",
"react-dom": "19.2.4",
"react": "19.2.6",
"react-dom": "19.2.6",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/jsrepo/src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
resolveWantedItems,
updateFiles,
} from '@/utils/add';
export { type StringifyFormat, type StringifyOptions, stringify } from '@/utils/json';
export { joinAbsolute } from '@/utils/path';
export {
detectPackageManager,
Expand Down
4 changes: 2 additions & 2 deletions packages/jsrepo/src/outputs/distributed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Output, RegistryPluginsSchema, RemoteDependencySchema } from '@/ou
import { MANIFEST_FILE, UnresolvedImportSchema } from '@/utils/build';
import { RegistryItemAddSchema, RegistryMetaSchema } from '@/utils/config';
import { existsSync, readFileSync, rmSync, writeFileSync } from '@/utils/fs';
import { stringify } from '@/utils/json';
import { type StringifyFormat, stringify } from '@/utils/json';
import { joinAbsolute } from '@/utils/path';
import type { AbsolutePath, ItemRelativePath } from '@/utils/types';
import { safeParseFromJSON } from '@/utils/zod';
Expand All @@ -12,7 +12,7 @@ export type DistributedOutputOptions = {
/** The directory to output the files to */
dir: string;
/** Whether or not to format the output. @default false */
format?: boolean;
format?: StringifyFormat;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/jsrepo/src/outputs/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { type Output, RegistryPluginsSchema, RemoteDependencySchema } from '@/ou
import { MANIFEST_FILE, UnresolvedImportSchema } from '@/utils/build';
import { RegistryItemAddSchema, RegistryMetaSchema } from '@/utils/config';
import { rmSync, writeFileSync } from '@/utils/fs';
import { stringify } from '@/utils/json';
import { type StringifyFormat, stringify } from '@/utils/json';
import { joinAbsolute, type RelativeToCwdPath, relativeToCwd } from '@/utils/path';
import type { ItemRelativePath } from '@/utils/types';

export type RepositoryOutputOptions = {
/** Whether or not to format the output. @default false */
format?: boolean;
format?: StringifyFormat;
};

/**
Expand Down
16 changes: 14 additions & 2 deletions packages/jsrepo/src/utils/json.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
export function stringify(data: unknown, options: { format?: boolean } = {}): string {
return JSON.stringify(data, null, options.format ? '\t' : undefined);
export type StringifyOptions = {
format?: StringifyFormat;
};

export type StringifyFormat = boolean | { space: string };

export function stringify(data: unknown, options: StringifyOptions = {}): string {
let spacer: string | undefined;
if (options.format === undefined || options.format === true) {
spacer = '\t';
} else if (typeof options.format === 'object') {
spacer = options.format.space;
}
return JSON.stringify(data, null, spacer);
}
24 changes: 24 additions & 0 deletions packages/jsrepo/tests/utils/json.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest';
import { stringify } from '@/utils/json';

describe('stringify', () => {
const nested = { foo: 1, bar: { baz: 'qux' } };

it('uses tab indentation when format is omitted', () => {
expect(stringify(nested)).toBe(JSON.stringify(nested, null, '\t'));
});

it('uses tab indentation when format is true', () => {
expect(stringify(nested, { format: true })).toBe(JSON.stringify(nested, null, '\t'));
});

it('uses compact JSON when format is false', () => {
expect(stringify(nested, { format: false })).toBe(JSON.stringify(nested));
});

it('uses custom spacing when format is an object with space', () => {
expect(stringify(nested, { format: { space: ' ' } })).toBe(
JSON.stringify(nested, null, ' ')
);
});
});
3 changes: 1 addition & 2 deletions packages/migrate/src/commands/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cancel, confirm, isCancel, log, text } from '@clack/prompts';
import { Command } from 'commander';
import type { RegistryConfig, RegistryItem, RegistryItemFile } from 'jsrepo/config';
import { DEFAULT_PROVIDERS } from 'jsrepo/providers';
import { resolveRegistries } from 'jsrepo/utils';
import { resolveRegistries, stringify } from 'jsrepo/utils';
import { err, ok, type Result } from 'nevereverthrow';
import { detect, resolveCommand } from 'package-manager-detector';
import path from 'pathe';
Expand All @@ -23,7 +23,6 @@ import {
NoPackageJsonFoundError,
} from '@/utils/errors';
import { readFileSync, rmSync, writeFileSync } from '@/utils/fs';
import { stringify } from '@/utils/json';
import { type PackageJson, tryGetPackage } from '@/utils/package';
import { joinAbsolute } from '@/utils/path';
import { installDependencies, intro, outro, runCommands } from '@/utils/prompts';
Expand Down
3 changes: 0 additions & 3 deletions packages/migrate/src/utils/json.ts

This file was deleted.

8 changes: 2 additions & 6 deletions packages/shadcn/src/output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs';
import path from 'node:path';
import { JsrepoError } from 'jsrepo';
import { JsrepoError, type StringifyFormat, stringify } from 'jsrepo';
import type { Output } from 'jsrepo/outputs';
import {
type Registry,
Expand All @@ -11,7 +11,7 @@ import {
} from 'shadcn/schema';

export type OutputOptions = {
format?: boolean;
format?: StringifyFormat;
dir: string;
};

Expand Down Expand Up @@ -172,7 +172,3 @@ function getType(type?: string) {
if (!type) return 'registry:ui';
return type.startsWith('registry:') ? type : `registry:${type}`;
}

function stringify(data: unknown, options: { format?: boolean } = {}): string {
return JSON.stringify(data, null, options.format ? '\t' : undefined);
}
Loading
Loading