@netlify/build 28.2.1 → 28.3.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.
@@ -1,94 +1,21 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import { join, resolve } from 'path';
3
- import Ajv from 'ajv';
4
- import ajvErrors from 'ajv-errors';
3
+ import { ManifestValidationError, validateManifest } from '@netlify/edge-bundler';
5
4
  import { addErrorInfo } from '../../../error/info.js';
6
- const ajv = new Ajv({ allErrors: true });
7
- ajvErrors(ajv);
8
- // regex pattern for manifest route pattern
9
- // checks if the pattern string starts with ^ and ends with $
10
- // we define this format in edge-bundler:
11
- // https://github.com/netlify/edge-bundler/blob/main/src/manifest.ts#L66
12
- const normalizedPatternRegex = /^\^.*\$$/;
13
- ajv.addFormat('regexPattern', {
14
- async: true,
15
- validate: (data) => normalizedPatternRegex.test(data),
16
- });
17
- const bundlesSchema = {
18
- $async: true,
19
- type: 'object',
20
- required: ['asset', 'format'],
21
- properties: {
22
- asset: { type: 'string' },
23
- format: { type: 'string' },
24
- },
25
- additionalProperties: false,
26
- };
27
- const routesSchema = {
28
- $async: true,
29
- type: 'object',
30
- required: ['function', 'pattern'],
31
- properties: {
32
- name: { type: 'string' },
33
- function: { type: 'string' },
34
- pattern: { type: 'string', format: 'regexPattern', errorMessage: `must match format ${normalizedPatternRegex}` },
35
- },
36
- additionalProperties: false,
37
- };
38
- const layersSchema = {
39
- $async: true,
40
- type: 'object',
41
- required: ['flag', 'name'],
42
- properties: {
43
- flag: { type: 'string' },
44
- name: { type: 'string' },
45
- local: { type: 'string' },
46
- },
47
- additionalProperties: false,
48
- };
49
- const edgeManifestSchema = {
50
- $async: true,
51
- type: 'object',
52
- required: ['bundles', 'routes', 'bundler_version'],
53
- properties: {
54
- bundles: {
55
- type: 'array',
56
- items: bundlesSchema,
57
- },
58
- routes: {
59
- type: 'array',
60
- items: routesSchema,
61
- },
62
- post_cache_routes: {
63
- type: 'array',
64
- items: routesSchema,
65
- },
66
- layers: {
67
- type: 'array',
68
- items: layersSchema,
69
- },
70
- bundler_version: { type: 'string' },
71
- },
72
- additionalProperties: false,
73
- errorMessage: "Couldn't validate Edge Functions manifest.json",
74
- };
75
- const validateManifest = async (manifestData) => {
76
- const validate = ajv.compile(edgeManifestSchema);
77
- await validate(manifestData);
78
- };
79
5
  export const validateEdgeFunctionsManifest = async function ({ buildDir, constants: { EDGE_FUNCTIONS_DIST: distDirectory }, }) {
6
+ const edgeFunctionsDistPath = resolve(buildDir, distDirectory);
7
+ const manifestPath = join(edgeFunctionsDistPath, 'manifest.json');
8
+ const data = await fs.readFile(manifestPath);
9
+ // @ts-expect-error TypeScript is not aware that parse can handle Buffer
10
+ const manifestData = JSON.parse(data);
80
11
  try {
81
- const edgeFunctionsDistPath = resolve(buildDir, distDirectory);
82
- const manifestPath = join(edgeFunctionsDistPath, 'manifest.json');
83
- const data = await fs.readFile(manifestPath);
84
- const manifestData = JSON.parse(data);
85
- await validateManifest(manifestData);
12
+ validateManifest(manifestData);
86
13
  }
87
14
  catch (error) {
88
- const isValidationErr = error instanceof Ajv.ValidationError;
89
- const parsedErr = isValidationErr ? error.errors : error;
90
- addErrorInfo(parsedErr, { type: 'coreStep' });
91
- throw new Error(isValidationErr ? JSON.stringify(parsedErr, null, 2) : parsedErr);
15
+ if (error instanceof ManifestValidationError) {
16
+ addErrorInfo(error, { type: 'coreStep' });
17
+ }
18
+ throw error;
92
19
  }
93
20
  return {};
94
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "28.2.1",
3
+ "version": "28.3.0",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./lib/core/main.js",
@@ -66,15 +66,13 @@
66
66
  "@bugsnag/js": "^7.0.0",
67
67
  "@netlify/cache-utils": "^5.0.2",
68
68
  "@netlify/config": "^20.0.1",
69
- "@netlify/edge-bundler": "4.3.0",
69
+ "@netlify/edge-bundler": "4.4.1",
70
70
  "@netlify/functions-utils": "^5.0.4",
71
71
  "@netlify/git-utils": "^5.0.2",
72
72
  "@netlify/plugins-list": "^6.54.0",
73
73
  "@netlify/run-utils": "^5.0.2",
74
74
  "@netlify/zip-it-and-ship-it": "^7.1.2",
75
75
  "@sindresorhus/slugify": "^2.0.0",
76
- "ajv": "^8.11.0",
77
- "ajv-errors": "^3.0.0",
78
76
  "ansi-escapes": "^5.0.0",
79
77
  "chalk": "^5.0.0",
80
78
  "clean-stack": "^4.0.0",
@@ -150,5 +148,5 @@
150
148
  "module": "commonjs"
151
149
  }
152
150
  },
153
- "gitHead": "68feefc0d483a887c91c7647aa74f3eed65c3d93"
151
+ "gitHead": "40509d63b9e4b640bc3e4f7a5be052f8b978deea"
154
152
  }