Skip to content
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
7 changes: 6 additions & 1 deletion packages/build/src/commands/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const pathExists = require('path-exists')

// @todo Remove once we drop support for the legact default functions directory.
const { LEGACY_DEFAULT_FUNCTIONS_DIR } = require('../core/constants')

// Some `constants` have a default value when a specific file exists.
// Those default values are assigned by `@netlify/config`. However, the build
// command or plugins might create those specific files, in which case, the
Expand All @@ -19,7 +22,9 @@ const getConstants = async function ({ constants, buildDir }) {
// The current directory is the build directory, which is correct, so we don't
// need to resolve paths
const DEFAULT_PATHS = [
{ constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
// @todo Remove once we drop support for the legact default functions directory.
{ constantName: 'FUNCTIONS_SRC', defaultPath: LEGACY_DEFAULT_FUNCTIONS_DIR },
{ constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
{ constantName: 'EDGE_HANDLERS_SRC', defaultPath: 'edge-handlers' },
]

Expand Down
38 changes: 18 additions & 20 deletions packages/build/src/core/constants.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
'use strict'

const { relative, normalize, join } = require('path')
const { relative, normalize } = require('path')

const { getCacheDir } = require('@netlify/cache-utils')
const mapObj = require('map-obj')
const pathExists = require('path-exists')

const { version } = require('../../package.json')
const { logDefaultFunctionsSrcWarning, logNetlifyDirWarning } = require('../log/messages/core')
const { logLegacyDefaultFunctionsSrcWarning } = require('../log/messages/core')

// @todo Remove once we drop support for the legact default functions directory.
const LEGACY_DEFAULT_FUNCTIONS_DIR = 'netlify-automatic-functions'
const checkForLegacyDefaultFunctionsDir = async function (logs, buildDir) {
if (await pathExists(`${buildDir}/${LEGACY_DEFAULT_FUNCTIONS_DIR}`)) {
logLegacyDefaultFunctionsSrcWarning(logs, LEGACY_DEFAULT_FUNCTIONS_DIR)
}
}

// Retrieve constants passed to plugins
const getConstants = async function ({
Expand All @@ -22,7 +30,8 @@ const getConstants = async function ({
mode,
logs,
}) {
await validateNetlifyDir(logs, buildDir)
// @todo Remove once we drop support for the legact default functions directory.
await checkForLegacyDefaultFunctionsDir(logs, buildDir)
Copy link
Member Author

Choose a reason for hiding this comment

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

Theoretically there's nothing stopping people from explicitcly defining netlify-automatic-functions in the config as being their functions directory, in which case this warning should not be printed. However, to achieve this we would need to move this logic to @netlify/config, because at this point we don't know whether functions was added by the user or by us.

@ehmicky do you have an opinion on this?

Copy link
Contributor

@ehmicky ehmicky Jan 22, 2021

Choose a reason for hiding this comment

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

We ran some logs few weeks ago which confirmed that virtually no one was using netlify-automatic-functions since we have not documented it.

The main risk here is for users of @netlify/plugin-nextjs who installed it in their package.json. Those users will not know about netlify-automatic-functions since this is done under the hood. Instead, the way to fix this error would be for them to upgrade @netlify/plugin-nextjs (after we've released the new versions using netlify/functions).

I think this warning message is still safe to keep, but we might not need to move it to @netlify/config.

On the other hand, we might want to create an issue/PR to print a warning message in @netlify/build when a build is using the old version of @netlify/plugin-nextjs. What do you think?


const isLocal = mode !== 'buildbot'
const cacheDir = await getCacheDir({ mode })
Expand Down Expand Up @@ -73,22 +82,6 @@ const getConstants = async function ({
return constantsA
}

// Temporary warning until we launch this feature in February 2021
// TODO: remove once the feature is launched
const validateNetlifyDir = async function (logs, buildDir) {
if (await pathExists(`${buildDir}/${DEFAULT_FUNCTIONS_SRC}`)) {
logDefaultFunctionsSrcWarning(logs, NETLIFY_DIR, DEFAULT_FUNCTIONS_SRC)
return
}

if (await pathExists(`${buildDir}/${NETLIFY_DIR}`)) {
logNetlifyDirWarning(logs, NETLIFY_DIR, DEFAULT_FUNCTIONS_SRC)
}
}

const NETLIFY_DIR = 'netlify'
const DEFAULT_FUNCTIONS_SRC = join(NETLIFY_DIR, 'functions')

// The current directory is `buildDir`. Most constants are inside this `buildDir`.
// Instead of passing absolute paths, we pass paths relative to `buildDir`, so
// that logs are less verbose.
Expand All @@ -115,4 +108,9 @@ const CONSTANT_PATHS = new Set([
'CACHE_DIR',
])

module.exports = { getConstants }
module.exports = {
getConstants,

// @todo Remove once we drop support for the legact default functions directory.
LEGACY_DEFAULT_FUNCTIONS_DIR,
}
39 changes: 15 additions & 24 deletions packages/build/src/log/messages/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,6 @@ const logBuildStart = function (logs) {
logMessage(logs, `${name} ${version}`)
}

const logDefaultFunctionsSrcWarning = function (logs, netlifyDir, defaultFunctionsSrc) {
logError(
logs,
`
Detected site repository path: "${defaultFunctionsSrc}"
Starting in February 2021, this path will be used to detect and deploy Netlify functions.
To avoid potential build failures or irregularities, we recommend changing the name of the "${netlifyDir}" directory.
For more information, visit the Community update notification: community.netlify.com/t/upcoming-change-netlify-functions-as-zero-config-default-folder-for-deploying-netlify-functions/28789`,
)
}

const logNetlifyDirWarning = function (logs, netlifyDir, defaultFunctionsSrc) {
logError(
logs,
`
Detected site repository path: "${netlifyDir}"
Netlify will begin using this path for detecting default deployment features, starting with "${defaultFunctionsSrc}" in February 2021.
To avoid potential build failures or irregularities in the future, we recommend changing the name of the "${netlifyDir}" directory.
For more information, visit the Community update notification: community.netlify.com/t/upcoming-change-netlify-functions-as-zero-config-default-folder-for-deploying-netlify-functions/28789`,
)
}

const logBuildError = function ({ error, netlifyConfig, mode, logs, debug, testOpts }) {
const fullErrorInfo = getFullErrorInfo({ error, colors: true, debug })
const { severity } = fullErrorInfo
Expand Down Expand Up @@ -78,12 +56,25 @@ failed since something is still running.`),
)
}

const logLegacyDefaultFunctionsSrcWarning = function (logs, legacyDefaultFunctionsSrc) {
logError(
logs,
`
Detected site repository path: \`${legacyDefaultFunctionsSrc}\`. Netlify no longer recognizes this path as a default Functions directory location and can’t detect and build serverless functions stored there.

If you created this directory yourself, we recommend that you:
- rename the Functions directory to \`netlify/functions\`
- or explicitly set \`${legacyDefaultFunctionsSrc}\` as the Functions directory in your site’s build settings.

If you are using the \`@netlify/plugin-nextjs\` plugin, you should update it by running \`npm install @netlify/plugin-nextjs\` in your project directory.`,
)
}

module.exports = {
logBuildStart,
logDefaultFunctionsSrcWarning,
logNetlifyDirWarning,
logBuildError,
logBuildSuccess,
logTimer,
logLingeringProcesses,
logLegacyDefaultFunctionsSrcWarning,
}
Binary file modified packages/build/tests/commands/snapshots/tests.js.snap
Binary file not shown.
86 changes: 0 additions & 86 deletions packages/build/tests/core/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -945,92 +945,6 @@ Generated by [AVA](https://ava.li).
(Netlify Build completed in 1ms)`

## Print a warning message when "netlify" directory is used

> Snapshot 1

`␊
────────────────────────────────────────────────────────────────␊
Netlify Build ␊
────────────────────────────────────────────────────────────────␊
> Version␊
@netlify/build 1.0.0␊
> Flags␊
debug: true␊
featureFlags: {}␊
repositoryRoot: /file/path␊
testOpts:␊
pluginsListUrl: test␊
silentLingeringProcesses: true␊
> Current directory␊
/file/path␊
> Config file␊
No config file was defined: using default values.␊
> Resolved config␊
{}␊
> Context␊
production␊
Detected site repository path: "netlify"␊
Netlify will begin using this path for detecting default deployment features, starting with "netlify/functions" in February 2021.␊
To avoid potential build failures or irregularities in the future, we recommend changing the name of the "netlify" directory.␊
For more information, visit the Community update notification: community.netlify.com/t/upcoming-change-netlify-functions-as-zero-config-default-folder-for-deploying-netlify-functions/28789␊
────────────────────────────────────────────────────────────────␊
Netlify Build Complete ␊
────────────────────────────────────────────────────────────────␊
(Netlify Build completed in 1ms)`

## Print a warning message when "netlify/functions" directory is used

> Snapshot 1

`␊
────────────────────────────────────────────────────────────────␊
Netlify Build ␊
────────────────────────────────────────────────────────────────␊
> Version␊
@netlify/build 1.0.0␊
> Flags␊
debug: true␊
featureFlags: {}␊
repositoryRoot: /file/path␊
testOpts:␊
pluginsListUrl: test␊
silentLingeringProcesses: true␊
> Current directory␊
/file/path␊
> Config file␊
No config file was defined: using default values.␊
> Resolved config␊
{}␊
> Context␊
production␊
Detected site repository path: "netlify/functions"␊
Starting in February 2021, this path will be used to detect and deploy Netlify functions.␊
To avoid potential build failures or irregularities, we recommend changing the name of the "netlify" directory.␊
For more information, visit the Community update notification: community.netlify.com/t/upcoming-change-netlify-functions-as-zero-config-default-folder-for-deploying-netlify-functions/28789␊
────────────────────────────────────────────────────────────────␊
Netlify Build Complete ␊
────────────────────────────────────────────────────────────────␊
(Netlify Build completed in 1ms)`

## Telemetry error

> Snapshot 1
Expand Down
Binary file modified packages/build/tests/core/snapshots/tests.js.snap
Binary file not shown.
8 changes: 0 additions & 8 deletions packages/build/tests/core/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,6 @@ test('--featureFlags can be used', async (t) => {
await runFixture(t, 'empty', { flags: { featureFlags: 'test,test,testTwo' } })
})

test('Print a warning message when "netlify" directory is used', async (t) => {
await runFixture(t, 'netlify_dir')
})

test('Print a warning message when "netlify/functions" directory is used', async (t) => {
await runFixture(t, 'netlify_functions_dir')
})

// Normalize telemetry request so it can be snapshot
const normalizeSnapshot = function ({ body, ...request }) {
return { ...request, body: normalizeBody(body) }
Expand Down
Binary file modified packages/build/tests/env/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/error/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/install/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/manifest/snapshots/tests.js.snap
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: test
inputs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[plugins]]
package = "./plugin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

module.exports = {
onPreBuild({ constants: { FUNCTIONS_SRC } }) {
console.log(FUNCTIONS_SRC)
},
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
'use strict'

const { mkdir, rmdir } = require('fs')
const { dirname } = require('path')
const { promisify } = require('util')

const pMkdir = promisify(mkdir)
const pRmdir = promisify(rmdir)

const DEFAULT_FUNCTIONS_SRC = 'netlify-automatic-functions'
const DEFAULT_FUNCTIONS_SRC = 'netlify/functions'

module.exports = {
async onPreBuild({ constants: { FUNCTIONS_SRC } }) {
console.log(FUNCTIONS_SRC === undefined)
await pMkdir(dirname(DEFAULT_FUNCTIONS_SRC))
await pMkdir(DEFAULT_FUNCTIONS_SRC)
},
async onBuild({ constants: { FUNCTIONS_SRC } }) {
console.log(FUNCTIONS_SRC)
await pRmdir(DEFAULT_FUNCTIONS_SRC)
await pRmdir(dirname(DEFAULT_FUNCTIONS_SRC))
},
onPostBuild({ constants: { FUNCTIONS_SRC } }) {
console.log(FUNCTIONS_SRC === undefined)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict'

const { mkdir } = require('fs')
const { dirname } = require('path')
const { promisify } = require('util')

const pMkdir = promisify(mkdir)

const DEFAULT_FUNCTIONS_SRC = 'netlify-automatic-functions'
const DEFAULT_FUNCTIONS_SRC = 'netlify/functions'

module.exports = {
async onPreBuild() {
await pMkdir(dirname(DEFAULT_FUNCTIONS_SRC))
await pMkdir(DEFAULT_FUNCTIONS_SRC)
},
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use strict'

const { mkdir } = require('fs')
const { dirname } = require('path')
const { promisify } = require('util')

const pMkdir = promisify(mkdir)

const DEFAULT_FUNCTIONS_SRC = 'netlify-automatic-functions'
const DEFAULT_FUNCTIONS_SRC = 'netlify/functions'

module.exports = {
async onPreBuild({ constants: { FUNCTIONS_SRC } }) {
console.log(FUNCTIONS_SRC.endsWith('test'))
await pMkdir(dirname(DEFAULT_FUNCTIONS_SRC))
await pMkdir(DEFAULT_FUNCTIONS_SRC)
},
onBuild({ constants: { FUNCTIONS_SRC } }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: test
inputs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[plugins]]
package = "./plugin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

module.exports = {
onPreBuild({ constants: { FUNCTIONS_SRC } }) {
console.log(FUNCTIONS_SRC)
},
}
Loading