fix(cli): accept capacitor.config.js as a --capacitor-config target - #2889
Draft
posthog-eu[bot] wants to merge 1 commit into
Draft
fix(cli): accept capacitor.config.js as a --capacitor-config target#2889posthog-eu[bot] wants to merge 1 commit into
posthog-eu[bot] wants to merge 1 commit into
Conversation
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
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Monorepo apps whose config is
capacitor.config.jscouldn't use the new--capacitor-configflag at all — the CLI rejected the path before doing any work.Problem
--capacitor-configvalidator (cli/src/config/index.ts) matched only.ts/.json, socapacitor.config.jswas 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.jsis a first-class config for Capacitor itself and is already ininit's owncapacitorConfigFileslist, so the exclusion was inconsistent.Changes
.jsin the extension regex and name all three extensions in the error message.loadConfigTargetgets a.jsbranch thatrequire()s the file, mirroring Capacitor's owncapacitor.config.jsloader.writeConfigonly formats.ts/.jsonand silently no-ops on.js, so simply widening the regex would trade a clear error for a silent failed write.writeConfigTargetnow emits CommonJS itself via Capacitor'sformatJSObject, matching how Capacitor renders.ts..mjs/.cjsare 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
cli/test/test-capacitor-config-target.mjs:resolveCapacitorConfigTargetPathnow accepts acapacitor.config.jstarget and still rejects.mjs.loadConfigForWritereads acapacitor.config.jstarget correctly.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, andbun run test:init-monorepo-targetingall pass.Screenshots
n/a — CLI validation/serialization change; covered by the test above.
Checklist
bun run lint:backend && bun run lint.Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.