Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
e68e50d6
Unverified
Commit
e68e50d6
authored
Dec 11, 2019
by
Joe Haddad
Committed by
GitHub
Dec 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add More Configuration File Options (#9713)
parent
2347e3e4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
5 deletions
+37
-5
find-config.ts
packages/next/lib/find-config.ts
+16
-5
find-config.test.js
test/unit/find-config.test.js
+18
-0
.testrc.js
test/unit/fixtures/config-js/.testrc.js
+1
-0
test.config.js
test/unit/fixtures/config-long-js/test.config.js
+1
-0
test.config.json
test/unit/fixtures/config-long-json/test.config.json
+1
-0
No files found.
packages/next/lib/find-config.ts
View file @
e68e50d6
...
@@ -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`
,
{
[
cwd
:
directory
,
`.
${
key
}
rc.json`
,
})
`
${
key
}
.config.json`
,
`.
${
key
}
rc.js`
,
`
${
key
}
.config.js`
,
],
{
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'
)
...
...
test/unit/find-config.test.js
View file @
e68e50d6
...
@@ -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'
),
...
...
test/unit/fixtures/config-js/.testrc.js
0 → 100644
View file @
e68e50d6
module
.
exports
=
{
foo
:
'bar'
}
test/unit/fixtures/config-long-js/test.config.js
0 → 100644
View file @
e68e50d6
module
.
exports
=
{
foo
:
'bar'
}
test/unit/fixtures/config-long-json/test.config.json
0 → 100644
View file @
e68e50d6
{
"foo"
:
"bar"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment