@vercel/routing-utils 5.0.2 → 5.0.4

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,17 +25,29 @@ __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
33
  var import_path_to_regexp = require("path-to-regexp");
33
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
+ }
34
46
  function pathToRegexp(callerId, path, keys, options) {
47
+ const newKeys = cloneKeys(keys);
35
48
  const currentRegExp = (0, import_path_to_regexp.pathToRegexp)(path, keys, options);
36
49
  try {
37
50
  const currentKeys = keys;
38
- const newKeys = [];
39
51
  const newRegExp = (0, import_path_to_regexp_updated.pathToRegexp)(path, newKeys, options);
40
52
  const isDiffRegExp = currentRegExp.toString() !== newRegExp.toString();
41
53
  if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffRegExp) {
@@ -46,7 +58,7 @@ function pathToRegexp(callerId, path, keys, options) {
46
58
  });
47
59
  console.error(`[vc] PATH TO REGEXP PATH DIFF @ #${callerId}: ${message}`);
48
60
  }
49
- const isDiffKeys = keys?.toString() !== newKeys?.toString();
61
+ const isDiffKeys = !compareKeys(keys, newKeys);
50
62
  if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffKeys) {
51
63
  const message = JSON.stringify({
52
64
  isDiffKeys,
@@ -57,7 +69,11 @@ function pathToRegexp(callerId, path, keys, options) {
57
69
  }
58
70
  } catch (err) {
59
71
  const error = err;
60
- console.error(`[vc] PATH TO REGEXP ERROR @ #${callerId}: ${error.message}`);
72
+ const message = JSON.stringify({
73
+ path,
74
+ error: error.message
75
+ });
76
+ console.error(`[vc] PATH TO REGEXP ERROR @ #${callerId}: ${message}`);
61
77
  }
62
78
  return currentRegExp;
63
79
  }
@@ -379,5 +395,6 @@ function toRoute(filePath) {
379
395
  convertRewrites,
380
396
  convertTrailingSlash,
381
397
  getCleanUrls,
398
+ pathToRegexp,
382
399
  sourceToRegex
383
400
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/routing-utils",
3
- "version": "5.0.2",
3
+ "version": "5.0.4",
4
4
  "description": "Vercel routing utilities",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",