Skip to content

Commit 71b5c65

Browse files
committed
chore: changes from review
1 parent 08d1bfe commit 71b5c65

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

helpers/checkNxConfig.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ const checkNxConfig = ({ netlifyConfig, nextConfig, failBuild, constants: { PUBL
99
"- When using Nx you must set a value for 'distDir' in your next.config.js, and the value cannot be '.next'",
1010
)
1111
}
12-
if (!PUBLISH_DIR.startsWith('apps')) {
12+
// The PUBLISH_DIR constant is normalized, so no leading slash is needed
13+
if (!PUBLISH_DIR.startsWith('apps/')) {
1314
errors.push(
1415
"Please set the 'publish' value in your Netlify build config to a folder inside your app directory. e.g. 'apps/myapp/out'",
1516
)
1617
}
17-
18+
// Look for the config file as a sibling of the publish dir
1819
const expectedConfigFile = path.resolve(netlifyConfig.build.publish, '..', 'next.config.js')
1920

2021
if (expectedConfigFile !== nextConfig.configFile) {

helpers/getNextRoot.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const { existsSync } = require('fs')
22
const path = require('path')
33

4+
/**
5+
* If we're in a monorepo then the Next root may not be the same as the base directory
6+
* If there's no next.config.js in the root, we instead look for it as a sibling of the publish dir
7+
*/
48
const getNextRoot = ({ netlifyConfig }) => {
59
let nextRoot = process.cwd()
610
if (!existsSync(path.join(nextRoot, 'next.config.js')) && netlifyConfig.build.publish) {

helpers/verifyBuildTarget.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getNextRoot = require('./getNextRoot')
99
const verifyBuildTarget = async ({ failBuild, netlifyConfig }) => {
1010
const nextRoot = getNextRoot({ netlifyConfig })
1111

12-
const { target, configFile, ...rest } = await getNextConfig(failBuild, nextRoot)
12+
const { target, configFile } = await getNextConfig(failBuild, nextRoot)
1313

1414
// If the next config exists, log warning if target isnt in acceptableTargets
1515
const acceptableTargets = ['serverless', 'experimental-serverless-trace']
@@ -46,10 +46,11 @@ const verifyBuildTarget = async ({ failBuild, netlifyConfig }) => {
4646
if (!configFile) {
4747
await writeFile(
4848
path.resolve('next.config.js'),
49-
`module.exports = {
50-
// Supported targets are "serverless" and "experimental-serverless-trace"
51-
target: "serverless"
52-
}`,
49+
`
50+
module.exports = {
51+
// Supported targets are "serverless" and "experimental-serverless-trace"
52+
target: "serverless"
53+
}`,
5354
)
5455
}
5556
// Force the new config to be generated

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = {
3737
// Because we memoize nextConfig, we need to do this after the write file
3838
const nextConfig = await getNextConfig(utils.failBuild, nextRoot)
3939

40+
// Nx needs special config handling, so check for it specifically
4041
const isNx = Boolean(
4142
(packageJson.devDependencies && packageJson.devDependencies['@nrwl/next']) ||
4243
(packageJson.dependencies && packageJson.dependencies['@nrwl/next']),

src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const build = async (functionsPath, publishPath, nextRoot) => {
1919
functionsPath,
2020
publishPath,
2121
})
22+
23+
// If we're in a monorepo we need to move into the Next site root
2224
const oldCwd = process.cwd()
2325
if (nextRoot !== oldCwd) {
2426
process.chdir(nextRoot)
@@ -35,6 +37,7 @@ const build = async (functionsPath, publishPath, nextRoot) => {
3537

3638
setupHeaders(publishPath)
3739

40+
// ...and move back after
3841
if (nextRoot !== oldCwd) {
3942
process.chdir(oldCwd)
4043
}

0 commit comments

Comments
 (0)