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

refactor: improved type safety of platformConfig in createRun function #2286

Conversation

hoonjoo-park
Copy link
Contributor

Summary:

I improved type safety of platformConfig in createRun function. and removed unnecessary optional chaining of the platformConfig.
(code is located in cli-platform-apple/src/commands/runCommand/createRun.ts)

before I modified type of platformConfig, we couldn't infer that platformConfig could be undefined.
so, I added undefined type to platformConfig as optional.

Additionally, there was unnecessary optional chaining, so I removed it.

// * already checked if platformConfig is 'undefined'.
if (
  platformConfig === undefined ||
  supportedPlatforms[platformName] === undefined
) {
  throw new CLIError(
    `Unable to find ${platformReadableName} platform config`,
  );
}

//  * as far as I see, we don't need optional chaining in here
if (platformConfig?.automaticPodsInstallation || args.forcePods) {
  const isAppRunningNewArchitecture = platformConfig?.sourceDir
    ? await getArchitecture(platformConfig.sourceDir)
    : undefined;

  await resolvePods(ctx.root, ctx.dependencies, platformName, {
    forceInstall: args.forcePods,
    newArchEnabled: isAppRunningNewArchitecture,
  });

  installedPods = true;
}

Test Plan:

We need to check that the function is working properly, even if we put a platformName that is invalid.

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

@hoonjoo-park hoonjoo-park force-pushed the refactor/platformConfig-type-safety branch from 6735861 to 55f2938 Compare February 8, 2024 15:44
Copy link
Collaborator

@szymonrybczak szymonrybczak left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@thymikee thymikee merged commit 9efcef7 into react-native-community:main Feb 19, 2024
10 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.

3 participants