diff --git a/packages/next/lib/find-config.ts b/packages/next/lib/find-config.ts index bf00df5cb3521..5d4089479e388 100644 --- a/packages/next/lib/find-config.ts +++ b/packages/next/lib/find-config.ts @@ -23,12 +23,23 @@ export async function findConfig( } // 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 - // like some configuration loaders. - const filePath = await findUp(`.${key}rc.json`, { - cwd: directory, - }) + // known filenames. + const filePath = await findUp( + [ + `.${key}rc.json`, + `${key}.config.json`, + `.${key}rc.js`, + `${key}.config.js`, + ], + { + cwd: directory, + } + ) if (filePath) { + if (filePath.endsWith('.js')) { + return require(filePath) + } + // We load JSON contents with JSON5 to allow users to comment in their // configuration file. This pattern was popularized by TypeScript. const fileContents = fs.readFileSync(filePath, 'utf8') diff --git a/test/unit/find-config.test.js b/test/unit/find-config.test.js index 604f27be12219..2d050c6d24045 100644 --- a/test/unit/find-config.test.js +++ b/test/unit/find-config.test.js @@ -10,6 +10,24 @@ describe('find config', () => { 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 () => { const config = await findConfig( join(fixtureDir, 'config-package-json'), diff --git a/test/unit/fixtures/config-js/.testrc.js b/test/unit/fixtures/config-js/.testrc.js new file mode 100644 index 0000000000000..de12511469b29 --- /dev/null +++ b/test/unit/fixtures/config-js/.testrc.js @@ -0,0 +1 @@ +module.exports = { foo: 'bar' } diff --git a/test/unit/fixtures/config-long-js/test.config.js b/test/unit/fixtures/config-long-js/test.config.js new file mode 100644 index 0000000000000..de12511469b29 --- /dev/null +++ b/test/unit/fixtures/config-long-js/test.config.js @@ -0,0 +1 @@ +module.exports = { foo: 'bar' } diff --git a/test/unit/fixtures/config-long-json/test.config.json b/test/unit/fixtures/config-long-json/test.config.json new file mode 100644 index 0000000000000..8c850a5fd2f53 --- /dev/null +++ b/test/unit/fixtures/config-long-json/test.config.json @@ -0,0 +1 @@ +{ "foo": "bar" }