@vercel/routing-utils 2.1.11 → 2.2.1
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/append.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -12
- package/dist/merge.js +3 -3
- package/dist/schemas.d.ts +3 -0
- package/dist/schemas.js +3 -0
- package/dist/superstatic.js +8 -8
- package/dist/types.d.ts +6 -6
- package/package.json +4 -4
package/dist/append.js
CHANGED
|
@@ -10,7 +10,7 @@ function appendRoutesToPhase({ routes: prevRoutes, newRoutes, phase, }) {
|
|
|
10
10
|
let isInPhase = false;
|
|
11
11
|
let insertIndex = -1;
|
|
12
12
|
routes.forEach((r, i) => {
|
|
13
|
-
if (index_1.isHandler(r)) {
|
|
13
|
+
if ((0, index_1.isHandler)(r)) {
|
|
14
14
|
if (r.handle === phase) {
|
|
15
15
|
isInPhase = true;
|
|
16
16
|
}
|
|
@@ -25,7 +25,7 @@ function appendRoutesToPhase({ routes: prevRoutes, newRoutes, phase, }) {
|
|
|
25
25
|
}
|
|
26
26
|
else if (phase === null) {
|
|
27
27
|
// If the phase is null, we want to insert the routes at the beginning
|
|
28
|
-
const lastPhase = routes.findIndex(r => index_1.isHandler(r) && r.handle);
|
|
28
|
+
const lastPhase = routes.findIndex(r => (0, index_1.isHandler)(r) && r.handle);
|
|
29
29
|
if (lastPhase === -1) {
|
|
30
30
|
routes.push(...newRoutes);
|
|
31
31
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './schemas';
|
|
|
5
5
|
export { getCleanUrls } from './superstatic';
|
|
6
6
|
export * from './types';
|
|
7
7
|
declare const VALID_HANDLE_VALUES: readonly ["filesystem", "hit", "miss", "rewrite", "error", "resource"];
|
|
8
|
-
export
|
|
8
|
+
export type HandleValue = typeof VALID_HANDLE_VALUES[number];
|
|
9
9
|
export declare function isHandler(route: Route): route is RouteWithHandle;
|
|
10
10
|
export declare function isValidHandleValue(handle: string): handle is HandleValue;
|
|
11
11
|
export declare function normalizeRoutes(inputRoutes: Route[] | null): NormalizedRoutes;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -126,7 +130,7 @@ function checkPatternSyntax(type, index, { source, destination, has, }) {
|
|
|
126
130
|
let sourceSegments = new Set();
|
|
127
131
|
const destinationSegments = new Set();
|
|
128
132
|
try {
|
|
129
|
-
sourceSegments = new Set(superstatic_1.sourceToRegex(source).segments);
|
|
133
|
+
sourceSegments = new Set((0, superstatic_1.sourceToRegex)(source).segments);
|
|
130
134
|
}
|
|
131
135
|
catch (err) {
|
|
132
136
|
return {
|
|
@@ -136,12 +140,12 @@ function checkPatternSyntax(type, index, { source, destination, has, }) {
|
|
|
136
140
|
}
|
|
137
141
|
if (destination) {
|
|
138
142
|
try {
|
|
139
|
-
const { hostname, pathname, query } = url_1.parse(destination, true);
|
|
140
|
-
superstatic_1.sourceToRegex(hostname || '').segments.forEach(name => destinationSegments.add(name));
|
|
141
|
-
superstatic_1.sourceToRegex(pathname || '').segments.forEach(name => destinationSegments.add(name));
|
|
143
|
+
const { hostname, pathname, query } = (0, url_1.parse)(destination, true);
|
|
144
|
+
(0, superstatic_1.sourceToRegex)(hostname || '').segments.forEach(name => destinationSegments.add(name));
|
|
145
|
+
(0, superstatic_1.sourceToRegex)(pathname || '').segments.forEach(name => destinationSegments.add(name));
|
|
142
146
|
for (const strOrArray of Object.values(query)) {
|
|
143
147
|
const value = Array.isArray(strOrArray) ? strOrArray[0] : strOrArray;
|
|
144
|
-
superstatic_1.sourceToRegex(value || '').segments.forEach(name => destinationSegments.add(name));
|
|
148
|
+
(0, superstatic_1.sourceToRegex)(value || '').segments.forEach(name => destinationSegments.add(name));
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
151
|
catch (err) {
|
|
@@ -149,7 +153,7 @@ function checkPatternSyntax(type, index, { source, destination, has, }) {
|
|
|
149
153
|
// replicate all possible URL parsing here so we consume the error.
|
|
150
154
|
// If this really is an error, we'll throw later in convertRedirects().
|
|
151
155
|
}
|
|
152
|
-
const hasSegments = superstatic_1.collectHasSegments(has);
|
|
156
|
+
const hasSegments = (0, superstatic_1.collectHasSegments)(has);
|
|
153
157
|
for (const segment of destinationSegments) {
|
|
154
158
|
if (!sourceSegments.has(segment) && !hasSegments.includes(segment)) {
|
|
155
159
|
return {
|
|
@@ -200,7 +204,7 @@ function getTransformedRoutes(vercelConfig) {
|
|
|
200
204
|
return normalizeRoutes(routes);
|
|
201
205
|
}
|
|
202
206
|
if (typeof cleanUrls !== 'undefined') {
|
|
203
|
-
const normalized = normalizeRoutes(superstatic_1.convertCleanUrls(cleanUrls, trailingSlash));
|
|
207
|
+
const normalized = normalizeRoutes((0, superstatic_1.convertCleanUrls)(cleanUrls, trailingSlash));
|
|
204
208
|
if (normalized.error) {
|
|
205
209
|
normalized.error.code = 'invalid_clean_urls';
|
|
206
210
|
return { routes, error: normalized.error };
|
|
@@ -209,7 +213,7 @@ function getTransformedRoutes(vercelConfig) {
|
|
|
209
213
|
routes.push(...(normalized.routes || []));
|
|
210
214
|
}
|
|
211
215
|
if (typeof trailingSlash !== 'undefined') {
|
|
212
|
-
const normalized = normalizeRoutes(superstatic_1.convertTrailingSlash(trailingSlash));
|
|
216
|
+
const normalized = normalizeRoutes((0, superstatic_1.convertTrailingSlash)(trailingSlash));
|
|
213
217
|
if (normalized.error) {
|
|
214
218
|
normalized.error.code = 'invalid_trailing_slash';
|
|
215
219
|
return { routes, error: normalized.error };
|
|
@@ -244,7 +248,7 @@ function getTransformedRoutes(vercelConfig) {
|
|
|
244
248
|
error: createError(code, redirectErrorMessage, 'https://vercel.link/redirects-json', 'Learn More'),
|
|
245
249
|
};
|
|
246
250
|
}
|
|
247
|
-
const normalized = normalizeRoutes(superstatic_1.convertRedirects(redirects));
|
|
251
|
+
const normalized = normalizeRoutes((0, superstatic_1.convertRedirects)(redirects));
|
|
248
252
|
if (normalized.error) {
|
|
249
253
|
normalized.error.code = code;
|
|
250
254
|
return { routes, error: normalized.error };
|
|
@@ -272,7 +276,7 @@ function getTransformedRoutes(vercelConfig) {
|
|
|
272
276
|
error: createError(code, patternError.message, patternError.link, 'Learn More'),
|
|
273
277
|
};
|
|
274
278
|
}
|
|
275
|
-
const normalized = normalizeRoutes(superstatic_1.convertHeaders(headers));
|
|
279
|
+
const normalized = normalizeRoutes((0, superstatic_1.convertHeaders)(headers));
|
|
276
280
|
if (normalized.error) {
|
|
277
281
|
normalized.error.code = code;
|
|
278
282
|
return { routes, error: normalized.error };
|
|
@@ -300,7 +304,7 @@ function getTransformedRoutes(vercelConfig) {
|
|
|
300
304
|
error: createError(code, patternError.message, patternError.link, 'Learn More'),
|
|
301
305
|
};
|
|
302
306
|
}
|
|
303
|
-
const normalized = normalizeRoutes(superstatic_1.convertRewrites(rewrites));
|
|
307
|
+
const normalized = normalizeRoutes((0, superstatic_1.convertRewrites)(rewrites));
|
|
304
308
|
if (normalized.error) {
|
|
305
309
|
normalized.error.code = code;
|
|
306
310
|
return { routes, error: normalized.error };
|
package/dist/merge.js
CHANGED
|
@@ -19,7 +19,7 @@ function getCheckAndContinue(routes) {
|
|
|
19
19
|
const continues = [];
|
|
20
20
|
const others = [];
|
|
21
21
|
for (const route of routes) {
|
|
22
|
-
if (index_1.isHandler(route)) {
|
|
22
|
+
if ((0, index_1.isHandler)(route)) {
|
|
23
23
|
// Should never happen, only here to make TS happy
|
|
24
24
|
throw new Error(`Unexpected route found in getCheckAndContinue(): ${JSON.stringify(route)}`);
|
|
25
25
|
}
|
|
@@ -39,7 +39,7 @@ function mergeRoutes({ userRoutes, builds }) {
|
|
|
39
39
|
const userHandleMap = new Map();
|
|
40
40
|
let userPrevHandle = null;
|
|
41
41
|
(userRoutes || []).forEach(route => {
|
|
42
|
-
if (index_1.isHandler(route)) {
|
|
42
|
+
if ((0, index_1.isHandler)(route)) {
|
|
43
43
|
userPrevHandle = route.handle;
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
@@ -61,7 +61,7 @@ function mergeRoutes({ userRoutes, builds }) {
|
|
|
61
61
|
sortedBuilders.forEach(use => {
|
|
62
62
|
let builderPrevHandle = null;
|
|
63
63
|
br[use].forEach(route => {
|
|
64
|
-
if (index_1.isHandler(route)) {
|
|
64
|
+
if ((0, index_1.isHandler)(route)) {
|
|
65
65
|
builderPrevHandle = route.handle;
|
|
66
66
|
}
|
|
67
67
|
else {
|
package/dist/schemas.d.ts
CHANGED
package/dist/schemas.js
CHANGED
package/dist/superstatic.js
CHANGED
|
@@ -167,7 +167,7 @@ function convertTrailingSlash(enable, status = 308) {
|
|
|
167
167
|
exports.convertTrailingSlash = convertTrailingSlash;
|
|
168
168
|
function sourceToRegex(source) {
|
|
169
169
|
const keys = [];
|
|
170
|
-
const r = path_to_regexp_1.pathToRegexp(source, keys, {
|
|
170
|
+
const r = (0, path_to_regexp_1.pathToRegexp)(source, keys, {
|
|
171
171
|
strict: true,
|
|
172
172
|
sensitive: true,
|
|
173
173
|
delimiter: '/',
|
|
@@ -233,7 +233,7 @@ function replaceSegments(segments, hasItemSegments, destination, isRedirect, int
|
|
|
233
233
|
indexes[name] = '$' + name;
|
|
234
234
|
escapedDestination = escapeSegment(escapedDestination, name);
|
|
235
235
|
});
|
|
236
|
-
const parsedDestination = url_1.parse(escapedDestination, true);
|
|
236
|
+
const parsedDestination = (0, url_1.parse)(escapedDestination, true);
|
|
237
237
|
delete parsedDestination.href;
|
|
238
238
|
delete parsedDestination.path;
|
|
239
239
|
delete parsedDestination.search;
|
|
@@ -248,9 +248,9 @@ function replaceSegments(segments, hasItemSegments, destination, isRedirect, int
|
|
|
248
248
|
const hashKeys = [];
|
|
249
249
|
const hostnameKeys = [];
|
|
250
250
|
try {
|
|
251
|
-
path_to_regexp_1.pathToRegexp(pathname, pathnameKeys);
|
|
252
|
-
path_to_regexp_1.pathToRegexp(hash || '', hashKeys);
|
|
253
|
-
path_to_regexp_1.pathToRegexp(hostname || '', hostnameKeys);
|
|
251
|
+
(0, path_to_regexp_1.pathToRegexp)(pathname, pathnameKeys);
|
|
252
|
+
(0, path_to_regexp_1.pathToRegexp)(hash || '', hashKeys);
|
|
253
|
+
(0, path_to_regexp_1.pathToRegexp)(hostname || '', hostnameKeys);
|
|
254
254
|
}
|
|
255
255
|
catch (_) {
|
|
256
256
|
// this is not fatal so don't error when failing to parse the
|
|
@@ -287,7 +287,7 @@ function replaceSegments(segments, hasItemSegments, destination, isRedirect, int
|
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
destination = url_1.format({
|
|
290
|
+
destination = (0, url_1.format)({
|
|
291
291
|
...rest,
|
|
292
292
|
hostname,
|
|
293
293
|
pathname,
|
|
@@ -306,7 +306,7 @@ function safelyCompile(value, indexes, attemptDirectCompile) {
|
|
|
306
306
|
// Attempt compiling normally with path-to-regexp first and fall back
|
|
307
307
|
// to safely compiling to handle edge cases if path-to-regexp compile
|
|
308
308
|
// fails
|
|
309
|
-
return path_to_regexp_1.compile(value, { validate: false })(indexes);
|
|
309
|
+
return (0, path_to_regexp_1.compile)(value, { validate: false })(indexes);
|
|
310
310
|
}
|
|
311
311
|
catch (e) {
|
|
312
312
|
// non-fatal, we continue to safely compile
|
|
@@ -329,7 +329,7 @@ function safelyCompile(value, indexes, attemptDirectCompile) {
|
|
|
329
329
|
.replace(/--ESCAPED_PARAM_ASTERISK/g, '*');
|
|
330
330
|
// the value needs to start with a forward-slash to be compiled
|
|
331
331
|
// correctly
|
|
332
|
-
return path_to_regexp_1.compile(`/${value}`, { validate: false })(indexes).slice(1);
|
|
332
|
+
return (0, path_to_regexp_1.compile)(`/${value}`, { validate: false })(indexes).slice(1);
|
|
333
333
|
}
|
|
334
334
|
function toSegmentDest(index) {
|
|
335
335
|
const i = index + 1; // js is base 0, regex is base 1
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HandleValue } from './index';
|
|
2
|
-
export
|
|
2
|
+
export type RouteApiError = {
|
|
3
3
|
name: string;
|
|
4
4
|
code: string;
|
|
5
5
|
message: string;
|
|
@@ -7,7 +7,7 @@ export declare type RouteApiError = {
|
|
|
7
7
|
action?: string;
|
|
8
8
|
errors?: string[];
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type HasField = Array<{
|
|
11
11
|
type: 'host';
|
|
12
12
|
value: string;
|
|
13
13
|
} | {
|
|
@@ -15,7 +15,7 @@ export declare type HasField = Array<{
|
|
|
15
15
|
key: string;
|
|
16
16
|
value?: string;
|
|
17
17
|
}>;
|
|
18
|
-
export
|
|
18
|
+
export type RouteWithSrc = {
|
|
19
19
|
src: string;
|
|
20
20
|
dest?: string;
|
|
21
21
|
headers?: {
|
|
@@ -48,14 +48,14 @@ export declare type RouteWithSrc = {
|
|
|
48
48
|
*/
|
|
49
49
|
middleware?: number;
|
|
50
50
|
};
|
|
51
|
-
export
|
|
51
|
+
export type RouteWithHandle = {
|
|
52
52
|
handle: HandleValue;
|
|
53
53
|
src?: string;
|
|
54
54
|
dest?: string;
|
|
55
55
|
status?: number;
|
|
56
56
|
};
|
|
57
|
-
export
|
|
58
|
-
export
|
|
57
|
+
export type Route = RouteWithSrc | RouteWithHandle;
|
|
58
|
+
export type NormalizedRoutes = {
|
|
59
59
|
routes: Route[] | null;
|
|
60
60
|
error: RouteApiError | null;
|
|
61
61
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/routing-utils",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Vercel routing utilities",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/vercel/vercel.git",
|
|
13
13
|
"directory": "packages/routing-utils"
|
|
14
14
|
},
|
|
15
|
-
"license": "
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc",
|
|
18
18
|
"test": "jest --env node --verbose --runInBand --bail",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"@types/jest": "27.4.1",
|
|
26
26
|
"@types/node": "14.18.33",
|
|
27
27
|
"ajv": "^6.0.0",
|
|
28
|
-
"typescript": "4.
|
|
28
|
+
"typescript": "4.9.5"
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
31
|
"ajv": "^6.0.0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "2de365f9cfea3ce283d2bf855507c71209f1e3d8"
|
|
34
34
|
}
|