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: provide extends directive for configs #1212

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

antongolub
Copy link

@antongolub antongolub commented Feb 6, 2024

This PR brings declarative config extension via extends references. Just like tsconfig, eslint, typedoc and many others.

  • Accepts: string | Record<any, any> | Array<string | Record<any, any>>
    • 'foo' → require('foo')
    • './foo.js' → require(path.resolve(, 'foo.js'))
    • ['foo', 'bar'] → merge(base, ...extras.load(...))
    • [{"extends": "./base.json", "foo": "bar"}] → ...

closes #977

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Feb 6, 2024
@antongolub antongolub changed the title feat: provide extends directive resolution for configs feat: provide extends directive for configs Feb 7, 2024
@antongolub
Copy link
Author

antongolub commented Feb 14, 2024

@huntie, could you clarify this point?

The actual cosmiconfig preset defines searchPlaces without .yml and .es6, but it adds appropriate loaders. This looks inconsistent. What is the desired behavior?

const explorer = cosmiconfig('metro', {
  searchPlaces: [
    'metro.config.js',
    'metro.config.cjs',
    'metro.config.json',
    'package.json',
  ],
  loaders: {
    '.json': cosmiconfig.loadJson,
    '.yaml': cosmiconfig.loadYaml,
    '.yml': cosmiconfig.loadYaml,
    '.js': cosmiconfig.loadJs,
    '.cjs': cosmiconfig.loadJs,
    '.es6': cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml,
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Add extends config loading support
2 participants