@netlify/edge-bundler 11.0.0 → 11.1.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,6 +1,10 @@
|
|
|
1
|
-
declare const defaultFlags: {
|
|
1
|
+
declare const defaultFlags: {
|
|
2
|
+
edge_bundler_pcre_regexp: boolean;
|
|
3
|
+
};
|
|
2
4
|
type FeatureFlag = keyof typeof defaultFlags;
|
|
3
5
|
type FeatureFlags = Partial<Record<FeatureFlag, boolean>>;
|
|
4
|
-
declare const getFlags: (input?: Record<string, boolean>, flags?: {
|
|
6
|
+
declare const getFlags: (input?: Record<string, boolean>, flags?: {
|
|
7
|
+
edge_bundler_pcre_regexp: boolean;
|
|
8
|
+
}) => FeatureFlags;
|
|
5
9
|
export { defaultFlags, getFlags };
|
|
6
10
|
export type { FeatureFlag, FeatureFlags };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const defaultFlags = {
|
|
1
|
+
const defaultFlags = {
|
|
2
|
+
edge_bundler_pcre_regexp: false,
|
|
3
|
+
};
|
|
2
4
|
const getFlags = (input = {}, flags = defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
|
|
3
5
|
...result,
|
|
4
6
|
[key]: input[key] === undefined ? defaultValue : input[key],
|
package/dist/node/manifest.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ interface GenerateManifestOptions {
|
|
|
42
42
|
layers?: Layer[];
|
|
43
43
|
userFunctionConfig?: Record<string, FunctionConfig>;
|
|
44
44
|
}
|
|
45
|
-
declare const generateManifest: ({ bundles, declarations, functions, userFunctionConfig, internalFunctionConfig, importMap, layers, }: GenerateManifestOptions) => {
|
|
45
|
+
declare const generateManifest: ({ bundles, declarations, featureFlags, functions, userFunctionConfig, internalFunctionConfig, importMap, layers, }: GenerateManifestOptions) => {
|
|
46
46
|
declarationsWithoutFunction: string[];
|
|
47
47
|
manifest: Manifest;
|
|
48
48
|
unroutedFunctions: string[];
|
package/dist/node/manifest.js
CHANGED
|
@@ -46,7 +46,7 @@ const normalizeMethods = (method, name) => {
|
|
|
46
46
|
return method.toUpperCase();
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
|
-
const generateManifest = ({ bundles = [], declarations = [], functions, userFunctionConfig = {}, internalFunctionConfig = {}, importMap, layers = [], }) => {
|
|
49
|
+
const generateManifest = ({ bundles = [], declarations = [], featureFlags, functions, userFunctionConfig = {}, internalFunctionConfig = {}, importMap, layers = [], }) => {
|
|
50
50
|
const preCacheRoutes = [];
|
|
51
51
|
const postCacheRoutes = [];
|
|
52
52
|
const manifestFunctionConfig = Object.fromEntries(functions.map(({ name }) => [name, { excluded_patterns: [] }]));
|
|
@@ -74,14 +74,14 @@ const generateManifest = ({ bundles = [], declarations = [], functions, userFunc
|
|
|
74
74
|
declarationsWithoutFunction.add(declaration.function);
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
const pattern = getRegularExpression(declaration);
|
|
77
|
+
const pattern = getRegularExpression(declaration, Boolean(featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.edge_bundler_pcre_regexp));
|
|
78
78
|
// If there is no `pattern`, the declaration will never be triggered, so we
|
|
79
79
|
// can discard it.
|
|
80
80
|
if (!pattern) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
routedFunctions.add(declaration.function);
|
|
84
|
-
const excludedPattern = getExcludedRegularExpressions(declaration);
|
|
84
|
+
const excludedPattern = getExcludedRegularExpressions(declaration, Boolean(featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.edge_bundler_pcre_regexp));
|
|
85
85
|
const route = {
|
|
86
86
|
function: func.name,
|
|
87
87
|
pattern: serializePattern(pattern),
|
|
@@ -135,8 +135,11 @@ const pathToRegularExpression = (path) => {
|
|
|
135
135
|
throw wrapBundleError(error);
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
|
-
const getRegularExpression = (declaration) => {
|
|
138
|
+
const getRegularExpression = (declaration, pcreRegexpEngine) => {
|
|
139
139
|
if ('pattern' in declaration) {
|
|
140
|
+
if (pcreRegexpEngine) {
|
|
141
|
+
return declaration.pattern;
|
|
142
|
+
}
|
|
140
143
|
try {
|
|
141
144
|
return parsePattern(declaration.pattern);
|
|
142
145
|
}
|
|
@@ -146,11 +149,14 @@ const getRegularExpression = (declaration) => {
|
|
|
146
149
|
}
|
|
147
150
|
return pathToRegularExpression(declaration.path);
|
|
148
151
|
};
|
|
149
|
-
const getExcludedRegularExpressions = (declaration) => {
|
|
152
|
+
const getExcludedRegularExpressions = (declaration, pcreRegexpEngine) => {
|
|
150
153
|
if ('excludedPattern' in declaration && declaration.excludedPattern) {
|
|
151
154
|
const excludedPatterns = Array.isArray(declaration.excludedPattern)
|
|
152
155
|
? declaration.excludedPattern
|
|
153
156
|
: [declaration.excludedPattern];
|
|
157
|
+
if (pcreRegexpEngine) {
|
|
158
|
+
return excludedPatterns;
|
|
159
|
+
}
|
|
154
160
|
return excludedPatterns.map((excludedPattern) => {
|
|
155
161
|
try {
|
|
156
162
|
return parsePattern(excludedPattern);
|
|
@@ -386,15 +386,29 @@ test('Generates a manifest with layers', () => {
|
|
|
386
386
|
expect(manifest2.routes).toEqual(expectedRoutes);
|
|
387
387
|
expect(manifest2.layers).toEqual(layers);
|
|
388
388
|
});
|
|
389
|
-
test('Throws an error if the regular expression contains a negative lookahead', () => {
|
|
389
|
+
test('Throws an error if the regular expression contains a negative lookahead and support for the PCRE engine is disabled', () => {
|
|
390
390
|
const functions = [{ name: 'func-1', path: '/path/to/func-1.ts' }];
|
|
391
|
-
const declarations = [{ function: 'func-1', pattern: '
|
|
391
|
+
const declarations = [{ function: 'func-1', pattern: '^\\/((?!api|_next\\/static|_next\\/image|favicon.ico).*)$' }];
|
|
392
392
|
expect(() => generateManifest({
|
|
393
393
|
bundles: [],
|
|
394
394
|
declarations,
|
|
395
395
|
functions,
|
|
396
396
|
})).toThrowError(/^Could not parse path declaration of function 'func-1': Regular expressions with lookaheads are not supported$/);
|
|
397
397
|
});
|
|
398
|
+
test('Accepts regular expressions with lookaheads if support for the PCRE engine is enabled', () => {
|
|
399
|
+
const functions = [{ name: 'func-1', path: '/path/to/func-1.ts' }];
|
|
400
|
+
const declarations = [{ function: 'func-1', pattern: '^\\/((?!api|_next\\/static|_next\\/image|favicon.ico).*)$' }];
|
|
401
|
+
const { manifest } = generateManifest({
|
|
402
|
+
bundles: [],
|
|
403
|
+
declarations,
|
|
404
|
+
featureFlags: { edge_bundler_pcre_regexp: true },
|
|
405
|
+
functions,
|
|
406
|
+
});
|
|
407
|
+
const [route] = manifest.routes;
|
|
408
|
+
const regexp = new RegExp(route.pattern);
|
|
409
|
+
expect(regexp.test('/foo')).toBeTruthy();
|
|
410
|
+
expect(regexp.test('/_next/static/foo')).toBeFalsy();
|
|
411
|
+
});
|
|
398
412
|
test('Converts named capture groups to unnamed capture groups in regular expressions', () => {
|
|
399
413
|
const functions = [{ name: 'func-1', path: '/path/to/func-1.ts' }];
|
|
400
414
|
const declarations = [{ function: 'func-1', pattern: '^/(?<name>\\w+)$' }];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/edge-bundler",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "Intelligently prepare Netlify Edge Functions for deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.js",
|
|
@@ -75,13 +75,13 @@
|
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@import-maps/resolve": "^1.0.1",
|
|
78
|
-
"@vercel/nft": "^0.
|
|
78
|
+
"@vercel/nft": "^0.26.0",
|
|
79
79
|
"ajv": "^8.11.2",
|
|
80
80
|
"ajv-errors": "^3.0.0",
|
|
81
81
|
"better-ajv-errors": "^1.2.0",
|
|
82
82
|
"common-path-prefix": "^3.0.0",
|
|
83
83
|
"env-paths": "^3.0.0",
|
|
84
|
-
"esbuild": "0.19.
|
|
84
|
+
"esbuild": "0.19.11",
|
|
85
85
|
"execa": "^6.0.0",
|
|
86
86
|
"find-up": "^6.3.0",
|
|
87
87
|
"get-package-name": "^2.2.0",
|