Skip to content

support for configs in jsonc or json#54

Open
mrhut10 wants to merge 1 commit into
zpg6:mainfrom
mrhut10:feat/support-wrangler-config-formats
Open

support for configs in jsonc or json#54
mrhut10 wants to merge 1 commit into
zpg6:mainfrom
mrhut10:feat/support-wrangler-config-formats

Conversation

@mrhut10
Copy link
Copy Markdown

@mrhut10 mrhut10 commented Apr 22, 2026

hoping this allows the CLI to work with other config file types. as identified in
#20 and in #53 I believe

@zpg6
Copy link
Copy Markdown
Owner

zpg6 commented Apr 22, 2026

Hi @mrhut10, thanks for contributing this! I'll test and merge in the next few days.

@mrhut10
Copy link
Copy Markdown
Author

mrhut10 commented Apr 22, 2026

cheers @zpg6 look forward to the feedback,
appeared to be working for me locally with my .jsonc config but i didn't attempt to test .toml or .json directly other than the unit tests so would be good to test that e2e as well.

let me know if can help any more

@zpg6
Copy link
Copy Markdown
Owner

zpg6 commented Apr 22, 2026

@mrhut10 If you can conduct e2e testing, even exploratory and leave me a few notes, that would speed us along :)

@mrhut10 mrhut10 mentioned this pull request Apr 23, 2026
@mrhut10
Copy link
Copy Markdown
Author

mrhut10 commented Apr 23, 2026

@mrhut10 If you can conduct e2e testing, even exploratory and leave me a few notes, that would speed us along :)

yep test evidence.

CLI under test: @better-auth-cloudflare/cli@0.1.19 at commit b320c38, consumed via file:../better-auth-cloudflare.

done via a worktree for each configs wrangler.jsonc | wrangler.json | wrangler.toml

Check wrangler.jsonc wrangler.json wrangler.toml
migrate --migrate-target=skip (auto-detect, parse, run auth:update + db:generate)
migrate --migrate-target=dev (full flow + wrangler d1 migrations apply --local)
migrate --migrate-target=skip --config=./custom.<ext> (explicit path override with non-default filename)

let me know if anything else needs testing with it

@mrhut10
Copy link
Copy Markdown
Author

mrhut10 commented Apr 29, 2026

Have you had a chance to review @zpg6 ?

@zpg6
Copy link
Copy Markdown
Owner

zpg6 commented Apr 29, 2026

Have you had a chance to review @zpg6 ?

Hi @mrhut10, sorry for delay still finding time to review your great work here. Thanks

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/better-auth-cloudflare@54

commit: b320c38

@mrhut10
Copy link
Copy Markdown
Author

mrhut10 commented May 9, 2026

let me know if can help at all @zpg6

Copy link
Copy Markdown

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

Adds support for the CLI (notably migrate) to detect and parse Cloudflare Wrangler configuration from wrangler.json, wrangler.jsonc, or wrangler.toml, addressing requests in Issues #20 and #53.

Changes:

  • Implement wrangler config auto-detection + parsing for JSON/JSONC/TOML, and add --config override for the migrate workflow.
  • Add unit tests covering TOML/JSON/JSONC parsing behavior.
  • Update docs/CLI help text to describe multi-format wrangler config support.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
docs/configuration.md Updates configuration docs to describe supported wrangler config formats.
cli/tests/wrangler-config.test.ts Adds unit tests for parsing wrangler config across TOML/JSON/JSONC.
cli/src/lib/helpers.ts Adds config discovery + unified parsing logic for JSON/JSONC/TOML.
cli/src/index.ts Updates migrate flow to use auto-detected (or explicit) wrangler config + adds --config help text.
cli/README.md Updates CLI documentation wording around wrangler config support.
cli/package.json Adds JSONC parsing dependency.
Comments suppressed due to low confidence (1)

cli/package.json:51

  • The CLI now require()s jsonc-simple-parser at runtime (and also @iarna/toml when parsing TOML), but these are listed under devDependencies. When this package is installed from npm, devDependencies are not installed, so the CLI will fail with Cannot find module .... Move these runtime dependencies into dependencies (or avoid the runtime require).
    "dependencies": {
        "ora": "^9.0.0",
        "picocolors": "^1.0.0",
        "prompts": "^2.4.2"
    },
    "devDependencies": {
        "@iarna/toml": "^2.2.5",
        "jsonc-simple-parser": "^1.0.0",
        "@types/node": "^22.7.5",
        "@types/prompts": "^2.4.9",
        "bun-types": "^1.1.33",
        "postgres": "^3.4.4",
        "typescript": "^5.5.4"
    },

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

Comment thread cli/src/lib/helpers.ts
Comment on lines +269 to +276
function parseWranglerConfigObject(parsed: Record<string, unknown>): {
databases: DatabaseConfig[];
hasMultipleDatabases: boolean;
} {
const databases: DatabaseConfig[] = [];

const d1Databases = parsed.d1_databases as Array<Record<string, unknown>> | undefined;
if (d1Databases && Array.isArray(d1Databases)) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I prefer something more typesafe, but obviously let's not concern ourselves with irrelevant wrangler fields

Comment thread cli/src/lib/helpers.ts
Comment on lines +256 to +257
const databases: DatabaseConfig[] = [];

Comment thread cli/src/index.ts
Comment on lines +785 to +792
// Check for explicit config path from --config flag
const explicitConfigPath = cliArgs?.config as string | undefined;

// Read and parse wrangler.toml to detect database configurations
debugLog(`Reading wrangler.toml from: ${wranglerPath}`);
let wranglerContent: string;
try {
wranglerContent = readFileSync(wranglerPath, "utf8");
} catch (e) {
fatal("Failed to read wrangler.toml");
return;
// Find wrangler config file (supports wrangler.json, wrangler.jsonc, wrangler.toml)
const config = explicitConfigPath
? findWranglerConfigWithExplicitPath(explicitConfigPath)
: findWranglerConfig(process.cwd());

Comment thread cli/README.md
☁️ Handles Cloudflare resource creation:

- Runs `wrangler d1/kv/r2 create` commands and configures `wrangler.toml`
- Runs `wrangler d1/kv/r2 create` commands and configures your wrangler config file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, and I prefer the CLI generate use toml by default still

@zpg6
Copy link
Copy Markdown
Owner

zpg6 commented May 9, 2026

@mrhut10 - lets make these fixes, then we merge and I will patch the CLI on npm

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