Skip to content

Commit 08d39e2

Browse files
authored
Merge pull request #28 from netlify/bug/fix-functions-src
2 parents 2849dc5 + 884efbd commit 08d39e2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const isStaticExportProject = require('./helpers/isStaticExportProject')
1515
// - Between the build and postbuild steps, any functions are bundled
1616

1717
module.exports = {
18-
async onPreBuild({ netlifyConfig, packageJson, utils }) {
18+
async onPreBuild({ netlifyConfig, packageJson, utils, constants: { FUNCTIONS_SRC } }) {
1919
const { failBuild } = utils.build
2020

2121
if (!packageJson) {
@@ -46,7 +46,8 @@ module.exports = {
4646
// failBuild(`This plugin cannot support apps that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.`);
4747
// }
4848

49-
const isFunctionsDirectoryCorrect = build && build.functions && build.functions === path.resolve('out_functions')
49+
const isFunctionsDirectoryCorrect =
50+
FUNCTIONS_SRC !== undefined && path.resolve(FUNCTIONS_SRC) === path.resolve('out_functions')
5051
if (!isFunctionsDirectoryCorrect) {
5152
// to do rephrase
5253
failBuild(

test/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('preBuild()', () => {
3939
netlifyConfig: {},
4040
packageJson,
4141
utils,
42+
constants: { FUNCTIONS_SRC: 'out_functions' },
4243
})
4344

4445
expect(utils.build.failBuild.mock.calls[0][0]).toEqual(
@@ -54,6 +55,7 @@ describe('preBuild()', () => {
5455
netlifyConfig,
5556
packageJson,
5657
utils,
58+
constants: { FUNCTIONS_SRC: 'out_functions' },
5759
})
5860

5961
expect(utils.build.failBuild.mock.calls[0][0]).toEqual(
@@ -62,13 +64,13 @@ describe('preBuild()', () => {
6264
})
6365

6466
test('fail build if the app has no functions directory defined', async () => {
65-
const netlifyConfig = { build: {} }
6667
const packageJson = {}
6768

6869
await plugin.onPreBuild({
69-
netlifyConfig,
70+
netlifyConfig: {},
7071
packageJson,
7172
utils,
73+
constants: {},
7274
})
7375

7476
expect(utils.build.failBuild.mock.calls[0][0]).toEqual(
@@ -81,23 +83,24 @@ describe('preBuild()', () => {
8183
netlifyConfig: {},
8284
packageJson: {},
8385
utils,
86+
constants: { FUNCTIONS_SRC: 'out_functions' },
8487
})
8588

8689
expect(makef.createFile.mock.calls.length).toEqual(1)
8790
})
8891

8992
test(`fail build if the app's next config has an invalid target`, async () => {
90-
const netlifyConfig = { build: { functions: path.resolve('out_functions') } }
9193
mockFs({
9294
'next.config.js': {
9395
target: 'nonsense',
9496
},
9597
})
9698

9799
await plugin.onPreBuild({
98-
netlifyConfig,
100+
netlifyConfig: {},
99101
packageJson: {},
100102
utils,
103+
constants: { FUNCTIONS_SRC: 'out_functions' },
101104
})
102105

103106
mockFs.restore()

0 commit comments

Comments
 (0)