@netlify/edge-bundler 8.5.0 → 8.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/dist/node/bundler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const defaultFlags = {
|
|
2
2
|
edge_functions_cache_deno_dir: false,
|
|
3
3
|
edge_functions_config_export: false,
|
|
4
|
+
edge_functions_fail_unsupported_regex: false,
|
|
4
5
|
};
|
|
5
6
|
const getFlags = (input = {}, flags = defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
|
|
6
7
|
...result,
|
package/dist/node/manifest.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Bundle } from './bundle.js';
|
|
|
2
2
|
import { FunctionConfig } from './config.js';
|
|
3
3
|
import { Declaration } from './declaration.js';
|
|
4
4
|
import { EdgeFunction } from './edge_function.js';
|
|
5
|
+
import { FeatureFlags } from './feature_flags.js';
|
|
5
6
|
import { Layer } from './layer.js';
|
|
6
7
|
interface Route {
|
|
7
8
|
function: string;
|
|
@@ -29,6 +30,7 @@ interface Manifest {
|
|
|
29
30
|
interface GenerateManifestOptions {
|
|
30
31
|
bundles?: Bundle[];
|
|
31
32
|
declarations?: Declaration[];
|
|
33
|
+
featureFlags?: FeatureFlags;
|
|
32
34
|
functions: EdgeFunction[];
|
|
33
35
|
functionConfig?: Record<string, FunctionConfig>;
|
|
34
36
|
importMap?: string;
|
|
@@ -39,7 +41,7 @@ interface Route {
|
|
|
39
41
|
name?: string;
|
|
40
42
|
pattern: string;
|
|
41
43
|
}
|
|
42
|
-
declare const generateManifest: ({ bundles, declarations, functions, functionConfig, importMap, layers, }: GenerateManifestOptions) => Manifest;
|
|
44
|
+
declare const generateManifest: ({ bundles, declarations, featureFlags, functions, functionConfig, importMap, layers, }: GenerateManifestOptions) => Manifest;
|
|
43
45
|
interface WriteManifestOptions extends GenerateManifestOptions {
|
|
44
46
|
distDirectory: string;
|
|
45
47
|
}
|
package/dist/node/manifest.js
CHANGED
|
@@ -18,7 +18,7 @@ const sanitizeEdgeFunctionConfig = (config) => {
|
|
|
18
18
|
}
|
|
19
19
|
return newConfig;
|
|
20
20
|
};
|
|
21
|
-
const generateManifest = ({ bundles = [], declarations = [], functions, functionConfig = {}, importMap, layers = [], }) => {
|
|
21
|
+
const generateManifest = ({ bundles = [], declarations = [], featureFlags, functions, functionConfig = {}, importMap, layers = [], }) => {
|
|
22
22
|
const preCacheRoutes = [];
|
|
23
23
|
const postCacheRoutes = [];
|
|
24
24
|
const manifestFunctionConfig = Object.fromEntries(functions.map(({ name }) => [name, { excluded_patterns: [] }]));
|
|
@@ -34,13 +34,13 @@ const generateManifest = ({ bundles = [], declarations = [], functions, function
|
|
|
34
34
|
if (func === undefined) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const pattern = getRegularExpression(declaration);
|
|
37
|
+
const pattern = getRegularExpression(declaration, featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.edge_functions_fail_unsupported_regex);
|
|
38
38
|
const route = {
|
|
39
39
|
function: func.name,
|
|
40
40
|
name: declaration.name,
|
|
41
41
|
pattern: serializePattern(pattern),
|
|
42
42
|
};
|
|
43
|
-
const excludedPattern = getExcludedRegularExpression(declaration);
|
|
43
|
+
const excludedPattern = getExcludedRegularExpression(declaration, featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.edge_functions_fail_unsupported_regex);
|
|
44
44
|
if (excludedPattern) {
|
|
45
45
|
manifestFunctionConfig[func.name].excluded_patterns.push(serializePattern(excludedPattern));
|
|
46
46
|
}
|
|
@@ -76,24 +76,34 @@ const pathToRegularExpression = (path) => {
|
|
|
76
76
|
const normalizedSource = `^${regularExpression.source}\\/?$`;
|
|
77
77
|
return normalizedSource;
|
|
78
78
|
};
|
|
79
|
-
const getRegularExpression = (declaration) => {
|
|
79
|
+
const getRegularExpression = (declaration, failUnsupportedRegex = false) => {
|
|
80
80
|
if ('pattern' in declaration) {
|
|
81
81
|
try {
|
|
82
82
|
return parsePattern(declaration.pattern);
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
85
|
-
|
|
85
|
+
// eslint-disable-next-line max-depth
|
|
86
|
+
if (failUnsupportedRegex) {
|
|
87
|
+
throw new Error(`Could not parse path declaration of function '${declaration.function}': ${error.message}`);
|
|
88
|
+
}
|
|
89
|
+
console.warn(`Function '${declaration.function}' uses an unsupported regular expression and will not be invoked: ${error.message}`);
|
|
90
|
+
return declaration.pattern;
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
return pathToRegularExpression(declaration.path);
|
|
89
94
|
};
|
|
90
|
-
const getExcludedRegularExpression = (declaration) => {
|
|
95
|
+
const getExcludedRegularExpression = (declaration, failUnsupportedRegex = false) => {
|
|
91
96
|
if ('excludedPattern' in declaration && declaration.excludedPattern) {
|
|
92
97
|
try {
|
|
93
98
|
return parsePattern(declaration.excludedPattern);
|
|
94
99
|
}
|
|
95
100
|
catch (error) {
|
|
96
|
-
|
|
101
|
+
// eslint-disable-next-line max-depth
|
|
102
|
+
if (failUnsupportedRegex) {
|
|
103
|
+
throw new Error(`Could not parse path declaration of function '${declaration.function}': ${error.message}`);
|
|
104
|
+
}
|
|
105
|
+
console.warn(`Function '${declaration.function}' uses an unsupported regular expression and will therefore not be invoked: ${error.message}`);
|
|
106
|
+
return declaration.excludedPattern;
|
|
97
107
|
}
|
|
98
108
|
}
|
|
99
109
|
if ('path' in declaration && declaration.excludedPath) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { env } from 'process';
|
|
2
|
-
import { test, expect } from 'vitest';
|
|
2
|
+
import { test, expect, vi } from 'vitest';
|
|
3
3
|
import { BundleFormat } from './bundle.js';
|
|
4
4
|
import { generateManifest } from './manifest.js';
|
|
5
5
|
test('Generates a manifest with different bundles', () => {
|
|
@@ -164,10 +164,31 @@ test('Generates a manifest with layers', () => {
|
|
|
164
164
|
expect(manifest2.routes).toEqual(expectedRoutes);
|
|
165
165
|
expect(manifest2.layers).toEqual(layers);
|
|
166
166
|
});
|
|
167
|
-
test('
|
|
167
|
+
test('Shows a warning if the regular expression contains a negative lookahead', () => {
|
|
168
|
+
const mockConsoleWarn = vi.fn();
|
|
169
|
+
const consoleWarn = console.warn;
|
|
170
|
+
console.warn = mockConsoleWarn;
|
|
168
171
|
const functions = [{ name: 'func-1', path: '/path/to/func-1.ts' }];
|
|
169
172
|
const declarations = [{ function: 'func-1', pattern: '^/\\w+(?=\\d)$' }];
|
|
170
|
-
|
|
173
|
+
const manifest = generateManifest({
|
|
174
|
+
bundles: [],
|
|
175
|
+
declarations,
|
|
176
|
+
functions,
|
|
177
|
+
});
|
|
178
|
+
console.warn = consoleWarn;
|
|
179
|
+
expect(manifest.routes).toEqual([{ function: 'func-1', pattern: '^/\\w+(?=\\d)$' }]);
|
|
180
|
+
expect(mockConsoleWarn).toHaveBeenCalledOnce();
|
|
181
|
+
expect(mockConsoleWarn).toHaveBeenCalledWith("Function 'func-1' uses an unsupported regular expression and will not be invoked: Regular expressions with lookaheads are not supported");
|
|
182
|
+
});
|
|
183
|
+
test('Throws an error if the regular expression contains a negative lookahead and the `edge_functions_fail_unsupported_regex` flag is set', () => {
|
|
184
|
+
const functions = [{ name: 'func-1', path: '/path/to/func-1.ts' }];
|
|
185
|
+
const declarations = [{ function: 'func-1', pattern: '^/\\w+(?=\\d)$' }];
|
|
186
|
+
expect(() => generateManifest({
|
|
187
|
+
bundles: [],
|
|
188
|
+
declarations,
|
|
189
|
+
featureFlags: { edge_functions_fail_unsupported_regex: true },
|
|
190
|
+
functions,
|
|
191
|
+
})).toThrowError(/^Could not parse path declaration of function 'func-1': Regular expressions with lookaheads are not supported$/);
|
|
171
192
|
});
|
|
172
193
|
test('Converts named capture groups to unnamed capture groups in regular expressions', () => {
|
|
173
194
|
const functions = [{ name: 'func-1', path: '/path/to/func-1.ts' }];
|