@netlify/build 26.6.0-rc → 27.0.2

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.
Files changed (36) hide show
  1. package/package.json +40 -40
  2. package/src/core/config.js +2 -0
  3. package/src/core/constants.js +15 -6
  4. package/src/core/feature_flags.js +2 -1
  5. package/src/core/flags.js +6 -0
  6. package/src/core/main.js +2 -0
  7. package/src/core/missing_side_file.js +1 -1
  8. package/src/core/normalize_flags.js +2 -0
  9. package/src/core/user_node_version.js +1 -1
  10. package/src/error/handle.js +1 -1
  11. package/src/error/monitor/report.js +4 -1
  12. package/src/install/local.js +2 -2
  13. package/src/install/main.js +2 -2
  14. package/src/install/missing.js +1 -1
  15. package/src/log/messages/config.js +1 -0
  16. package/src/log/messages/core_steps.js +4 -3
  17. package/src/log/messages/mutations.js +1 -1
  18. package/src/plugins/child/error.js +1 -1
  19. package/src/plugins/error.js +4 -1
  20. package/src/plugins/ipc.js +1 -1
  21. package/src/plugins/manifest/path.js +1 -1
  22. package/src/plugins/spawn.js +2 -2
  23. package/src/plugins_core/build_command.js +1 -1
  24. package/src/plugins_core/deploy/buildbot_client.js +1 -1
  25. package/src/plugins_core/deploy/index.js +2 -0
  26. package/src/plugins_core/edge_functions/index.js +103 -0
  27. package/src/plugins_core/edge_functions/lib/internal_manifest.js +54 -0
  28. package/src/plugins_core/functions/index.js +7 -50
  29. package/src/plugins_core/functions/zisi.js +53 -0
  30. package/src/plugins_core/functions_install/index.js +1 -1
  31. package/src/plugins_core/list.js +3 -24
  32. package/src/steps/get.js +2 -1
  33. package/src/steps/run_step.js +3 -3
  34. package/src/steps/update_config.js +1 -1
  35. package/src/utils/package.js +2 -2
  36. package/types/netlify_plugin_constants.d.ts +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "26.6.0-rc",
3
+ "version": "27.0.2",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./src/core/main.js",
@@ -56,54 +56,54 @@
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.4",
64
- "@netlify/plugins-list": "^6.3.0",
64
+ "@netlify/plugins-list": "^6.22.0",
65
65
  "@netlify/run-utils": "^4.0.0",
66
- "@netlify/zip-it-and-ship-it": "5.5.1",
67
- "@sindresorhus/slugify": "^1.1.0",
66
+ "@netlify/zip-it-and-ship-it": "5.9.1",
67
+ "@sindresorhus/slugify": "^2.0.0",
68
68
  "@types/node": "^16.0.0",
69
- "ansi-escapes": "^4.3.2",
70
- "chalk": "^4.1.2",
71
- "clean-stack": "^3.0.1",
72
- "execa": "^5.1.1",
73
- "figures": "^3.2.0",
74
- "filter-obj": "^2.0.1",
69
+ "ansi-escapes": "^5.0.0",
70
+ "chalk": "^5.0.0",
71
+ "clean-stack": "^4.0.0",
72
+ "execa": "^6.0.0",
73
+ "figures": "^4.0.0",
74
+ "filter-obj": "^3.0.0",
75
75
  "got": "^10.0.0",
76
- "indent-string": "^4.0.0",
77
- "is-plain-obj": "^3.0.0",
76
+ "indent-string": "^5.0.0",
77
+ "is-plain-obj": "^4.0.0",
78
78
  "js-yaml": "^4.0.0",
79
- "keep-func-props": "^3.0.0",
80
- "locate-path": "^6.0.0",
81
- "log-process-errors": "^6.0.0",
82
- "map-obj": "^4.0.0",
79
+ "keep-func-props": "^4.0.0",
80
+ "locate-path": "^7.0.0",
81
+ "log-process-errors": "^8.0.0",
82
+ "map-obj": "^5.0.0",
83
83
  "memoize-one": "^6.0.0",
