Unverified Commit e68e50d6 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Add More Configuration File Options (#9713)

parent 2347e3e4
...@@ -23,12 +23,23 @@ export async function findConfig<T>( ...@@ -23,12 +23,23 @@ export async function findConfig<T>(
} }
// If we didn't find the configuration in `package.json`, we should look for // If we didn't find the configuration in `package.json`, we should look for
// known filenames. The /rc$/ version of this file does not support YAML // known filenames.
// like some configuration loaders. const filePath = await findUp(
const filePath = await findUp(`.${key}rc.json`, { [
`.${key}rc.json`,
`${key}.config.json`,
`.${key}rc.js`,
`${key}.config.js`,
],
{
cwd: directory, cwd: directory,
}) }
)
if (filePath) { if (filePath) {
if (filePath.endsWith('.js')) {
return require(filePath)
}
// We load JSON contents with JSON5 to allow users to comment in their // We load JSON contents with JSON5 to allow users to comment in their
// configuration file. This pattern was popularized by TypeScript. // configuration file. This pattern was popularized by TypeScript.
const fileContents = fs.readFileSync(filePath, 'utf8') const fileContents = fs.readFileSync(filePath, 'utf8')
......
...@@ -10,6 +10,24 @@ describe('find config', () => { ...@@ -10,6 +10,24 @@ describe('find config', () => {
expect(config).toEqual({ foo: 'bar' }) expect(config).toEqual({ foo: 'bar' })
}) })
it('should resolve rc.js', async () => {
const config = await findConfig(join(fixtureDir, 'config-js'), 'test')
expect(config).toEqual({ foo: 'bar' })
})
it('should resolve .config.json', async () => {
const config = await findConfig(
join(fixtureDir, 'config-long-json'),
'test'
)
expect(config).toEqual({ foo: 'bar' })
})
it('should resolve .config.js', async () => {
const config = await findConfig(join(fixtureDir, 'config-long-js'), 'test')
expect(config).toEqual({ foo: 'bar' })
})
it('should resolve package.json', async () => { it('should resolve package.json', async () => {
const config = await findConfig( const config = await findConfig(
join(fixtureDir, 'config-package-json'), join(fixtureDir, 'config-package-json'),
......
module.exports = { foo: 'bar' }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment