Skip to content

Commit 562c662

Browse files
committed
test changes and updates
1 parent 8ae0685 commit 562c662

20 files changed

+10135
-2677
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ yarn-debug.log*
77
yarn-error.log*
88
lerna-debug.log*
99

10-
# Tests
11-
next.config.js
12-
1310
# Diagnostic reports (https://nodejs.org/api/report.html)
1411
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
1512

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ node_modules
1717
.next
1818

1919
# Test
20-
next.config.js
2120
__mocks__
21+
sample

__mocks__/makef.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
createFile: jest.fn()
3+
};

index.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
const { existsSync, readFileSync, appendFileSync } = require('fs')
1+
const fs = require('fs')
2+
const { promisify } = require('util')
3+
const exists = promisify(fs.exists)
24
const path = require('path')
35
const nextOnNetlify = require('next-on-netlify')
46
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
57
const { default: loadConfig } = require('next/dist/next-server/server/config')
8+
const makef = require('makef')
69
const makeDir = require('make-dir')
710
const cpx = require('cpx')
811
const isStaticExportProject = require('./helpers/isStaticExportProject')
@@ -12,9 +15,23 @@ const isStaticExportProject = require('./helpers/isStaticExportProject')
1215
// - Between the build and postbuild steps, any functions are bundled
1316

1417
module.exports = {
15-
async onPreBuild({ netlifyConfig = {}, packageJson: { scripts = {}, dependencies = {} }, utils }) {
18+
// TO-DO: remove default packageJson once CLI issue is diagnosed
19+
async onPreBuild({ netlifyConfig, packageJson = {}, utils }) {
1620
const { failBuild } = utils.build
21+
22+
if (!packageJson) {
23+
failBuild(`Could not find a package.json for this project`)
24+
return
25+
}
26+
27+
if (!netlifyConfig) {
28+
failBuild(`Could not find a Netlify configuration for this project`)
29+
return
30+
}
31+
1732
const { build } = netlifyConfig
33+
const { scripts = {}, dependencies = {} } = packageJson
34+
1835
// TO-DO: Post alpha, try to remove this workaround for missing deps in
1936
// the next-on-netlify function template
2037
await utils.run.command('npm install next-on-netlify@latest')
@@ -38,7 +55,8 @@ module.exports = {
3855
)
3956
}
4057

41-
if (existsSync('next.config.js')) {
58+
const hasNextConfig = await exists('next.config.js')
59+
if (hasNextConfig) {
4260
// If the next config exists, fail build if target isnt in acceptableTargets
4361
const acceptableTargets = ['serverless', 'experimental-serverless-trace']
4462
const nextConfig = loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.'))
@@ -53,7 +71,7 @@ module.exports = {
5371
target: 'serverless'
5472
}
5573
`
56-
appendFileSync('next.config.js', nextConfig)
74+
makef.createFile({ 'next.config.js': nextConfig })
5775
console.log(`** Adding next.config.js with target set to 'serverless' **`)
5876
}
5977
},
@@ -69,7 +87,8 @@ module.exports = {
6987
// if (!existsSync(FUNCTIONS_DIST)) {
7088
// await makeDir(FUNCTIONS_DIST);
7189
// }
72-
if (!existsSync(PUBLISH_DIR)) {
90+
const hasPublishDir = await exists(PUBLISH_DIR)
91+
if (!hasPublishDir) {
7392
await makeDir(PUBLISH_DIR)
7493
}
7594

0 commit comments

Comments
 (0)