@netlify/build 27.5.0-rc → 27.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "27.5.0-rc",
3
+ "version": "27.7.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.6.0",
59
+ "@netlify/edge-bundler": "^1.8.0",
60
60
  "@netlify/cache-utils": "^4.0.0",
61
- "@netlify/config": "^18.1.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",
@@ -32,9 +32,9 @@ const normalizeMessage = function (message, [regExp, replacement]) {
32
32
 
33
33
  const NORMALIZE_REGEXPS = [
34
34
  // Base64 URL
35
- [/(data:[^;]+;base64),[\w+/-]+/g, 'dataURI'],
35
+ [/(data:[^;]+;base64),[\w+/-=]+/g, 'dataURI'],
36
36
  // File paths
37
- [/(["'`, ]|^)([^"'`, \n]*[/\\][^"'`, \n]*)(["'`, ]|$)/gm, '$1/file/path$3'],
37
+ [/(["'`, ]|^)([^"'`, \n]*[/\\][^"'`, \n]*)(?=["'`, ]|$)/gm, '$1/file/path'],
38
38
  // Semantic versions
39
39
  [/\d+\.\d+\.\d+(-\d+)?/g, '1.0.0'],
40
40
  [/version "[^"]+"/g, 'version "1.0.0"'],
@@ -45,7 +45,7 @@ const NORMALIZE_REGEXPS = [
45
45
  // Numbers, e.g. number of issues/problems
46
46
  [/\d+/g, '0'],
47
47
  // Hexadecimal strings
48
- [/[\da-fA-F]{6,}/g, 'hex'],
48
+ [/[\da-fA-F-]{6,}/g, 'hex'],
49
49
  // On unknown inputs, we print the inputs
50
50
  [/(does not accept any inputs but you specified: ).*/, '$1'],
51
51
  [/(Unknown inputs for plugin).*/, '$1'],
@@ -74,4 +74,6 @@ const NORMALIZE_REGEXPS = [
74
74
  [/(Parse Error):[^]*/, '$1'],
75
75
  // Multiple empty lines
76
76
  [/^\s*$/gm, ''],
77
+ // Function bundling errors
78
+ [/Bundling of function "([^"]+)" failed/gm, 'Bundling of function "functionName" failed'],
77
79
  ]
@@ -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
- return `While bundling Function "${functionName}"`
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 } }) => `Bundling of Function "${functionName}" failed`,
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',
@@ -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
- const { manifest } = await bundle(sourcePaths, distPath, declarations, {
50
- cacheDirectory,
51
- debug,
52
- distImportMapPath,
53
- featureFlags,
54
- importMaps: [importMap].filter(Boolean),
55
- })
56
-
57
- if (debug) {
58
- logEdgeManifest({ manifest, logs, debug })
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
+ }