@netlify/build 26.5.3 → 27.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "26.5.3",
3
+ "version": "27.0.1",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./src/core/main.js",
@@ -56,11 +56,11 @@
56
56
  "license": "MIT",
57
57
  "dependencies": {
58
58
  "@bugsnag/js": "^7.0.0",
59
+ "@netlify/edge-bundler": "^0.12.0",
59
60
  "@netlify/cache-utils": "^4.0.0",
60
- "@netlify/config": "^17.0.0",
61
+ "@netlify/config": "^18.0.0",
61
62
  "@netlify/functions-utils": "^4.0.0",
62
63
  "@netlify/git-utils": "^4.0.0",
63
- "@netlify/plugin-edge-handlers": "^3.0.7",
64
64
  "@netlify/plugins-list": "^6.19.0",
65
65
  "@netlify/run-utils": "^4.0.0",
66
66
  "@netlify/zip-it-and-ship-it": "5.9.0",
@@ -11,7 +11,7 @@ export const getConstants = async function ({
11
11
  configPath,
12
12
  buildDir,
13
13
  functionsDistDir,
14
- edgeHandlersDistDir,
14
+ edgeFunctionsDistDir,
15
15
  cacheDir,
16
16
  netlifyConfig,
17
17
  siteInfo: { id: siteId },
@@ -27,8 +27,8 @@ export const getConstants = async function ({
27
27
  CONFIG_PATH: configPath,
28
28
  // The directory where built serverless functions are placed before deployment
29
29
  FUNCTIONS_DIST: functionsDistDir,
30
- // The directory where built Edge Handlers are placed before deployment
31
- EDGE_HANDLERS_DIST: edgeHandlersDistDir,
30
+ // The directory where built Edge Functions are placed before deployment
31
+ EDGE_FUNCTIONS_DIST: edgeFunctionsDistDir,
32
32
  // Path to the Netlify build cache folder
33
33
  CACHE_DIR: normalizedCacheDir,
34
34
  // Boolean indicating whether the build was run locally (Netlify CLI) or in the production CI
@@ -44,15 +44,15 @@ export const getConstants = async function ({
44
44
  // The directory where internal functions (i.e. generated programmatically
45
45
  // via plugins or others) live
46
46
  INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
47
- // The directory where internal Edge Handlers (i.e. generated programmatically
47
+ // The directory where internal Edge Functions (i.e. generated programmatically
48
48
  // via plugins or others) live
49
- INTERNAL_EDGE_HANDLERS_SRC: `${buildDir}/${INTERNAL_EDGE_HANDLERS_SRC}`,
49
+ INTERNAL_EDGE_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_EDGE_FUNCTIONS_SRC}`,
50
50
  }
51
51
  const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig })
52
52
  return constantsA
53
53
  }
54
54
 
55
- const INTERNAL_EDGE_HANDLERS_SRC = '.netlify/edge-handlers'
55
+ const INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions'
56
56
  const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal'
57
57
 
58
58
  // Retrieve constants which might change during the build if a plugin modifies
@@ -62,7 +62,7 @@ export const addMutableConstants = async function ({
62
62
  constants,
63
63
  buildDir,
64
64
  netlifyConfig: {
65
- build: { publish, edge_handlers: edgeHandlers },
65
+ build: { publish, edge_functions: edgeFunctions },
66
66
  functionsDirectory,
67
67
  },
68
68
  }) {
@@ -72,8 +72,8 @@ export const addMutableConstants = async function ({
72
72
  PUBLISH_DIR: publish,
73
73
  // The directory where function source code lives
74
74
  FUNCTIONS_SRC: functionsDirectory,
75
- // The directory where edge handlers source code lives
76
- EDGE_HANDLERS_SRC: edgeHandlers,
75
+ // The directory where Edge Functions source code lives
76
+ EDGE_FUNCTIONS_SRC: edgeFunctions,
77
77
  }
78
78
  const constantsB = await addDefaultConstants(constantsA, buildDir)
79
79
  const constantsC = normalizeConstantsPaths(constantsB, buildDir)
@@ -100,7 +100,7 @@ const DEFAULT_PATHS = [
100
100
  // @todo Remove once we drop support for the legacy default functions directory.
101
101
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
102
102
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
103
- { constantName: 'EDGE_HANDLERS_SRC', defaultPath: 'netlify/edge-handlers' },
103
+ { constantName: 'EDGE_FUNCTIONS_SRC', defaultPath: 'netlify/edge-functions' },
104
104
  ]
105
105
 
106
106
  const addDefaultConstant = async function ({ constants, constantName, defaultPath, buildDir }) {
@@ -148,9 +148,9 @@ const CONSTANT_PATHS = new Set([
148
148
  'PUBLISH_DIR',
149
149
  'FUNCTIONS_SRC',
150
150
  'FUNCTIONS_DIST',
151
- 'INTERNAL_EDGE_HANDLERS_SRC',
151
+ 'INTERNAL_EDGE_FUNCTIONS_SRC',
152
152
  'INTERNAL_FUNCTIONS_SRC',
153
- 'EDGE_HANDLERS_DIST',
154
- 'EDGE_HANDLERS_SRC',
153
+ 'EDGE_FUNCTIONS_DIST',
154
+ 'EDGE_FUNCTIONS_SRC',
155
155
  'CACHE_DIR',
156
156
  ])
@@ -17,5 +17,7 @@ export const DEFAULT_FEATURE_FLAGS = {
17
17
  buildbot_es_modules_esbuild: false,
18
18
  buildbot_zisi_trace_nft: false,
19
19
  buildbot_zisi_esbuild_parser: false,
20
+ edge_functions_cache_cli: false,
21
+ edge_functions_produce_eszip: false,
20
22
  zisi_parse_isc: false,
21
23
  }
package/src/core/flags.js CHANGED
@@ -110,9 +110,9 @@ Default: Current Node.js binary`,
110
110
  Default: automatically guessed`,
111
111
  hidden: true,
112
112
  },
113
- edgeHandlersDistDir: {
113
+ edgeFunctionsDistDir: {
114
114
  string: true,
115
- describe: `Path to the directory where packaged Edge Handlers are kept.
115
+ describe: `Path to the directory where packaged Edge Functions are kept.
116
116
  Default: automatically guessed`,
117
117
  hidden: true,
118
118
  },
package/src/core/main.js CHANGED
@@ -164,7 +164,7 @@ const tExecBuild = async function ({
164
164
  verbose,
165
165
  nodePath,
166
166
  functionsDistDir,
167
- edgeHandlersDistDir,
167
+ edgeFunctionsDistDir,
168
168
  cacheDir,
169
169
  dry,
170
170
  mode,
@@ -230,7 +230,7 @@ const tExecBuild = async function ({
230
230
  configPath,
231
231
  buildDir,
232
232
  functionsDistDir,
233
- edgeHandlersDistDir,
233
+ edgeFunctionsDistDir,
234
234
  cacheDir,
235
235
  netlifyConfig,
236
236
  siteInfo,
@@ -41,7 +41,7 @@ const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
41
41
  telemetry: false,
42
42
  verbose: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
43
43
  functionsDistDir: DEFAULT_FUNCTIONS_DIST,
44
- edgeHandlersDistDir: DEFAULT_EDGE_HANDLERS_DIST,
44
+ edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
45
45
  cacheDir: DEFAULT_CACHE_DIR,
46
46
  deployId: combinedEnv.DEPLOY_ID,
47
47
  buildId: combinedEnv.BUILD_ID,
@@ -63,7 +63,7 @@ const computeTelemetry = function (flags, envOpts) {
63
63
  }
64
64
 
65
65
  const REQUIRE_MODE = 'require'
66
- const DEFAULT_EDGE_HANDLERS_DIST = '.netlify/edge-handlers-dist/'
66
+ const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/'
67
67
  const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
68
68
  const DEFAULT_CACHE_DIR = '.netlify/cache/'
69
69
  const DEFAULT_STATSD_PORT = 8125
@@ -34,7 +34,7 @@ const TEST_FLAGS = ['buffer', 'telemetry']
34
34
  const INTERNAL_FLAGS = [
35
35
  'nodePath',
36
36
  'functionsDistDir',
37
- 'edgeHandlersDistDir',
37
+ 'edgeFunctionsDistDir',
38
38
  'defaultConfig',
39
39
  'cachedConfigPath',
40
40
  'sendStatus',
@@ -59,9 +59,10 @@ export const logFunctionsToBundle = function ({
59
59
  userFunctionsSrcExists,
60
60
  internalFunctions,
61
61
  internalFunctionsSrc,
62
+ type = 'Functions',
62
63
  }) {
63
64
  if (internalFunctions.length !== 0) {
64
- log(logs, `Packaging Functions from ${THEME.highlightWords(internalFunctionsSrc)} directory:`)
65
+ log(logs, `Packaging ${type} from ${THEME.highlightWords(internalFunctionsSrc)} directory:`)
65
66
  logArray(logs, internalFunctions, { indent: false })
66
67
  }
67
68
 
@@ -70,7 +71,7 @@ export const logFunctionsToBundle = function ({
70
71
  }
71
72
 
72
73
  if (userFunctions.length === 0) {
73
- log(logs, `No Functions were found in ${THEME.highlightWords(userFunctionsSrc)} directory`)
74
+ log(logs, `No ${type} were found in ${THEME.highlightWords(userFunctionsSrc)} directory`)
74
75
 
75
76
  return
76
77
  }
@@ -79,7 +80,7 @@ export const logFunctionsToBundle = function ({
79
80
  log(logs, '')
80
81
  }
81
82
 
82
- log(logs, `Packaging Functions from ${THEME.highlightWords(userFunctionsSrc)} directory:`)
83
+ log(logs, `Packaging ${type} from ${THEME.highlightWords(userFunctionsSrc)} directory:`)
83
84
  logArray(logs, userFunctions, { indent: false })
84
85
  }
85
86
 
@@ -0,0 +1,103 @@
1
+ import { dirname, join, resolve } from 'path'
2
+
3
+ import { bundle, find } from '@netlify/edge-bundler'
4
+ import { pathExists } from 'path-exists'
5
+
6
+ import { logFunctionsToBundle } from '../../log/messages/core_steps.js'
7
+
8
+ import { parseManifest } from './lib/internal_manifest.js'
9
+
10
+ // TODO: Replace this with a custom cache directory.
11
+ const DENO_CLI_CACHE_DIRECTORY = '.netlify/plugins/deno-cli'
12
+ const IMPORT_MAP_FILENAME = 'edge-functions-import-map.json'
13
+
14
+ const coreStep = async function ({
15
+ buildDir,
16
+ constants: {
17
+ EDGE_FUNCTIONS_DIST: distDirectory,
18
+ EDGE_FUNCTIONS_SRC: srcDirectory,
19
+ INTERNAL_EDGE_FUNCTIONS_SRC: internalSrcDirectory,
20
+ IS_LOCAL: isRunningLocally,
21
+ },
22
+ debug,
23
+ featureFlags,
24
+ logs,
25
+ netlifyConfig,
26
+ }) {
27
+ const { edge_functions: configDeclarations = [] } = netlifyConfig
28
+ const distPath = resolve(buildDir, distDirectory)
29
+ const internalSrcPath = resolve(buildDir, internalSrcDirectory)
30
+ const distImportMapPath = join(dirname(internalSrcPath), IMPORT_MAP_FILENAME)
31
+ const srcPath = srcDirectory ? resolve(buildDir, srcDirectory) : undefined
32
+ const sourcePaths = [internalSrcPath, srcPath].filter(Boolean)
33
+
34
+ logFunctions({ internalSrcDirectory, internalSrcPath, logs, srcDirectory, srcPath })
35
+
36
+ const { declarations: internalDeclarations, importMap } = await parseManifest(internalSrcPath)
37
+ const declarations = [...configDeclarations, ...internalDeclarations]
38
+
39
+ // If we're running in buildbot and the feature flag is enabled, we set the
40
+ // Deno cache dir to a directory that is persisted between builds.
41
+ const cacheDirectory =
42
+ !isRunningLocally && featureFlags.edge_functions_cache_cli ? resolve(buildDir, DENO_CLI_CACHE_DIRECTORY) : undefined
43
+
44
+ await bundle(sourcePaths, distPath, declarations, {
45
+ cacheDirectory,
46
+ debug,
47
+ distImportMapPath,
48
+ featureFlags,
49
+ importMaps: [importMap].filter(Boolean),
50
+ })
51
+
52
+ return {}
53
+ }
54
+
55
+ // We run this core step if at least one of the functions directories (the
56
+ // one configured by the user or the internal one) exists. We use a dynamic
57
+ // `condition` because the directories might be created by the build command
58
+ // or plugins.
59
+ const hasEdgeFunctionsDirectories = async function ({
60
+ buildDir,
61
+ constants: { INTERNAL_EDGE_FUNCTIONS_SRC, EDGE_FUNCTIONS_SRC },
62
+ }) {
63
+ const hasFunctionsSrc = EDGE_FUNCTIONS_SRC !== undefined && EDGE_FUNCTIONS_SRC !== ''
64
+
65
+ if (hasFunctionsSrc) {
66
+ return true
67
+ }
68
+
69
+ const internalFunctionsSrc = resolve(buildDir, INTERNAL_EDGE_FUNCTIONS_SRC)
70
+
71
+ return await pathExists(internalFunctionsSrc)
72
+ }
73
+
74
+ const logFunctions = async ({
75
+ internalSrcDirectory,
76
+ internalSrcPath,
77
+ logs,
78
+ srcDirectory: userFunctionsSrc,
79
+ srcPath,
80
+ }) => {
81
+ const [userFunctions, internalFunctions] = await Promise.all([find([srcPath]), find([internalSrcPath])])
82
+ const userFunctionsSrcExists = await pathExists(srcPath)
83
+ const internalFunctionsSrc = internalSrcDirectory
84
+
85
+ logFunctionsToBundle({
86
+ logs,
87
+ userFunctions: userFunctions.map(({ name }) => name),
88
+ userFunctionsSrc,
89
+ userFunctionsSrcExists,
90
+ internalFunctions: internalFunctions.map(({ name }) => name),
91
+ internalFunctionsSrc,
92
+ type: 'Edge Functions',
93
+ })
94
+ }
95
+
96
+ export const bundleEdgeFunctions = {
97
+ event: 'onBuild',
98
+ coreStep,
99
+ coreStepId: 'edge_functions_bundling',
100
+ coreStepName: 'Edge Functions bundling',
101
+ coreStepDescription: () => 'Edge Functions bundling',
102
+ condition: hasEdgeFunctionsDirectories,
103
+ }
@@ -0,0 +1,54 @@
1
+ import { promises as fs } from 'fs'
2
+ import { dirname, join, resolve } from 'path'
3
+
4
+ const parseManifest = async (internalSourceDirectory) => {
5
+ const manifestPath = join(internalSourceDirectory, 'manifest.json')
6
+
7
+ try {
8
+ const data = await fs.readFile(manifestPath)
9
+ const manifest = JSON.parse(data)
10
+
11
+ if (manifest.version !== 1) {
12
+ throw new Error('Unsupported manifest version')
13
+ }
14
+
15
+ const result = {
16
+ declarations: manifest.functions,
17
+ }
18
+
19
+ if (manifest.import_map) {
20
+ const importMapPath = resolve(dirname(manifestPath), manifest.import_map)
21
+ const importMap = await readImportMap(importMapPath)
22
+
23
+ return {
24
+ ...result,
25
+ importMap,
26
+ }
27
+ }
28
+
29
+ return result
30
+ } catch {
31
+ // no-op
32
+ }
33
+
34
+ return {
35
+ declarations: [],
36
+ }
37
+ }
38
+
39
+ const readImportMap = async (path) => {
40
+ try {
41
+ const data = await fs.readFile(path)
42
+ const importMap = JSON.parse(data)
43
+
44
+ return importMap
45
+ } catch {
46
+ // no-op
47
+ }
48
+
49
+ return {
50
+ imports: {},
51
+ }
52
+ }
53
+
54
+ export { parseManifest }
@@ -1,26 +1,17 @@
1
- import { createRequire } from 'module'
2
1
  import { fileURLToPath } from 'url'
3
2
 
4
3
  import { LOCAL_INSTALL_PLUGIN_NAME } from '../install/local.js'
5
4
 
6
- // TODO: use `import.resolve()` once it is available without any experimental
7
- // flags
8
- const require = createRequire(import.meta.url)
9
-
10
5
  const FUNCTIONS_INSTALL_PLUGIN = fileURLToPath(new URL('functions_install/index.js', import.meta.url))
11
6
 
12
7
  // List of core plugin names
13
8
  const FUNCTIONS_INSTALL_PLUGIN_NAME = '@netlify/plugin-functions-install-core'
14
- const EDGE_HANDLERS_PLUGIN_NAME = '@netlify/plugin-edge-handlers'
15
- const CORE_PLUGINS = new Set([FUNCTIONS_INSTALL_PLUGIN_NAME, LOCAL_INSTALL_PLUGIN_NAME, EDGE_HANDLERS_PLUGIN_NAME])
16
-
17
- const EDGE_HANDLERS_PLUGIN_PATH = require.resolve(EDGE_HANDLERS_PLUGIN_NAME)
9
+ const CORE_PLUGINS = new Set([FUNCTIONS_INSTALL_PLUGIN_NAME, LOCAL_INSTALL_PLUGIN_NAME])
18
10
 
19
11
  // Plugins that are installed and enabled by default
20
- export const listCorePlugins = function ({ FUNCTIONS_SRC, EDGE_HANDLERS_SRC }) {
12
+ export const listCorePlugins = function ({ FUNCTIONS_SRC }) {
21
13
  const functionsInstallPlugin = getFunctionsInstallPlugin(FUNCTIONS_SRC)
22
- const edgeHandlersPlugin = getEdgeHandlersPlugin(EDGE_HANDLERS_SRC)
23
- return [functionsInstallPlugin, edgeHandlersPlugin].filter(Boolean)
14
+ return [functionsInstallPlugin].filter(Boolean)
24
15
  }
25
16
 
26
17
  const getFunctionsInstallPlugin = function (FUNCTIONS_SRC) {
@@ -31,18 +22,6 @@ const getFunctionsInstallPlugin = function (FUNCTIONS_SRC) {
31
22
  return { package: FUNCTIONS_INSTALL_PLUGIN_NAME, pluginPath: FUNCTIONS_INSTALL_PLUGIN, optional: true }
32
23
  }
33
24
 
34
- // To enable Edge handlers, create a `netlify/edge-handlers` directory in the build
35
- // directory.
36
- // The location can be overridden using the `build.edge_handlers` property in
37
- // `netlify.toml`.
38
- const getEdgeHandlersPlugin = function (EDGE_HANDLERS_SRC) {
39
- if (EDGE_HANDLERS_SRC === undefined) {
40
- return
41
- }
42
-
43
- return { package: EDGE_HANDLERS_PLUGIN_NAME, pluginPath: EDGE_HANDLERS_PLUGIN_PATH }
44
- }
45
-
46
25
  export const isCorePlugin = function (packageName) {
47
26
  return CORE_PLUGINS.has(packageName)
48
27
  }
package/src/steps/get.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { EVENTS } from '../plugins/events.js'
2
2
  import { buildCommandCore } from '../plugins_core/build_command.js'
3
3
  import { deploySite } from '../plugins_core/deploy/index.js'
4
+ import { bundleEdgeFunctions } from '../plugins_core/edge_functions/index.js'
4
5
  import { bundleFunctions } from '../plugins_core/functions/index.js'
5
6
 
6
7
  // Get all build steps
@@ -12,7 +13,7 @@ export const getSteps = function (steps) {
12
13
  }
13
14
 
14
15
  const addCoreSteps = function (steps) {
15
- return [buildCommandCore, ...steps, bundleFunctions, deploySite]
16
+ return [buildCommandCore, ...steps, bundleFunctions, bundleEdgeFunctions, deploySite]
16
17
  }
17
18
 
18
19
  // Sort plugin steps by event order.
@@ -159,7 +159,7 @@ export const runStep = async function ({
159
159
  //
160
160
  // Otherwise, most failures will make the build fail. This includes:
161
161
  // - the build command failed
162
- // - Functions or Edge handlers bundling failed
162
+ // - Functions or Edge Functions bundling failed
163
163
  // - the deploy failed (deploying files to our CDN)
164
164
  // - a plugin `onPreBuild`, `onBuild` or `onPostBuild` event handler failed.
165
165
  // This includes uncaught exceptions and using `utils.build.failBuild()`
@@ -173,8 +173,8 @@ export const runStep = async function ({
173
173
  //
174
174
  // Finally, some plugins (only core plugins for the moment) might be enabled or
175
175
  // not depending on whether a specific action is happening during the build,
176
- // such as creating a file. For example, the Functions and Edge handlers core
177
- // plugins are disabled if no Functions or Edge handlers directory is specified
176
+ // such as creating a file. For example, the Functions and Edge Functions core
177
+ // plugins are disabled if no Functions or Edge Functions directory is specified
178
178
  // or available. However, one might be created by a build plugin, in which case,
179
179
  // those core plugins should be triggered. We use a dynamic `condition()` to
180
180
  // model this behavior.