@netlify/build 27.4.2 → 27.6.0
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 +5 -3
- package/src/error/parse/location.js +6 -2
- package/src/error/type.js +7 -1
- package/src/plugins/child/status.js +10 -3
- package/src/plugins_core/edge_functions/index.js +22 -10
- package/src/plugins_core/edge_functions/lib/error.js +21 -0
- package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +89 -0
- package/src/status/report.js +11 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/build",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.6.0",
|
|
4
4
|
"description": "Netlify build module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/core/main.js",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@bugsnag/js": "^7.0.0",
|
|
59
|
-
"@netlify/edge-bundler": "^1.
|
|
59
|
+
"@netlify/edge-bundler": "^1.7.0",
|
|
60
60
|
"@netlify/cache-utils": "^4.0.0",
|
|
61
|
-
"@netlify/config": "^18.1.
|
|
61
|
+
"@netlify/config": "^18.1.2",
|
|
62
62
|
"@netlify/functions-utils": "^4.2.2",
|
|
63
63
|
"@netlify/git-utils": "^4.0.0",
|
|
64
64
|
"@netlify/plugins-list": "^6.35.0",
|
|
@@ -66,6 +66,8 @@
|
|
|
66
66
|
"@netlify/zip-it-and-ship-it": "5.13.2",
|
|
67
67
|
"@sindresorhus/slugify": "^2.0.0",
|
|
68
68
|
"@types/node": "^16.0.0",
|
|
69
|
+
"ajv": "^8.11.0",
|
|
70
|
+
"ajv-errors": "^3.0.0",
|
|
69
71
|
"ansi-escapes": "^5.0.0",
|
|
70
72
|
"chalk": "^5.0.0",
|
|
71
73
|
"clean-stack": "^4.0.0",
|
|
@@ -23,8 +23,12 @@ const getBuildCommandLocation = function ({ buildCommand, buildCommandOrigin })
|
|
|
23
23
|
${buildCommand}`
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const getFunctionsBundlingLocation = function ({ functionName }) {
|
|
27
|
-
|
|
26
|
+
const getFunctionsBundlingLocation = function ({ functionName, functionType }) {
|
|
27
|
+
if (functionType === 'edge') {
|
|
28
|
+
return 'While bundling edge function'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return `While bundling function "${functionName}"`
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
const getCoreStepLocation = function ({ coreStepName }) {
|
package/src/error/type.js
CHANGED
|
@@ -81,7 +81,13 @@ const TYPES = {
|
|
|
81
81
|
|
|
82
82
|
// User error during Functions bundling
|
|
83
83
|
functionsBundling: {
|
|
84
|
-
title: ({ location: { functionName } }) =>
|
|
84
|
+
title: ({ location: { functionName, functionType } }) => {
|
|
85
|
+
if (functionType === 'edge') {
|
|
86
|
+
return 'Bundling of edge function failed'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return `Bundling of function "${functionName}" failed`
|
|
90
|
+
},
|
|
85
91
|
stackType: 'none',
|
|
86
92
|
locationType: 'functionsBundling',
|
|
87
93
|
severity: 'info',
|
|
@@ -6,18 +6,19 @@ import { addErrorInfo } from '../../error/info.js'
|
|
|
6
6
|
// Report status information to the UI
|
|
7
7
|
export const show = function (runState, showArgs) {
|
|
8
8
|
validateShowArgs(showArgs)
|
|
9
|
-
const { title, summary, text } = removeEmptyStrings(showArgs)
|
|
10
|
-
runState.status = { state: 'success', title, summary, text }
|
|
9
|
+
const { title, summary, text, extraData } = removeEmptyStrings(showArgs)
|
|
10
|
+
runState.status = { state: 'success', title, summary, text, extraData }
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// Validate arguments of `utils.status.show()`
|
|
14
14
|
const validateShowArgs = function (showArgs) {
|
|
15
15
|
try {
|
|
16
16
|
validateShowArgsObject(showArgs)
|
|
17
|
-
const { title, summary, text, ...otherArgs } = showArgs
|
|
17
|
+
const { title, summary, text, extraData, ...otherArgs } = showArgs
|
|
18
18
|
validateShowArgsKeys(otherArgs)
|
|
19
19
|
Object.entries({ title, summary, text }).forEach(validateStringArg)
|
|
20
20
|
validateShowArgsSummary(summary)
|
|
21
|
+
validateShowArgsExtraData(extraData)
|
|
21
22
|
} catch (error) {
|
|
22
23
|
error.message = `utils.status.show() ${error.message}`
|
|
23
24
|
addErrorInfo(error, { type: 'pluginValidation' })
|
|
@@ -54,6 +55,12 @@ const validateShowArgsSummary = function (summary) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
const validateShowArgsExtraData = function (extraData) {
|
|
59
|
+
if (extraData !== undefined && Array.isArray(extraData) === false) {
|
|
60
|
+
throw new TypeError('provided extra data must be an array')
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
57
64
|
const removeEmptyStrings = function (showArgs) {
|
|
58
65
|
return mapObj(showArgs, removeEmptyString)
|
|
59
66
|
}
|
|
@@ -7,12 +7,15 @@ import { pathExists } from 'path-exists'
|
|
|
7
7
|
import { logFunctionsToBundle } from '../../log/messages/core_steps.js'
|
|
8
8
|
import { logEdgeManifest } from '../../log/messages/edge_manifest.js'
|
|
9
9
|
|
|
10
|
+
import { tagBundlingError } from './lib/error.js'
|
|
10
11
|
import { parseManifest } from './lib/internal_manifest.js'
|
|
12
|
+
import { validateEdgeFunctionsManifest } from './validate_manifest/validate_edge_functions_manifest.js'
|
|
11
13
|
|
|
12
14
|
// TODO: Replace this with a custom cache directory.
|
|
13
15
|
const DENO_CLI_CACHE_DIRECTORY = '.netlify/plugins/deno-cli'
|
|
14
16
|
const IMPORT_MAP_FILENAME = 'edge-functions-import-map.json'
|
|
15
17
|
|
|
18
|
+
// eslint-disable-next-line complexity, max-statements
|
|
16
19
|
const coreStep = async function ({
|
|
17
20
|
buildDir,
|
|
18
21
|
constants: {
|
|
@@ -46,18 +49,27 @@ const coreStep = async function ({
|
|
|
46
49
|
// Edge Bundler expects the dist directory to exist.
|
|
47
50
|
await fs.mkdir(distPath, { recursive: true })
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
try {
|
|
53
|
+
const { manifest } = await bundle(sourcePaths, distPath, declarations, {
|
|
54
|
+
basePath: buildDir,
|
|
55
|
+
cacheDirectory,
|
|
56
|
+
debug,
|
|
57
|
+
distImportMapPath,
|
|
58
|
+
featureFlags,
|
|
59
|
+
importMaps: [importMap].filter(Boolean),
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
if (debug) {
|
|
63
|
+
logEdgeManifest({ manifest, logs, debug })
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
tagBundlingError(error)
|
|
67
|
+
|
|
68
|
+
throw error
|
|
59
69
|
}
|
|
60
70
|
|
|
71
|
+
await validateEdgeFunctionsManifest({ buildDir, constants: { EDGE_FUNCTIONS_DIST: distDirectory } })
|
|
72
|
+
|
|
61
73
|
return {}
|
|
62
74
|
}
|
|
63
75
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CUSTOM_ERROR_KEY, getErrorInfo, isBuildError } from '../../../error/info.js'
|
|
2
|
+
|
|
3
|
+
// If we have a custom error tagged with `functionsBundling` (which happens if
|
|
4
|
+
// there is an issue with user code), we tag it as coming from an edge function
|
|
5
|
+
// so that we can adjust the downstream error messages accordingly.
|
|
6
|
+
export const tagBundlingError = (error) => {
|
|
7
|
+
if (!isBuildError(error)) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const [errorInfo = {}] = getErrorInfo(error)
|
|
12
|
+
|
|
13
|
+
if (errorInfo.type !== 'functionsBundling') {
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
error[CUSTOM_ERROR_KEY].location = {
|
|
18
|
+
...error[CUSTOM_ERROR_KEY].location,
|
|
19
|
+
functionType: 'edge',
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { promises as fs } from 'fs'
|
|
2
|
+
import { join, resolve } from 'path'
|
|
3
|
+
|
|
4
|
+
import Ajv from 'ajv'
|
|
5
|
+
import ajvErrors from 'ajv-errors'
|
|
6
|
+
|
|
7
|
+
import { addErrorInfo } from '../../../error/info.js'
|
|
8
|
+
|
|
9
|
+
const ajv = new Ajv({ allErrors: true })
|
|
10
|
+
ajvErrors(ajv)
|
|
11
|
+
|
|
12
|
+
// regex pattern for manifest route pattern
|
|
13
|
+
// checks if the pattern string starts with ^ and ends with $
|
|
14
|
+
// we define this format in edge-bundler:
|
|
15
|
+
// https://github.com/netlify/edge-bundler/blob/main/src/manifest.ts#L66
|
|
16
|
+
const normalizedPatternRegex = /^\^.*\$$/
|
|
17
|
+
ajv.addFormat('regexPattern', {
|
|
18
|
+
async: true,
|
|
19
|
+
validate: (data) => normalizedPatternRegex.test(data),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const bundlesSchema = {
|
|
23
|
+
$async: true,
|
|
24
|
+
type: 'object',
|
|
25
|
+
required: ['asset', 'format'],
|
|
26
|
+
properties: {
|
|
27
|
+
asset: { type: 'string' },
|
|
28
|
+
format: { type: 'string' },
|
|
29
|
+
},
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const routesSchema = {
|
|
34
|
+
$async: true,
|
|
35
|
+
type: 'object',
|
|
36
|
+
required: ['function', 'pattern'],
|
|
37
|
+
properties: {
|
|
38
|
+
function: { type: 'string' },
|
|
39
|
+
pattern: { type: 'string', format: 'regexPattern', errorMessage: `must match format ${normalizedPatternRegex}` },
|
|
40
|
+
},
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const edgeManifestSchema = {
|
|
45
|
+
$async: true,
|
|
46
|
+
type: 'object',
|
|
47
|
+
required: ['bundles', 'routes', 'bundler_version'],
|
|
48
|
+
properties: {
|
|
49
|
+
bundles: {
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: bundlesSchema,
|
|
52
|
+
},
|
|
53
|
+
routes: {
|
|
54
|
+
type: 'array',
|
|
55
|
+
items: routesSchema,
|
|
56
|
+
},
|
|
57
|
+
bundler_version: { type: 'string' },
|
|
58
|
+
},
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
errorMessage: "Couldn't validate Edge Functions manifest.json",
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const validateManifest = async (manifestData) => {
|
|
64
|
+
const validate = ajv.compile(edgeManifestSchema)
|
|
65
|
+
|
|
66
|
+
await validate(manifestData)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const validateEdgeFunctionsManifest = async function ({
|
|
70
|
+
buildDir,
|
|
71
|
+
constants: { EDGE_FUNCTIONS_DIST: distDirectory },
|
|
72
|
+
}) {
|
|
73
|
+
try {
|
|
74
|
+
const edgeFunctionsDistPath = resolve(buildDir, distDirectory)
|
|
75
|
+
const manifestPath = join(edgeFunctionsDistPath, 'manifest.json')
|
|
76
|
+
const data = await fs.readFile(manifestPath)
|
|
77
|
+
const manifestData = JSON.parse(data)
|
|
78
|
+
|
|
79
|
+
await validateManifest(manifestData)
|
|
80
|
+
} catch (error) {
|
|
81
|
+
const isValidationErr = error instanceof Ajv.ValidationError
|
|
82
|
+
const parsedErr = isValidationErr ? error.errors : error
|
|
83
|
+
|
|
84
|
+
addErrorInfo(parsedErr, { type: 'coreStep' })
|
|
85
|
+
throw new Error(isValidationErr ? JSON.stringify(parsedErr, null, 2) : parsedErr)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {}
|
|
89
|
+
}
|
package/src/status/report.js
CHANGED
|
@@ -104,7 +104,7 @@ const sendApiStatuses = async function ({
|
|
|
104
104
|
|
|
105
105
|
const sendApiStatus = async function ({
|
|
106
106
|
api,
|
|
107
|
-
status: { packageName, version, state, event, title, summary, text },
|
|
107
|
+
status: { packageName, version, state, event, title, summary, text, extraData },
|
|
108
108
|
childEnv,
|
|
109
109
|
mode,
|
|
110
110
|
netlifyConfig,
|
|
@@ -117,7 +117,16 @@ const sendApiStatus = async function ({
|
|
|
117
117
|
try {
|
|
118
118
|
await api.createPluginRun({
|
|
119
119
|
deploy_id: deployId,
|
|
120
|
-
body: {
|
|
120
|
+
body: {
|
|
121
|
+
package: packageName,
|
|
122
|
+
version,
|
|
123
|
+
state,
|
|
124
|
+
reporting_event: event,
|
|
125
|
+
title,
|
|
126
|
+
summary,
|
|
127
|
+
text,
|
|
128
|
+
extra_data: extraData,
|
|
129
|
+
},
|
|
121
130
|
})
|
|
122
131
|
// Bitballoon API randomly fails with 502.
|
|
123
132
|
// Builds should be successful when this API call fails, but we still want
|