84
- "os-name": "^4.0.1",
85
- "p-event": "^4.1.0",
84
+ "os-name": "^5.0.0",
85
+ "p-event": "^5.0.0",
86
86
  "p-every": "^2.0.0",
87
- "p-filter": "^2.1.0",
88
- "p-locate": "^5.0.0",
89
- "p-reduce": "^2.1.0",
90
- "path-exists": "^4.0.0",
91
- "path-type": "^4.0.0",
92
- "pkg-dir": "^5.0.0",
87
+ "p-filter": "^3.0.0",
88
+ "p-locate": "^6.0.0",
89
+ "p-reduce": "^3.0.0",
90
+ "path-exists": "^5.0.0",
91
+ "path-type": "^5.0.0",
92
+ "pkg-dir": "^6.0.0",
93
93
  "pretty-ms": "^7.0.0",
94
- "ps-list": "^7.0.0",
95
- "read-pkg-up": "^7.0.1",
94
+ "ps-list": "^8.0.0",
95
+ "read-pkg-up": "^9.0.0",
96
96
  "readdirp": "^3.4.0",
97
97
  "resolve": "^2.0.0-next.1",
98
98
  "rfdc": "^1.3.0",
99
99
  "safe-json-stringify": "^1.2.0",
100
100
  "semver": "^7.0.0",
101
101
  "statsd-client": "0.4.7",
102
- "string-width": "^4.2.0",
103
- "strip-ansi": "^6.0.0",
104
- "supports-color": "^8.0.0",
102
+ "string-width": "^5.0.0",
103
+ "strip-ansi": "^7.0.0",
104
+ "supports-color": "^9.0.0",
105
105
  "tmp-promise": "^3.0.2",
106
- "ts-node": "^10.4.0",
106
+ "ts-node": "10.4.0",
107
107
  "typescript": "^4.5.4",
108
108
  "update-notifier": "^5.0.0",
109
109
  "uuid": "^8.0.0",
@@ -112,20 +112,20 @@
112
112
  "devDependencies": {
113
113
  "@netlify/nock-udp": "^1.0.0",
114
114
  "atob": "^2.1.2",
115
- "ava": "^3.15.0",
115
+ "ava": "^4.0.0",
116
116
  "cpy": "^8.1.0",
117
117
  "del": "^6.0.0",
118
118
  "fast-safe-stringify": "^2.0.7",
119
- "get-bin-path": "^5.1.0",
120
- "get-node": "^11.0.2",
121
- "get-port": "^5.1.1",
119
+ "get-bin-path": "^6.0.0",
120
+ "get-node": "^12.0.0",
121
+ "get-port": "^6.0.0",
122
122
  "get-stream": "^6.0.0",
123
- "has-ansi": "^4.0.0",
123
+ "has-ansi": "^5.0.0",
124
124
  "is-ci": "^3.0.0",
125
125
  "moize": "^6.0.0",
126
- "path-key": "^3.1.1",
127
- "process-exists": "^4.0.0",
128
- "sinon": "^12.0.0",
126
+ "path-key": "^4.0.0",
127
+ "process-exists": "^5.0.0",
128
+ "sinon": "^13.0.0",
129
129
  "yarn": "^1.22.4"
130
130
  },
