@vercel/redwood 2.2.0 → 2.3.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.
Files changed (2) hide show
  1. package/dist/index.js +2094 -5
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
6
11
  var __export = (target, all) => {
7
12
  for (var name in all)
8
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,8 +20,2074 @@ var __copyProps = (to, from, except, desc) => {
15
20
  }
16
21
  return to;
17
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
18
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
32
 
33
+ // ../../node_modules/.pnpm/path-to-regexp@6.1.0/node_modules/path-to-regexp/dist/index.js
34
+ var require_dist = __commonJS({
35
+ "../../node_modules/.pnpm/path-to-regexp@6.1.0/node_modules/path-to-regexp/dist/index.js"(exports) {
36
+ "use strict";
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ function lexer(str) {
39
+ var tokens = [];
40
+ var i = 0;
41
+ while (i < str.length) {
42
+ var char = str[i];
43
+ if (char === "*" || char === "+" || char === "?") {
44
+ tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
45
+ continue;
46
+ }
47
+ if (char === "\\") {
48
+ tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
49
+ continue;
50
+ }
51
+ if (char === "{") {
52
+ tokens.push({ type: "OPEN", index: i, value: str[i++] });
53
+ continue;
54
+ }
55
+ if (char === "}") {
56
+ tokens.push({ type: "CLOSE", index: i, value: str[i++] });
57
+ continue;
58
+ }
59
+ if (char === ":") {
60
+ var name = "";
61
+ var j = i + 1;
62
+ while (j < str.length) {
63
+ var code = str.charCodeAt(j);
64
+ if (
65
+ // `0-9`
66
+ code >= 48 && code <= 57 || // `A-Z`
67
+ code >= 65 && code <= 90 || // `a-z`
68
+ code >= 97 && code <= 122 || // `_`
69
+ code === 95
70
+ ) {
71
+ name += str[j++];
72
+ continue;
73
+ }
74
+ break;
75
+ }
76
+ if (!name)
77
+ throw new TypeError("Missing parameter name at " + i);
78
+ tokens.push({ type: "NAME", index: i, value: name });
79
+ i = j;
80
+ continue;
81
+ }
82
+ if (char === "(") {
83
+ var count = 1;
84
+ var pattern = "";
85
+ var j = i + 1;
86
+ if (str[j] === "?") {
87
+ throw new TypeError('Pattern cannot start with "?" at ' + j);
88
+ }
89
+ while (j < str.length) {
90
+ if (str[j] === "\\") {
91
+ pattern += str[j++] + str[j++];
92
+ continue;
93
+ }
94
+ if (str[j] === ")") {
95
+ count--;
96
+ if (count === 0) {
97
+ j++;
98
+ break;
99
+ }
100
+ } else if (str[j] === "(") {
101
+ count++;
102
+ if (str[j + 1] !== "?") {
103
+ throw new TypeError("Capturing groups are not allowed at " + j);
104
+ }
105
+ }
106
+ pattern += str[j++];
107
+ }
108
+ if (count)
109
+ throw new TypeError("Unbalanced pattern at " + i);
110
+ if (!pattern)
111
+ throw new TypeError("Missing pattern at " + i);
112
+ tokens.push({ type: "PATTERN", index: i, value: pattern });
113
+ i = j;
114
+ continue;
115
+ }
116
+ tokens.push({ type: "CHAR", index: i, value: str[i++] });
117
+ }
118
+ tokens.push({ type: "END", index: i, value: "" });
119
+ return tokens;
120
+ }
121
+ function parse(str, options) {
122
+ if (options === void 0) {
123
+ options = {};
124
+ }
125
+ var tokens = lexer(str);
126
+ var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
127
+ var defaultPattern = "[^" + escapeString(options.delimiter || "/#?") + "]+?";
128
+ var result = [];
129
+ var key = 0;
130
+ var i = 0;
131
+ var path = "";
132
+ var tryConsume = function(type) {
133
+ if (i < tokens.length && tokens[i].type === type)
134
+ return tokens[i++].value;
135
+ };
136
+ var mustConsume = function(type) {
137
+ var value2 = tryConsume(type);
138
+ if (value2 !== void 0)
139
+ return value2;
140
+ var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
141
+ throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
142
+ };
143
+ var consumeText = function() {
144
+ var result2 = "";
145
+ var value2;
146
+ while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
147
+ result2 += value2;
148
+ }
149
+ return result2;
150
+ };
151
+ while (i < tokens.length) {
152
+ var char = tryConsume("CHAR");
153
+ var name = tryConsume("NAME");
154
+ var pattern = tryConsume("PATTERN");
155
+ if (name || pattern) {
156
+ var prefix = char || "";
157
+ if (prefixes.indexOf(prefix) === -1) {
158
+ path += prefix;
159
+ prefix = "";
160
+ }
161
+ if (path) {
162
+ result.push(path);
163
+ path = "";
164
+ }
165
+ result.push({
166
+ name: name || key++,
167
+ prefix,
168
+ suffix: "",
169
+ pattern: pattern || defaultPattern,
170
+ modifier: tryConsume("MODIFIER") || ""
171
+ });
172
+ continue;
173
+ }
174
+ var value = char || tryConsume("ESCAPED_CHAR");
175
+ if (value) {
176
+ path += value;
177
+ continue;
178
+ }
179
+ if (path) {
180
+ result.push(path);
181
+ path = "";
182
+ }
183
+ var open = tryConsume("OPEN");
184
+ if (open) {
185
+ var prefix = consumeText();
186
+ var name_1 = tryConsume("NAME") || "";
187
+ var pattern_1 = tryConsume("PATTERN") || "";
188
+ var suffix = consumeText();
189
+ mustConsume("CLOSE");
190
+ result.push({
191
+ name: name_1 || (pattern_1 ? key++ : ""),
192
+ pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
193
+ prefix,
194
+ suffix,
195
+ modifier: tryConsume("MODIFIER") || ""
196
+ });
197
+ continue;
198
+ }
199
+ mustConsume("END");
200
+ }
201
+ return result;
202
+ }
203
+ exports.parse = parse;
204
+ function compile(str, options) {
205
+ return tokensToFunction(parse(str, options), options);
206
+ }
207
+ exports.compile = compile;
208
+ function tokensToFunction(tokens, options) {
209
+ if (options === void 0) {
210
+ options = {};
211
+ }
212
+ var reFlags = flags(options);
213
+ var _a = options.encode, encode = _a === void 0 ? function(x) {
214
+ return x;
215
+ } : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
216
+ var matches = tokens.map(function(token) {
217
+ if (typeof token === "object") {
218
+ return new RegExp("^(?:" + token.pattern + ")$", reFlags);
219
+ }
220
+ });
221
+ return function(data) {
222
+ var path = "";
223
+ for (var i = 0; i < tokens.length; i++) {
224
+ var token = tokens[i];
225
+ if (typeof token === "string") {
226
+ path += token;
227
+ continue;
228
+ }
229
+ var value = data ? data[token.name] : void 0;
230
+ var optional = token.modifier === "?" || token.modifier === "*";
231
+ var repeat = token.modifier === "*" || token.modifier === "+";
232
+ if (Array.isArray(value)) {
233
+ if (!repeat) {
234
+ throw new TypeError('Expected "' + token.name + '" to not repeat, but got an array');
235
+ }
236
+ if (value.length === 0) {
237
+ if (optional)
238
+ continue;
239
+ throw new TypeError('Expected "' + token.name + '" to not be empty');
240
+ }
241
+ for (var j = 0; j < value.length; j++) {
242
+ var segment = encode(value[j], token);
243
+ if (validate && !matches[i].test(segment)) {
244
+ throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"');
245
+ }
246
+ path += token.prefix + segment + token.suffix;
247
+ }
248
+ continue;
249
+ }
250
+ if (typeof value === "string" || typeof value === "number") {
251
+ var segment = encode(String(value), token);
252
+ if (validate && !matches[i].test(segment)) {
253
+ throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"');
254
+ }
255
+ path += token.prefix + segment + token.suffix;
256
+ continue;
257
+ }
258
+ if (optional)
259
+ continue;
260
+ var typeOfMessage = repeat ? "an array" : "a string";
261
+ throw new TypeError('Expected "' + token.name + '" to be ' + typeOfMessage);
262
+ }
263
+ return path;
264
+ };
265
+ }
266
+ exports.tokensToFunction = tokensToFunction;
267
+ function match(str, options) {
268
+ var keys = [];
269
+ var re = pathToRegexp(str, keys, options);
270
+ return regexpToFunction(re, keys, options);
271
+ }
272
+ exports.match = match;
273
+ function regexpToFunction(re, keys, options) {
274
+ if (options === void 0) {
275
+ options = {};
276
+ }
277
+ var _a = options.decode, decode = _a === void 0 ? function(x) {
278
+ return x;
279
+ } : _a;
280
+ return function(pathname) {
281
+ var m = re.exec(pathname);
282
+ if (!m)
283
+ return false;
284
+ var path = m[0], index = m.index;
285
+ var params = /* @__PURE__ */ Object.create(null);
286
+ var _loop_1 = function(i2) {
287
+ if (m[i2] === void 0)
288
+ return "continue";
289
+ var key = keys[i2 - 1];
290
+ if (key.modifier === "*" || key.modifier === "+") {
291
+ params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
292
+ return decode(value, key);
293
+ });
294
+ } else {
295
+ params[key.name] = decode(m[i2], key);
296
+ }
297
+ };
298
+ for (var i = 1; i < m.length; i++) {
299
+ _loop_1(i);
300
+ }
301
+ return { path, index, params };
302
+ };
303
+ }
304
+ exports.regexpToFunction = regexpToFunction;
305
+ function escapeString(str) {
306
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
307
+ }
308
+ function flags(options) {
309
+ return options && options.sensitive ? "" : "i";
310
+ }
311
+ function regexpToRegexp(path, keys) {
312
+ if (!keys)
313
+ return path;
314
+ var groups = path.source.match(/\((?!\?)/g);
315
+ if (groups) {
316
+ for (var i = 0; i < groups.length; i++) {
317
+ keys.push({
318
+ name: i,
319
+ prefix: "",
320
+ suffix: "",
321
+ modifier: "",
322
+ pattern: ""
323
+ });
324
+ }
325
+ }
326
+ return path;
327
+ }
328
+ function arrayToRegexp(paths, keys, options) {
329
+ var parts = paths.map(function(path) {
330
+ return pathToRegexp(path, keys, options).source;
331
+ });
332
+ return new RegExp("(?:" + parts.join("|") + ")", flags(options));
333
+ }
334
+ function stringToRegexp(path, keys, options) {
335
+ return tokensToRegexp(parse(path, options), keys, options);
336
+ }
337
+ function tokensToRegexp(tokens, keys, options) {
338
+ if (options === void 0) {
339
+ options = {};
340
+ }
341
+ var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
342
+ return x;
343
+ } : _d;
344
+ var endsWith = "[" + escapeString(options.endsWith || "") + "]|$";
345
+ var delimiter = "[" + escapeString(options.delimiter || "/#?") + "]";
346
+ var route = start ? "^" : "";
347
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
348
+ var token = tokens_1[_i];
349
+ if (typeof token === "string") {
350
+ route += escapeString(encode(token));
351
+ } else {
352
+ var prefix = escapeString(encode(token.prefix));
353
+ var suffix = escapeString(encode(token.suffix));
354
+ if (token.pattern) {
355
+ if (keys)
356
+ keys.push(token);
357
+ if (prefix || suffix) {
358
+ if (token.modifier === "+" || token.modifier === "*") {
359
+ var mod = token.modifier === "*" ? "?" : "";
360
+ route += "(?:" + prefix + "((?:" + token.pattern + ")(?:" + suffix + prefix + "(?:" + token.pattern + "))*)" + suffix + ")" + mod;
361
+ } else {
362
+ route += "(?:" + prefix + "(" + token.pattern + ")" + suffix + ")" + token.modifier;
363
+ }
364
+ } else {
365
+ route += "(" + token.pattern + ")" + token.modifier;
366
+ }
367
+ } else {
368
+ route += "(?:" + prefix + suffix + ")" + token.modifier;
369
+ }
370
+ }
371
+ }
372
+ if (end) {
373
+ if (!strict)
374
+ route += delimiter + "?";
375
+ route += !options.endsWith ? "$" : "(?=" + endsWith + ")";
376
+ } else {
377
+ var endToken = tokens[tokens.length - 1];
378
+ var isEndDelimited = typeof endToken === "string" ? delimiter.indexOf(endToken[endToken.length - 1]) > -1 : (
379
+ // tslint:disable-next-line
380
+ endToken === void 0
381
+ );
382
+ if (!strict) {
383
+ route += "(?:" + delimiter + "(?=" + endsWith + "))?";
384
+ }
385
+ if (!isEndDelimited) {
386
+ route += "(?=" + delimiter + "|" + endsWith + ")";
387
+ }
388
+ }
389
+ return new RegExp(route, flags(options));
390
+ }
391
+ exports.tokensToRegexp = tokensToRegexp;
392
+ function pathToRegexp(path, keys, options) {
393
+ if (path instanceof RegExp)
394
+ return regexpToRegexp(path, keys);
395
+ if (Array.isArray(path))
396
+ return arrayToRegexp(path, keys, options);
397
+ return stringToRegexp(path, keys, options);
398
+ }
399
+ exports.pathToRegexp = pathToRegexp;
400
+ }
401
+ });
402
+
403
+ // ../../node_modules/.pnpm/path-to-regexp@6.3.0/node_modules/path-to-regexp/dist/index.js
404
+ var require_dist2 = __commonJS({
405
+ "../../node_modules/.pnpm/path-to-regexp@6.3.0/node_modules/path-to-regexp/dist/index.js"(exports) {
406
+ "use strict";
407
+ Object.defineProperty(exports, "__esModule", { value: true });
408
+ exports.pathToRegexp = exports.tokensToRegexp = exports.regexpToFunction = exports.match = exports.tokensToFunction = exports.compile = exports.parse = void 0;
409
+ function lexer(str) {
410
+ var tokens = [];
411
+ var i = 0;
412
+ while (i < str.length) {
413
+ var char = str[i];
414
+ if (char === "*" || char === "+" || char === "?") {
415
+ tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
416
+ continue;
417
+ }
418
+ if (char === "\\") {
419
+ tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
420
+ continue;
421
+ }
422
+ if (char === "{") {
423
+ tokens.push({ type: "OPEN", index: i, value: str[i++] });
424
+ continue;
425
+ }
426
+ if (char === "}") {
427
+ tokens.push({ type: "CLOSE", index: i, value: str[i++] });
428
+ continue;
429
+ }
430
+ if (char === ":") {
431
+ var name = "";
432
+ var j = i + 1;
433
+ while (j < str.length) {
434
+ var code = str.charCodeAt(j);
435
+ if (
436
+ // `0-9`
437
+ code >= 48 && code <= 57 || // `A-Z`
438
+ code >= 65 && code <= 90 || // `a-z`
439
+ code >= 97 && code <= 122 || // `_`
440
+ code === 95
441
+ ) {
442
+ name += str[j++];
443
+ continue;
444
+ }
445
+ break;
446
+ }
447
+ if (!name)
448
+ throw new TypeError("Missing parameter name at ".concat(i));
449
+ tokens.push({ type: "NAME", index: i, value: name });
450
+ i = j;
451
+ continue;
452
+ }
453
+ if (char === "(") {
454
+ var count = 1;
455
+ var pattern = "";
456
+ var j = i + 1;
457
+ if (str[j] === "?") {
458
+ throw new TypeError('Pattern cannot start with "?" at '.concat(j));
459
+ }
460
+ while (j < str.length) {
461
+ if (str[j] === "\\") {
462
+ pattern += str[j++] + str[j++];
463
+ continue;
464
+ }
465
+ if (str[j] === ")") {
466
+ count--;
467
+ if (count === 0) {
468
+ j++;
469
+ break;
470
+ }
471
+ } else if (str[j] === "(") {
472
+ count++;
473
+ if (str[j + 1] !== "?") {
474
+ throw new TypeError("Capturing groups are not allowed at ".concat(j));
475
+ }
476
+ }
477
+ pattern += str[j++];
478
+ }
479
+ if (count)
480
+ throw new TypeError("Unbalanced pattern at ".concat(i));
481
+ if (!pattern)
482
+ throw new TypeError("Missing pattern at ".concat(i));
483
+ tokens.push({ type: "PATTERN", index: i, value: pattern });
484
+ i = j;
485
+ continue;
486
+ }
487
+ tokens.push({ type: "CHAR", index: i, value: str[i++] });
488
+ }
489
+ tokens.push({ type: "END", index: i, value: "" });
490
+ return tokens;
491
+ }
492
+ function parse(str, options) {
493
+ if (options === void 0) {
494
+ options = {};
495
+ }
496
+ var tokens = lexer(str);
497
+ var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a, _b = options.delimiter, delimiter = _b === void 0 ? "/#?" : _b;
498
+ var result = [];
499
+ var key = 0;
500
+ var i = 0;
501
+ var path = "";
502
+ var tryConsume = function(type) {
503
+ if (i < tokens.length && tokens[i].type === type)
504
+ return tokens[i++].value;
505
+ };
506
+ var mustConsume = function(type) {
507
+ var value2 = tryConsume(type);
508
+ if (value2 !== void 0)
509
+ return value2;
510
+ var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
511
+ throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
512
+ };
513
+ var consumeText = function() {
514
+ var result2 = "";
515
+ var value2;
516
+ while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
517
+ result2 += value2;
518
+ }
519
+ return result2;
520
+ };
521
+ var isSafe = function(value2) {
522
+ for (var _i = 0, delimiter_1 = delimiter; _i < delimiter_1.length; _i++) {
523
+ var char2 = delimiter_1[_i];
524
+ if (value2.indexOf(char2) > -1)
525
+ return true;
526
+ }
527
+ return false;
528
+ };
529
+ var safePattern = function(prefix2) {
530
+ var prev = result[result.length - 1];
531
+ var prevText = prefix2 || (prev && typeof prev === "string" ? prev : "");
532
+ if (prev && !prevText) {
533
+ throw new TypeError('Must have text between two parameters, missing text after "'.concat(prev.name, '"'));
534
+ }
535
+ if (!prevText || isSafe(prevText))
536
+ return "[^".concat(escapeString(delimiter), "]+?");
537
+ return "(?:(?!".concat(escapeString(prevText), ")[^").concat(escapeString(delimiter), "])+?");
538
+ };
539
+ while (i < tokens.length) {
540
+ var char = tryConsume("CHAR");
541
+ var name = tryConsume("NAME");
542
+ var pattern = tryConsume("PATTERN");
543
+ if (name || pattern) {
544
+ var prefix = char || "";
545
+ if (prefixes.indexOf(prefix) === -1) {
546
+ path += prefix;
547
+ prefix = "";
548
+ }
549
+ if (path) {
550
+ result.push(path);
551
+ path = "";
552
+ }
553
+ result.push({
554
+ name: name || key++,
555
+ prefix,
556
+ suffix: "",
557
+ pattern: pattern || safePattern(prefix),
558
+ modifier: tryConsume("MODIFIER") || ""
559
+ });
560
+ continue;
561
+ }
562
+ var value = char || tryConsume("ESCAPED_CHAR");
563
+ if (value) {
564
+ path += value;
565
+ continue;
566
+ }
567
+ if (path) {
568
+ result.push(path);
569
+ path = "";
570
+ }
571
+ var open = tryConsume("OPEN");
572
+ if (open) {
573
+ var prefix = consumeText();
574
+ var name_1 = tryConsume("NAME") || "";
575
+ var pattern_1 = tryConsume("PATTERN") || "";
576
+ var suffix = consumeText();
577
+ mustConsume("CLOSE");
578
+ result.push({
579
+ name: name_1 || (pattern_1 ? key++ : ""),
580
+ pattern: name_1 && !pattern_1 ? safePattern(prefix) : pattern_1,
581
+ prefix,
582
+ suffix,
583
+ modifier: tryConsume("MODIFIER") || ""
584
+ });
585
+ continue;
586
+ }
587
+ mustConsume("END");
588
+ }
589
+ return result;
590
+ }
591
+ exports.parse = parse;
592
+ function compile(str, options) {
593
+ return tokensToFunction(parse(str, options), options);
594
+ }
595
+ exports.compile = compile;
596
+ function tokensToFunction(tokens, options) {
597
+ if (options === void 0) {
598
+ options = {};
599
+ }
600
+ var reFlags = flags(options);
601
+ var _a = options.encode, encode = _a === void 0 ? function(x) {
602
+ return x;
603
+ } : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
604
+ var matches = tokens.map(function(token) {
605
+ if (typeof token === "object") {
606
+ return new RegExp("^(?:".concat(token.pattern, ")$"), reFlags);
607
+ }
608
+ });
609
+ return function(data) {
610
+ var path = "";
611
+ for (var i = 0; i < tokens.length; i++) {
612
+ var token = tokens[i];
613
+ if (typeof token === "string") {
614
+ path += token;
615
+ continue;
616
+ }
617
+ var value = data ? data[token.name] : void 0;
618
+ var optional = token.modifier === "?" || token.modifier === "*";
619
+ var repeat = token.modifier === "*" || token.modifier === "+";
620
+ if (Array.isArray(value)) {
621
+ if (!repeat) {
622
+ throw new TypeError('Expected "'.concat(token.name, '" to not repeat, but got an array'));
623
+ }
624
+ if (value.length === 0) {
625
+ if (optional)
626
+ continue;
627
+ throw new TypeError('Expected "'.concat(token.name, '" to not be empty'));
628
+ }
629
+ for (var j = 0; j < value.length; j++) {
630
+ var segment = encode(value[j], token);
631
+ if (validate && !matches[i].test(segment)) {
632
+ throw new TypeError('Expected all "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
633
+ }
634
+ path += token.prefix + segment + token.suffix;
635
+ }
636
+ continue;
637
+ }
638
+ if (typeof value === "string" || typeof value === "number") {
639
+ var segment = encode(String(value), token);
640
+ if (validate && !matches[i].test(segment)) {
641
+ throw new TypeError('Expected "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
642
+ }
643
+ path += token.prefix + segment + token.suffix;
644
+ continue;
645
+ }
646
+ if (optional)
647
+ continue;
648
+ var typeOfMessage = repeat ? "an array" : "a string";
649
+ throw new TypeError('Expected "'.concat(token.name, '" to be ').concat(typeOfMessage));
650
+ }
651
+ return path;
652
+ };
653
+ }
654
+ exports.tokensToFunction = tokensToFunction;
655
+ function match(str, options) {
656
+ var keys = [];
657
+ var re = pathToRegexp(str, keys, options);
658
+ return regexpToFunction(re, keys, options);
659
+ }
660
+ exports.match = match;
661
+ function regexpToFunction(re, keys, options) {
662
+ if (options === void 0) {
663
+ options = {};
664
+ }
665
+ var _a = options.decode, decode = _a === void 0 ? function(x) {
666
+ return x;
667
+ } : _a;
668
+ return function(pathname) {
669
+ var m = re.exec(pathname);
670
+ if (!m)
671
+ return false;
672
+ var path = m[0], index = m.index;
673
+ var params = /* @__PURE__ */ Object.create(null);
674
+ var _loop_1 = function(i2) {
675
+ if (m[i2] === void 0)
676
+ return "continue";
677
+ var key = keys[i2 - 1];
678
+ if (key.modifier === "*" || key.modifier === "+") {
679
+ params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
680
+ return decode(value, key);
681
+ });
682
+ } else {
683
+ params[key.name] = decode(m[i2], key);
684
+ }
685
+ };
686
+ for (var i = 1; i < m.length; i++) {
687
+ _loop_1(i);
688
+ }
689
+ return { path, index, params };
690
+ };
691
+ }
692
+ exports.regexpToFunction = regexpToFunction;
693
+ function escapeString(str) {
694
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
695
+ }
696
+ function flags(options) {
697
+ return options && options.sensitive ? "" : "i";
698
+ }
699
+ function regexpToRegexp(path, keys) {
700
+ if (!keys)
701
+ return path;
702
+ var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
703
+ var index = 0;
704
+ var execResult = groupsRegex.exec(path.source);
705
+ while (execResult) {
706
+ keys.push({
707
+ // Use parenthesized substring match if available, index otherwise
708
+ name: execResult[1] || index++,
709
+ prefix: "",
710
+ suffix: "",
711
+ modifier: "",
712
+ pattern: ""
713
+ });
714
+ execResult = groupsRegex.exec(path.source);
715
+ }
716
+ return path;
717
+ }
718
+ function arrayToRegexp(paths, keys, options) {
719
+ var parts = paths.map(function(path) {
720
+ return pathToRegexp(path, keys, options).source;
721
+ });
722
+ return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
723
+ }
724
+ function stringToRegexp(path, keys, options) {
725
+ return tokensToRegexp(parse(path, options), keys, options);
726
+ }
727
+ function tokensToRegexp(tokens, keys, options) {
728
+ if (options === void 0) {
729
+ options = {};
730
+ }
731
+ var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
732
+ return x;
733
+ } : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
734
+ var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
735
+ var delimiterRe = "[".concat(escapeString(delimiter), "]");
736
+ var route = start ? "^" : "";
737
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
738
+ var token = tokens_1[_i];
739
+ if (typeof token === "string") {
740
+ route += escapeString(encode(token));
741
+ } else {
742
+ var prefix = escapeString(encode(token.prefix));
743
+ var suffix = escapeString(encode(token.suffix));
744
+ if (token.pattern) {
745
+ if (keys)
746
+ keys.push(token);
747
+ if (prefix || suffix) {
748
+ if (token.modifier === "+" || token.modifier === "*") {
749
+ var mod = token.modifier === "*" ? "?" : "";
750
+ route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
751
+ } else {
752
+ route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
753
+ }
754
+ } else {
755
+ if (token.modifier === "+" || token.modifier === "*") {
756
+ throw new TypeError('Can not repeat "'.concat(token.name, '" without a prefix and suffix'));
757
+ }
758
+ route += "(".concat(token.pattern, ")").concat(token.modifier);
759
+ }
760
+ } else {
761
+ route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
762
+ }
763
+ }
764
+ }
765
+ if (end) {
766
+ if (!strict)
767
+ route += "".concat(delimiterRe, "?");
768
+ route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
769
+ } else {
770
+ var endToken = tokens[tokens.length - 1];
771
+ var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
772
+ if (!strict) {
773
+ route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
774
+ }
775
+ if (!isEndDelimited) {
776
+ route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
777
+ }
778
+ }
779
+ return new RegExp(route, flags(options));
780
+ }
781
+ exports.tokensToRegexp = tokensToRegexp;
782
+ function pathToRegexp(path, keys, options) {
783
+ if (path instanceof RegExp)
784
+ return regexpToRegexp(path, keys);
785
+ if (Array.isArray(path))
786
+ return arrayToRegexp(path, keys, options);
787
+ return stringToRegexp(path, keys, options);
788
+ }
789
+ exports.pathToRegexp = pathToRegexp;
790
+ }
791
+ });
792
+
793
+ // ../routing-utils/dist/superstatic.js
794
+ var require_superstatic = __commonJS({
795
+ "../routing-utils/dist/superstatic.js"(exports, module2) {
796
+ "use strict";
797
+ var __defProp2 = Object.defineProperty;
798
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
799
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
800
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
801
+ var __export2 = (target, all) => {
802
+ for (var name in all)
803
+ __defProp2(target, name, { get: all[name], enumerable: true });
804
+ };
805
+ var __copyProps2 = (to, from, except, desc) => {
806
+ if (from && typeof from === "object" || typeof from === "function") {
807
+ for (let key of __getOwnPropNames2(from))
808
+ if (!__hasOwnProp2.call(to, key) && key !== except)
809
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
810
+ }
811
+ return to;
812
+ };
813
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
814
+ var superstatic_exports = {};
815
+ __export2(superstatic_exports, {
816
+ collectHasSegments: () => collectHasSegments,
817
+ convertCleanUrls: () => convertCleanUrls,
818
+ convertHeaders: () => convertHeaders,
819
+ convertRedirects: () => convertRedirects,
820
+ convertRewrites: () => convertRewrites,
821
+ convertTrailingSlash: () => convertTrailingSlash,
822
+ getCleanUrls: () => getCleanUrls2,
823
+ pathToRegexp: () => pathToRegexp,
824
+ sourceToRegex: () => sourceToRegex
825
+ });
826
+ module2.exports = __toCommonJS2(superstatic_exports);
827
+ var import_url = require("url");
828
+ var import_path_to_regexp = require_dist();
829
+ var import_path_to_regexp_updated = require_dist2();
830
+ function cloneKeys(keys) {
831
+ if (typeof keys === "undefined") {
832
+ return void 0;
833
+ }
834
+ return keys.slice(0);
835
+ }
836
+ function compareKeys(left, right) {
837
+ const leftSerialized = typeof left === "undefined" ? "undefined" : left.toString();
838
+ const rightSerialized = typeof right === "undefined" ? "undefined" : right.toString();
839
+ return leftSerialized === rightSerialized;
840
+ }
841
+ function pathToRegexp(callerId, path, keys, options) {
842
+ const newKeys = cloneKeys(keys);
843
+ const currentRegExp = (0, import_path_to_regexp.pathToRegexp)(path, keys, options);
844
+ try {
845
+ const currentKeys = keys;
846
+ const newRegExp = (0, import_path_to_regexp_updated.pathToRegexp)(path, newKeys, options);
847
+ const isDiffRegExp = currentRegExp.toString() !== newRegExp.toString();
848
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffRegExp) {
849
+ const message = JSON.stringify({
850
+ path,
851
+ currentRegExp: currentRegExp.toString(),
852
+ newRegExp: newRegExp.toString()
853
+ });
854
+ console.error(`[vc] PATH TO REGEXP PATH DIFF @ #${callerId}: ${message}`);
855
+ }
856
+ const isDiffKeys = !compareKeys(keys, newKeys);
857
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffKeys) {
858
+ const message = JSON.stringify({
859
+ isDiffKeys,
860
+ currentKeys,
861
+ newKeys
862
+ });
863
+ console.error(`[vc] PATH TO REGEXP KEYS DIFF @ #${callerId}: ${message}`);
864
+ }
865
+ } catch (err) {
866
+ const error = err;
867
+ const message = JSON.stringify({
868
+ path,
869
+ error: error.message
870
+ });
871
+ console.error(`[vc] PATH TO REGEXP ERROR @ #${callerId}: ${message}`);
872
+ }
873
+ return currentRegExp;
874
+ }
875
+ var UN_NAMED_SEGMENT = "__UN_NAMED_SEGMENT__";
876
+ function getCleanUrls2(filePaths) {
877
+ const htmlFiles = filePaths.map(toRoute).filter((f) => f.endsWith(".html")).map((f) => ({
878
+ html: f,
879
+ clean: f.slice(0, -5)
880
+ }));
881
+ return htmlFiles;
882
+ }
883
+ function convertCleanUrls(cleanUrls, trailingSlash, status = 308) {
884
+ const routes = [];
885
+ if (cleanUrls) {
886
+ const loc = trailingSlash ? "/$1/" : "/$1";
887
+ routes.push({
888
+ src: "^/(?:(.+)/)?index(?:\\.html)?/?$",
889
+ headers: { Location: loc },
890
+ status
891
+ });
892
+ routes.push({
893
+ src: "^/(.*)\\.html/?$",
894
+ headers: { Location: loc },
895
+ status
896
+ });
897
+ }
898
+ return routes;
899
+ }
900
+ function convertRedirects(redirects, defaultStatus = 308) {
901
+ return redirects.map((r) => {
902
+ const { src, segments } = sourceToRegex(r.source);
903
+ const hasSegments = collectHasSegments(r.has);
904
+ normalizeHasKeys(r.has);
905
+ normalizeHasKeys(r.missing);
906
+ try {
907
+ const loc = replaceSegments(segments, hasSegments, r.destination, true);
908
+ let status;
909
+ if (typeof r.permanent === "boolean") {
910
+ status = r.permanent ? 308 : 307;
911
+ } else if (r.statusCode) {
912
+ status = r.statusCode;
913
+ } else {
914
+ status = defaultStatus;
915
+ }
916
+ const route = {
917
+ src,
918
+ headers: { Location: loc },
919
+ status
920
+ };
921
+ if (r.has) {
922
+ route.has = r.has;
923
+ }
924
+ if (r.missing) {
925
+ route.missing = r.missing;
926
+ }
927
+ return route;
928
+ } catch (e) {
929
+ throw new Error(`Failed to parse redirect: ${JSON.stringify(r)}`);
930
+ }
931
+ });
932
+ }
933
+ function convertRewrites(rewrites, internalParamNames) {
934
+ return rewrites.map((r) => {
935
+ const { src, segments } = sourceToRegex(r.source);
936
+ const hasSegments = collectHasSegments(r.has);
937
+ normalizeHasKeys(r.has);
938
+ normalizeHasKeys(r.missing);
939
+ try {
940
+ const dest = replaceSegments(
941
+ segments,
942
+ hasSegments,
943
+ r.destination,
944
+ false,
945
+ internalParamNames
946
+ );
947
+ const route = { src, dest, check: true };
948
+ if (r.has) {
949
+ route.has = r.has;
950
+ }
951
+ if (r.missing) {
952
+ route.missing = r.missing;
953
+ }
954
+ if (r.statusCode) {
955
+ route.status = r.statusCode;
956
+ }
957
+ return route;
958
+ } catch (e) {
959
+ throw new Error(`Failed to parse rewrite: ${JSON.stringify(r)}`);
960
+ }
961
+ });
962
+ }
963
+ function convertHeaders(headers) {
964
+ return headers.map((h) => {
965
+ const obj = {};
966
+ const { src, segments } = sourceToRegex(h.source);
967
+ const hasSegments = collectHasSegments(h.has);
968
+ normalizeHasKeys(h.has);
969
+ normalizeHasKeys(h.missing);
970
+ const namedSegments = segments.filter((name) => name !== UN_NAMED_SEGMENT);
971
+ const indexes = {};
972
+ segments.forEach((name, index) => {
973
+ indexes[name] = toSegmentDest(index);
974
+ });
975
+ hasSegments.forEach((name) => {
976
+ indexes[name] = "$" + name;
977
+ });
978
+ h.headers.forEach(({ key, value }) => {
979
+ if (namedSegments.length > 0 || hasSegments.length > 0) {
980
+ if (key.includes(":")) {
981
+ key = safelyCompile(key, indexes);
982
+ }
983
+ if (value.includes(":")) {
984
+ value = safelyCompile(value, indexes);
985
+ }
986
+ }
987
+ obj[key] = value;
988
+ });
989
+ const route = {
990
+ src,
991
+ headers: obj,
992
+ continue: true
993
+ };
994
+ if (h.has) {
995
+ route.has = h.has;
996
+ }
997
+ if (h.missing) {
998
+ route.missing = h.missing;
999
+ }
1000
+ return route;
1001
+ });
1002
+ }
1003
+ function convertTrailingSlash(enable, status = 308) {
1004
+ const routes = [];
1005
+ if (enable) {
1006
+ routes.push({
1007
+ src: "^/\\.well-known(?:/.*)?$"
1008
+ });
1009
+ routes.push({
1010
+ src: "^/((?:[^/]+/)*[^/\\.]+)$",
1011
+ headers: { Location: "/$1/" },
1012
+ status
1013
+ });
1014
+ routes.push({
1015
+ src: "^/((?:[^/]+/)*[^/]+\\.\\w+)/$",
1016
+ headers: { Location: "/$1" },
1017
+ status
1018
+ });
1019
+ } else {
1020
+ routes.push({
1021
+ src: "^/(.*)\\/$",
1022
+ headers: { Location: "/$1" },
1023
+ status
1024
+ });
1025
+ }
1026
+ return routes;
1027
+ }
1028
+ function sourceToRegex(source) {
1029
+ const keys = [];
1030
+ const r = pathToRegexp("632", source, keys, {
1031
+ strict: true,
1032
+ sensitive: true,
1033
+ delimiter: "/"
1034
+ });
1035
+ const segments = keys.map((k) => k.name).map((name) => {
1036
+ if (typeof name !== "string") {
1037
+ return UN_NAMED_SEGMENT;
1038
+ }
1039
+ return name;
1040
+ });
1041
+ return { src: r.source, segments };
1042
+ }
1043
+ var namedGroupsRegex = /\(\?<([a-zA-Z][a-zA-Z0-9]*)>/g;
1044
+ var normalizeHasKeys = (hasItems = []) => {
1045
+ for (const hasItem of hasItems) {
1046
+ if ("key" in hasItem && hasItem.type === "header") {
1047
+ hasItem.key = hasItem.key.toLowerCase();
1048
+ }
1049
+ }
1050
+ return hasItems;
1051
+ };
1052
+ function collectHasSegments(has) {
1053
+ const hasSegments = /* @__PURE__ */ new Set();
1054
+ for (const hasItem of has || []) {
1055
+ if (!hasItem.value && "key" in hasItem) {
1056
+ hasSegments.add(hasItem.key);
1057
+ }
1058
+ if (hasItem.value) {
1059
+ for (const match of hasItem.value.matchAll(namedGroupsRegex)) {
1060
+ if (match[1]) {
1061
+ hasSegments.add(match[1]);
1062
+ }
1063
+ }
1064
+ if (hasItem.type === "host") {
1065
+ hasSegments.add("host");
1066
+ }
1067
+ }
1068
+ }
1069
+ return [...hasSegments];
1070
+ }
1071
+ var escapeSegment = (str, segmentName) => str.replace(new RegExp(`:${segmentName}`, "g"), `__ESC_COLON_${segmentName}`);
1072
+ var unescapeSegments = (str) => str.replace(/__ESC_COLON_/gi, ":");
1073
+ function replaceSegments(segments, hasItemSegments, destination, isRedirect, internalParamNames) {
1074
+ const namedSegments = segments.filter((name) => name !== UN_NAMED_SEGMENT);
1075
+ const canNeedReplacing = destination.includes(":") && namedSegments.length > 0 || hasItemSegments.length > 0 || !isRedirect;
1076
+ if (!canNeedReplacing) {
1077
+ return destination;
1078
+ }
1079
+ let escapedDestination = destination;
1080
+ const indexes = {};
1081
+ segments.forEach((name, index) => {
1082
+ indexes[name] = toSegmentDest(index);
1083
+ escapedDestination = escapeSegment(escapedDestination, name);
1084
+ });
1085
+ hasItemSegments.forEach((name) => {
1086
+ indexes[name] = "$" + name;
1087
+ escapedDestination = escapeSegment(escapedDestination, name);
1088
+ });
1089
+ const parsedDestination = (0, import_url.parse)(escapedDestination, true);
1090
+ delete parsedDestination.href;
1091
+ delete parsedDestination.path;
1092
+ delete parsedDestination.search;
1093
+ delete parsedDestination.host;
1094
+ let { pathname, hash, query, hostname, ...rest } = parsedDestination;
1095
+ pathname = unescapeSegments(pathname || "");
1096
+ hash = unescapeSegments(hash || "");
1097
+ hostname = unescapeSegments(hostname || "");
1098
+ let destParams = /* @__PURE__ */ new Set();
1099
+ const pathnameKeys = [];
1100
+ const hashKeys = [];
1101
+ const hostnameKeys = [];
1102
+ try {
1103
+ pathToRegexp("528", pathname, pathnameKeys);
1104
+ pathToRegexp("834", hash || "", hashKeys);
1105
+ pathToRegexp("712", hostname || "", hostnameKeys);
1106
+ } catch (_) {
1107
+ }
1108
+ destParams = new Set(
1109
+ [...pathnameKeys, ...hashKeys, ...hostnameKeys].map((key) => key.name).filter((val) => typeof val === "string")
1110
+ );
1111
+ pathname = safelyCompile(pathname, indexes, true);
1112
+ hash = hash ? safelyCompile(hash, indexes, true) : null;
1113
+ hostname = hostname ? safelyCompile(hostname, indexes, true) : null;
1114
+ for (const [key, strOrArray] of Object.entries(query)) {
1115
+ if (Array.isArray(strOrArray)) {
1116
+ query[key] = strOrArray.map(
1117
+ (str) => safelyCompile(unescapeSegments(str), indexes, true)
1118
+ );
1119
+ } else {
1120
+ query[key] = safelyCompile(
1121
+ unescapeSegments(strOrArray),
1122
+ indexes,
1123
+ true
1124
+ );
1125
+ }
1126
+ }
1127
+ const paramKeys = Object.keys(indexes);
1128
+ const needsQueryUpdating = (
1129
+ // we do not consider an internal param since it is added automatically
1130
+ !isRedirect && !paramKeys.some(
1131
+ (param) => !(internalParamNames && internalParamNames.includes(param)) && destParams.has(param)
1132
+ )
1133
+ );
1134
+ if (needsQueryUpdating) {
1135
+ for (const param of paramKeys) {
1136
+ if (!(param in query) && param !== UN_NAMED_SEGMENT) {
1137
+ query[param] = indexes[param];
1138
+ }
1139
+ }
1140
+ }
1141
+ destination = (0, import_url.format)({
1142
+ ...rest,
1143
+ hostname,
1144
+ pathname,
1145
+ query,
1146
+ hash
1147
+ });
1148
+ return destination.replace(/%24/g, "$");
1149
+ }
1150
+ function safelyCompile(value, indexes, attemptDirectCompile) {
1151
+ if (!value) {
1152
+ return value;
1153
+ }
1154
+ if (attemptDirectCompile) {
1155
+ try {
1156
+ return (0, import_path_to_regexp.compile)(value, { validate: false })(indexes);
1157
+ } catch (e) {
1158
+ }
1159
+ }
1160
+ for (const key of Object.keys(indexes)) {
1161
+ if (value.includes(`:${key}`)) {
1162
+ value = value.replace(
1163
+ new RegExp(`:${key}\\*`, "g"),
1164
+ `:${key}--ESCAPED_PARAM_ASTERISK`
1165
+ ).replace(
1166
+ new RegExp(`:${key}\\?`, "g"),
1167
+ `:${key}--ESCAPED_PARAM_QUESTION`
1168
+ ).replace(new RegExp(`:${key}\\+`, "g"), `:${key}--ESCAPED_PARAM_PLUS`).replace(
1169
+ new RegExp(`:${key}(?!\\w)`, "g"),
1170
+ `--ESCAPED_PARAM_COLON${key}`
1171
+ );
1172
+ }
1173
+ }
1174
+ value = value.replace(/(:|\*|\?|\+|\(|\)|\{|\})/g, "\\$1").replace(/--ESCAPED_PARAM_PLUS/g, "+").replace(/--ESCAPED_PARAM_COLON/g, ":").replace(/--ESCAPED_PARAM_QUESTION/g, "?").replace(/--ESCAPED_PARAM_ASTERISK/g, "*");
1175
+ return (0, import_path_to_regexp.compile)(`/${value}`, { validate: false })(indexes).slice(1);
1176
+ }
1177
+ function toSegmentDest(index) {
1178
+ const i = index + 1;
1179
+ return "$" + i.toString();
1180
+ }
1181
+ function toRoute(filePath) {
1182
+ return filePath.startsWith("/") ? filePath : "/" + filePath;
1183
+ }
1184
+ }
1185
+ });
1186
+
1187
+ // ../routing-utils/dist/append.js
1188
+ var require_append = __commonJS({
1189
+ "../routing-utils/dist/append.js"(exports, module2) {
1190
+ "use strict";
1191
+ var __defProp2 = Object.defineProperty;
1192
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
1193
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
1194
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
1195
+ var __export2 = (target, all) => {
1196
+ for (var name in all)
1197
+ __defProp2(target, name, { get: all[name], enumerable: true });
1198
+ };
1199
+ var __copyProps2 = (to, from, except, desc) => {
1200
+ if (from && typeof from === "object" || typeof from === "function") {
1201
+ for (let key of __getOwnPropNames2(from))
1202
+ if (!__hasOwnProp2.call(to, key) && key !== except)
1203
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
1204
+ }
1205
+ return to;
1206
+ };
1207
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1208
+ var append_exports = {};
1209
+ __export2(append_exports, {
1210
+ appendRoutesToPhase: () => appendRoutesToPhase2
1211
+ });
1212
+ module2.exports = __toCommonJS2(append_exports);
1213
+ var import_index = require_dist3();
1214
+ function appendRoutesToPhase2({
1215
+ routes: prevRoutes,
1216
+ newRoutes,
1217
+ phase
1218
+ }) {
1219
+ const routes = prevRoutes ? [...prevRoutes] : [];
1220
+ if (newRoutes === null || newRoutes.length === 0) {
1221
+ return routes;
1222
+ }
1223
+ let isInPhase = false;
1224
+ let insertIndex = -1;
1225
+ routes.forEach((r, i) => {
1226
+ if ((0, import_index.isHandler)(r)) {
1227
+ if (r.handle === phase) {
1228
+ isInPhase = true;
1229
+ } else if (isInPhase) {
1230
+ insertIndex = i;
1231
+ isInPhase = false;
1232
+ }
1233
+ }
1234
+ });
1235
+ if (isInPhase) {
1236
+ routes.push(...newRoutes);
1237
+ } else if (phase === null) {
1238
+ const lastPhase = routes.findIndex((r) => (0, import_index.isHandler)(r) && r.handle);
1239
+ if (lastPhase === -1) {
1240
+ routes.push(...newRoutes);
1241
+ } else {
1242
+ routes.splice(lastPhase, 0, ...newRoutes);
1243
+ }
1244
+ } else if (insertIndex > -1) {
1245
+ routes.splice(insertIndex, 0, ...newRoutes);
1246
+ } else {
1247
+ routes.push({ handle: phase });
1248
+ routes.push(...newRoutes);
1249
+ }
1250
+ return routes;
1251
+ }
1252
+ }
1253
+ });
1254
+
1255
+ // ../routing-utils/dist/merge.js
1256
+ var require_merge = __commonJS({
1257
+ "../routing-utils/dist/merge.js"(exports, module2) {
1258
+ "use strict";
1259
+ var __defProp2 = Object.defineProperty;
1260
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
1261
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
1262
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
1263
+ var __export2 = (target, all) => {
1264
+ for (var name in all)
1265
+ __defProp2(target, name, { get: all[name], enumerable: true });
1266
+ };
1267
+ var __copyProps2 = (to, from, except, desc) => {
1268
+ if (from && typeof from === "object" || typeof from === "function") {
1269
+ for (let key of __getOwnPropNames2(from))
1270
+ if (!__hasOwnProp2.call(to, key) && key !== except)
1271
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
1272
+ }
1273
+ return to;
1274
+ };
1275
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1276
+ var merge_exports = {};
1277
+ __export2(merge_exports, {
1278
+ mergeRoutes: () => mergeRoutes2
1279
+ });
1280
+ module2.exports = __toCommonJS2(merge_exports);
1281
+ var import_index = require_dist3();
1282
+ function getBuilderRoutesMapping(builds) {
1283
+ const builderRoutes = {};
1284
+ for (const { entrypoint, routes, use } of builds) {
1285
+ if (routes) {
1286
+ if (!builderRoutes[entrypoint]) {
1287
+ builderRoutes[entrypoint] = {};
1288
+ }
1289
+ builderRoutes[entrypoint][use] = routes;
1290
+ }
1291
+ }
1292
+ return builderRoutes;
1293
+ }
1294
+ function getCheckAndContinue(routes) {
1295
+ const checks = [];
1296
+ const continues = [];
1297
+ const others = [];
1298
+ for (const route of routes) {
1299
+ if ((0, import_index.isHandler)(route)) {
1300
+ throw new Error(
1301
+ `Unexpected route found in getCheckAndContinue(): ${JSON.stringify(
1302
+ route
1303
+ )}`
1304
+ );
1305
+ } else if (route.check && !route.override) {
1306
+ checks.push(route);
1307
+ } else if (route.continue && !route.override) {
1308
+ continues.push(route);
1309
+ } else {
1310
+ others.push(route);
1311
+ }
1312
+ }
1313
+ return { checks, continues, others };
1314
+ }
1315
+ function mergeRoutes2({ userRoutes, builds }) {
1316
+ const userHandleMap = /* @__PURE__ */ new Map();
1317
+ let userPrevHandle = null;
1318
+ (userRoutes || []).forEach((route) => {
1319
+ if ((0, import_index.isHandler)(route)) {
1320
+ userPrevHandle = route.handle;
1321
+ } else {
1322
+ const routes = userHandleMap.get(userPrevHandle);
1323
+ if (!routes) {
1324
+ userHandleMap.set(userPrevHandle, [route]);
1325
+ } else {
1326
+ routes.push(route);
1327
+ }
1328
+ }
1329
+ });
1330
+ const builderHandleMap = /* @__PURE__ */ new Map();
1331
+ const builderRoutes = getBuilderRoutesMapping(builds);
1332
+ const sortedPaths = Object.keys(builderRoutes).sort();
1333
+ sortedPaths.forEach((path) => {
1334
+ const br = builderRoutes[path];
1335
+ const sortedBuilders = Object.keys(br).sort();
1336
+ sortedBuilders.forEach((use) => {
1337
+ let builderPrevHandle = null;
1338
+ br[use].forEach((route) => {
1339
+ if ((0, import_index.isHandler)(route)) {
1340
+ builderPrevHandle = route.handle;
1341
+ } else {
1342
+ const routes = builderHandleMap.get(builderPrevHandle);
1343
+ if (!routes) {
1344
+ builderHandleMap.set(builderPrevHandle, [route]);
1345
+ } else {
1346
+ routes.push(route);
1347
+ }
1348
+ }
1349
+ });
1350
+ });
1351
+ });
1352
+ const outputRoutes = [];
1353
+ const uniqueHandleValues = /* @__PURE__ */ new Set([
1354
+ null,
1355
+ ...userHandleMap.keys(),
1356
+ ...builderHandleMap.keys()
1357
+ ]);
1358
+ for (const handle of uniqueHandleValues) {
1359
+ const userRoutes2 = userHandleMap.get(handle) || [];
1360
+ const builderRoutes2 = builderHandleMap.get(handle) || [];
1361
+ const builderSorted = getCheckAndContinue(builderRoutes2);
1362
+ if (handle !== null && (userRoutes2.length > 0 || builderRoutes2.length > 0)) {
1363
+ outputRoutes.push({ handle });
1364
+ }
1365
+ outputRoutes.push(...builderSorted.continues);
1366
+ outputRoutes.push(...userRoutes2);
1367
+ outputRoutes.push(...builderSorted.checks);
1368
+ outputRoutes.push(...builderSorted.others);
1369
+ }
1370
+ return outputRoutes;
1371
+ }
1372
+ }
1373
+ });
1374
+
1375
+ // ../routing-utils/dist/schemas.js
1376
+ var require_schemas = __commonJS({
1377
+ "../routing-utils/dist/schemas.js"(exports, module2) {
1378
+ "use strict";
1379
+ var __defProp2 = Object.defineProperty;
1380
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
1381
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
1382
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
1383
+ var __export2 = (target, all) => {
1384
+ for (var name in all)
1385
+ __defProp2(target, name, { get: all[name], enumerable: true });
1386
+ };
1387
+ var __copyProps2 = (to, from, except, desc) => {
1388
+ if (from && typeof from === "object" || typeof from === "function") {
1389
+ for (let key of __getOwnPropNames2(from))
1390
+ if (!__hasOwnProp2.call(to, key) && key !== except)
1391
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
1392
+ }
1393
+ return to;
1394
+ };
1395
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1396
+ var schemas_exports = {};
1397
+ __export2(schemas_exports, {
1398
+ cleanUrlsSchema: () => cleanUrlsSchema,
1399
+ hasSchema: () => hasSchema,
1400
+ headersSchema: () => headersSchema,
1401
+ redirectsSchema: () => redirectsSchema,
1402
+ rewritesSchema: () => rewritesSchema,
1403
+ routesSchema: () => routesSchema,
1404
+ trailingSlashSchema: () => trailingSlashSchema
1405
+ });
1406
+ module2.exports = __toCommonJS2(schemas_exports);
1407
+ var hasSchema = {
1408
+ description: "An array of requirements that are needed to match",
1409
+ type: "array",
1410
+ maxItems: 16,
1411
+ items: {
1412
+ anyOf: [
1413
+ {
1414
+ type: "object",
1415
+ additionalProperties: false,
1416
+ required: ["type", "value"],
1417
+ properties: {
1418
+ type: {
1419
+ description: "The type of request element to check",
1420
+ type: "string",
1421
+ enum: ["host"]
1422
+ },
1423
+ value: {
1424
+ description: "A regular expression used to match the value. Named groups can be used in the destination",
1425
+ type: "string",
1426
+ maxLength: 4096
1427
+ }
1428
+ }
1429
+ },
1430
+ {
1431
+ type: "object",
1432
+ additionalProperties: false,
1433
+ required: ["type", "key"],
1434
+ properties: {
1435
+ type: {
1436
+ description: "The type of request element to check",
1437
+ type: "string",
1438
+ enum: ["header", "cookie", "query"]
1439
+ },
1440
+ key: {
1441
+ description: "The name of the element contained in the particular type",
1442
+ type: "string",
1443
+ maxLength: 4096
1444
+ },
1445
+ value: {
1446
+ description: "A regular expression used to match the value. Named groups can be used in the destination",
1447
+ type: "string",
1448
+ maxLength: 4096
1449
+ }
1450
+ }
1451
+ }
1452
+ ]
1453
+ }
1454
+ };
1455
+ var routesSchema = {
1456
+ type: "array",
1457
+ maxItems: 2048,
1458
+ deprecated: true,
1459
+ description: "A list of routes objects used to rewrite paths to point towards other internal or external paths",
1460
+ example: [{ dest: "https://docs.example.com", src: "/docs" }],
1461
+ items: {
1462
+ anyOf: [
1463
+ {
1464
+ type: "object",
1465
+ required: ["src"],
1466
+ additionalProperties: false,
1467
+ properties: {
1468
+ src: {
1469
+ type: "string",
1470
+ maxLength: 4096
1471
+ },
1472
+ dest: {
1473
+ type: "string",
1474
+ maxLength: 4096
1475
+ },
1476
+ headers: {
1477
+ type: "object",
1478
+ additionalProperties: false,
1479
+ minProperties: 1,
1480
+ maxProperties: 100,
1481
+ patternProperties: {
1482
+ "^.{1,256}$": {
1483
+ type: "string",
1484
+ maxLength: 4096
1485
+ }
1486
+ }
1487
+ },
1488
+ methods: {
1489
+ type: "array",
1490
+ maxItems: 10,
1491
+ items: {
1492
+ type: "string",
1493
+ maxLength: 32
1494
+ }
1495
+ },
1496
+ caseSensitive: {
1497
+ type: "boolean"
1498
+ },
1499
+ important: {
1500
+ type: "boolean"
1501
+ },
1502
+ user: {
1503
+ type: "boolean"
1504
+ },
1505
+ continue: {
1506
+ type: "boolean"
1507
+ },
1508
+ override: {
1509
+ type: "boolean"
1510
+ },
1511
+ check: {
1512
+ type: "boolean"
1513
+ },
1514
+ isInternal: {
1515
+ type: "boolean"
1516
+ },
1517
+ status: {
1518
+ type: "integer",
1519
+ minimum: 100,
1520
+ maximum: 999
1521
+ },
1522
+ locale: {
1523
+ type: "object",
1524
+ additionalProperties: false,
1525
+ minProperties: 1,
1526
+ properties: {
1527
+ redirect: {
1528
+ type: "object",
1529
+ additionalProperties: false,
1530
+ minProperties: 1,
1531
+ maxProperties: 100,
1532
+ patternProperties: {
1533
+ "^.{1,256}$": {
1534
+ type: "string",
1535
+ maxLength: 4096
1536
+ }
1537
+ }
1538
+ },
1539
+ value: {
1540
+ type: "string",
1541
+ maxLength: 4096
1542
+ },
1543
+ path: {
1544
+ type: "string",
1545
+ maxLength: 4096
1546
+ },
1547
+ cookie: {
1548
+ type: "string",
1549
+ maxLength: 4096
1550
+ },
1551
+ default: {
1552
+ type: "string",
1553
+ maxLength: 4096
1554
+ }
1555
+ }
1556
+ },
1557
+ middleware: { type: "number" },
1558
+ middlewarePath: { type: "string" },
1559
+ middlewareRawSrc: {
1560
+ type: "array",
1561
+ items: {
1562
+ type: "string"
1563
+ }
1564
+ },
1565
+ has: hasSchema,
1566
+ missing: hasSchema
1567
+ }
1568
+ },
1569
+ {
1570
+ type: "object",
1571
+ required: ["handle"],
1572
+ additionalProperties: false,
1573
+ properties: {
1574
+ handle: {
1575
+ type: "string",
1576
+ maxLength: 32,
1577
+ enum: ["error", "filesystem", "hit", "miss", "resource", "rewrite"]
1578
+ }
1579
+ }
1580
+ }
1581
+ ]
1582
+ }
1583
+ };
1584
+ var rewritesSchema = {
1585
+ type: "array",
1586
+ maxItems: 2048,
1587
+ description: "A list of rewrite definitions.",
1588
+ items: {
1589
+ type: "object",
1590
+ additionalProperties: false,
1591
+ required: ["source", "destination"],
1592
+ properties: {
1593
+ source: {
1594
+ description: "A pattern that matches each incoming pathname (excluding querystring).",
1595
+ type: "string",
1596
+ maxLength: 4096
1597
+ },
1598
+ destination: {
1599
+ description: "An absolute pathname to an existing resource or an external URL.",
1600
+ type: "string",
1601
+ maxLength: 4096
1602
+ },
1603
+ has: hasSchema,
1604
+ missing: hasSchema,
1605
+ statusCode: {
1606
+ description: "An optional integer to override the status code of the response.",
1607
+ type: "integer",
1608
+ minimum: 100,
1609
+ maximum: 999
1610
+ }
1611
+ }
1612
+ }
1613
+ };
1614
+ var redirectsSchema = {
1615
+ title: "Redirects",
1616
+ type: "array",
1617
+ maxItems: 2048,
1618
+ description: "A list of redirect definitions.",
1619
+ items: {
1620
+ type: "object",
1621
+ additionalProperties: false,
1622
+ required: ["source", "destination"],
1623
+ properties: {
1624
+ source: {
1625
+ description: "A pattern that matches each incoming pathname (excluding querystring).",
1626
+ type: "string",
1627
+ maxLength: 4096
1628
+ },
1629
+ destination: {
1630
+ description: "A location destination defined as an absolute pathname or external URL.",
1631
+ type: "string",
1632
+ maxLength: 4096
1633
+ },
1634
+ permanent: {
1635
+ description: "A boolean to toggle between permanent and temporary redirect. When `true`, the status code is `308`. When `false` the status code is `307`.",
1636
+ type: "boolean"
1637
+ },
1638
+ statusCode: {
1639
+ description: "An optional integer to define the status code of the redirect.",
1640
+ private: true,
1641
+ type: "integer",
1642
+ minimum: 100,
1643
+ maximum: 999
1644
+ },
1645
+ has: hasSchema,
1646
+ missing: hasSchema
1647
+ }
1648
+ }
1649
+ };
1650
+ var headersSchema = {
1651
+ type: "array",
1652
+ maxItems: 2048,
1653
+ description: "A list of header definitions.",
1654
+ items: {
1655
+ type: "object",
1656
+ additionalProperties: false,
1657
+ required: ["source", "headers"],
1658
+ properties: {
1659
+ source: {
1660
+ description: "A pattern that matches each incoming pathname (excluding querystring)",
1661
+ type: "string",
1662
+ maxLength: 4096
1663
+ },
1664
+ headers: {
1665
+ description: "An array of key/value pairs representing each response header.",
1666
+ type: "array",
1667
+ maxItems: 1024,
1668
+ items: {
1669
+ type: "object",
1670
+ additionalProperties: false,
1671
+ required: ["key", "value"],
1672
+ properties: {
1673
+ key: {
1674
+ type: "string",
1675
+ maxLength: 4096
1676
+ },
1677
+ value: {
1678
+ type: "string",
1679
+ maxLength: 4096
1680
+ }
1681
+ }
1682
+ }
1683
+ },
1684
+ has: hasSchema,
1685
+ missing: hasSchema
1686
+ }
1687
+ }
1688
+ };
1689
+ var cleanUrlsSchema = {
1690
+ description: "When set to `true`, all HTML files and Serverless Functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.",
1691
+ type: "boolean"
1692
+ };
1693
+ var trailingSlashSchema = {
1694
+ description: "When `false`, visiting a path that ends with a forward slash will respond with a `308` status code and redirect to the path without the trailing slash.",
1695
+ type: "boolean"
1696
+ };
1697
+ }
1698
+ });
1699
+
1700
+ // ../routing-utils/dist/types.js
1701
+ var require_types = __commonJS({
1702
+ "../routing-utils/dist/types.js"(exports, module2) {
1703
+ "use strict";
1704
+ var __defProp2 = Object.defineProperty;
1705
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
1706
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
1707
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
1708
+ var __copyProps2 = (to, from, except, desc) => {
1709
+ if (from && typeof from === "object" || typeof from === "function") {
1710
+ for (let key of __getOwnPropNames2(from))
1711
+ if (!__hasOwnProp2.call(to, key) && key !== except)
1712
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
1713
+ }
1714
+ return to;
1715
+ };
1716
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1717
+ var types_exports = {};
1718
+ module2.exports = __toCommonJS2(types_exports);
1719
+ }
1720
+ });
1721
+
1722
+ // ../routing-utils/dist/index.js
1723
+ var require_dist3 = __commonJS({
1724
+ "../routing-utils/dist/index.js"(exports, module2) {
1725
+ "use strict";
1726
+ var __defProp2 = Object.defineProperty;
1727
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
1728
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
1729
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
1730
+ var __export2 = (target, all) => {
1731
+ for (var name in all)
1732
+ __defProp2(target, name, { get: all[name], enumerable: true });
1733
+ };
1734
+ var __copyProps2 = (to, from, except, desc) => {
1735
+ if (from && typeof from === "object" || typeof from === "function") {
1736
+ for (let key of __getOwnPropNames2(from))
1737
+ if (!__hasOwnProp2.call(to, key) && key !== except)
1738
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
1739
+ }
1740
+ return to;
1741
+ };
1742
+ var __reExport = (target, mod, secondTarget) => (__copyProps2(target, mod, "default"), secondTarget && __copyProps2(secondTarget, mod, "default"));
1743
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1744
+ var src_exports2 = {};
1745
+ __export2(src_exports2, {
1746
+ appendRoutesToPhase: () => import_append.appendRoutesToPhase,
1747
+ getCleanUrls: () => import_superstatic2.getCleanUrls,
1748
+ getTransformedRoutes: () => getTransformedRoutes2,
1749
+ isHandler: () => isHandler,
1750
+ isValidHandleValue: () => isValidHandleValue,
1751
+ mergeRoutes: () => import_merge.mergeRoutes,
1752
+ normalizeRoutes: () => normalizeRoutes
1753
+ });
1754
+ module2.exports = __toCommonJS2(src_exports2);
1755
+ var import_url = require("url");
1756
+ var import_superstatic = require_superstatic();
1757
+ var import_append = require_append();
1758
+ var import_merge = require_merge();
1759
+ __reExport(src_exports2, require_schemas(), module2.exports);
1760
+ var import_superstatic2 = require_superstatic();
1761
+ __reExport(src_exports2, require_types(), module2.exports);
1762
+ var VALID_HANDLE_VALUES = [
1763
+ "filesystem",
1764
+ "hit",
1765
+ "miss",
1766
+ "rewrite",
1767
+ "error",
1768
+ "resource"
1769
+ ];
1770
+ var validHandleValues = new Set(VALID_HANDLE_VALUES);
1771
+ function isHandler(route) {
1772
+ return typeof route.handle !== "undefined";
1773
+ }
1774
+ function isValidHandleValue(handle) {
1775
+ return validHandleValues.has(handle);
1776
+ }
1777
+ function normalizeRoutes(inputRoutes) {
1778
+ if (!inputRoutes || inputRoutes.length === 0) {
1779
+ return { routes: inputRoutes, error: null };
1780
+ }
1781
+ const routes = [];
1782
+ const handling = [];
1783
+ const errors = [];
1784
+ inputRoutes.forEach((r, i) => {
1785
+ const route = { ...r };
1786
+ routes.push(route);
1787
+ const keys = Object.keys(route);
1788
+ if (isHandler(route)) {
1789
+ const { handle } = route;
1790
+ if (keys.length !== 1) {
1791
+ const unknownProp = keys.find((prop) => prop !== "handle");
1792
+ errors.push(
1793
+ `Route at index ${i} has unknown property \`${unknownProp}\`.`
1794
+ );
1795
+ } else if (!isValidHandleValue(handle)) {
1796
+ errors.push(
1797
+ `Route at index ${i} has unknown handle value \`handle: ${handle}\`.`
1798
+ );
1799
+ } else if (handling.includes(handle)) {
1800
+ errors.push(
1801
+ `Route at index ${i} is a duplicate. Please use one \`handle: ${handle}\` at most.`
1802
+ );
1803
+ } else {
1804
+ handling.push(handle);
1805
+ }
1806
+ } else if (route.src) {
1807
+ if (!route.src.startsWith("^")) {
1808
+ route.src = `^${route.src}`;
1809
+ }
1810
+ if (!route.src.endsWith("$")) {
1811
+ route.src = `${route.src}$`;
1812
+ }
1813
+ route.src = route.src.replace(/\\\//g, "/");
1814
+ const regError = checkRegexSyntax("Route", i, route.src);
1815
+ if (regError) {
1816
+ errors.push(regError);
1817
+ }
1818
+ const handleValue = handling[handling.length - 1];
1819
+ if (handleValue === "hit") {
1820
+ if (route.dest) {
1821
+ errors.push(
1822
+ `Route at index ${i} cannot define \`dest\` after \`handle: hit\`.`
1823
+ );
1824
+ }
1825
+ if (route.status) {
1826
+ errors.push(
1827
+ `Route at index ${i} cannot define \`status\` after \`handle: hit\`.`
1828
+ );
1829
+ }
1830
+ if (!route.continue) {
1831
+ errors.push(
1832
+ `Route at index ${i} must define \`continue: true\` after \`handle: hit\`.`
1833
+ );
1834
+ }
1835
+ } else if (handleValue === "miss") {
1836
+ if (route.dest && !route.check) {
1837
+ errors.push(
1838
+ `Route at index ${i} must define \`check: true\` after \`handle: miss\`.`
1839
+ );
1840
+ } else if (!route.dest && !route.continue) {
1841
+ errors.push(
1842
+ `Route at index ${i} must define \`continue: true\` after \`handle: miss\`.`
1843
+ );
1844
+ }
1845
+ }
1846
+ } else {
1847
+ errors.push(
1848
+ `Route at index ${i} must define either \`handle\` or \`src\` property.`
1849
+ );
1850
+ }
1851
+ });
1852
+ const error = errors.length > 0 ? createError(
1853
+ "invalid_route",
1854
+ errors,
1855
+ "https://vercel.link/routes-json",
1856
+ "Learn More"
1857
+ ) : null;
1858
+ return { routes, error };
1859
+ }
1860
+ function checkRegexSyntax(type, index, src) {
1861
+ try {
1862
+ new RegExp(src);
1863
+ } catch (err) {
1864
+ const prop = type === "Route" ? "src" : "source";
1865
+ return `${type} at index ${index} has invalid \`${prop}\` regular expression "${src}".`;
1866
+ }
1867
+ return null;
1868
+ }
1869
+ function checkPatternSyntax(type, index, {
1870
+ source,
1871
+ destination,
1872
+ has
1873
+ }) {
1874
+ let sourceSegments = /* @__PURE__ */ new Set();
1875
+ const destinationSegments = /* @__PURE__ */ new Set();
1876
+ try {
1877
+ sourceSegments = new Set((0, import_superstatic.sourceToRegex)(source).segments);
1878
+ } catch (err) {
1879
+ return {
1880
+ message: `${type} at index ${index} has invalid \`source\` pattern "${source}".`,
1881
+ link: "https://vercel.link/invalid-route-source-pattern"
1882
+ };
1883
+ }
1884
+ if (destination) {
1885
+ try {
1886
+ const { hostname, pathname, query } = (0, import_url.parse)(destination, true);
1887
+ (0, import_superstatic.sourceToRegex)(hostname || "").segments.forEach(
1888
+ (name) => destinationSegments.add(name)
1889
+ );
1890
+ (0, import_superstatic.sourceToRegex)(pathname || "").segments.forEach(
1891
+ (name) => destinationSegments.add(name)
1892
+ );
1893
+ for (const strOrArray of Object.values(query)) {
1894
+ const value = Array.isArray(strOrArray) ? strOrArray[0] : strOrArray;
1895
+ (0, import_superstatic.sourceToRegex)(value || "").segments.forEach(
1896
+ (name) => destinationSegments.add(name)
1897
+ );
1898
+ }
1899
+ } catch (err) {
1900
+ }
1901
+ const hasSegments = (0, import_superstatic.collectHasSegments)(has);
1902
+ for (const segment of destinationSegments) {
1903
+ if (!sourceSegments.has(segment) && !hasSegments.includes(segment)) {
1904
+ return {
1905
+ message: `${type} at index ${index} has segment ":${segment}" in \`destination\` property but not in \`source\` or \`has\` property.`,
1906
+ link: "https://vercel.link/invalid-route-destination-segment"
1907
+ };
1908
+ }
1909
+ }
1910
+ }
1911
+ return null;
1912
+ }
1913
+ function checkRedirect(r, index) {
1914
+ if (typeof r.permanent !== "undefined" && typeof r.statusCode !== "undefined") {
1915
+ return `Redirect at index ${index} cannot define both \`permanent\` and \`statusCode\` properties.`;
1916
+ }
1917
+ return null;
1918
+ }
1919
+ function createError(code, allErrors, link, action) {
1920
+ const errors = Array.isArray(allErrors) ? allErrors : [allErrors];
1921
+ const message = errors[0];
1922
+ const error = {
1923
+ name: "RouteApiError",
1924
+ code,
1925
+ message,
1926
+ link,
1927
+ action,
1928
+ errors
1929
+ };
1930
+ return error;
1931
+ }
1932
+ function notEmpty(value) {
1933
+ return value !== null && value !== void 0;
1934
+ }
1935
+ function getTransformedRoutes2(vercelConfig) {
1936
+ const { cleanUrls, rewrites, redirects, headers, trailingSlash } = vercelConfig;
1937
+ let { routes = null } = vercelConfig;
1938
+ if (routes) {
1939
+ const hasNewProperties = typeof cleanUrls !== "undefined" || typeof trailingSlash !== "undefined" || typeof redirects !== "undefined" || typeof headers !== "undefined" || typeof rewrites !== "undefined";
1940
+ if (hasNewProperties) {
1941
+ const error = createError(
1942
+ "invalid_mixed_routes",
1943
+ "If `rewrites`, `redirects`, `headers`, `cleanUrls` or `trailingSlash` are used, then `routes` cannot be present.",
1944
+ "https://vercel.link/mix-routing-props",
1945
+ "Learn More"
1946
+ );
1947
+ return { routes, error };
1948
+ }
1949
+ return normalizeRoutes(routes);
1950
+ }
1951
+ if (typeof cleanUrls !== "undefined") {
1952
+ const normalized = normalizeRoutes(
1953
+ (0, import_superstatic.convertCleanUrls)(cleanUrls, trailingSlash)
1954
+ );
1955
+ if (normalized.error) {
1956
+ normalized.error.code = "invalid_clean_urls";
1957
+ return { routes, error: normalized.error };
1958
+ }
1959
+ routes = routes || [];
1960
+ routes.push(...normalized.routes || []);
1961
+ }
1962
+ if (typeof trailingSlash !== "undefined") {
1963
+ const normalized = normalizeRoutes((0, import_superstatic.convertTrailingSlash)(trailingSlash));
1964
+ if (normalized.error) {
1965
+ normalized.error.code = "invalid_trailing_slash";
1966
+ return { routes, error: normalized.error };
1967
+ }
1968
+ routes = routes || [];
1969
+ routes.push(...normalized.routes || []);
1970
+ }
1971
+ if (typeof redirects !== "undefined") {
1972
+ const code = "invalid_redirect";
1973
+ const regexErrorMessage = redirects.map((r, i) => checkRegexSyntax("Redirect", i, r.source)).find(notEmpty);
1974
+ if (regexErrorMessage) {
1975
+ return {
1976
+ routes,
1977
+ error: createError(
1978
+ "invalid_redirect",
1979
+ regexErrorMessage,
1980
+ "https://vercel.link/invalid-route-source-pattern",
1981
+ "Learn More"
1982
+ )
1983
+ };
1984
+ }
1985
+ const patternError = redirects.map((r, i) => checkPatternSyntax("Redirect", i, r)).find(notEmpty);
1986
+ if (patternError) {
1987
+ return {
1988
+ routes,
1989
+ error: createError(
1990
+ code,
1991
+ patternError.message,
1992
+ patternError.link,
1993
+ "Learn More"
1994
+ )
1995
+ };
1996
+ }
1997
+ const redirectErrorMessage = redirects.map(checkRedirect).find(notEmpty);
1998
+ if (redirectErrorMessage) {
1999
+ return {
2000
+ routes,
2001
+ error: createError(
2002
+ code,
2003
+ redirectErrorMessage,
2004
+ "https://vercel.link/redirects-json",
2005
+ "Learn More"
2006
+ )
2007
+ };
2008
+ }
2009
+ const normalized = normalizeRoutes((0, import_superstatic.convertRedirects)(redirects));
2010
+ if (normalized.error) {
2011
+ normalized.error.code = code;
2012
+ return { routes, error: normalized.error };
2013
+ }
2014
+ routes = routes || [];
2015
+ routes.push(...normalized.routes || []);
2016
+ }
2017
+ if (typeof headers !== "undefined") {
2018
+ const code = "invalid_header";
2019
+ const regexErrorMessage = headers.map((r, i) => checkRegexSyntax("Header", i, r.source)).find(notEmpty);
2020
+ if (regexErrorMessage) {
2021
+ return {
2022
+ routes,
2023
+ error: createError(
2024
+ code,
2025
+ regexErrorMessage,
2026
+ "https://vercel.link/invalid-route-source-pattern",
2027
+ "Learn More"
2028
+ )
2029
+ };
2030
+ }
2031
+ const patternError = headers.map((r, i) => checkPatternSyntax("Header", i, r)).find(notEmpty);
2032
+ if (patternError) {
2033
+ return {
2034
+ routes,
2035
+ error: createError(
2036
+ code,
2037
+ patternError.message,
2038
+ patternError.link,
2039
+ "Learn More"
2040
+ )
2041
+ };
2042
+ }
2043
+ const normalized = normalizeRoutes((0, import_superstatic.convertHeaders)(headers));
2044
+ if (normalized.error) {
2045
+ normalized.error.code = code;
2046
+ return { routes, error: normalized.error };
2047
+ }
2048
+ routes = routes || [];
2049
+ routes.push(...normalized.routes || []);
2050
+ }
2051
+ if (typeof rewrites !== "undefined") {
2052
+ const code = "invalid_rewrite";
2053
+ const regexErrorMessage = rewrites.map((r, i) => checkRegexSyntax("Rewrite", i, r.source)).find(notEmpty);
2054
+ if (regexErrorMessage) {
2055
+ return {
2056
+ routes,
2057
+ error: createError(
2058
+ code,
2059
+ regexErrorMessage,
2060
+ "https://vercel.link/invalid-route-source-pattern",
2061
+ "Learn More"
2062
+ )
2063
+ };
2064
+ }
2065
+ const patternError = rewrites.map((r, i) => checkPatternSyntax("Rewrite", i, r)).find(notEmpty);
2066
+ if (patternError) {
2067
+ return {
2068
+ routes,
2069
+ error: createError(
2070
+ code,
2071
+ patternError.message,
2072
+ patternError.link,
2073
+ "Learn More"
2074
+ )
2075
+ };
2076
+ }
2077
+ const normalized = normalizeRoutes((0, import_superstatic.convertRewrites)(rewrites));
2078
+ if (normalized.error) {
2079
+ normalized.error.code = code;
2080
+ return { routes, error: normalized.error };
2081
+ }
2082
+ routes = routes || [];
2083
+ routes.push({ handle: "filesystem" });
2084
+ routes.push(...normalized.routes || []);
2085
+ }
2086
+ return { routes, error: null };
2087
+ }
2088
+ }
2089
+ });
2090
+
20
2091
  // src/index.ts
21
2092
  var src_exports = {};
22
2093
  __export(src_exports, {
@@ -32,7 +2103,7 @@ var import_fs = require("fs");
32
2103
  var import_semver = require("semver");
33
2104
  var import_build_utils = require("@vercel/build-utils");
34
2105
  var import_nft = require("@vercel/nft");
35
- var import_routing_utils = require("@vercel/routing-utils");
2106
+ var import_routing_utils = __toESM(require_dist3());
36
2107
  var version = 2;
37
2108
  var build = async ({
38
2109
  workPath,
@@ -74,7 +2145,8 @@ var build = async ({
74
2145
  packageJsonPackageManager,
75
2146
  nodeVersion,
76
2147
  env: spawnOpts.env || {},
77
- turboSupportsCorepackHome
2148
+ turboSupportsCorepackHome,
2149
+ projectCreatedAt: config.projectSettings?.createdAt
78
2150
  });
79
2151
  if (typeof installCommand === "string") {
80
2152
  if (installCommand.trim()) {
@@ -87,7 +2159,14 @@ var build = async ({
87
2159
  console.log(`Skipping "install" command...`);
88
2160
  }
89
2161
  } else {
90
- await (0, import_build_utils.runNpmInstall)(entrypointFsDirname, [], spawnOpts, meta, nodeVersion);
2162
+ await (0, import_build_utils.runNpmInstall)(
2163
+ entrypointFsDirname,
2164
+ [],
2165
+ spawnOpts,
2166
+ meta,
2167
+ nodeVersion,
2168
+ config.projectSettings?.createdAt
2169
+ );
91
2170
  }
92
2171
  if (meta.isDev) {
93
2172
  throw new Error("Detected `@vercel/redwood` dev but this is not supported");
@@ -104,10 +2183,20 @@ var build = async ({
104
2183
  });
105
2184
  } else if (hasScript("vercel-build", pkg)) {
106
2185
  (0, import_build_utils.debug)(`Executing "yarn vercel-build"`);
107
- await (0, import_build_utils.runPackageJsonScript)(workPath, "vercel-build", spawnOpts);
2186
+ await (0, import_build_utils.runPackageJsonScript)(
2187
+ workPath,
2188
+ "vercel-build",
2189
+ spawnOpts,
2190
+ config.projectSettings?.createdAt
2191
+ );
108
2192
  } else if (hasScript("build", pkg)) {
109
2193
  (0, import_build_utils.debug)(`Executing "yarn build"`);
110
- await (0, import_build_utils.runPackageJsonScript)(workPath, "build", spawnOpts);
2194
+ await (0, import_build_utils.runPackageJsonScript)(
2195
+ workPath,
2196
+ "build",
2197
+ spawnOpts,
2198
+ config.projectSettings?.createdAt
2199
+ );
111
2200
  } else {
112
2201
  const { devDependencies = {} } = pkg || {};
113
2202
  const versionRange = devDependencies["@redwoodjs/core"];