@vercel/config 0.0.32 → 0.0.33
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/router.js +39 -8
- package/package.json +3 -2
package/dist/router.js
CHANGED
|
@@ -2,7 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.routes = exports.createRoutes = exports.Router = exports.matchers = exports.deploymentEnv = void 0;
|
|
4
4
|
const pretty_cache_header_1 = require("pretty-cache-header");
|
|
5
|
+
const routing_utils_1 = require("@vercel/routing-utils");
|
|
5
6
|
const validation_1 = require("./utils/validation");
|
|
7
|
+
/**
|
|
8
|
+
* Convert a destination string from path-to-regexp format to use capture group references.
|
|
9
|
+
* Replaces :paramName with $index based on the segments array.
|
|
10
|
+
*/
|
|
11
|
+
function convertDestination(destination, segments) {
|
|
12
|
+
let result = destination;
|
|
13
|
+
segments.forEach((segment, index) => {
|
|
14
|
+
const patterns = [
|
|
15
|
+
new RegExp(`:${segment}\\*`, 'g'),
|
|
16
|
+
new RegExp(`:${segment}\\+`, 'g'),
|
|
17
|
+
new RegExp(`:${segment}(?![a-zA-Z0-9_])`, 'g'),
|
|
18
|
+
];
|
|
19
|
+
for (const pattern of patterns) {
|
|
20
|
+
result = result.replace(pattern, `$${index + 1}`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
6
25
|
/**
|
|
7
26
|
* Helper function to reference a Vercel project environment variable.
|
|
8
27
|
* These are placeholders that get resolved at request time by Vercel's routing layer.
|
|
@@ -163,9 +182,12 @@ class Router {
|
|
|
163
182
|
transforms.push(transform);
|
|
164
183
|
}
|
|
165
184
|
}
|
|
185
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
186
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
187
|
+
const convertedDest = convertDestination(destination, segments);
|
|
166
188
|
const route = {
|
|
167
|
-
src:
|
|
168
|
-
dest:
|
|
189
|
+
src: regexSrc,
|
|
190
|
+
dest: convertedDest,
|
|
169
191
|
transforms,
|
|
170
192
|
};
|
|
171
193
|
if (has)
|
|
@@ -186,9 +208,12 @@ class Router {
|
|
|
186
208
|
const destEnvVars = extractEnvVars(destination, pathParams);
|
|
187
209
|
if (destEnvVars.length > 0) {
|
|
188
210
|
// Need Route format to include env field
|
|
211
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
212
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
213
|
+
const convertedDest = convertDestination(destination, segments);
|
|
189
214
|
const route = {
|
|
190
|
-
src:
|
|
191
|
-
dest:
|
|
215
|
+
src: regexSrc,
|
|
216
|
+
dest: convertedDest,
|
|
192
217
|
env: destEnvVars,
|
|
193
218
|
};
|
|
194
219
|
if (has)
|
|
@@ -245,9 +270,12 @@ class Router {
|
|
|
245
270
|
}
|
|
246
271
|
transforms.push(transform);
|
|
247
272
|
}
|
|
273
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
274
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
275
|
+
const convertedDest = convertDestination(destination, segments);
|
|
248
276
|
const route = {
|
|
249
|
-
src:
|
|
250
|
-
dest:
|
|
277
|
+
src: regexSrc,
|
|
278
|
+
dest: convertedDest,
|
|
251
279
|
status: statusCode || (permanent ? 308 : 307),
|
|
252
280
|
transforms,
|
|
253
281
|
};
|
|
@@ -267,9 +295,12 @@ class Router {
|
|
|
267
295
|
const destEnvVars = extractEnvVars(destination, pathParams);
|
|
268
296
|
if (destEnvVars.length > 0) {
|
|
269
297
|
// Need Route format to include env field
|
|
298
|
+
// Convert path-to-regexp patterns to regex for routes format
|
|
299
|
+
const { src: regexSrc, segments } = (0, routing_utils_1.sourceToRegex)(source);
|
|
300
|
+
const convertedDest = convertDestination(destination, segments);
|
|
270
301
|
const route = {
|
|
271
|
-
src:
|
|
272
|
-
dest:
|
|
302
|
+
src: regexSrc,
|
|
303
|
+
dest: convertedDest,
|
|
273
304
|
status: statusCode || (permanent ? 308 : 307),
|
|
274
305
|
env: destEnvVars,
|
|
275
306
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/config",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "A TypeScript SDK for programmatically configuring Vercel projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://vercel.com/docs/projects/project-configuration",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"pretty-cache-header": "^1.0.0",
|
|
38
|
-
"zod": "^3.22.0"
|
|
38
|
+
"zod": "^3.22.0",
|
|
39
|
+
"@vercel/routing-utils": "5.3.3"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/node": "20.11.0",
|