@vercel/routing-utils 5.0.3 → 5.0.5

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,4 +1,10 @@
1
1
  import { Route, Redirect, Rewrite, HasField, Header } from './types';
2
+ import { Key } from 'path-to-regexp';
3
+ export declare function pathToRegexp(callerId: string, path: string, keys?: Key[], options?: {
4
+ strict: boolean;
5
+ sensitive: boolean;
6
+ delimiter: string;
7
+ }): RegExp;
2
8
  export declare function getCleanUrls(filePaths: string[]): {
3
9
  html: string;
4
10
  clean: string;
@@ -25,11 +25,58 @@ __export(superstatic_exports, {
25
25
  convertRewrites: () => convertRewrites,
26
26
  convertTrailingSlash: () => convertTrailingSlash,
27
27
  getCleanUrls: () => getCleanUrls,
28
+ pathToRegexp: () => pathToRegexp,
28
29
  sourceToRegex: () => sourceToRegex
29
30
  });
30
31
  module.exports = __toCommonJS(superstatic_exports);
31
32
  var import_url = require("url");
32
- var import_path_to_regexp = require("@vercel-internals/path-to-regexp");
33
+ var import_path_to_regexp = require("path-to-regexp");
34
+ var import_path_to_regexp_updated = require("path-to-regexp-updated");
35
+ function cloneKeys(keys) {
36
+ if (typeof keys === "undefined") {
37
+ return void 0;
38
+ }
39
+ return keys.slice(0);
40
+ }
41
+ function compareKeys(left, right) {
42
+ const leftSerialized = typeof left === "undefined" ? "undefined" : left.toString();
43
+ const rightSerialized = typeof right === "undefined" ? "undefined" : right.toString();
44
+ return leftSerialized === rightSerialized;
45
+ }
46
+ function pathToRegexp(callerId, path, keys, options) {
47
+ const newKeys = cloneKeys(keys);
48
+ const currentRegExp = (0, import_path_to_regexp.pathToRegexp)(path, keys, options);
49
+ try {
50
+ const currentKeys = keys;
51
+ const newRegExp = (0, import_path_to_regexp_updated.pathToRegexp)(path, newKeys, options);
52
+ const isDiffRegExp = currentRegExp.toString() !== newRegExp.toString();
53
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffRegExp) {
54
+ const message = JSON.stringify({
55
+ path,
56
+ currentRegExp: currentRegExp.toString(),
57
+ newRegExp: newRegExp.toString()
58
+ });
59
+ console.error(`[vc] PATH TO REGEXP PATH DIFF @ #${callerId}: ${message}`);
60
+ }
61
+ const isDiffKeys = !compareKeys(keys, newKeys);
62
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffKeys) {
63
+ const message = JSON.stringify({
64
+ isDiffKeys,
65
+ currentKeys,
66
+ newKeys
67
+ });
68
+ console.error(`[vc] PATH TO REGEXP KEYS DIFF @ #${callerId}: ${message}`);
69
+ }
70
+ } catch (err) {
71
+ const error = err;
72
+ const message = JSON.stringify({
73
+ path,
74
+ error: error.message
75
+ });
76
+ console.error(`[vc] PATH TO REGEXP ERROR @ #${callerId}: ${message}`);
77
+ }
78
+ return currentRegExp;
79
+ }
33
80
  const UN_NAMED_SEGMENT = "__UN_NAMED_SEGMENT__";
34
81
  function getCleanUrls(filePaths) {
35
82
  const htmlFiles = filePaths.map(toRoute).filter((f) => f.endsWith(".html")).map((f) => ({
@@ -185,7 +232,7 @@ function convertTrailingSlash(enable, status = 308) {
185
232
  }
186
233
  function sourceToRegex(source) {
187
234
  const keys = [];
188
- const r = (0, import_path_to_regexp.pathToRegexp)("632", source, keys, {
235
+ const r = pathToRegexp("632", source, keys, {
189
236
  strict: true,
190
237
  sensitive: true,
191
238
  delimiter: "/"
@@ -258,9 +305,9 @@ function replaceSegments(segments, hasItemSegments, destination, isRedirect, int
258
305
  const hashKeys = [];
259
306
  const hostnameKeys = [];
260
307
  try {
261
- (0, import_path_to_regexp.pathToRegexp)("528", pathname, pathnameKeys);
262
- (0, import_path_to_regexp.pathToRegexp)("834", hash || "", hashKeys);
263
- (0, import_path_to_regexp.pathToRegexp)("712", hostname || "", hostnameKeys);
308
+ pathToRegexp("528", pathname, pathnameKeys);
309
+ pathToRegexp("834", hash || "", hashKeys);
310
+ pathToRegexp("712", hostname || "", hostnameKeys);
264
311
  } catch (_) {
265
312
  }
266
313
  destParams = new Set(
@@ -348,5 +395,6 @@ function toRoute(filePath) {
348
395
  convertRewrites,
349
396
  convertTrailingSlash,
350
397
  getCleanUrls,
398
+ pathToRegexp,
351
399
  sourceToRegex
352
400
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/routing-utils",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "Vercel routing utilities",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -13,11 +13,13 @@
13
13
  "directory": "packages/routing-utils"
14
14
  },
15
15
  "license": "Apache-2.0",
16
- "dependencies": {},
16
+ "dependencies": {
17
+ "path-to-regexp-updated": "npm:path-to-regexp@6.3.0",
18
+ "path-to-regexp": "6.1.0"
19
+ },
17
20
  "devDependencies": {
18
21
  "@types/jest": "27.4.1",
19
22
  "@types/node": "14.18.33",
20
- "@vercel-internals/path-to-regexp": "1.0.0",
21
23
  "ajv": "^6.12.3",
22
24
  "jest-junit": "16.0.0",
23
25
  "typescript": "4.9.5"