@netlify/build 27.5.0 → 27.8.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 +4 -2
- package/src/error/monitor/normalize.js +23 -4
- package/src/error/monitor/report.js +7 -2
- package/src/error/parse/location.js +6 -2
- package/src/error/type.js +8 -1
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/build",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.8.0",
|
|
4
4
|
"description": "Netlify build module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/core/main.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@bugsnag/js": "^7.0.0",
|
|
59
|
-
"@netlify/edge-bundler": "^1.
|
|
59
|
+
"@netlify/edge-bundler": "^1.8.0",
|
|
60
60
|
"@netlify/cache-utils": "^4.0.0",
|
|
61
61
|
"@netlify/config": "^18.1.2",
|
|
62
62
|
"@netlify/functions-utils": "^4.2.2",
|
|
@@ -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",
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
// them consistent
|
|
4
4
|
export const normalizeGroupingMessage = function (message, type) {
|
|
5
5
|
const messageA = removeDependenciesLogs(message, type)
|
|
6
|
-
|
|
6
|
+
const messageB = NORMALIZE_REGEXPS.reduce(normalizeMessage, messageA)
|
|
7
|
+
|
|
8
|
+
// If this is a functions bundling error, we'll use additional normalization
|
|
9
|
+
// rules to group errors more aggressively.
|
|
10
|
+
if (type === 'functionsBundling') {
|
|
11
|
+
return FUNCTIONS_BUNDLING_REGEXPS.reduce(normalizeMessage, messageB)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return messageB
|
|
7
15
|
}
|
|
8
16
|
|
|
9
17
|
// Discard debug/info installation information
|
|
@@ -32,9 +40,9 @@ const normalizeMessage = function (message, [regExp, replacement]) {
|
|
|
32
40
|
|
|
33
41
|
const NORMALIZE_REGEXPS = [
|
|
34
42
|
// Base64 URL
|
|
35
|
-
[/(data:[^;]+;base64),[\w
|
|
43
|
+
[/(data:[^;]+;base64),[\w+/-=]+/g, 'dataURI'],
|
|
36
44
|
// File paths
|
|
37
|
-
[/(["'`, ]|^)([^"'`, \n]*[/\\][^"'`, \n]*)(["'`, ]|$)/gm, '$1/file/path
|
|
45
|
+
[/(["'`, ]|^)([^"'`, \n]*[/\\][^"'`, \n]*)(?=["'`, ]|$)/gm, '$1/file/path'],
|
|
38
46
|
// Semantic versions
|
|
39
47
|
[/\d+\.\d+\.\d+(-\d+)?/g, '1.0.0'],
|
|
40
48
|
[/version "[^"]+"/g, 'version "1.0.0"'],
|
|
@@ -45,7 +53,7 @@ const NORMALIZE_REGEXPS = [
|
|
|
45
53
|
// Numbers, e.g. number of issues/problems
|
|
46
54
|
[/\d+/g, '0'],
|
|
47
55
|
// Hexadecimal strings
|
|
48
|
-
[/[\da-fA-F]{6,}/g, 'hex'],
|
|
56
|
+
[/[\da-fA-F-]{6,}/g, 'hex'],
|
|
49
57
|
// On unknown inputs, we print the inputs
|
|
50
58
|
[/(does not accept any inputs but you specified: ).*/, '$1'],
|
|
51
59
|
[/(Unknown inputs for plugin).*/, '$1'],
|
|
@@ -75,3 +83,14 @@ const NORMALIZE_REGEXPS = [
|
|
|
75
83
|
// Multiple empty lines
|
|
76
84
|
[/^\s*$/gm, ''],
|
|
77
85
|
]
|
|
86
|
+
|
|
87
|
+
const FUNCTIONS_BUNDLING_REGEXPS = [
|
|
88
|
+
// String literals and identifiers
|
|
89
|
+
[/"([^"]+)"/g, '""'],
|
|
90
|
+
[/'([^']+)'/g, "''"],
|
|
91
|
+
[/`([^`]+)`/g, '``'],
|
|
92
|
+
|
|
93
|
+
// Rust crates
|
|
94
|
+
[/(?:Downloaded \S+ v[\d.]+\s*)+/gm, 'Downloaded crates'],
|
|
95
|
+
[/(?:Compiling \S+ v[\d.]+\s*)+/gm, 'Compiled crates'],
|
|
96
|
+
]
|
|
@@ -21,7 +21,7 @@ export const reportBuildError = async function ({ error, errorMonitor, childEnv,
|
|
|
21
21
|
const { errorInfo, type, severity, title, group = title } = parseErrorInfo(error)
|
|
22
22
|
const severityA = getSeverity(severity, errorInfo)
|
|
23
23
|
const groupA = getGroup(group, errorInfo)
|
|
24
|
-
const groupingHash = getGroupingHash(groupA, error, type)
|
|
24
|
+
const groupingHash = getGroupingHash(groupA, error, type, errorInfo)
|
|
25
25
|
const metadata = getMetadata(errorInfo, childEnv, groupingHash)
|
|
26
26
|
const app = getApp()
|
|
27
27
|
const eventProps = getEventProps({ severity: severityA, group: groupA, groupingHash, metadata, app })
|
|
@@ -52,7 +52,12 @@ const getGroup = function (group, errorInfo) {
|
|
|
52
52
|
return group(errorInfo)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const getGroupingHash = function (group, error, type) {
|
|
55
|
+
const getGroupingHash = function (group, error, type, errorInfo = {}) {
|
|
56
|
+
// If the error has a `normalizedMessage`, we use it as the grouping hash.
|
|
57
|
+
if (errorInfo.normalizedMessage) {
|
|
58
|
+
return errorInfo.normalizedMessage
|
|
59
|
+
}
|
|
60
|
+
|
|
56
61
|
const message = error instanceof Error && typeof error.message === 'string' ? error.message : String(error)
|
|
57
62
|
const messageA = normalizeGroupingMessage(message, type)
|
|
58
63
|
return `${group}\n${messageA}`
|
|
@@ -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,14 @@ 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
|
+
},
|
|
91
|
+
group: ({ location: { functionType = 'serverless' } }) => `'Bundling of ${functionType} function failed`,
|
|
85
92
|
stackType: 'none',
|
|
86
93
|
locationType: 'functionsBundling',
|
|
87
94
|
severity: 'info',
|
|
@@ -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
|
+
}
|