Skip to content

Fix next.config.js resolution #35

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

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const util = require('util')
const nextOnNetlify = require('next-on-netlify')
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
const { default: loadConfig } = require('next/dist/next-server/server/config')
const findUp = require('find-up')
const makeDir = require('make-dir')
const pathExists = require('path-exists')
const cpx = require('cpx')
Expand Down Expand Up @@ -52,8 +53,8 @@ module.exports = {
)
}

const hasNextConfig = await pathExists('next.config.js')
if (hasNextConfig) {
const nextConfigPath = await findUp('next.config.js')
if (nextConfigPath !== undefined) {
// If the next config exists, fail build if target isnt in acceptableTargets
const acceptableTargets = ['serverless', 'experimental-serverless-trace']
const nextConfig = loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.'))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
"dependencies": {
"cpx": "^1.5.0",
"find-up": "^4.1.0",
"make-dir": "^3.1.0",
"next": "^9.5.3",
"next-on-netlify": "^2.6.0",
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions test/fixtures/deep_invalid_next_config/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
target: 'server',
}
25 changes: 14 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ describe('preBuild()', () => {
expect(await pathExists('next.config.js')).toBeTruthy()
})

test(`fail build if the app's next config has an invalid target`, async () => {
await useFixture('invalid_next_config')
await expect(
plugin.onPreBuild({
netlifyConfig: {},
packageJson: DUMMY_PACKAGE_JSON,
utils,
constants: { FUNCTIONS_SRC: 'out_functions' },
}),
).rejects.toThrow(`next.config.js must be one of: serverless, experimental-serverless-trace`)
})
test.each(['invalid_next_config', 'deep_invalid_next_config'])(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:O

`fail build if the app's next config has an invalid target`,
async (fixtureName) => {
await useFixture(fixtureName)
await expect(
plugin.onPreBuild({
netlifyConfig: {},
packageJson: DUMMY_PACKAGE_JSON,
utils,
constants: { FUNCTIONS_SRC: 'out_functions' },
}),
).rejects.toThrow(`next.config.js must be one of: serverless, experimental-serverless-trace`)
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

friendly reminder to update this with the new fixture and failBuild logic whenever you merge everything :) <3

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and fixed! 👍

)
})

describe('onBuild()', () => {
Expand Down