From b786750018f27cd490bfd672b7ac326abc92a330 Mon Sep 17 00:00:00 2001 From: Devin Shoemaker Date: Thu, 5 Aug 2021 13:25:02 -0500 Subject: [PATCH] fix: support Capacitor 1 apps The Ionic CLI attempts to get the users Capacitor config with the `npx cap config --json` command that was introduced in Capacitor 3. This code assumes that if the command does not work then an output (stdout) would not be returned. This is the case with Capacitor 2 as it returns the "command not found" error to stderror. However, Capacitor 1 returns this to stdout which then causes an error because there is an output, but it not JSON and not parsable. --- .../cli/src/lib/integrations/capacitor/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/@ionic/cli/src/lib/integrations/capacitor/index.ts b/packages/@ionic/cli/src/lib/integrations/capacitor/index.ts index f2e6f8e85c..d6c22d3e82 100644 --- a/packages/@ionic/cli/src/lib/integrations/capacitor/index.ts +++ b/packages/@ionic/cli/src/lib/integrations/capacitor/index.ts @@ -195,9 +195,16 @@ export class Integration extends BaseIntegration { if (!output) { debug('Could not get config from Capacitor CLI (probably old version)'); return; + } else { + try { + // Capacitor 1 returns the `command not found` error in stdout instead of stderror like in Capacitor 2 + // This ensures that the output from the command is valid JSON to account for this + return JSON.parse(output); + } catch(e) { + debug('Could not get config from Capacitor CLI (probably old version)', e); + return; + } } - - return JSON.parse(output); }); getCapacitorConfig = lodash.memoize(async (): Promise => {