Skip to content

Functions UI build settings #28

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 13, 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 @@ -15,7 +15,7 @@ const isStaticExportProject = require('./helpers/isStaticExportProject')
// - Between the build and postbuild steps, any functions are bundled

module.exports = {
async onPreBuild({ netlifyConfig, packageJson, utils }) {
async onPreBuild({ netlifyConfig, packageJson, utils, constants: { FUNCTIONS_SRC } }) {
const { failBuild } = utils.build

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

const isFunctionsDirectoryCorrect = build && build.functions && build.functions === path.resolve('out_functions')
const isFunctionsDirectoryCorrect =
FUNCTIONS_SRC !== undefined && path.resolve(FUNCTIONS_SRC) === path.resolve('out_functions')
if (!isFunctionsDirectoryCorrect) {
// to do rephrase
failBuild(
Expand Down
11 changes: 7 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('preBuild()', () => {
netlifyConfig: {},
packageJson,
utils,
constants: { FUNCTIONS_SRC: 'out_functions' },
})

expect(utils.build.failBuild.mock.calls[0][0]).toEqual(
Expand All @@ -54,6 +55,7 @@ describe('preBuild()', () => {
netlifyConfig,
packageJson,
utils,
constants: { FUNCTIONS_SRC: 'out_functions' },
})

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

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

await plugin.onPreBuild({
netlifyConfig,
netlifyConfig: {},
packageJson,
utils,
constants: {},
})

expect(utils.build.failBuild.mock.calls[0][0]).toEqual(
Expand All @@ -81,23 +83,24 @@ describe('preBuild()', () => {
netlifyConfig: {},
packageJson: {},
utils,
constants: { FUNCTIONS_SRC: 'out_functions' },
})

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

test(`fail build if the app's next config has an invalid target`, async () => {
const netlifyConfig = { build: { functions: path.resolve('out_functions') } }
mockFs({
'next.config.js': {
target: 'nonsense',
},
})

await plugin.onPreBuild({
netlifyConfig,
netlifyConfig: {},
packageJson: {},
utils,
constants: { FUNCTIONS_SRC: 'out_functions' },
})

mockFs.restore()
Expand Down