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: drop cosmiconfig #802

Merged
merged 1 commit into from
Mar 29, 2025
Merged

refactor: drop cosmiconfig #802

merged 1 commit into from
Mar 29, 2025

Conversation

satya164
Copy link
Member

Summary

cosmiconfig is no longer maintained. Apart from that, we can't support ESM configuration properly because cosmiconfig only supports loading it asynchronously - but we need to be able to load it synchronously in babel config.

I also took a look at lilconfig, but it also has the same limitation.

Node 20.19.0 onwards supports synchronous require of ESM, so this limitation is not a technical limitation. So I decided to implement config loading myself since we don't need any advanced features of these config loaders such as traversing up until they find the config.

Test plan

Tested in a sample project with both bob build and in the example app with metro.

@satya164 satya164 requested review from atlj and Copilot March 27, 2025 18:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors configuration loading by dropping the deprecated and limited cosmiconfig in favor of a custom synchronous loader. Key changes include:

  • Removal of cosmiconfig and lilconfig dependencies.
  • Implementation of a custom loadConfig function for synchronous config loading.
  • Updates to configuration loading in babel-config, init, and build scripts.

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

File Description
packages/react-native-builder-bob/src/utils/loadConfig.ts Implements a custom synchronous configuration loader, including special handling of package.json.
packages/react-native-builder-bob/src/init.ts Updates config loading to use the new loadConfig with an explicit root parameter.
packages/react-native-builder-bob/src/build.ts Uses the new loadConfig synchronously instead of cosmiconfig.
packages/react-native-builder-bob/babel-config.js Replaces cosmiconfigSync with the new loadConfig and updates error handling accordingly.
Files not reviewed (1)
  • packages/react-native-builder-bob/package.json: Language not supported
Comments suppressed due to low confidence (2)

packages/react-native-builder-bob/src/utils/loadConfig.ts:65

  • [nitpick] For errors other than MODULE_NOT_FOUND, the code rethrows the exception; consider adding an inline comment to clarify why non-module-not-found errors are rethrown to aid future maintainers.
throw e;

packages/react-native-builder-bob/babel-config.js:20

  • The thrown error message ('Couldn't find a valid configuration.') might be too generic; consider specifying that no configuration file was found in the expected search places to improve clarity.
if (result == null) {

@satya164 satya164 force-pushed the @satya164/drop-cosmiconfig branch from b515dca to 6c500e4 Compare March 27, 2025 18:35
@satya164 satya164 force-pushed the @satya164/drop-cosmiconfig branch from 6c500e4 to 860bff6 Compare March 29, 2025 14:43
@satya164 satya164 enabled auto-merge March 29, 2025 16:19
@satya164 satya164 disabled auto-merge March 29, 2025 16:19
@satya164 satya164 merged commit 45a4db3 into main Mar 29, 2025
21 checks passed
@satya164 satya164 deleted the @satya164/drop-cosmiconfig branch March 29, 2025 16:19
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.

1 participant