Skip to content

feat: provide extends directive for configs#1212

Open
antongolub wants to merge 15 commits intofacebook:mainfrom
antongolub-forks:cfg-extends
Open

feat: provide extends directive for configs#1212
antongolub wants to merge 15 commits intofacebook:mainfrom
antongolub-forks:cfg-extends

Conversation

@antongolub
Copy link
Copy Markdown

@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
Copy Markdown
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