diff --git a/packages/build/src/commands/constants.js b/packages/build/src/commands/constants.js index 3cb2bbb01d..add94e7ae6 100644 --- a/packages/build/src/commands/constants.js +++ b/packages/build/src/commands/constants.js @@ -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 @@ -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' }, ] diff --git a/packages/build/src/core/constants.js b/packages/build/src/core/constants.js index 1466b120ef..b2685042e2 100644 --- a/packages/build/src/core/constants.js +++ b/packages/build/src/core/constants.js @@ -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 ({ @@ -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) const isLocal = mode !== 'buildbot' const cacheDir = await getCacheDir({ mode }) @@ -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. @@ -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, +} diff --git a/packages/build/src/log/messages/core.js b/packages/build/src/log/messages/core.js index 63b2d2b27c..255abe2283 100644 --- a/packages/build/src/log/messages/core.js +++ b/packages/build/src/log/messages/core.js @@ -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 @@ -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, } diff --git a/packages/build/tests/commands/snapshots/tests.js.snap b/packages/build/tests/commands/snapshots/tests.js.snap index d2f686984e..42306a4a9a 100644 Binary files a/packages/build/tests/commands/snapshots/tests.js.snap and b/packages/build/tests/commands/snapshots/tests.js.snap differ diff --git a/packages/build/tests/core/snapshots/tests.js.md b/packages/build/tests/core/snapshots/tests.js.md index 3eb0e39c82..c7ade1609a 100644 --- a/packages/build/tests/core/snapshots/tests.js.md +++ b/packages/build/tests/core/snapshots/tests.js.md @@ -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 diff --git a/packages/build/tests/core/snapshots/tests.js.snap b/packages/build/tests/core/snapshots/tests.js.snap index 0362c17195..d3340baa56 100644 Binary files a/packages/build/tests/core/snapshots/tests.js.snap and b/packages/build/tests/core/snapshots/tests.js.snap differ diff --git a/packages/build/tests/core/tests.js b/packages/build/tests/core/tests.js index d325767ae3..64218e9b77 100644 --- a/packages/build/tests/core/tests.js +++ b/packages/build/tests/core/tests.js @@ -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) } diff --git a/packages/build/tests/env/snapshots/tests.js.snap b/packages/build/tests/env/snapshots/tests.js.snap index b642fff0b4..02e0fef071 100644 Binary files a/packages/build/tests/env/snapshots/tests.js.snap and b/packages/build/tests/env/snapshots/tests.js.snap differ diff --git a/packages/build/tests/error/snapshots/tests.js.snap b/packages/build/tests/error/snapshots/tests.js.snap index 4f3209d8a8..8b6398c082 100644 Binary files a/packages/build/tests/error/snapshots/tests.js.snap and b/packages/build/tests/error/snapshots/tests.js.snap differ diff --git a/packages/build/tests/install/snapshots/tests.js.snap b/packages/build/tests/install/snapshots/tests.js.snap index fb24c14942..9a911fc93c 100644 Binary files a/packages/build/tests/install/snapshots/tests.js.snap and b/packages/build/tests/install/snapshots/tests.js.snap differ diff --git a/packages/build/tests/manifest/snapshots/tests.js.snap b/packages/build/tests/manifest/snapshots/tests.js.snap index 74b813e3ca..ff8b504c05 100644 Binary files a/packages/build/tests/manifest/snapshots/tests.js.snap and b/packages/build/tests/manifest/snapshots/tests.js.snap differ diff --git a/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/manifest.yml b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/manifest.yml new file mode 100644 index 0000000000..a3512f0259 --- /dev/null +++ b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/manifest.yml @@ -0,0 +1,2 @@ +name: test +inputs: [] diff --git a/packages/build/tests/core/fixtures/netlify_dir/netlify/.gitkeep b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/netlify-automatic-functions/.gitkeep similarity index 100% rename from packages/build/tests/core/fixtures/netlify_dir/netlify/.gitkeep rename to packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/netlify-automatic-functions/.gitkeep diff --git a/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/netlify.toml b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/netlify.toml new file mode 100644 index 0000000000..81b0ce8bb1 --- /dev/null +++ b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/netlify.toml @@ -0,0 +1,2 @@ +[[plugins]] +package = "./plugin" diff --git a/packages/build/tests/core/fixtures/netlify_functions_dir/netlify/functions/.gitkeep b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/netlify/functions/.gitkeep similarity index 100% rename from packages/build/tests/core/fixtures/netlify_functions_dir/netlify/functions/.gitkeep rename to packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/netlify/functions/.gitkeep diff --git a/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/plugin.js b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/plugin.js new file mode 100644 index 0000000000..6d4d9c04c7 --- /dev/null +++ b/packages/build/tests/plugins/fixtures/functions_src_default_and_legacy/plugin.js @@ -0,0 +1,7 @@ +'use strict' + +module.exports = { + onPreBuild({ constants: { FUNCTIONS_SRC } }) { + console.log(FUNCTIONS_SRC) + }, +} diff --git a/packages/build/tests/plugins/fixtures/functions_src_dynamic/plugin.js b/packages/build/tests/plugins/fixtures/functions_src_dynamic/plugin.js index ebeb6b3390..de993cb339 100644 --- a/packages/build/tests/plugins/fixtures/functions_src_dynamic/plugin.js +++ b/packages/build/tests/plugins/fixtures/functions_src_dynamic/plugin.js @@ -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) diff --git a/packages/build/tests/plugins/fixtures/functions_src_dynamic_bundle/plugin.js b/packages/build/tests/plugins/fixtures/functions_src_dynamic_bundle/plugin.js index 46d5fdf012..6c48a28ce7 100644 --- a/packages/build/tests/plugins/fixtures/functions_src_dynamic_bundle/plugin.js +++ b/packages/build/tests/plugins/fixtures/functions_src_dynamic_bundle/plugin.js @@ -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) }, } diff --git a/packages/build/tests/plugins/fixtures/functions_src_dynamic_ignore/plugin.js b/packages/build/tests/plugins/fixtures/functions_src_dynamic_ignore/plugin.js index 775af8c26e..a97b32d542 100644 --- a/packages/build/tests/plugins/fixtures/functions_src_dynamic_ignore/plugin.js +++ b/packages/build/tests/plugins/fixtures/functions_src_dynamic_ignore/plugin.js @@ -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 } }) { diff --git a/packages/build/tests/plugins/fixtures/functions_src_legacy/manifest.yml b/packages/build/tests/plugins/fixtures/functions_src_legacy/manifest.yml new file mode 100644 index 0000000000..a3512f0259 --- /dev/null +++ b/packages/build/tests/plugins/fixtures/functions_src_legacy/manifest.yml @@ -0,0 +1,2 @@ +name: test +inputs: [] diff --git a/packages/config/tests/normalize/fixtures/default_functions_not_defined/netlify-automatic-functions/.gitkeep b/packages/build/tests/plugins/fixtures/functions_src_legacy/netlify-automatic-functions/.gitkeep similarity index 100% rename from packages/config/tests/normalize/fixtures/default_functions_not_defined/netlify-automatic-functions/.gitkeep rename to packages/build/tests/plugins/fixtures/functions_src_legacy/netlify-automatic-functions/.gitkeep diff --git a/packages/build/tests/plugins/fixtures/functions_src_legacy/netlify.toml b/packages/build/tests/plugins/fixtures/functions_src_legacy/netlify.toml new file mode 100644 index 0000000000..81b0ce8bb1 --- /dev/null +++ b/packages/build/tests/plugins/fixtures/functions_src_legacy/netlify.toml @@ -0,0 +1,2 @@ +[[plugins]] +package = "./plugin" diff --git a/packages/build/tests/plugins/fixtures/functions_src_legacy/plugin.js b/packages/build/tests/plugins/fixtures/functions_src_legacy/plugin.js new file mode 100644 index 0000000000..6d4d9c04c7 --- /dev/null +++ b/packages/build/tests/plugins/fixtures/functions_src_legacy/plugin.js @@ -0,0 +1,7 @@ +'use strict' + +module.exports = { + onPreBuild({ constants: { FUNCTIONS_SRC } }) { + console.log(FUNCTIONS_SRC) + }, +} diff --git a/packages/build/tests/plugins/snapshots/tests.js.md b/packages/build/tests/plugins/snapshots/tests.js.md index b7a5fd412e..db7a82d48e 100644 --- a/packages/build/tests/plugins/snapshots/tests.js.md +++ b/packages/build/tests/plugins/snapshots/tests.js.md @@ -3778,7 +3778,7 @@ Generated by [AVA](https://ava.li). 2. onBuild command from /file/path ␊ ────────────────────────────────────────────────────────────────␊ ␊ - netlify-automatic-functions␊ + netlify/functions␊ ␊ (/file/path onBuild completed in 1ms)␊ ␊ @@ -3967,7 +3967,77 @@ Generated by [AVA](https://ava.li). 2. Functions bundling ␊ ────────────────────────────────────────────────────────────────␊ ␊ - No Functions were found in netlify-automatic-functions directory␊ + No Functions were found in netlify/functions directory␊ + ␊ + (Functions bundling completed in 1ms)␊ + ␊ + ────────────────────────────────────────────────────────────────␊ + Netlify Build Complete ␊ + ────────────────────────────────────────────────────────────────␊ + ␊ + (Netlify Build completed in 1ms)` + +## constants.FUNCTIONS_SRC ignores the legacy default functions directory if the new default directory exists + +> 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␊ + /file/path␊ + ␊ + > Resolved config␊ + build:␊ + functions: /file/path␊ + plugins:␊ + - inputs: {}␊ + origin: config␊ + package: /file/path␊ + ␊ + > Context␊ + production␊ + ␊ + Detected site repository path: `netlify-automatic-functions`. 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 `netlify-automatic-functions` 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.␊ + ␊ + > Loading plugins␊ + - /file/path from netlify.toml␊ + ␊ + ────────────────────────────────────────────────────────────────␊ + 1. onPreBuild command from /file/path ␊ + ────────────────────────────────────────────────────────────────␊ + ␊ + netlify/functions␊ + ␊ + (/file/path onPreBuild completed in 1ms)␊ + ␊ + ────────────────────────────────────────────────────────────────␊ + 2. Functions bundling ␊ + ────────────────────────────────────────────────────────────────␊ + ␊ + No Functions were found in netlify/functions directory␊ ␊ (Functions bundling completed in 1ms)␊ ␊ @@ -4101,6 +4171,76 @@ Generated by [AVA](https://ava.li). ␊ (Netlify Build completed in 1ms)` +## constants.FUNCTIONS_SRC uses legacy default functions directory, if it exists, and shows a warning + +> 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␊ + /file/path␊ + ␊ + > Resolved config␊ + build:␊ + functions: /file/path␊ + plugins:␊ + - inputs: {}␊ + origin: config␊ + package: /file/path␊ + ␊ + > Context␊ + production␊ + ␊ + Detected site repository path: `netlify-automatic-functions`. 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 `netlify-automatic-functions` 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.␊ + ␊ + > Loading plugins␊ + - /file/path from netlify.toml␊ + ␊ + ────────────────────────────────────────────────────────────────␊ + 1. onPreBuild command from /file/path ␊ + ────────────────────────────────────────────────────────────────␊ + ␊ + netlify-automatic-functions␊ + ␊ + (/file/path onPreBuild completed in 1ms)␊ + ␊ + ────────────────────────────────────────────────────────────────␊ + 2. Functions bundling ␊ + ────────────────────────────────────────────────────────────────␊ + ␊ + No Functions were found in netlify-automatic-functions directory␊ + ␊ + (Functions bundling completed in 1ms)␊ + ␊ + ────────────────────────────────────────────────────────────────␊ + Netlify Build Complete ␊ + ────────────────────────────────────────────────────────────────␊ + ␊ + (Netlify Build completed in 1ms)` + ## constants.IS_LOCAL CI > Snapshot 1 diff --git a/packages/build/tests/plugins/snapshots/tests.js.snap b/packages/build/tests/plugins/snapshots/tests.js.snap index 92cf2cabd8..aaa3552501 100644 Binary files a/packages/build/tests/plugins/snapshots/tests.js.snap and b/packages/build/tests/plugins/snapshots/tests.js.snap differ diff --git a/packages/build/tests/plugins/tests.js b/packages/build/tests/plugins/tests.js index 769e005c51..33e50edba8 100644 --- a/packages/build/tests/plugins/tests.js +++ b/packages/build/tests/plugins/tests.js @@ -50,6 +50,14 @@ test('constants.FUNCTIONS_SRC default value', async (t) => { await runFixture(t, 'functions_src_default') }) +test('constants.FUNCTIONS_SRC uses legacy default functions directory, if it exists, and shows a warning', async (t) => { + await runFixture(t, 'functions_src_legacy') +}) + +test('constants.FUNCTIONS_SRC ignores the legacy default functions directory if the new default directory exists', async (t) => { + await runFixture(t, 'functions_src_default_and_legacy') +}) + test('constants.FUNCTIONS_SRC relative path', async (t) => { await runFixture(t, 'functions_src_relative') }) diff --git a/packages/build/tests/status/snapshots/tests.js.snap b/packages/build/tests/status/snapshots/tests.js.snap index ccd641202d..189a5eed3f 100644 Binary files a/packages/build/tests/status/snapshots/tests.js.snap and b/packages/build/tests/status/snapshots/tests.js.snap differ diff --git a/packages/config/src/files.js b/packages/config/src/files.js index 8355d6f810..a5877dcf81 100644 --- a/packages/config/src/files.js +++ b/packages/config/src/files.js @@ -84,7 +84,9 @@ const addDefaultPaths = async function (build, baseRel) { } const DEFAULT_PATHS = [ + // @todo Remove once we drop support for the legact default functions directory. { property: 'functions', defaultPath: 'netlify-automatic-functions' }, + { property: 'functions', defaultPath: 'netlify/functions' }, { property: 'edge_handlers', defaultPath: 'edge-handlers' }, ] diff --git a/packages/config/tests/api/snapshots/tests.js.snap b/packages/config/tests/api/snapshots/tests.js.snap index fb1a6d95c7..cdc7b2457f 100644 Binary files a/packages/config/tests/api/snapshots/tests.js.snap and b/packages/config/tests/api/snapshots/tests.js.snap differ diff --git a/packages/config/tests/cli/snapshots/tests.js.snap b/packages/config/tests/cli/snapshots/tests.js.snap index 8719b4ac6a..1f5e62619c 100644 Binary files a/packages/config/tests/cli/snapshots/tests.js.snap and b/packages/config/tests/cli/snapshots/tests.js.snap differ diff --git a/packages/config/tests/log/snapshots/tests.js.snap b/packages/config/tests/log/snapshots/tests.js.snap index 329fe83e36..fc2855fed2 100644 Binary files a/packages/config/tests/log/snapshots/tests.js.snap and b/packages/config/tests/log/snapshots/tests.js.snap differ diff --git a/packages/config/tests/normalize/fixtures/default_functions_not_defined/netlify/functions/.gitkeep b/packages/config/tests/normalize/fixtures/default_functions_not_defined/netlify/functions/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/config/tests/normalize/fixtures/default_functions_not_defined_directory_not_found/.gitkeep b/packages/config/tests/normalize/fixtures/default_functions_not_defined_directory_not_found/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/config/tests/normalize/snapshots/tests.js.md b/packages/config/tests/normalize/snapshots/tests.js.md index fa95191c7e..f19c2af70e 100644 --- a/packages/config/tests/normalize/snapshots/tests.js.md +++ b/packages/config/tests/normalize/snapshots/tests.js.md @@ -353,7 +353,7 @@ Generated by [AVA](https://ava.li). "siteInfo": {}␊ }` -## Assign default functions if build.functions is not defined +## Assign default functions if build.functions is not defined and default directory exists > Snapshot 1 @@ -784,6 +784,91 @@ Generated by [AVA](https://ava.li). "siteInfo": {}␊ }` +## Does not assign default functions if default functions directory does not exist + +> Snapshot 1 + + `{␊ + "branch": "branch",␊ + "buildDir": "/file/path",␊ + "config": {␊ + "build": {␊ + "environment": {}␊ + },␊ + "plugins": []␊ + },␊ + "context": "production",␊ + "env": {␊ + "BRANCH": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "branch"␊ + },␊ + "CACHED_COMMIT_REF": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "HEXADECIMAL_ID"␊ + },␊ + "COMMIT_REF": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "HEXADECIMAL_ID"␊ + },␊ + "CONTEXT": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "production"␊ + },␊ + "GATSBY_TELEMETRY_DISABLED": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "1"␊ + },␊ + "HEAD": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "branch"␊ + },␊ + "LANG": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "en_US.UTF-8"␊ + },␊ + "LANGUAGE": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "en_US:en"␊ + },␊ + "LC_ALL": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "en_US.UTF-8"␊ + },␊ + "NEXT_TELEMETRY_DISABLED": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "1"␊ + },␊ + "PULL_REQUEST": {␊ + "sources": [␊ + "general"␊ + ],␊ + "value": "false"␊ + }␊ + },␊ + "siteInfo": {}␊ + }` + ## Some properties can be capitalized > Snapshot 1 diff --git a/packages/config/tests/normalize/snapshots/tests.js.snap b/packages/config/tests/normalize/snapshots/tests.js.snap index 4cdeb2e5e3..c743166561 100644 Binary files a/packages/config/tests/normalize/snapshots/tests.js.snap and b/packages/config/tests/normalize/snapshots/tests.js.snap differ diff --git a/packages/config/tests/normalize/tests.js b/packages/config/tests/normalize/tests.js index 0452209553..b744589912 100644 --- a/packages/config/tests/normalize/tests.js +++ b/packages/config/tests/normalize/tests.js @@ -53,10 +53,14 @@ test('Add build.commandOrigin ui if it came from defaultConfig', async (t) => { await runFixture(t, 'empty', { flags: { defaultConfig } }) }) -test('Assign default functions if build.functions is not defined', async (t) => { +test('Assign default functions if build.functions is not defined and default directory exists', async (t) => { await runFixture(t, 'default_functions_not_defined') }) +test('Does not assign default functions if default functions directory does not exist', async (t) => { + await runFixture(t, 'default_functions_not_defined_directory_not_found') +}) + test('Does not assign default functions if build.functions is defined', async (t) => { await runFixture(t, 'default_functions_defined') }) diff --git a/packages/config/tests/validate/snapshots/tests.js.snap b/packages/config/tests/validate/snapshots/tests.js.snap index a748f111d6..01e38efc71 100644 Binary files a/packages/config/tests/validate/snapshots/tests.js.snap and b/packages/config/tests/validate/snapshots/tests.js.snap differ