Skip to content

fix(cli): accept capacitor.config.js as a --capacitor-config target - #2889

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-accept-capacitorconfigjs-as-a-53cffc
Draft

fix(cli): accept capacitor.config.js as a --capacitor-config target#2889
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-accept-capacitorconfigjs-as-a-53cffc

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Aug 6, 2026

Copy link
Copy Markdown

Summary

Monorepo apps whose config is capacitor.config.js couldn't use the new --capacitor-config flag at all — the CLI rejected the path before doing any work.

Problem

  • The --capacitor-config validator (cli/src/config/index.ts) matched only .ts/.json, so capacitor.config.js was rejected with …must point to a capacitor.config.*.ts or capacitor.config.*.json file, which reads like a wrong path rather than an unsupported extension.
  • capacitor.config.js is a first-class config for Capacitor itself and is already in init's own capacitorConfigFiles list, so the exclusion was inconsistent.

Changes

  • Accept .js in the extension regex and name all three extensions in the error message.
  • loadConfigTarget gets a .js branch that require()s the file, mirroring Capacitor's own capacitor.config.js loader.
  • Add JS write support. Capacitor's writeConfig only formats .ts/.json and silently no-ops on .js, so simply widening the regex would trade a clear error for a silent failed write. writeConfigTarget now emits CommonJS itself via Capacitor's formatJSObject, matching how Capacitor renders .ts.

.mjs/.cjs are intentionally left out: Capacitor never loads them as configs and the writer emits CommonJS, so allowing them would let reads pass but writes silently no-op.

Test plan

  • Extended cli/test/test-capacitor-config-target.mjs:
    • resolveCapacitorConfigTargetPath now accepts a capacitor.config.js target and still rejects .mjs.
    • loadConfigForWrite reads a capacitor.config.js target correctly.
    • A real CLI write (capgo app setting … --capacitor-config <capacitor.config.js>) updates the JS file, preserves app-scoped plugins, and leaves the root config untouched.
  • bun run lint, bun run typecheck, bun run build, and bun run test:init-monorepo-targeting all pass.

Screenshots

n/a — CLI validation/serialization change; covered by the test above.

Checklist

  • My code follows the code style of this project and passes bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce my tests.

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

The `--capacitor-config` validator only matched `.ts`/`.json`, so monorepo apps
using `capacitor.config.js` were rejected outright with a misleading error that
read like a wrong path rather than an unsupported extension.

- Widen the accepted-extension regex to include `.js` and name all three
  extensions in the error message.
- Add a `.js` load branch to `loadConfigTarget`, mirroring Capacitor's own
  `require()`-based `capacitor.config.js` loader.
- Add JS write support: Capacitor's `writeConfig` silently no-ops on `.js`
  (it only formats `.ts`/`.json`), so `writeConfigTarget` now emits CommonJS
  itself using Capacitor's `formatJSObject`, matching how it renders `.ts`.
- Cover load + write of a `capacitor.config.js` target in the existing test.

Generated-By: PostHog Code
Task-Id: 98e54bc7-9597-4b83-a37e-266ef13e9f92
@codspeed-hq

codspeed-hq Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing posthog-self-driving/fixcli-accept-capacitorconfigjs-as-a-53cffc (a97a128) with main (60a641e)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

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.

0 participants