Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): allow async in capacitor config file #4299

Merged
merged 4 commits into from
Jan 23, 2024

Conversation

buschtoens
Copy link
Contributor

@buschtoens buschtoens commented Mar 5, 2021

This allows users to generate their config asynchronously.

// capacitor.config.ts
import type { CapacitorConfig } from '@capacitor/cli';

async function generateConfig(): Promise<CapacitorConfig> {
  // ...
}

export default generateConfig();

This allows users to generate their config asynchronously.
@alfredosalzillo
Copy link

Would be better if instead of exporting a Promise as default it's allowed to export function and async function ?

export default async function () {
  ....
  return yourconfig
}

@buschtoens
Copy link
Contributor Author

Another, possibly more standard / intuitive, option is using top-level await.

// capacitor.config.ts
import type { CapacitorConfig } from '@capacitor/cli';

const appId = await determineAppId();

const config: CapacitorConfig = {
  appId,
  appName: 'My Capacitor App',
  // ...
};

export default config;

@ZaLiTHkA
Copy link

ZaLiTHkA commented Nov 21, 2022

while working on a "whitelabel" project using Ionic 6 with Angular 14 and Capacitor 4, I ran into an issue with trying to retrieve the IP address of the current dev machine's primary network interface.. the only NPM packages that I found with enough "business logic" to sufficiently retrieve and inspect the network interfaces all work with Promises, whereas those with pure synchronous logic simply don't get sufficient information. this async support would have solved that issue for me in a heartbeat.

I see this PR has been open and untouched for a long time now, so just to check: is there any update on this idea? or do we simply need to find (or make) another plan for cases like mine?

@@ -136,7 +138,7 @@ async function loadExtConfigJS(
extConfigType: 'js',
extConfigName,
extConfigFilePath: extConfigFilePath,
extConfig: require(extConfigFilePath),
extConfig: await require(extConfigFilePath),
Copy link
Member

Choose a reason for hiding this comment

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

is this await needed?
seems to work fine without it.
Is there a case where it would be needed?

@jcesarmobile
Copy link
Member

@giralte-ionic @theproducer @markemer @dallastjames
thoughts on this?
Having a .ts/.js config file but not being able to use async code is very limiting.
I tried in the past to add top level await support, which would be the ideal feature to have, but I was not able to make it work, so this would be at least a big improvement and it's simple enough.

@markemer
Copy link
Member

@giralte-ionic @theproducer @markemer @dallastjames thoughts on this? Having a .ts/.js config file but not being able to use async code is very limiting. I tried in the past to add top level await support, which would be the ideal feature to have, but I was not able to make it work, so this would be at least a big improvement and it's simple enough.

I mean, it seems harmless enough to me with a useful feature addition.

@jcesarmobile jcesarmobile changed the title feat(cli): allow async capacitor.config.{ts,js} feat(cli): allow async in capacitor config file Jan 23, 2024
@jcesarmobile jcesarmobile merged commit 5cecc3e into ionic-team:main Jan 23, 2024
6 checks passed
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.

6 participants