131
131
  "engines": {
@@ -143,6 +143,7 @@ export const saveUpdatedConfig = async function ({
143
143
  headersPath,
144
144
  redirectsPath,
145
145
  logs,
146
+ featureFlags,
146
147
  context,
147
148
  branch,
148
149
  debug,
@@ -160,6 +161,7 @@ export const saveUpdatedConfig = async function ({
160
161
  context,
161
162
  branch,
162
163
  logs,
164
+ featureFlags,
163
165
  })
164
166
 
165
167
  await logConfigOnUpload({ logs, configPath, debug })
@@ -2,7 +2,7 @@ import { relative, normalize } from 'path'
2
2
 
3
3
  import { getCacheDir } from '@netlify/cache-utils'
4
4
  import mapObj from 'map-obj'
5
- import pathExists from 'path-exists'
5
+ import { pathExists } from 'path-exists'
6
6
 
7
7
  import { ROOT_PACKAGE_JSON } from '../utils/json.js'
8
8
 
@@ -11,6 +11,7 @@ export const getConstants = async function ({
11
11
  configPath,
12
12
  buildDir,
13
13
  functionsDistDir,
14
+ edgeFunctionsDistDir,
14
15
  cacheDir,
15
16
  netlifyConfig,
16
17
  siteInfo: { id: siteId },
@@ -26,6 +27,8 @@ export const getConstants = async function ({
26
27
  CONFIG_PATH: configPath,
27
28
  // The directory where built serverless functions are placed before deployment
28
29
  FUNCTIONS_DIST: functionsDistDir,
30
+ // The directory where built Edge Functions are placed before deployment
31
+ EDGE_FUNCTIONS_DIST: edgeFunctionsDistDir,
29
32
  // Path to the Netlify build cache folder
30
33
  CACHE_DIR: normalizedCacheDir,
31
34
  // Boolean indicating whether the build was run locally (Netlify CLI) or in the production CI
@@ -41,11 +44,15 @@ export const getConstants = async function ({
41
44
  // The directory where internal functions (i.e. generated programmatically
42
45
  // via plugins or others) live
43
46
  INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
47
+ // The directory where internal Edge Functions (i.e. generated programmatically
48
+ // via plugins or others) live
49
+ INTERNAL_EDGE_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_EDGE_FUNCTIONS_SRC}`,
44
50
  }
45
51
  const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig })
46
52
  return constantsA
47
53
  }
48
54
 
55
+ const INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions'
49
56
  const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal'
50
57
 
51
58
  // Retrieve constants which might change during the build if a plugin modifies
@@ -55,7 +62,7 @@ export const addMutableConstants = async function ({
55
62
  constants,
56
63
  buildDir,
57
64
  netlifyConfig: {
58
- build: { publish, edge_handlers: edgeHandlers },
65
+ build: { publish, edge_functions: edgeFunctions },
59
66
  functionsDirectory,
60
67
  },
61
68
  }) {
@@ -65,8 +72,8 @@ export const addMutableConstants = async function ({
65
72
  PUBLISH_DIR: publish,
66
73
  // The directory where function source code lives
67
74
  FUNCTIONS_SRC: functionsDirectory,
68
- // The directory where edge handlers source code lives
69
- EDGE_HANDLERS_SRC: edgeHandlers,
75
+ // The directory where Edge Functions source code lives
76
+ EDGE_FUNCTIONS_SRC: edgeFunctions,
70
77
  }
71
78
  const constantsB = await addDefaultConstants(constantsA, buildDir)
72
79
  const constantsC = normalizeConstantsPaths(constantsB, buildDir)
@@ -93,7 +100,7 @@ const DEFAULT_PATHS = [
93
100
  // @todo Remove once we drop support for the legacy default functions directory.
94
101
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
95
102
  { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
96
- { constantName: 'EDGE_HANDLERS_SRC', defaultPath: 'netlify/edge-handlers' },
103
+ { constantName: 'EDGE_FUNCTIONS_SRC', defaultPath: 'netlify/edge-functions' },
97
104
  ]
98
105
 
99
106
  const addDefaultConstant = async function ({ constants, constantName, defaultPath, buildDir }) {
@@ -141,7 +148,9 @@ const CONSTANT_PATHS = new Set([
141
148
  'PUBLISH_DIR',
142
149
  'FUNCTIONS_SRC',
143
150
  'FUNCTIONS_DIST',
151
+ 'INTERNAL_EDGE_FUNCTIONS_SRC',
144
152
  'INTERNAL_FUNCTIONS_SRC',
145
- 'EDGE_HANDLERS_SRC',
153
+ 'EDGE_FUNCTIONS_DIST',
154
+ 'EDGE_FUNCTIONS_SRC',
146
155
  'CACHE_DIR',
147
156
  ])
@@ -14,9 +14,10 @@ const getFeatureFlag = function (name) {
14
14
  // Default values for feature flags
15
15
  export const DEFAULT_FEATURE_FLAGS = {
16
16
  buildbot_build_go_functions: false,
17
- buildbot_create_functions_manifest: false,
18
17
  buildbot_es_modules_esbuild: false,
19
18
  buildbot_zisi_trace_nft: false,
20
19
  buildbot_zisi_esbuild_parser: false,
20
+ edge_functions_cache_cli: false,
21
+ edge_functions_produce_eszip: false,
21
22
  zisi_parse_isc: false,
22
23
  }
package/src/core/flags.js CHANGED
@@ -107,6 +107,12 @@ Default: Current Node.js binary`,
107
107
  functionsDistDir: {
108
108
  string: true,
109
109
  describe: `Path to the directory where packaged functions are kept.
110
+ Default: automatically guessed`,
111
+ hidden: true,
112
+ },
113
+ edgeFunctionsDistDir: {
114
+ string: true,
115
+ describe: `Path to the directory where packaged Edge Functions are kept.
110
116
  Default: automatically guessed`,
111
117
  hidden: true,
112
118
  },
package/src/core/main.js CHANGED
@@ -164,6 +164,7 @@ const tExecBuild = async function ({
164
164
  verbose,
165
165
  nodePath,
166
166
  functionsDistDir,
167
+ edgeFunctionsDistDir,
167
168
  cacheDir,
168
169
  dry,
169
170
  mode,
@@ -229,6 +230,7 @@ const tExecBuild = async function ({
229
230
  configPath,
230
231
  buildDir,
231
232
  functionsDistDir,
233
+ edgeFunctionsDistDir,
232
234
  cacheDir,
233
235
  netlifyConfig,
234
236
  siteInfo,
@@ -1,6 +1,6 @@
1
1
  import { relative } from 'path'
2
2
 
3
- import pathExists from 'path-exists'
3
+ import { pathExists } from 'path-exists'
4
4
 
5
5
  import { logMissingSideFile } from '../log/messages/core.js'
6
6
 
@@ -41,6 +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
+ edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
44
45
  cacheDir: DEFAULT_CACHE_DIR,
45
46
  deployId: combinedEnv.DEPLOY_ID,
46
47
  buildId: combinedEnv.BUILD_ID,
@@ -62,6 +63,7 @@ const computeTelemetry = function (flags, envOpts) {
62
63
  }
63
64
 
64
65
  const REQUIRE_MODE = 'require'
66
+ const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/'
65
67
  const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
66
68
  const DEFAULT_CACHE_DIR = '.netlify/cache/'
67
69
  const DEFAULT_STATSD_PORT = 8125
@@ -1,6 +1,6 @@
1
1
  import { version as currentVersion, execPath } from 'process'
2
2
 
3
- import execa from 'execa'
3
+ import { execa } from 'execa'
4
4
  import semver from 'semver'
5
5
 
6
6
  import { addErrorInfo } from '../error/info.js'
@@ -1,6 +1,6 @@
1
1
  import { cwd as getCwd } from 'process'
2
2
 
3
- import pathExists from 'path-exists'
3
+ import { pathExists } from 'path-exists'
4
4
 
5
5
  import { logBuildError } from '../log/messages/core.js'
6
6
  import { logOldCliVersionError } from '../log/old_version.js'
@@ -89,7 +89,10 @@ const getApp = function () {
89
89
  // But we change it back after Bugsnag is done reporting.
90
90
  const updateErrorName = function (error, type) {
91
91
  const { name } = error
92
- error.name = type
92
+ // This might fail if `name` is a getter or is non-writable.
93
+ try {
94
+ error.name = type
95
+ } catch {}
93
96
  return name
94
97
  }
95
98
 
@@ -1,4 +1,4 @@
1
- import pkgDir from 'pkg-dir'
1
+ import { packageDirectory } from 'pkg-dir'
2
2
 
3
3
  import { logInstallLocalPluginsDeps } from '../log/messages/install.js'
4
4
 
@@ -57,6 +57,6 @@ const hasPackageDir = function ({ packageDir }) {
57
57
 
58
58
  // We only install dependencies of local plugins that have their own `package.json`
59
59
  const removeMainRoot = async function (localPluginsOptions, buildDir) {
60
- const mainPackageDir = await pkgDir(buildDir)
60
+ const mainPackageDir = await packageDirectory({ cwd: buildDir })
61
61
  return localPluginsOptions.filter(({ packageDir }) => packageDir !== mainPackageDir)
62
62
  }
@@ -1,7 +1,7 @@
1
1
  import { homedir } from 'os'
2
2
 
3
- import execa from 'execa'
4
- import pathExists from 'path-exists'
3
+ import { execa } from 'execa'
4
+ import { pathExists } from 'path-exists'
5
5
 
6
6
  import { addErrorInfo } from '../error/info.js'
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { promises as fs } from 'fs'
2
2
  import { normalize } from 'path'
3
3
 
4
- import pathExists from 'path-exists'
4
+ import { pathExists } from 'path-exists'
5
5
  import { isFile } from 'path-type'
6
6
 
7
7
  import { logInstallMissingPlugins } from '../log/messages/install.js'
@@ -34,6 +34,7 @@ const TEST_FLAGS = ['buffer', 'telemetry']
34
34
  const INTERNAL_FLAGS = [
35
35
  'nodePath',
36
36
  'functionsDistDir',
37
+ 'edgeFunctionsDistDir',
37
38
  'defaultConfig',
38
39
  'cachedConfigPath',
39
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
 
@@ -1,7 +1,7 @@
1
1
  import { promises as fs } from 'fs'
2
2
  import { inspect } from 'util'
3
3
 
4
- import pathExists from 'path-exists'
4
+ import { pathExists } from 'path-exists'
5
5
 
6
6
  import { log, logMessage, logSubHeader } from '../logger.js'
7
7
 
@@ -16,7 +16,7 @@ export const handleError = async function (error, verbose) {
16
16
  // On uncaught exceptions and unhandled rejections, print the stack trace.
17
17
  // Also, prevent child processes from crashing on uncaught exceptions.
18
18
  export const handleProcessErrors = function () {
19
- logProcessErrors({ log: handleProcessError, exitOn: [], level: { multipleResolves: 'silent' } })
19
+ logProcessErrors({ log: handleProcessError, exitOn: [] })
20
20
  }
21
21
 
22
22
  const handleProcessError = async function (error, level, originalError) {
@@ -36,7 +36,10 @@ const normalizeError = function (type, func, message, { error } = {}) {
36
36
 
37
37
  const getError = function (error, message, func) {
38
38
  if (error instanceof Error) {
39
- error.message = `${message}\n${error.message}`
39
+ // This might fail if `name` is a getter or is non-writable.
40
+ try {
41
+ error.message = `${message}\n${error.message}`
42
+ } catch {}
40
43
  return error
41
44
  }
42
45
 
@@ -1,7 +1,7 @@
1
1
  import process from 'process'
2
2
  import { promisify } from 'util'
3
3
 
4
- import pEvent from 'p-event'
4
+ import { pEvent } from 'p-event'
5
5
  import { v4 as uuidv4 } from 'uuid'
6
6
 
7
7
  import { jsonToError, errorToJson } from '../error/build.js'
@@ -1,4 +1,4 @@
1
- import locatePath from 'locate-path'
1
+ import { locatePath } from 'locate-path'
2
2
 
3
3
  import { addErrorInfo } from '../../error/info.js'
4
4
 
@@ -1,6 +1,6 @@
1
1
  import { fileURLToPath } from 'url'
2
2
 
3
- import execa from 'execa'
3
+ import { execaNode } from 'execa'
4
4
 
5
5
  import { addErrorInfo } from '../error/info.js'
6
6
  import { logLoadingPlugins, logOutdatedPlugins, logIncompatiblePlugins } from '../log/messages/compatibility.js'
@@ -31,7 +31,7 @@ const tStartPlugins = async function ({ pluginsOptions, buildDir, childEnv, logs
31
31
  export const startPlugins = measureDuration(tStartPlugins, 'start_plugins')
32
32
 
33
33
  const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv }) {
34
- const childProcess = execa.node(CHILD_MAIN_FILE, {
34
+ const childProcess = execaNode(CHILD_MAIN_FILE, {
35
35
  cwd: buildDir,
36
36
  preferLocal: true,
37
37
  localDir: pluginDir,
@@ -1,6 +1,6 @@
1
1
  import { platform } from 'process'
2
2
 
3
- import execa from 'execa'
3
+ import { execa } from 'execa'
4
4
 
5
5
  import { addErrorInfo } from '../error/info.js'
6
6
  import { getBuildCommandDescription } from '../log/description.js'
@@ -2,7 +2,7 @@ import net from 'net'
2
2
  import { normalize, resolve, relative } from 'path'
3
3
  import { promisify } from 'util'
4
4
 
5
- import pEvent from 'p-event'
5
+ import { pEvent } from 'p-event'
6
6
 
7
7
  import { addErrorInfo } from '../../error/info.js'
8
8
  import { runsAfterDeploy } from '../../plugins/events.js'
@@ -16,6 +16,7 @@ const coreStep = async function ({
16
16
  buildbotServerSocket,
17
17
  events,
18
18
  logs,
19
+ featureFlags,
19
20
  context,
20
21
  branch,
21
22
  configMutations,
@@ -35,6 +36,7 @@ const coreStep = async function ({
35
36
  headersPath,
36
37
  redirectsPath,
37
38
  logs,
39
+ featureFlags,
38
40
  context,
39
41
  branch,
40
42
  debug,
@@ -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,69 +1,23 @@
1
- import { join, resolve } from 'path'
1
+ import { resolve } from 'path'
2
2
 
3
3
  import { zipFunctions } from '@netlify/zip-it-and-ship-it'
4
- import mapObject from 'map-obj'
5
- import pathExists from 'path-exists'
4
+ import { pathExists } from 'path-exists'
6
5
 
7
6
  import { log } from '../../log/logger.js'
8
7
  import { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle } from '../../log/messages/core_steps.js'
9
8
 
10
9
  import { getZipError } from './error.js'
11
- import { getZisiFeatureFlags } from './feature_flags.js'
12
10
  import { getUserAndInternalFunctions, validateFunctionsSrc } from './utils.js'
11
+ import { getZisiParameters } from './zisi.js'
13
12
 
14
13
  // Returns `true` if at least one of the functions has been configured to use
15
14
  // esbuild.
16
15
  const isUsingEsbuild = (functionsConfig = {}) =>
17
16
  Object.values(functionsConfig).some((configObject) => configObject.node_bundler === 'esbuild')
18
17
 
19
- // The function configuration keys returned by @netlify/config are not an exact
20
- // match to the properties that @netlify/zip-it-and-ship-it expects. We do that
21
- // translation here.
22
- const normalizeFunctionConfig = ({ buildDir, functionConfig = {}, isRunningLocally }) => ({
23
- externalNodeModules: functionConfig.external_node_modules,
24
- includedFiles: functionConfig.included_files,
25
- includedFilesBasePath: buildDir,
26
- ignoredNodeModules: functionConfig.ignored_node_modules,
27
- schedule: functionConfig.schedule,
28
-
29
- // When the user selects esbuild as the Node bundler, we still want to use
30
- // the legacy ZISI bundler as a fallback. Rather than asking the user to
31
- // make this decision, we abstract that complexity away by injecting the
32
- // fallback behavior ourselves. We do this by transforming the value
33
- // `esbuild` into `esbuild_zisi`, which zip-it-and-ship-it understands.
34
- nodeBundler: functionConfig.node_bundler === 'esbuild' ? 'esbuild_zisi' : functionConfig.node_bundler,
35
-
36
- // If the build is running in buildbot, we set the Rust target directory to a
37
- // path that will get cached in between builds, allowing us to speed up the
38
- // build process.
39
- rustTargetDirectory: isRunningLocally ? undefined : resolve(buildDir, '.netlify', 'rust-functions-cache', '[name]'),
40
-
41
- // Go functions should be zipped only when building locally. When running in
42
- // buildbot, the Go API client will handle the zipping.
43
- zipGo: isRunningLocally ? true : undefined,
44
- })
45
-
46
- const getZisiParameters = ({
47
- buildDir,
48
- featureFlags,
49
- functionsConfig,
50
- functionsDist,
51
- isRunningLocally,
52
- repositoryRoot,
53
- }) => {
54
- const isManifestEnabled = isRunningLocally || featureFlags.buildbot_create_functions_manifest === true
55
- const manifest = isManifestEnabled ? join(functionsDist, 'manifest.json') : undefined
56
- const config = mapObject(functionsConfig, (expression, object) => [
57
- expression,
58
- normalizeFunctionConfig({ buildDir, featureFlags, functionConfig: object, isRunningLocally }),
59
- ])
60
- const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
61
-
62
- return { basePath: buildDir, config, manifest, featureFlags: zisiFeatureFlags, repositoryRoot }
63
- }
64
-
65
18
  const zipFunctionsAndLogResults = async ({
66
19
  buildDir,
20
+ childEnv,
67
21
  featureFlags,
68
22
  functionsConfig,
69
23
  functionsDist,
@@ -75,6 +29,7 @@ const zipFunctionsAndLogResults = async ({
75
29
  }) => {
76
30
  const zisiParameters = getZisiParameters({
77
31
  buildDir,
32
+ childEnv,
78
33
  featureFlags,
79
34
  functionsConfig,
80
35
  functionsDist,
@@ -101,6 +56,7 @@ const zipFunctionsAndLogResults = async ({
101
56
  // Plugin to package Netlify functions with @netlify/zip-it-and-ship-it
102
57
  // eslint-disable-next-line complexity
103
58
  const coreStep = async function ({
59
+ childEnv,
104
60
  constants: {
105
61
  INTERNAL_FUNCTIONS_SRC: relativeInternalFunctionsSrc,
106
62
  IS_LOCAL: isRunningLocally,
@@ -149,6 +105,7 @@ const coreStep = async function ({
149
105
 
150
106
  const { bundler } = await zipFunctionsAndLogResults({
151
107
  buildDir,
108
+ childEnv,
152
109
  featureFlags,
153
110
  functionsConfig: netlifyConfig.functions,
154
111
  functionsDist,
@@ -0,0 +1,53 @@
1
+ import { join, resolve } from 'path'
2
+
3
+ import mapObject from 'map-obj'
4
+
5
+ import { getZisiFeatureFlags } from './feature_flags.js'
6
+
7
+ export const getZisiParameters = ({
8
+ buildDir,
9
+ childEnv,
10
+ featureFlags,
11
+ functionsConfig,
12
+ functionsDist,
13
+ isRunningLocally,
14
+ repositoryRoot,
15
+ }) => {
16
+ const nodeVersion = childEnv.AWS_LAMBDA_JS_RUNTIME
17
+ const manifest = join(functionsDist, 'manifest.json')
18
+ const config = mapObject(functionsConfig, (expression, object) => [
19
+ expression,
20
+ normalizeFunctionConfig({ buildDir, featureFlags, functionConfig: object, isRunningLocally, nodeVersion }),
21
+ ])
22
+ const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
23
+
24
+ return { basePath: buildDir, config, manifest, featureFlags: zisiFeatureFlags, repositoryRoot }
25
+ }
26
+
27
+ // The function configuration keys returned by @netlify/config are not an exact
28
+ // match to the properties that @netlify/zip-it-and-ship-it expects. We do that
29
+ // translation here.
30
+ export const normalizeFunctionConfig = ({ buildDir, functionConfig = {}, isRunningLocally, nodeVersion }) => ({
31
+ externalNodeModules: functionConfig.external_node_modules,
32
+ includedFiles: functionConfig.included_files,
33
+ includedFilesBasePath: buildDir,
34
+ ignoredNodeModules: functionConfig.ignored_node_modules,
35
+ nodeVersion,
36
+ schedule: functionConfig.schedule,
37
+
38
+ // When the user selects esbuild as the Node bundler, we still want to use
39
+ // the legacy ZISI bundler as a fallback. Rather than asking the user to
40
+ // make this decision, we abstract that complexity away by injecting the
41
+ // fallback behavior ourselves. We do this by transforming the value
42
+ // `esbuild` into `esbuild_zisi`, which zip-it-and-ship-it understands.
43
+ nodeBundler: functionConfig.node_bundler === 'esbuild' ? 'esbuild_zisi' : functionConfig.node_bundler,
44
+
45
+ // If the build is running in buildbot, we set the Rust target directory to a
46
+ // path that will get cached in between builds, allowing us to speed up the
47
+ // build process.
48
+ rustTargetDirectory: isRunningLocally ? undefined : resolve(buildDir, '.netlify', 'rust-functions-cache', '[name]'),
49
+
50
+ // Go functions should be zipped only when building locally. When running in
51
+ // buildbot, the Go API client will handle the zipping.
52
+ zipGo: isRunningLocally ? true : undefined,
53
+ })
@@ -1,4 +1,4 @@
1
- import pathExists from 'path-exists'
1
+ import { pathExists } from 'path-exists'
2
2
 
3
3
  import { installFunctionDependencies } from '../../install/functions.js'
4
4
 
@@ -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.
@@ -1,7 +1,7 @@
1
1
  import { isDeepStrictEqual } from 'util'
2
2
 
3
3
  import pFilter from 'p-filter'
4
- import pathExists from 'path-exists'
4
+ import { pathExists } from 'path-exists'
5
5
 
6
6
  import { resolveUpdatedConfig } from '../core/config.js'
7
7
  import { addErrorInfo } from '../error/info.js'
@@ -1,6 +1,6 @@
1
1
  import { dirname } from 'path'
2
2
 
3
- import readPkgUp from 'read-pkg-up'
3
+ import { readPackageUp } from 'read-pkg-up'
4
4
 
5
5
  // Retrieve `package.json` from a specific directory
6
6
  export const getPackageJson = async function (cwd, { normalize } = {}) {
@@ -16,7 +16,7 @@ export const getPackageJson = async function (cwd, { normalize } = {}) {
16
16
 
17
17
  const getPackageObj = async function ({ cwd, normalize = true }) {
18
18
  try {
19
- return await readPkgUp({ cwd, normalize })
19
+ return await readPackageUp({ cwd, normalize })
20
20
  // If the `package.json` is invalid and `normalize` is `true`, an error is
21
21
  // thrown. We return `undefined` then.
22
22
  } catch {}
@@ -13,6 +13,11 @@ export interface NetlifyPluginConstants {
13
13
  * `undefined` if no `netlify/functions` directory exists in the base directory and if not specified by the user.
14
14
  */
15
15
  FUNCTIONS_SRC?: string
16
+ /**
17
+ * the directory where internal Edge Handlers source code lives. This is where build plugins should place auto-generated handlers.
18
+ * `undefined` if the version of @netlify/build does not support internal Edge Handlers
19
+ */
20
+ INTERNAL_EDGE_HANDLERS_SRC?: string
16
21
  /**
17
22
  * the directory where internal function source code lives. This is where build plugins should place auto-generated functions.
18
23
  * `undefined` if the version of @netlify/build does not support internal functions
@@ -22,6 +27,10 @@ export interface NetlifyPluginConstants {
22
27
  * the directory where built serverless functions are placed before deployment. Its value is always defined, but the target might not have been created yet.
23
28
  */
24
29
  FUNCTIONS_DIST: string
30
+ /**
31
+ * the directory where built Edge Handlers are placed before deployment. Its value is always defined, but the target might not have been created yet.
32
+ */
33
+ EDGE_HANDLERS_DIST: string
25
34
  /**
26
35
  * the directory where Edge Handlers source code lives.
27
36
  * `undefined` if no `netlify/edge-handlers` directory exists in the base directory and if not specified in `netlify.toml`.