@vercel/static-build 2.8.37 → 2.8.38

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 +2846 -200
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -9312,6 +9312,7 @@ var require_frameworks = __commonJS({
9312
9312
  tagline: "SvelteKit is a framework for building web applications of all sizes.",
9313
9313
  description: "A SvelteKit legacy app optimized Edge-first.",
9314
9314
  website: "https://kit.svelte.dev",
9315
+ supersedes: ["vite"],
9315
9316
  sort: 99,
9316
9317
  envPrefix: "VITE_",
9317
9318
  detectors: {
@@ -9349,6 +9350,7 @@ var require_frameworks = __commonJS({
9349
9350
  tagline: "SvelteKit is a framework for building web applications of all sizes.",
9350
9351
  description: "A SvelteKit app optimized Edge-first.",
9351
9352
  website: "https://kit.svelte.dev",
9353
+ supersedes: ["vite"],
9352
9354
  detectors: {
9353
9355
  every: [
9354
9356
  {
@@ -19729,185 +19731,2729 @@ var require_is_official_runtime = __commonJS({
19729
19731
  }
19730
19732
  });
19731
19733
 
19732
- // ../fs-detectors/dist/services/types.js
19733
- var require_types2 = __commonJS({
19734
- "../fs-detectors/dist/services/types.js"(exports2, module2) {
19734
+ // ../../node_modules/.pnpm/path-to-regexp@6.1.0/node_modules/path-to-regexp/dist/index.js
19735
+ var require_dist4 = __commonJS({
19736
+ "../../node_modules/.pnpm/path-to-regexp@6.1.0/node_modules/path-to-regexp/dist/index.js"(exports2) {
19735
19737
  "use strict";
19736
- var __defProp2 = Object.defineProperty;
19737
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
19738
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
19739
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
19740
- var __export2 = (target, all) => {
19741
- for (var name in all)
19742
- __defProp2(target, name, { get: all[name], enumerable: true });
19743
- };
19744
- var __copyProps2 = (to, from, except, desc) => {
19745
- if (from && typeof from === "object" || typeof from === "function") {
19746
- for (let key of __getOwnPropNames2(from))
19747
- if (!__hasOwnProp2.call(to, key) && key !== except)
19748
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
19738
+ Object.defineProperty(exports2, "__esModule", { value: true });
19739
+ function lexer(str) {
19740
+ var tokens = [];
19741
+ var i = 0;
19742
+ while (i < str.length) {
19743
+ var char = str[i];
19744
+ if (char === "*" || char === "+" || char === "?") {
19745
+ tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
19746
+ continue;
19747
+ }
19748
+ if (char === "\\") {
19749
+ tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
19750
+ continue;
19751
+ }
19752
+ if (char === "{") {
19753
+ tokens.push({ type: "OPEN", index: i, value: str[i++] });
19754
+ continue;
19755
+ }
19756
+ if (char === "}") {
19757
+ tokens.push({ type: "CLOSE", index: i, value: str[i++] });
19758
+ continue;
19759
+ }
19760
+ if (char === ":") {
19761
+ var name = "";
19762
+ var j = i + 1;
19763
+ while (j < str.length) {
19764
+ var code = str.charCodeAt(j);
19765
+ if (
19766
+ // `0-9`
19767
+ code >= 48 && code <= 57 || // `A-Z`
19768
+ code >= 65 && code <= 90 || // `a-z`
19769
+ code >= 97 && code <= 122 || // `_`
19770
+ code === 95
19771
+ ) {
19772
+ name += str[j++];
19773
+ continue;
19774
+ }
19775
+ break;
19776
+ }
19777
+ if (!name)
19778
+ throw new TypeError("Missing parameter name at " + i);
19779
+ tokens.push({ type: "NAME", index: i, value: name });
19780
+ i = j;
19781
+ continue;
19782
+ }
19783
+ if (char === "(") {
19784
+ var count = 1;
19785
+ var pattern = "";
19786
+ var j = i + 1;
19787
+ if (str[j] === "?") {
19788
+ throw new TypeError('Pattern cannot start with "?" at ' + j);
19789
+ }
19790
+ while (j < str.length) {
19791
+ if (str[j] === "\\") {
19792
+ pattern += str[j++] + str[j++];
19793
+ continue;
19794
+ }
19795
+ if (str[j] === ")") {
19796
+ count--;
19797
+ if (count === 0) {
19798
+ j++;
19799
+ break;
19800
+ }
19801
+ } else if (str[j] === "(") {
19802
+ count++;
19803
+ if (str[j + 1] !== "?") {
19804
+ throw new TypeError("Capturing groups are not allowed at " + j);
19805
+ }
19806
+ }
19807
+ pattern += str[j++];
19808
+ }
19809
+ if (count)
19810
+ throw new TypeError("Unbalanced pattern at " + i);
19811
+ if (!pattern)
19812
+ throw new TypeError("Missing pattern at " + i);
19813
+ tokens.push({ type: "PATTERN", index: i, value: pattern });
19814
+ i = j;
19815
+ continue;
19816
+ }
19817
+ tokens.push({ type: "CHAR", index: i, value: str[i++] });
19749
19818
  }
19750
- return to;
19751
- };
19752
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
19753
- var types_exports = {};
19754
- __export2(types_exports, {
19755
- ENTRYPOINT_EXTENSIONS: () => ENTRYPOINT_EXTENSIONS,
19756
- ROUTE_OWNING_BUILDERS: () => ROUTE_OWNING_BUILDERS,
19757
- RUNTIME_BUILDERS: () => RUNTIME_BUILDERS,
19758
- STATIC_BUILDERS: () => STATIC_BUILDERS
19759
- });
19760
- module2.exports = __toCommonJS2(types_exports);
19761
- var RUNTIME_BUILDERS = {
19762
- node: "@vercel/node",
19763
- python: "@vercel/python",
19764
- go: "@vercel/go",
19765
- rust: "@vercel/rust",
19766
- ruby: "@vercel/ruby"
19767
- };
19768
- var ENTRYPOINT_EXTENSIONS = {
19769
- ".ts": "node",
19770
- ".mts": "node",
19771
- ".js": "node",
19772
- ".mjs": "node",
19773
- ".cjs": "node",
19774
- ".py": "python",
19775
- ".go": "go",
19776
- ".rs": "rust",
19777
- ".rb": "ruby",
19778
- ".ru": "ruby"
19779
- };
19780
- var STATIC_BUILDERS = /* @__PURE__ */ new Set([
19781
- "@vercel/static-build",
19782
- "@vercel/static"
19783
- ]);
19784
- var ROUTE_OWNING_BUILDERS = /* @__PURE__ */ new Set([
19785
- "@vercel/next",
19786
- "@vercel/backends"
19787
- ]);
19788
- }
19789
- });
19790
-
19791
- // ../fs-detectors/dist/services/utils.js
19792
- var require_utils4 = __commonJS({
19793
- "../fs-detectors/dist/services/utils.js"(exports2, module2) {
19794
- "use strict";
19795
- var __defProp2 = Object.defineProperty;
19796
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
19797
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
19798
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
19799
- var __export2 = (target, all) => {
19800
- for (var name in all)
19801
- __defProp2(target, name, { get: all[name], enumerable: true });
19802
- };
19803
- var __copyProps2 = (to, from, except, desc) => {
19804
- if (from && typeof from === "object" || typeof from === "function") {
19805
- for (let key of __getOwnPropNames2(from))
19806
- if (!__hasOwnProp2.call(to, key) && key !== except)
19807
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
19819
+ tokens.push({ type: "END", index: i, value: "" });
19820
+ return tokens;
19821
+ }
19822
+ function parse(str, options) {
19823
+ if (options === void 0) {
19824
+ options = {};
19808
19825
  }
19809
- return to;
19810
- };
19811
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
19812
- var utils_exports = {};
19813
- __export2(utils_exports, {
19814
- getBuilderForRuntime: () => getBuilderForRuntime,
19815
- inferServiceRuntime: () => inferServiceRuntime,
19816
- isRouteOwningBuilder: () => isRouteOwningBuilder2,
19817
- isStaticBuild: () => isStaticBuild2,
19818
- readVercelConfig: () => readVercelConfig
19819
- });
19820
- module2.exports = __toCommonJS2(utils_exports);
19821
- var import_framework_helpers = require("@vercel/build-utils/dist/framework-helpers");
19822
- var import_types = require_types2();
19823
- function getBuilderForRuntime(runtime) {
19824
- const builder = import_types.RUNTIME_BUILDERS[runtime];
19825
- if (!builder) {
19826
- throw new Error(`Unknown runtime: ${runtime}`);
19826
+ var tokens = lexer(str);
19827
+ var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
19828
+ var defaultPattern = "[^" + escapeString(options.delimiter || "/#?") + "]+?";
19829
+ var result = [];
19830
+ var key = 0;
19831
+ var i = 0;
19832
+ var path6 = "";
19833
+ var tryConsume = function(type) {
19834
+ if (i < tokens.length && tokens[i].type === type)
19835
+ return tokens[i++].value;
19836
+ };
19837
+ var mustConsume = function(type) {
19838
+ var value2 = tryConsume(type);
19839
+ if (value2 !== void 0)
19840
+ return value2;
19841
+ var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
19842
+ throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
19843
+ };
19844
+ var consumeText = function() {
19845
+ var result2 = "";
19846
+ var value2;
19847
+ while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
19848
+ result2 += value2;
19849
+ }
19850
+ return result2;
19851
+ };
19852
+ while (i < tokens.length) {
19853
+ var char = tryConsume("CHAR");
19854
+ var name = tryConsume("NAME");
19855
+ var pattern = tryConsume("PATTERN");
19856
+ if (name || pattern) {
19857
+ var prefix = char || "";
19858
+ if (prefixes.indexOf(prefix) === -1) {
19859
+ path6 += prefix;
19860
+ prefix = "";
19861
+ }
19862
+ if (path6) {
19863
+ result.push(path6);
19864
+ path6 = "";
19865
+ }
19866
+ result.push({
19867
+ name: name || key++,
19868
+ prefix,
19869
+ suffix: "",
19870
+ pattern: pattern || defaultPattern,
19871
+ modifier: tryConsume("MODIFIER") || ""
19872
+ });
19873
+ continue;
19874
+ }
19875
+ var value = char || tryConsume("ESCAPED_CHAR");
19876
+ if (value) {
19877
+ path6 += value;
19878
+ continue;
19879
+ }
19880
+ if (path6) {
19881
+ result.push(path6);
19882
+ path6 = "";
19883
+ }
19884
+ var open = tryConsume("OPEN");
19885
+ if (open) {
19886
+ var prefix = consumeText();
19887
+ var name_1 = tryConsume("NAME") || "";
19888
+ var pattern_1 = tryConsume("PATTERN") || "";
19889
+ var suffix = consumeText();
19890
+ mustConsume("CLOSE");
19891
+ result.push({
19892
+ name: name_1 || (pattern_1 ? key++ : ""),
19893
+ pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
19894
+ prefix,
19895
+ suffix,
19896
+ modifier: tryConsume("MODIFIER") || ""
19897
+ });
19898
+ continue;
19899
+ }
19900
+ mustConsume("END");
19827
19901
  }
19828
- return builder;
19829
- }
19830
- function isStaticBuild2(service) {
19831
- return import_types.STATIC_BUILDERS.has(service.builder.use);
19902
+ return result;
19832
19903
  }
19833
- function isRouteOwningBuilder2(service) {
19834
- return import_types.ROUTE_OWNING_BUILDERS.has(service.builder.use);
19904
+ exports2.parse = parse;
19905
+ function compile(str, options) {
19906
+ return tokensToFunction(parse(str, options), options);
19835
19907
  }
19836
- function inferServiceRuntime(config) {
19837
- if (config.runtime && config.runtime in import_types.RUNTIME_BUILDERS) {
19838
- return config.runtime;
19839
- }
19840
- if ((0, import_framework_helpers.isPythonFramework)(config.framework)) {
19841
- return "python";
19842
- }
19843
- if ((0, import_framework_helpers.isBackendFramework)(config.framework)) {
19844
- return "node";
19908
+ exports2.compile = compile;
19909
+ function tokensToFunction(tokens, options) {
19910
+ if (options === void 0) {
19911
+ options = {};
19845
19912
  }
19846
- if (config.builder) {
19847
- for (const [runtime, builderName] of Object.entries(import_types.RUNTIME_BUILDERS)) {
19848
- if (config.builder === builderName) {
19849
- return runtime;
19913
+ var reFlags = flags(options);
19914
+ var _a = options.encode, encode = _a === void 0 ? function(x) {
19915
+ return x;
19916
+ } : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
19917
+ var matches = tokens.map(function(token) {
19918
+ if (typeof token === "object") {
19919
+ return new RegExp("^(?:" + token.pattern + ")$", reFlags);
19920
+ }
19921
+ });
19922
+ return function(data) {
19923
+ var path6 = "";
19924
+ for (var i = 0; i < tokens.length; i++) {
19925
+ var token = tokens[i];
19926
+ if (typeof token === "string") {
19927
+ path6 += token;
19928
+ continue;
19929
+ }
19930
+ var value = data ? data[token.name] : void 0;
19931
+ var optional = token.modifier === "?" || token.modifier === "*";
19932
+ var repeat = token.modifier === "*" || token.modifier === "+";
19933
+ if (Array.isArray(value)) {
19934
+ if (!repeat) {
19935
+ throw new TypeError('Expected "' + token.name + '" to not repeat, but got an array');
19936
+ }
19937
+ if (value.length === 0) {
19938
+ if (optional)
19939
+ continue;
19940
+ throw new TypeError('Expected "' + token.name + '" to not be empty');
19941
+ }
19942
+ for (var j = 0; j < value.length; j++) {
19943
+ var segment = encode(value[j], token);
19944
+ if (validate && !matches[i].test(segment)) {
19945
+ throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"');
19946
+ }
19947
+ path6 += token.prefix + segment + token.suffix;
19948
+ }
19949
+ continue;
19850
19950
  }
19951
+ if (typeof value === "string" || typeof value === "number") {
19952
+ var segment = encode(String(value), token);
19953
+ if (validate && !matches[i].test(segment)) {
19954
+ throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"');
19955
+ }
19956
+ path6 += token.prefix + segment + token.suffix;
19957
+ continue;
19958
+ }
19959
+ if (optional)
19960
+ continue;
19961
+ var typeOfMessage = repeat ? "an array" : "a string";
19962
+ throw new TypeError('Expected "' + token.name + '" to be ' + typeOfMessage);
19851
19963
  }
19964
+ return path6;
19965
+ };
19966
+ }
19967
+ exports2.tokensToFunction = tokensToFunction;
19968
+ function match(str, options) {
19969
+ var keys = [];
19970
+ var re = pathToRegexp(str, keys, options);
19971
+ return regexpToFunction(re, keys, options);
19972
+ }
19973
+ exports2.match = match;
19974
+ function regexpToFunction(re, keys, options) {
19975
+ if (options === void 0) {
19976
+ options = {};
19852
19977
  }
19853
- if (config.entrypoint) {
19854
- for (const [ext, runtime] of Object.entries(import_types.ENTRYPOINT_EXTENSIONS)) {
19855
- if (config.entrypoint.endsWith(ext)) {
19856
- return runtime;
19978
+ var _a = options.decode, decode = _a === void 0 ? function(x) {
19979
+ return x;
19980
+ } : _a;
19981
+ return function(pathname) {
19982
+ var m = re.exec(pathname);
19983
+ if (!m)
19984
+ return false;
19985
+ var path6 = m[0], index = m.index;
19986
+ var params = /* @__PURE__ */ Object.create(null);
19987
+ var _loop_1 = function(i2) {
19988
+ if (m[i2] === void 0)
19989
+ return "continue";
19990
+ var key = keys[i2 - 1];
19991
+ if (key.modifier === "*" || key.modifier === "+") {
19992
+ params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
19993
+ return decode(value, key);
19994
+ });
19995
+ } else {
19996
+ params[key.name] = decode(m[i2], key);
19857
19997
  }
19998
+ };
19999
+ for (var i = 1; i < m.length; i++) {
20000
+ _loop_1(i);
20001
+ }
20002
+ return { path: path6, index, params };
20003
+ };
20004
+ }
20005
+ exports2.regexpToFunction = regexpToFunction;
20006
+ function escapeString(str) {
20007
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
20008
+ }
20009
+ function flags(options) {
20010
+ return options && options.sensitive ? "" : "i";
20011
+ }
20012
+ function regexpToRegexp(path6, keys) {
20013
+ if (!keys)
20014
+ return path6;
20015
+ var groups = path6.source.match(/\((?!\?)/g);
20016
+ if (groups) {
20017
+ for (var i = 0; i < groups.length; i++) {
20018
+ keys.push({
20019
+ name: i,
20020
+ prefix: "",
20021
+ suffix: "",
20022
+ modifier: "",
20023
+ pattern: ""
20024
+ });
19858
20025
  }
19859
20026
  }
19860
- return void 0;
20027
+ return path6;
19861
20028
  }
19862
- async function readVercelConfig(fs5) {
19863
- const hasVercelJson = await fs5.hasPath("vercel.json");
19864
- if (!hasVercelJson) {
19865
- return { config: null, error: null };
20029
+ function arrayToRegexp(paths, keys, options) {
20030
+ var parts = paths.map(function(path6) {
20031
+ return pathToRegexp(path6, keys, options).source;
20032
+ });
20033
+ return new RegExp("(?:" + parts.join("|") + ")", flags(options));
20034
+ }
20035
+ function stringToRegexp(path6, keys, options) {
20036
+ return tokensToRegexp(parse(path6, options), keys, options);
20037
+ }
20038
+ function tokensToRegexp(tokens, keys, options) {
20039
+ if (options === void 0) {
20040
+ options = {};
19866
20041
  }
19867
- try {
19868
- const content = await fs5.readFile("vercel.json");
19869
- const config = JSON.parse(content.toString());
19870
- return { config, error: null };
19871
- } catch {
19872
- return {
19873
- config: null,
19874
- error: {
19875
- code: "INVALID_VERCEL_JSON",
19876
- message: "Failed to parse vercel.json. Ensure it contains valid JSON."
20042
+ 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) {
20043
+ return x;
20044
+ } : _d;
20045
+ var endsWith = "[" + escapeString(options.endsWith || "") + "]|$";
20046
+ var delimiter = "[" + escapeString(options.delimiter || "/#?") + "]";
20047
+ var route = start ? "^" : "";
20048
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
20049
+ var token = tokens_1[_i];
20050
+ if (typeof token === "string") {
20051
+ route += escapeString(encode(token));
20052
+ } else {
20053
+ var prefix = escapeString(encode(token.prefix));
20054
+ var suffix = escapeString(encode(token.suffix));
20055
+ if (token.pattern) {
20056
+ if (keys)
20057
+ keys.push(token);
20058
+ if (prefix || suffix) {
20059
+ if (token.modifier === "+" || token.modifier === "*") {
20060
+ var mod = token.modifier === "*" ? "?" : "";
20061
+ route += "(?:" + prefix + "((?:" + token.pattern + ")(?:" + suffix + prefix + "(?:" + token.pattern + "))*)" + suffix + ")" + mod;
20062
+ } else {
20063
+ route += "(?:" + prefix + "(" + token.pattern + ")" + suffix + ")" + token.modifier;
20064
+ }
20065
+ } else {
20066
+ route += "(" + token.pattern + ")" + token.modifier;
20067
+ }
20068
+ } else {
20069
+ route += "(?:" + prefix + suffix + ")" + token.modifier;
19877
20070
  }
19878
- };
20071
+ }
19879
20072
  }
20073
+ if (end) {
20074
+ if (!strict)
20075
+ route += delimiter + "?";
20076
+ route += !options.endsWith ? "$" : "(?=" + endsWith + ")";
20077
+ } else {
20078
+ var endToken = tokens[tokens.length - 1];
20079
+ var isEndDelimited = typeof endToken === "string" ? delimiter.indexOf(endToken[endToken.length - 1]) > -1 : (
20080
+ // tslint:disable-next-line
20081
+ endToken === void 0
20082
+ );
20083
+ if (!strict) {
20084
+ route += "(?:" + delimiter + "(?=" + endsWith + "))?";
20085
+ }
20086
+ if (!isEndDelimited) {
20087
+ route += "(?=" + delimiter + "|" + endsWith + ")";
20088
+ }
20089
+ }
20090
+ return new RegExp(route, flags(options));
20091
+ }
20092
+ exports2.tokensToRegexp = tokensToRegexp;
20093
+ function pathToRegexp(path6, keys, options) {
20094
+ if (path6 instanceof RegExp)
20095
+ return regexpToRegexp(path6, keys);
20096
+ if (Array.isArray(path6))
20097
+ return arrayToRegexp(path6, keys, options);
20098
+ return stringToRegexp(path6, keys, options);
19880
20099
  }
20100
+ exports2.pathToRegexp = pathToRegexp;
19881
20101
  }
19882
20102
  });
19883
20103
 
19884
- // ../fs-detectors/dist/services/resolve.js
19885
- var require_resolve = __commonJS({
19886
- "../fs-detectors/dist/services/resolve.js"(exports2, module2) {
20104
+ // ../../node_modules/.pnpm/path-to-regexp@6.3.0/node_modules/path-to-regexp/dist/index.js
20105
+ var require_dist5 = __commonJS({
20106
+ "../../node_modules/.pnpm/path-to-regexp@6.3.0/node_modules/path-to-regexp/dist/index.js"(exports2) {
19887
20107
  "use strict";
19888
- var __create2 = Object.create;
19889
- var __defProp2 = Object.defineProperty;
19890
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
19891
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
19892
- var __getProtoOf2 = Object.getPrototypeOf;
19893
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
19894
- var __export2 = (target, all) => {
19895
- for (var name in all)
19896
- __defProp2(target, name, { get: all[name], enumerable: true });
19897
- };
19898
- var __copyProps2 = (to, from, except, desc) => {
19899
- if (from && typeof from === "object" || typeof from === "function") {
19900
- for (let key of __getOwnPropNames2(from))
19901
- if (!__hasOwnProp2.call(to, key) && key !== except)
19902
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
19903
- }
19904
- return to;
19905
- };
19906
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
19907
- // If the importer is in node compatibility mode or this is not an ESM
19908
- // file that has been converted to a CommonJS file using a Babel-
19909
- // compatible transform (i.e. "__esModule" has not been set), then set
19910
- // "default" to the CommonJS "module.exports" for node compatibility.
20108
+ Object.defineProperty(exports2, "__esModule", { value: true });
20109
+ exports2.pathToRegexp = exports2.tokensToRegexp = exports2.regexpToFunction = exports2.match = exports2.tokensToFunction = exports2.compile = exports2.parse = void 0;
20110
+ function lexer(str) {
20111
+ var tokens = [];
20112
+ var i = 0;
20113
+ while (i < str.length) {
20114
+ var char = str[i];
20115
+ if (char === "*" || char === "+" || char === "?") {
20116
+ tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
20117
+ continue;
20118
+ }
20119
+ if (char === "\\") {
20120
+ tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
20121
+ continue;
20122
+ }
20123
+ if (char === "{") {
20124
+ tokens.push({ type: "OPEN", index: i, value: str[i++] });
20125
+ continue;
20126
+ }
20127
+ if (char === "}") {
20128
+ tokens.push({ type: "CLOSE", index: i, value: str[i++] });
20129
+ continue;
20130
+ }
20131
+ if (char === ":") {
20132
+ var name = "";
20133
+ var j = i + 1;
20134
+ while (j < str.length) {
20135
+ var code = str.charCodeAt(j);
20136
+ if (
20137
+ // `0-9`
20138
+ code >= 48 && code <= 57 || // `A-Z`
20139
+ code >= 65 && code <= 90 || // `a-z`
20140
+ code >= 97 && code <= 122 || // `_`
20141
+ code === 95
20142
+ ) {
20143
+ name += str[j++];
20144
+ continue;
20145
+ }
20146
+ break;
20147
+ }
20148
+ if (!name)
20149
+ throw new TypeError("Missing parameter name at ".concat(i));
20150
+ tokens.push({ type: "NAME", index: i, value: name });
20151
+ i = j;
20152
+ continue;
20153
+ }
20154
+ if (char === "(") {
20155
+ var count = 1;
20156
+ var pattern = "";
20157
+ var j = i + 1;
20158
+ if (str[j] === "?") {
20159
+ throw new TypeError('Pattern cannot start with "?" at '.concat(j));
20160
+ }
20161
+ while (j < str.length) {
20162
+ if (str[j] === "\\") {
20163
+ pattern += str[j++] + str[j++];
20164
+ continue;
20165
+ }
20166
+ if (str[j] === ")") {
20167
+ count--;
20168
+ if (count === 0) {
20169
+ j++;
20170
+ break;
20171
+ }
20172
+ } else if (str[j] === "(") {
20173
+ count++;
20174
+ if (str[j + 1] !== "?") {
20175
+ throw new TypeError("Capturing groups are not allowed at ".concat(j));
20176
+ }
20177
+ }
20178
+ pattern += str[j++];
20179
+ }
20180
+ if (count)
20181
+ throw new TypeError("Unbalanced pattern at ".concat(i));
20182
+ if (!pattern)
20183
+ throw new TypeError("Missing pattern at ".concat(i));
20184
+ tokens.push({ type: "PATTERN", index: i, value: pattern });
20185
+ i = j;
20186
+ continue;
20187
+ }
20188
+ tokens.push({ type: "CHAR", index: i, value: str[i++] });
20189
+ }
20190
+ tokens.push({ type: "END", index: i, value: "" });
20191
+ return tokens;
20192
+ }
20193
+ function parse(str, options) {
20194
+ if (options === void 0) {
20195
+ options = {};
20196
+ }
20197
+ var tokens = lexer(str);
20198
+ var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a, _b = options.delimiter, delimiter = _b === void 0 ? "/#?" : _b;
20199
+ var result = [];
20200
+ var key = 0;
20201
+ var i = 0;
20202
+ var path6 = "";
20203
+ var tryConsume = function(type) {
20204
+ if (i < tokens.length && tokens[i].type === type)
20205
+ return tokens[i++].value;
20206
+ };
20207
+ var mustConsume = function(type) {
20208
+ var value2 = tryConsume(type);
20209
+ if (value2 !== void 0)
20210
+ return value2;
20211
+ var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
20212
+ throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
20213
+ };
20214
+ var consumeText = function() {
20215
+ var result2 = "";
20216
+ var value2;
20217
+ while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
20218
+ result2 += value2;
20219
+ }
20220
+ return result2;
20221
+ };
20222
+ var isSafe = function(value2) {
20223
+ for (var _i = 0, delimiter_1 = delimiter; _i < delimiter_1.length; _i++) {
20224
+ var char2 = delimiter_1[_i];
20225
+ if (value2.indexOf(char2) > -1)
20226
+ return true;
20227
+ }
20228
+ return false;
20229
+ };
20230
+ var safePattern = function(prefix2) {
20231
+ var prev = result[result.length - 1];
20232
+ var prevText = prefix2 || (prev && typeof prev === "string" ? prev : "");
20233
+ if (prev && !prevText) {
20234
+ throw new TypeError('Must have text between two parameters, missing text after "'.concat(prev.name, '"'));
20235
+ }
20236
+ if (!prevText || isSafe(prevText))
20237
+ return "[^".concat(escapeString(delimiter), "]+?");
20238
+ return "(?:(?!".concat(escapeString(prevText), ")[^").concat(escapeString(delimiter), "])+?");
20239
+ };
20240
+ while (i < tokens.length) {
20241
+ var char = tryConsume("CHAR");
20242
+ var name = tryConsume("NAME");
20243
+ var pattern = tryConsume("PATTERN");
20244
+ if (name || pattern) {
20245
+ var prefix = char || "";
20246
+ if (prefixes.indexOf(prefix) === -1) {
20247
+ path6 += prefix;
20248
+ prefix = "";
20249
+ }
20250
+ if (path6) {
20251
+ result.push(path6);
20252
+ path6 = "";
20253
+ }
20254
+ result.push({
20255
+ name: name || key++,
20256
+ prefix,
20257
+ suffix: "",
20258
+ pattern: pattern || safePattern(prefix),
20259
+ modifier: tryConsume("MODIFIER") || ""
20260
+ });
20261
+ continue;
20262
+ }
20263
+ var value = char || tryConsume("ESCAPED_CHAR");
20264
+ if (value) {
20265
+ path6 += value;
20266
+ continue;
20267
+ }
20268
+ if (path6) {
20269
+ result.push(path6);
20270
+ path6 = "";
20271
+ }
20272
+ var open = tryConsume("OPEN");
20273
+ if (open) {
20274
+ var prefix = consumeText();
20275
+ var name_1 = tryConsume("NAME") || "";
20276
+ var pattern_1 = tryConsume("PATTERN") || "";
20277
+ var suffix = consumeText();
20278
+ mustConsume("CLOSE");
20279
+ result.push({
20280
+ name: name_1 || (pattern_1 ? key++ : ""),
20281
+ pattern: name_1 && !pattern_1 ? safePattern(prefix) : pattern_1,
20282
+ prefix,
20283
+ suffix,
20284
+ modifier: tryConsume("MODIFIER") || ""
20285
+ });
20286
+ continue;
20287
+ }
20288
+ mustConsume("END");
20289
+ }
20290
+ return result;
20291
+ }
20292
+ exports2.parse = parse;
20293
+ function compile(str, options) {
20294
+ return tokensToFunction(parse(str, options), options);
20295
+ }
20296
+ exports2.compile = compile;
20297
+ function tokensToFunction(tokens, options) {
20298
+ if (options === void 0) {
20299
+ options = {};
20300
+ }
20301
+ var reFlags = flags(options);
20302
+ var _a = options.encode, encode = _a === void 0 ? function(x) {
20303
+ return x;
20304
+ } : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
20305
+ var matches = tokens.map(function(token) {
20306
+ if (typeof token === "object") {
20307
+ return new RegExp("^(?:".concat(token.pattern, ")$"), reFlags);
20308
+ }
20309
+ });
20310
+ return function(data) {
20311
+ var path6 = "";
20312
+ for (var i = 0; i < tokens.length; i++) {
20313
+ var token = tokens[i];
20314
+ if (typeof token === "string") {
20315
+ path6 += token;
20316
+ continue;
20317
+ }
20318
+ var value = data ? data[token.name] : void 0;
20319
+ var optional = token.modifier === "?" || token.modifier === "*";
20320
+ var repeat = token.modifier === "*" || token.modifier === "+";
20321
+ if (Array.isArray(value)) {
20322
+ if (!repeat) {
20323
+ throw new TypeError('Expected "'.concat(token.name, '" to not repeat, but got an array'));
20324
+ }
20325
+ if (value.length === 0) {
20326
+ if (optional)
20327
+ continue;
20328
+ throw new TypeError('Expected "'.concat(token.name, '" to not be empty'));
20329
+ }
20330
+ for (var j = 0; j < value.length; j++) {
20331
+ var segment = encode(value[j], token);
20332
+ if (validate && !matches[i].test(segment)) {
20333
+ throw new TypeError('Expected all "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
20334
+ }
20335
+ path6 += token.prefix + segment + token.suffix;
20336
+ }
20337
+ continue;
20338
+ }
20339
+ if (typeof value === "string" || typeof value === "number") {
20340
+ var segment = encode(String(value), token);
20341
+ if (validate && !matches[i].test(segment)) {
20342
+ throw new TypeError('Expected "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
20343
+ }
20344
+ path6 += token.prefix + segment + token.suffix;
20345
+ continue;
20346
+ }
20347
+ if (optional)
20348
+ continue;
20349
+ var typeOfMessage = repeat ? "an array" : "a string";
20350
+ throw new TypeError('Expected "'.concat(token.name, '" to be ').concat(typeOfMessage));
20351
+ }
20352
+ return path6;
20353
+ };
20354
+ }
20355
+ exports2.tokensToFunction = tokensToFunction;
20356
+ function match(str, options) {
20357
+ var keys = [];
20358
+ var re = pathToRegexp(str, keys, options);
20359
+ return regexpToFunction(re, keys, options);
20360
+ }
20361
+ exports2.match = match;
20362
+ function regexpToFunction(re, keys, options) {
20363
+ if (options === void 0) {
20364
+ options = {};
20365
+ }
20366
+ var _a = options.decode, decode = _a === void 0 ? function(x) {
20367
+ return x;
20368
+ } : _a;
20369
+ return function(pathname) {
20370
+ var m = re.exec(pathname);
20371
+ if (!m)
20372
+ return false;
20373
+ var path6 = m[0], index = m.index;
20374
+ var params = /* @__PURE__ */ Object.create(null);
20375
+ var _loop_1 = function(i2) {
20376
+ if (m[i2] === void 0)
20377
+ return "continue";
20378
+ var key = keys[i2 - 1];
20379
+ if (key.modifier === "*" || key.modifier === "+") {
20380
+ params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
20381
+ return decode(value, key);
20382
+ });
20383
+ } else {
20384
+ params[key.name] = decode(m[i2], key);
20385
+ }
20386
+ };
20387
+ for (var i = 1; i < m.length; i++) {
20388
+ _loop_1(i);
20389
+ }
20390
+ return { path: path6, index, params };
20391
+ };
20392
+ }
20393
+ exports2.regexpToFunction = regexpToFunction;
20394
+ function escapeString(str) {
20395
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
20396
+ }
20397
+ function flags(options) {
20398
+ return options && options.sensitive ? "" : "i";
20399
+ }
20400
+ function regexpToRegexp(path6, keys) {
20401
+ if (!keys)
20402
+ return path6;
20403
+ var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
20404
+ var index = 0;
20405
+ var execResult = groupsRegex.exec(path6.source);
20406
+ while (execResult) {
20407
+ keys.push({
20408
+ // Use parenthesized substring match if available, index otherwise
20409
+ name: execResult[1] || index++,
20410
+ prefix: "",
20411
+ suffix: "",
20412
+ modifier: "",
20413
+ pattern: ""
20414
+ });
20415
+ execResult = groupsRegex.exec(path6.source);
20416
+ }
20417
+ return path6;
20418
+ }
20419
+ function arrayToRegexp(paths, keys, options) {
20420
+ var parts = paths.map(function(path6) {
20421
+ return pathToRegexp(path6, keys, options).source;
20422
+ });
20423
+ return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
20424
+ }
20425
+ function stringToRegexp(path6, keys, options) {
20426
+ return tokensToRegexp(parse(path6, options), keys, options);
20427
+ }
20428
+ function tokensToRegexp(tokens, keys, options) {
20429
+ if (options === void 0) {
20430
+ options = {};
20431
+ }
20432
+ 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) {
20433
+ return x;
20434
+ } : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
20435
+ var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
20436
+ var delimiterRe = "[".concat(escapeString(delimiter), "]");
20437
+ var route = start ? "^" : "";
20438
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
20439
+ var token = tokens_1[_i];
20440
+ if (typeof token === "string") {
20441
+ route += escapeString(encode(token));
20442
+ } else {
20443
+ var prefix = escapeString(encode(token.prefix));
20444
+ var suffix = escapeString(encode(token.suffix));
20445
+ if (token.pattern) {
20446
+ if (keys)
20447
+ keys.push(token);
20448
+ if (prefix || suffix) {
20449
+ if (token.modifier === "+" || token.modifier === "*") {
20450
+ var mod = token.modifier === "*" ? "?" : "";
20451
+ route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
20452
+ } else {
20453
+ route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
20454
+ }
20455
+ } else {
20456
+ if (token.modifier === "+" || token.modifier === "*") {
20457
+ throw new TypeError('Can not repeat "'.concat(token.name, '" without a prefix and suffix'));
20458
+ }
20459
+ route += "(".concat(token.pattern, ")").concat(token.modifier);
20460
+ }
20461
+ } else {
20462
+ route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
20463
+ }
20464
+ }
20465
+ }
20466
+ if (end) {
20467
+ if (!strict)
20468
+ route += "".concat(delimiterRe, "?");
20469
+ route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
20470
+ } else {
20471
+ var endToken = tokens[tokens.length - 1];
20472
+ var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
20473
+ if (!strict) {
20474
+ route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
20475
+ }
20476
+ if (!isEndDelimited) {
20477
+ route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
20478
+ }
20479
+ }
20480
+ return new RegExp(route, flags(options));
20481
+ }
20482
+ exports2.tokensToRegexp = tokensToRegexp;
20483
+ function pathToRegexp(path6, keys, options) {
20484
+ if (path6 instanceof RegExp)
20485
+ return regexpToRegexp(path6, keys);
20486
+ if (Array.isArray(path6))
20487
+ return arrayToRegexp(path6, keys, options);
20488
+ return stringToRegexp(path6, keys, options);
20489
+ }
20490
+ exports2.pathToRegexp = pathToRegexp;
20491
+ }
20492
+ });
20493
+
20494
+ // ../routing-utils/dist/superstatic.js
20495
+ var require_superstatic = __commonJS({
20496
+ "../routing-utils/dist/superstatic.js"(exports2, module2) {
20497
+ "use strict";
20498
+ var __defProp2 = Object.defineProperty;
20499
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
20500
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
20501
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
20502
+ var __export2 = (target, all) => {
20503
+ for (var name in all)
20504
+ __defProp2(target, name, { get: all[name], enumerable: true });
20505
+ };
20506
+ var __copyProps2 = (to, from, except, desc) => {
20507
+ if (from && typeof from === "object" || typeof from === "function") {
20508
+ for (let key of __getOwnPropNames2(from))
20509
+ if (!__hasOwnProp2.call(to, key) && key !== except)
20510
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
20511
+ }
20512
+ return to;
20513
+ };
20514
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
20515
+ var superstatic_exports = {};
20516
+ __export2(superstatic_exports, {
20517
+ collectHasSegments: () => collectHasSegments,
20518
+ convertCleanUrls: () => convertCleanUrls,
20519
+ convertHeaders: () => convertHeaders,
20520
+ convertRedirects: () => convertRedirects,
20521
+ convertRewrites: () => convertRewrites,
20522
+ convertTrailingSlash: () => convertTrailingSlash,
20523
+ getCleanUrls: () => getCleanUrls2,
20524
+ pathToRegexp: () => pathToRegexp,
20525
+ sourceToRegex: () => sourceToRegex2
20526
+ });
20527
+ module2.exports = __toCommonJS2(superstatic_exports);
20528
+ var import_url = require("url");
20529
+ var import_path_to_regexp = require_dist4();
20530
+ var import_path_to_regexp_updated = require_dist5();
20531
+ function cloneKeys(keys) {
20532
+ if (typeof keys === "undefined") {
20533
+ return void 0;
20534
+ }
20535
+ return keys.slice(0);
20536
+ }
20537
+ function compareKeys(left, right) {
20538
+ const leftSerialized = typeof left === "undefined" ? "undefined" : left.toString();
20539
+ const rightSerialized = typeof right === "undefined" ? "undefined" : right.toString();
20540
+ return leftSerialized === rightSerialized;
20541
+ }
20542
+ function pathToRegexp(callerId, path6, keys, options) {
20543
+ const newKeys = cloneKeys(keys);
20544
+ const currentRegExp = (0, import_path_to_regexp.pathToRegexp)(path6, keys, options);
20545
+ try {
20546
+ const currentKeys = keys;
20547
+ const newRegExp = (0, import_path_to_regexp_updated.pathToRegexp)(path6, newKeys, options);
20548
+ const isDiffRegExp = currentRegExp.toString() !== newRegExp.toString();
20549
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffRegExp) {
20550
+ const message = JSON.stringify({
20551
+ path: path6,
20552
+ currentRegExp: currentRegExp.toString(),
20553
+ newRegExp: newRegExp.toString()
20554
+ });
20555
+ console.error(`[vc] PATH TO REGEXP PATH DIFF @ #${callerId}: ${message}`);
20556
+ }
20557
+ const isDiffKeys = !compareKeys(keys, newKeys);
20558
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffKeys) {
20559
+ const message = JSON.stringify({
20560
+ isDiffKeys,
20561
+ currentKeys,
20562
+ newKeys
20563
+ });
20564
+ console.error(`[vc] PATH TO REGEXP KEYS DIFF @ #${callerId}: ${message}`);
20565
+ }
20566
+ } catch (err) {
20567
+ const error = err;
20568
+ const message = JSON.stringify({
20569
+ path: path6,
20570
+ error: error.message
20571
+ });
20572
+ console.error(`[vc] PATH TO REGEXP ERROR @ #${callerId}: ${message}`);
20573
+ }
20574
+ return currentRegExp;
20575
+ }
20576
+ var UN_NAMED_SEGMENT = "__UN_NAMED_SEGMENT__";
20577
+ function getCleanUrls2(filePaths) {
20578
+ const htmlFiles = filePaths.map(toRoute).filter((f) => f.endsWith(".html")).map((f) => ({
20579
+ html: f,
20580
+ clean: f.slice(0, -5)
20581
+ }));
20582
+ return htmlFiles;
20583
+ }
20584
+ function convertCleanUrls(cleanUrls, trailingSlash, status = 308) {
20585
+ const routes = [];
20586
+ if (cleanUrls) {
20587
+ const loc = trailingSlash ? "/$1/" : "/$1";
20588
+ routes.push({
20589
+ src: "^/(?:(.+)/)?index(?:\\.html)?/?$",
20590
+ headers: { Location: loc },
20591
+ status
20592
+ });
20593
+ routes.push({
20594
+ src: "^/(.*)\\.html/?$",
20595
+ headers: { Location: loc },
20596
+ status
20597
+ });
20598
+ }
20599
+ return routes;
20600
+ }
20601
+ function convertRedirects(redirects, defaultStatus = 308) {
20602
+ return redirects.map((r) => {
20603
+ const { src, segments } = sourceToRegex2(r.source);
20604
+ const hasSegments = collectHasSegments(r.has);
20605
+ normalizeHasKeys(r.has);
20606
+ normalizeHasKeys(r.missing);
20607
+ try {
20608
+ const loc = replaceSegments(segments, hasSegments, r.destination, true);
20609
+ let status;
20610
+ if (typeof r.permanent === "boolean") {
20611
+ status = r.permanent ? 308 : 307;
20612
+ } else if (r.statusCode) {
20613
+ status = r.statusCode;
20614
+ } else {
20615
+ status = defaultStatus;
20616
+ }
20617
+ const route = {
20618
+ src,
20619
+ headers: { Location: loc },
20620
+ status
20621
+ };
20622
+ if (typeof r.env !== "undefined") {
20623
+ route.env = r.env;
20624
+ }
20625
+ if (r.has) {
20626
+ route.has = r.has;
20627
+ }
20628
+ if (r.missing) {
20629
+ route.missing = r.missing;
20630
+ }
20631
+ return route;
20632
+ } catch (e) {
20633
+ throw new Error(`Failed to parse redirect: ${JSON.stringify(r)}`);
20634
+ }
20635
+ });
20636
+ }
20637
+ function convertRewrites(rewrites, internalParamNames) {
20638
+ return rewrites.map((r) => {
20639
+ const { src, segments } = sourceToRegex2(r.source);
20640
+ const hasSegments = collectHasSegments(r.has);
20641
+ normalizeHasKeys(r.has);
20642
+ normalizeHasKeys(r.missing);
20643
+ try {
20644
+ const dest = replaceSegments(
20645
+ segments,
20646
+ hasSegments,
20647
+ r.destination,
20648
+ false,
20649
+ internalParamNames
20650
+ );
20651
+ const route = { src, dest, check: true };
20652
+ if (typeof r.env !== "undefined") {
20653
+ route.env = r.env;
20654
+ }
20655
+ if (r.has) {
20656
+ route.has = r.has;
20657
+ }
20658
+ if (r.missing) {
20659
+ route.missing = r.missing;
20660
+ }
20661
+ if (r.statusCode) {
20662
+ route.status = r.statusCode;
20663
+ }
20664
+ return route;
20665
+ } catch (e) {
20666
+ throw new Error(`Failed to parse rewrite: ${JSON.stringify(r)}`);
20667
+ }
20668
+ });
20669
+ }
20670
+ function convertHeaders(headers) {
20671
+ return headers.map((h) => {
20672
+ const obj = {};
20673
+ const { src, segments } = sourceToRegex2(h.source);
20674
+ const hasSegments = collectHasSegments(h.has);
20675
+ normalizeHasKeys(h.has);
20676
+ normalizeHasKeys(h.missing);
20677
+ const namedSegments = segments.filter((name) => name !== UN_NAMED_SEGMENT);
20678
+ const indexes = {};
20679
+ segments.forEach((name, index) => {
20680
+ indexes[name] = toSegmentDest(index);
20681
+ });
20682
+ hasSegments.forEach((name) => {
20683
+ indexes[name] = "$" + name;
20684
+ });
20685
+ h.headers.forEach(({ key, value }) => {
20686
+ if (namedSegments.length > 0 || hasSegments.length > 0) {
20687
+ if (key.includes(":")) {
20688
+ key = safelyCompile(key, indexes);
20689
+ }
20690
+ if (value.includes(":")) {
20691
+ value = safelyCompile(value, indexes);
20692
+ }
20693
+ }
20694
+ obj[key] = value;
20695
+ });
20696
+ const route = {
20697
+ src,
20698
+ headers: obj,
20699
+ continue: true
20700
+ };
20701
+ if (h.has) {
20702
+ route.has = h.has;
20703
+ }
20704
+ if (h.missing) {
20705
+ route.missing = h.missing;
20706
+ }
20707
+ return route;
20708
+ });
20709
+ }
20710
+ function convertTrailingSlash(enable, status = 308) {
20711
+ const routes = [];
20712
+ if (enable) {
20713
+ routes.push({
20714
+ src: "^/\\.well-known(?:/.*)?$"
20715
+ });
20716
+ routes.push({
20717
+ src: "^/((?:[^/]+/)*[^/\\.]+)$",
20718
+ headers: { Location: "/$1/" },
20719
+ status
20720
+ });
20721
+ routes.push({
20722
+ src: "^/((?:[^/]+/)*[^/]+\\.\\w+)/$",
20723
+ headers: { Location: "/$1" },
20724
+ status
20725
+ });
20726
+ } else {
20727
+ routes.push({
20728
+ src: "^/(.*)\\/$",
20729
+ headers: { Location: "/$1" },
20730
+ status
20731
+ });
20732
+ }
20733
+ return routes;
20734
+ }
20735
+ function sourceToRegex2(source) {
20736
+ const keys = [];
20737
+ const r = pathToRegexp("632", source, keys, {
20738
+ strict: true,
20739
+ sensitive: true,
20740
+ delimiter: "/"
20741
+ });
20742
+ const segments = keys.map((k) => k.name).map((name) => {
20743
+ if (typeof name !== "string") {
20744
+ return UN_NAMED_SEGMENT;
20745
+ }
20746
+ return name;
20747
+ });
20748
+ return { src: r.source, segments };
20749
+ }
20750
+ var namedGroupsRegex = /\(\?<([a-zA-Z][a-zA-Z0-9_]*)>/g;
20751
+ var normalizeHasKeys = (hasItems = []) => {
20752
+ for (const hasItem of hasItems) {
20753
+ if ("key" in hasItem && hasItem.type === "header") {
20754
+ hasItem.key = hasItem.key.toLowerCase();
20755
+ }
20756
+ }
20757
+ return hasItems;
20758
+ };
20759
+ function getStringValueForRegex(value) {
20760
+ if (typeof value === "string") {
20761
+ return value;
20762
+ }
20763
+ if (value && typeof value === "object" && value !== null) {
20764
+ if ("re" in value && typeof value.re === "string") {
20765
+ return value.re;
20766
+ }
20767
+ }
20768
+ return null;
20769
+ }
20770
+ function collectHasSegments(has) {
20771
+ const hasSegments = /* @__PURE__ */ new Set();
20772
+ for (const hasItem of has || []) {
20773
+ if (!hasItem.value && "key" in hasItem) {
20774
+ hasSegments.add(hasItem.key);
20775
+ }
20776
+ const stringValue = getStringValueForRegex(hasItem.value);
20777
+ if (stringValue) {
20778
+ for (const match of stringValue.matchAll(namedGroupsRegex)) {
20779
+ if (match[1]) {
20780
+ hasSegments.add(match[1]);
20781
+ }
20782
+ }
20783
+ if (hasItem.type === "host") {
20784
+ hasSegments.add("host");
20785
+ }
20786
+ }
20787
+ }
20788
+ return [...hasSegments];
20789
+ }
20790
+ var escapeSegment = (str, segmentName) => str.replace(new RegExp(`:${segmentName}`, "g"), `__ESC_COLON_${segmentName}`);
20791
+ var unescapeSegments = (str) => str.replace(/__ESC_COLON_/gi, ":");
20792
+ function replaceSegments(segments, hasItemSegments, destination, isRedirect, internalParamNames) {
20793
+ const namedSegments = segments.filter((name) => name !== UN_NAMED_SEGMENT);
20794
+ const canNeedReplacing = destination.includes(":") && namedSegments.length > 0 || hasItemSegments.length > 0 || !isRedirect;
20795
+ if (!canNeedReplacing) {
20796
+ return destination;
20797
+ }
20798
+ let escapedDestination = destination;
20799
+ const indexes = {};
20800
+ segments.forEach((name, index) => {
20801
+ indexes[name] = toSegmentDest(index);
20802
+ escapedDestination = escapeSegment(escapedDestination, name);
20803
+ });
20804
+ hasItemSegments.forEach((name) => {
20805
+ indexes[name] = "$" + name;
20806
+ escapedDestination = escapeSegment(escapedDestination, name);
20807
+ });
20808
+ const parsedDestination = (0, import_url.parse)(escapedDestination, true);
20809
+ delete parsedDestination.href;
20810
+ delete parsedDestination.path;
20811
+ delete parsedDestination.search;
20812
+ delete parsedDestination.host;
20813
+ let { pathname, hash, query, hostname, ...rest } = parsedDestination;
20814
+ pathname = unescapeSegments(pathname || "");
20815
+ hash = unescapeSegments(hash || "");
20816
+ hostname = unescapeSegments(hostname || "");
20817
+ let destParams = /* @__PURE__ */ new Set();
20818
+ const pathnameKeys = [];
20819
+ const hashKeys = [];
20820
+ const hostnameKeys = [];
20821
+ try {
20822
+ pathToRegexp("528", pathname, pathnameKeys);
20823
+ pathToRegexp("834", hash || "", hashKeys);
20824
+ pathToRegexp("712", hostname || "", hostnameKeys);
20825
+ } catch (_) {
20826
+ }
20827
+ destParams = new Set(
20828
+ [...pathnameKeys, ...hashKeys, ...hostnameKeys].map((key) => key.name).filter((val) => typeof val === "string")
20829
+ );
20830
+ pathname = safelyCompile(pathname, indexes, true);
20831
+ hash = hash ? safelyCompile(hash, indexes, true) : null;
20832
+ hostname = hostname ? safelyCompile(hostname, indexes, true) : null;
20833
+ for (const [key, strOrArray] of Object.entries(query)) {
20834
+ if (Array.isArray(strOrArray)) {
20835
+ query[key] = strOrArray.map(
20836
+ (str) => safelyCompile(unescapeSegments(str), indexes, true)
20837
+ );
20838
+ } else {
20839
+ query[key] = safelyCompile(
20840
+ unescapeSegments(strOrArray),
20841
+ indexes,
20842
+ true
20843
+ );
20844
+ }
20845
+ }
20846
+ const paramKeys = Object.keys(indexes);
20847
+ const needsQueryUpdating = (
20848
+ // we do not consider an internal param since it is added automatically
20849
+ !isRedirect && !paramKeys.some(
20850
+ (param) => !(internalParamNames && internalParamNames.includes(param)) && destParams.has(param)
20851
+ )
20852
+ );
20853
+ if (needsQueryUpdating) {
20854
+ for (const param of paramKeys) {
20855
+ if (!(param in query) && param !== UN_NAMED_SEGMENT) {
20856
+ query[param] = indexes[param];
20857
+ }
20858
+ }
20859
+ }
20860
+ destination = (0, import_url.format)({
20861
+ ...rest,
20862
+ hostname,
20863
+ pathname,
20864
+ query,
20865
+ hash
20866
+ });
20867
+ return destination.replace(/%24/g, "$");
20868
+ }
20869
+ function safelyCompile(value, indexes, attemptDirectCompile) {
20870
+ if (!value) {
20871
+ return value;
20872
+ }
20873
+ if (attemptDirectCompile) {
20874
+ try {
20875
+ return (0, import_path_to_regexp.compile)(value, { validate: false })(indexes);
20876
+ } catch (e) {
20877
+ }
20878
+ }
20879
+ for (const key of Object.keys(indexes)) {
20880
+ if (value.includes(`:${key}`)) {
20881
+ value = value.replace(
20882
+ new RegExp(`:${key}\\*`, "g"),
20883
+ `:${key}--ESCAPED_PARAM_ASTERISK`
20884
+ ).replace(
20885
+ new RegExp(`:${key}\\?`, "g"),
20886
+ `:${key}--ESCAPED_PARAM_QUESTION`
20887
+ ).replace(new RegExp(`:${key}\\+`, "g"), `:${key}--ESCAPED_PARAM_PLUS`).replace(
20888
+ new RegExp(`:${key}(?!\\w)`, "g"),
20889
+ `--ESCAPED_PARAM_COLON${key}`
20890
+ );
20891
+ }
20892
+ }
20893
+ 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, "*");
20894
+ return (0, import_path_to_regexp.compile)(`/${value}`, { validate: false })(indexes).slice(1);
20895
+ }
20896
+ function toSegmentDest(index) {
20897
+ const i = index + 1;
20898
+ return "$" + i.toString();
20899
+ }
20900
+ function toRoute(filePath) {
20901
+ return filePath.startsWith("/") ? filePath : "/" + filePath;
20902
+ }
20903
+ }
20904
+ });
20905
+
20906
+ // ../routing-utils/dist/append.js
20907
+ var require_append = __commonJS({
20908
+ "../routing-utils/dist/append.js"(exports2, module2) {
20909
+ "use strict";
20910
+ var __defProp2 = Object.defineProperty;
20911
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
20912
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
20913
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
20914
+ var __export2 = (target, all) => {
20915
+ for (var name in all)
20916
+ __defProp2(target, name, { get: all[name], enumerable: true });
20917
+ };
20918
+ var __copyProps2 = (to, from, except, desc) => {
20919
+ if (from && typeof from === "object" || typeof from === "function") {
20920
+ for (let key of __getOwnPropNames2(from))
20921
+ if (!__hasOwnProp2.call(to, key) && key !== except)
20922
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
20923
+ }
20924
+ return to;
20925
+ };
20926
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
20927
+ var append_exports = {};
20928
+ __export2(append_exports, {
20929
+ appendRoutesToPhase: () => appendRoutesToPhase2
20930
+ });
20931
+ module2.exports = __toCommonJS2(append_exports);
20932
+ var import_index = require_dist6();
20933
+ function appendRoutesToPhase2({
20934
+ routes: prevRoutes,
20935
+ newRoutes,
20936
+ phase
20937
+ }) {
20938
+ const routes = prevRoutes ? [...prevRoutes] : [];
20939
+ if (newRoutes === null || newRoutes.length === 0) {
20940
+ return routes;
20941
+ }
20942
+ let isInPhase = false;
20943
+ let insertIndex = -1;
20944
+ routes.forEach((r, i) => {
20945
+ if ((0, import_index.isHandler)(r)) {
20946
+ if (r.handle === phase) {
20947
+ isInPhase = true;
20948
+ } else if (isInPhase) {
20949
+ insertIndex = i;
20950
+ isInPhase = false;
20951
+ }
20952
+ }
20953
+ });
20954
+ if (isInPhase) {
20955
+ routes.push(...newRoutes);
20956
+ } else if (phase === null) {
20957
+ const lastPhase = routes.findIndex((r) => (0, import_index.isHandler)(r) && r.handle);
20958
+ if (lastPhase === -1) {
20959
+ routes.push(...newRoutes);
20960
+ } else {
20961
+ routes.splice(lastPhase, 0, ...newRoutes);
20962
+ }
20963
+ } else if (insertIndex > -1) {
20964
+ routes.splice(insertIndex, 0, ...newRoutes);
20965
+ } else {
20966
+ routes.push({ handle: phase });
20967
+ routes.push(...newRoutes);
20968
+ }
20969
+ return routes;
20970
+ }
20971
+ }
20972
+ });
20973
+
20974
+ // ../routing-utils/dist/merge.js
20975
+ var require_merge2 = __commonJS({
20976
+ "../routing-utils/dist/merge.js"(exports2, module2) {
20977
+ "use strict";
20978
+ var __defProp2 = Object.defineProperty;
20979
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
20980
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
20981
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
20982
+ var __export2 = (target, all) => {
20983
+ for (var name in all)
20984
+ __defProp2(target, name, { get: all[name], enumerable: true });
20985
+ };
20986
+ var __copyProps2 = (to, from, except, desc) => {
20987
+ if (from && typeof from === "object" || typeof from === "function") {
20988
+ for (let key of __getOwnPropNames2(from))
20989
+ if (!__hasOwnProp2.call(to, key) && key !== except)
20990
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
20991
+ }
20992
+ return to;
20993
+ };
20994
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
20995
+ var merge_exports = {};
20996
+ __export2(merge_exports, {
20997
+ mergeRoutes: () => mergeRoutes2
20998
+ });
20999
+ module2.exports = __toCommonJS2(merge_exports);
21000
+ var import_index = require_dist6();
21001
+ function getBuilderRoutesMapping(builds) {
21002
+ const builderRoutes = {};
21003
+ for (const { entrypoint, routes, use } of builds) {
21004
+ if (routes) {
21005
+ if (!builderRoutes[entrypoint]) {
21006
+ builderRoutes[entrypoint] = {};
21007
+ }
21008
+ builderRoutes[entrypoint][use] = routes;
21009
+ }
21010
+ }
21011
+ return builderRoutes;
21012
+ }
21013
+ function getCheckAndContinue(routes) {
21014
+ const checks = [];
21015
+ const continues = [];
21016
+ const others = [];
21017
+ for (const route of routes) {
21018
+ if ((0, import_index.isHandler)(route)) {
21019
+ throw new Error(
21020
+ `Unexpected route found in getCheckAndContinue(): ${JSON.stringify(
21021
+ route
21022
+ )}`
21023
+ );
21024
+ } else if (route.check && !route.override) {
21025
+ checks.push(route);
21026
+ } else if (route.continue && !route.override) {
21027
+ continues.push(route);
21028
+ } else {
21029
+ others.push(route);
21030
+ }
21031
+ }
21032
+ return { checks, continues, others };
21033
+ }
21034
+ function mergeRoutes2({ userRoutes, builds }) {
21035
+ const userHandleMap = /* @__PURE__ */ new Map();
21036
+ let userPrevHandle = null;
21037
+ (userRoutes || []).forEach((route) => {
21038
+ if ((0, import_index.isHandler)(route)) {
21039
+ userPrevHandle = route.handle;
21040
+ } else {
21041
+ const routes = userHandleMap.get(userPrevHandle);
21042
+ if (!routes) {
21043
+ userHandleMap.set(userPrevHandle, [route]);
21044
+ } else {
21045
+ routes.push(route);
21046
+ }
21047
+ }
21048
+ });
21049
+ const builderHandleMap = /* @__PURE__ */ new Map();
21050
+ const builderRoutes = getBuilderRoutesMapping(builds);
21051
+ const sortedPaths = Object.keys(builderRoutes).sort();
21052
+ sortedPaths.forEach((path6) => {
21053
+ const br = builderRoutes[path6];
21054
+ const sortedBuilders = Object.keys(br).sort();
21055
+ sortedBuilders.forEach((use) => {
21056
+ let builderPrevHandle = null;
21057
+ br[use].forEach((route) => {
21058
+ if ((0, import_index.isHandler)(route)) {
21059
+ builderPrevHandle = route.handle;
21060
+ } else {
21061
+ const routes = builderHandleMap.get(builderPrevHandle);
21062
+ if (!routes) {
21063
+ builderHandleMap.set(builderPrevHandle, [route]);
21064
+ } else {
21065
+ routes.push(route);
21066
+ }
21067
+ }
21068
+ });
21069
+ });
21070
+ });
21071
+ const outputRoutes = [];
21072
+ const uniqueHandleValues = /* @__PURE__ */ new Set([
21073
+ null,
21074
+ ...userHandleMap.keys(),
21075
+ ...builderHandleMap.keys()
21076
+ ]);
21077
+ for (const handle of uniqueHandleValues) {
21078
+ const userRoutes2 = userHandleMap.get(handle) || [];
21079
+ const builderRoutes2 = builderHandleMap.get(handle) || [];
21080
+ const builderSorted = getCheckAndContinue(builderRoutes2);
21081
+ if (handle !== null && (userRoutes2.length > 0 || builderRoutes2.length > 0)) {
21082
+ outputRoutes.push({ handle });
21083
+ }
21084
+ outputRoutes.push(...builderSorted.continues);
21085
+ outputRoutes.push(...userRoutes2);
21086
+ outputRoutes.push(...builderSorted.checks);
21087
+ outputRoutes.push(...builderSorted.others);
21088
+ }
21089
+ return outputRoutes;
21090
+ }
21091
+ }
21092
+ });
21093
+
21094
+ // ../routing-utils/dist/service-route-ownership.js
21095
+ var require_service_route_ownership = __commonJS({
21096
+ "../routing-utils/dist/service-route-ownership.js"(exports2, module2) {
21097
+ "use strict";
21098
+ var __defProp2 = Object.defineProperty;
21099
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
21100
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
21101
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
21102
+ var __export2 = (target, all) => {
21103
+ for (var name in all)
21104
+ __defProp2(target, name, { get: all[name], enumerable: true });
21105
+ };
21106
+ var __copyProps2 = (to, from, except, desc) => {
21107
+ if (from && typeof from === "object" || typeof from === "function") {
21108
+ for (let key of __getOwnPropNames2(from))
21109
+ if (!__hasOwnProp2.call(to, key) && key !== except)
21110
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
21111
+ }
21112
+ return to;
21113
+ };
21114
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
21115
+ var service_route_ownership_exports = {};
21116
+ __export2(service_route_ownership_exports, {
21117
+ getOwnershipGuard: () => getOwnershipGuard2,
21118
+ normalizeRoutePrefix: () => normalizeRoutePrefix2,
21119
+ scopeRouteSourceToOwnership: () => scopeRouteSourceToOwnership2
21120
+ });
21121
+ module2.exports = __toCommonJS2(service_route_ownership_exports);
21122
+ function normalizeRoutePrefix2(routePrefix) {
21123
+ let normalized = routePrefix.startsWith("/") ? routePrefix : `/${routePrefix}`;
21124
+ if (normalized !== "/" && normalized.endsWith("/")) {
21125
+ normalized = normalized.slice(0, -1);
21126
+ }
21127
+ return normalized || "/";
21128
+ }
21129
+ function escapeForRegex(value) {
21130
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
21131
+ }
21132
+ function toPrefixMatcher(routePrefix) {
21133
+ return `${escapeForRegex(routePrefix)}(?:/|$)`;
21134
+ }
21135
+ function isDescendantPrefix(candidate, prefix) {
21136
+ return candidate !== prefix && candidate.startsWith(`${prefix}/`);
21137
+ }
21138
+ function getOwnershipGuard2(ownerPrefix, allRoutePrefixes) {
21139
+ const owner = normalizeRoutePrefix2(ownerPrefix);
21140
+ const normalizedPrefixes = Array.from(
21141
+ new Set(allRoutePrefixes.map(normalizeRoutePrefix2))
21142
+ );
21143
+ const nonRootPrefixes = normalizedPrefixes.filter((prefix) => prefix !== "/").sort((a, b) => b.length - a.length);
21144
+ if (owner === "/") {
21145
+ return nonRootPrefixes.map((prefix) => `(?!${toPrefixMatcher(prefix)})`).join("");
21146
+ }
21147
+ const descendants = nonRootPrefixes.filter(
21148
+ (prefix) => isDescendantPrefix(prefix, owner)
21149
+ );
21150
+ const positive = `(?=${toPrefixMatcher(owner)})`;
21151
+ const negative = descendants.map((prefix) => `(?!${toPrefixMatcher(prefix)})`).join("");
21152
+ return `${positive}${negative}`;
21153
+ }
21154
+ function scopeRouteSourceToOwnership2(source, ownershipGuard) {
21155
+ if (!ownershipGuard) {
21156
+ return source;
21157
+ }
21158
+ const inner = source.startsWith("^") ? source.slice(1) : source;
21159
+ return `^${ownershipGuard}(?:${inner})`;
21160
+ }
21161
+ }
21162
+ });
21163
+
21164
+ // ../routing-utils/dist/schemas.js
21165
+ var require_schemas = __commonJS({
21166
+ "../routing-utils/dist/schemas.js"(exports2, module2) {
21167
+ "use strict";
21168
+ var __defProp2 = Object.defineProperty;
21169
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
21170
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
21171
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
21172
+ var __export2 = (target, all) => {
21173
+ for (var name in all)
21174
+ __defProp2(target, name, { get: all[name], enumerable: true });
21175
+ };
21176
+ var __copyProps2 = (to, from, except, desc) => {
21177
+ if (from && typeof from === "object" || typeof from === "function") {
21178
+ for (let key of __getOwnPropNames2(from))
21179
+ if (!__hasOwnProp2.call(to, key) && key !== except)
21180
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
21181
+ }
21182
+ return to;
21183
+ };
21184
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
21185
+ var schemas_exports = {};
21186
+ __export2(schemas_exports, {
21187
+ bulkRedirectsSchema: () => bulkRedirectsSchema,
21188
+ cleanUrlsSchema: () => cleanUrlsSchema,
21189
+ hasSchema: () => hasSchema,
21190
+ headersSchema: () => headersSchema,
21191
+ redirectsSchema: () => redirectsSchema,
21192
+ rewritesSchema: () => rewritesSchema,
21193
+ routesSchema: () => routesSchema,
21194
+ trailingSlashSchema: () => trailingSlashSchema
21195
+ });
21196
+ module2.exports = __toCommonJS2(schemas_exports);
21197
+ var mitigateSchema = {
21198
+ description: "Mitigation action to take on a route",
21199
+ type: "object",
21200
+ additionalProperties: false,
21201
+ required: ["action"],
21202
+ properties: {
21203
+ action: {
21204
+ description: "The mitigation action to take",
21205
+ type: "string",
21206
+ enum: ["challenge", "deny"]
21207
+ }
21208
+ }
21209
+ };
21210
+ var matchableValueSchema = {
21211
+ description: "A value to match against. Can be a string (regex) or a condition operation object",
21212
+ anyOf: [
21213
+ {
21214
+ description: "A regular expression used to match thev value. Named groups can be used in the destination.",
21215
+ type: "string",
21216
+ maxLength: 4096
21217
+ },
21218
+ {
21219
+ description: "A condition operation object",
21220
+ type: "object",
21221
+ additionalProperties: false,
21222
+ minProperties: 1,
21223
+ properties: {
21224
+ eq: {
21225
+ description: "Equal to",
21226
+ anyOf: [
21227
+ {
21228
+ type: "string",
21229
+ maxLength: 4096
21230
+ },
21231
+ {
21232
+ type: "number"
21233
+ }
21234
+ ]
21235
+ },
21236
+ neq: {
21237
+ description: "Not equal",
21238
+ type: "string",
21239
+ maxLength: 4096
21240
+ },
21241
+ inc: {
21242
+ description: "In array",
21243
+ type: "array",
21244
+ items: {
21245
+ type: "string",
21246
+ maxLength: 4096
21247
+ }
21248
+ },
21249
+ ninc: {
21250
+ description: "Not in array",
21251
+ type: "array",
21252
+ items: {
21253
+ type: "string",
21254
+ maxLength: 4096
21255
+ }
21256
+ },
21257
+ pre: {
21258
+ description: "Starts with",
21259
+ type: "string",
21260
+ maxLength: 4096
21261
+ },
21262
+ suf: {
21263
+ description: "Ends with",
21264
+ type: "string",
21265
+ maxLength: 4096
21266
+ },
21267
+ re: {
21268
+ description: "Regex",
21269
+ type: "string",
21270
+ maxLength: 4096
21271
+ },
21272
+ gt: {
21273
+ description: "Greater than",
21274
+ type: "number"
21275
+ },
21276
+ gte: {
21277
+ description: "Greater than or equal to",
21278
+ type: "number"
21279
+ },
21280
+ lt: {
21281
+ description: "Less than",
21282
+ type: "number"
21283
+ },
21284
+ lte: {
21285
+ description: "Less than or equal to",
21286
+ type: "number"
21287
+ }
21288
+ }
21289
+ }
21290
+ ]
21291
+ };
21292
+ var hasSchema = {
21293
+ description: "An array of requirements that are needed to match",
21294
+ type: "array",
21295
+ maxItems: 16,
21296
+ items: {
21297
+ anyOf: [
21298
+ {
21299
+ type: "object",
21300
+ additionalProperties: false,
21301
+ required: ["type", "value"],
21302
+ properties: {
21303
+ type: {
21304
+ description: "The type of request element to check",
21305
+ type: "string",
21306
+ enum: ["host"]
21307
+ },
21308
+ value: matchableValueSchema
21309
+ }
21310
+ },
21311
+ {
21312
+ type: "object",
21313
+ additionalProperties: false,
21314
+ required: ["type", "key"],
21315
+ properties: {
21316
+ type: {
21317
+ description: "The type of request element to check",
21318
+ type: "string",
21319
+ enum: ["header", "cookie", "query"]
21320
+ },
21321
+ key: {
21322
+ description: "The name of the element contained in the particular type",
21323
+ type: "string",
21324
+ maxLength: 4096
21325
+ },
21326
+ value: matchableValueSchema
21327
+ }
21328
+ }
21329
+ ]
21330
+ }
21331
+ };
21332
+ var transformsSchema = {
21333
+ description: "A list of transform rules to adjust the query parameters of a request or HTTP headers of request or response",
21334
+ type: "array",
21335
+ minItems: 1,
21336
+ items: {
21337
+ type: "object",
21338
+ additionalProperties: false,
21339
+ required: ["type", "op", "target"],
21340
+ properties: {
21341
+ type: {
21342
+ description: "The scope of the transform to apply",
21343
+ type: "string",
21344
+ enum: ["request.headers", "request.query", "response.headers"]
21345
+ },
21346
+ op: {
21347
+ description: "The operation to perform on the target",
21348
+ type: "string",
21349
+ enum: ["append", "set", "delete"]
21350
+ },
21351
+ target: {
21352
+ description: "The target of the transform",
21353
+ type: "object",
21354
+ required: ["key"],
21355
+ properties: {
21356
+ // re is not supported for transforms. Once supported, replace target.key with matchableValueSchema
21357
+ key: {
21358
+ description: "A value to match against. Can be a string or a condition operation object (without regex support)",
21359
+ anyOf: [
21360
+ {
21361
+ description: "A valid header name (letters, numbers, hyphens, underscores)",
21362
+ type: "string",
21363
+ maxLength: 4096
21364
+ },
21365
+ {
21366
+ description: "A condition operation object",
21367
+ type: "object",
21368
+ additionalProperties: false,
21369
+ minProperties: 1,
21370
+ properties: {
21371
+ eq: {
21372
+ description: "Equal to",
21373
+ anyOf: [
21374
+ {
21375
+ type: "string",
21376
+ maxLength: 4096
21377
+ },
21378
+ {
21379
+ type: "number"
21380
+ }
21381
+ ]
21382
+ },
21383
+ neq: {
21384
+ description: "Not equal",
21385
+ type: "string",
21386
+ maxLength: 4096
21387
+ },
21388
+ inc: {
21389
+ description: "In array",
21390
+ type: "array",
21391
+ items: {
21392
+ type: "string",
21393
+ maxLength: 4096
21394
+ }
21395
+ },
21396
+ ninc: {
21397
+ description: "Not in array",
21398
+ type: "array",
21399
+ items: {
21400
+ type: "string",
21401
+ maxLength: 4096
21402
+ }
21403
+ },
21404
+ pre: {
21405
+ description: "Starts with",
21406
+ type: "string",
21407
+ maxLength: 4096
21408
+ },
21409
+ suf: {
21410
+ description: "Ends with",
21411
+ type: "string",
21412
+ maxLength: 4096
21413
+ },
21414
+ gt: {
21415
+ description: "Greater than",
21416
+ type: "number"
21417
+ },
21418
+ gte: {
21419
+ description: "Greater than or equal to",
21420
+ type: "number"
21421
+ },
21422
+ lt: {
21423
+ description: "Less than",
21424
+ type: "number"
21425
+ },
21426
+ lte: {
21427
+ description: "Less than or equal to",
21428
+ type: "number"
21429
+ }
21430
+ }
21431
+ }
21432
+ ]
21433
+ }
21434
+ }
21435
+ },
21436
+ args: {
21437
+ description: "The arguments to the operation",
21438
+ anyOf: [
21439
+ {
21440
+ type: "string",
21441
+ maxLength: 4096
21442
+ },
21443
+ {
21444
+ type: "array",
21445
+ minItems: 1,
21446
+ items: {
21447
+ type: "string",
21448
+ maxLength: 4096
21449
+ }
21450
+ }
21451
+ ]
21452
+ },
21453
+ env: {
21454
+ description: "An array of environment variable names that should be replaced at runtime in the args value",
21455
+ type: "array",
21456
+ minItems: 1,
21457
+ maxItems: 64,
21458
+ items: {
21459
+ type: "string",
21460
+ maxLength: 256
21461
+ }
21462
+ }
21463
+ },
21464
+ allOf: [
21465
+ {
21466
+ if: {
21467
+ properties: {
21468
+ op: {
21469
+ enum: ["append", "set"]
21470
+ }
21471
+ }
21472
+ },
21473
+ then: {
21474
+ required: ["args"]
21475
+ }
21476
+ },
21477
+ {
21478
+ if: {
21479
+ allOf: [
21480
+ {
21481
+ properties: {
21482
+ type: {
21483
+ enum: ["request.headers", "response.headers"]
21484
+ }
21485
+ }
21486
+ },
21487
+ {
21488
+ properties: {
21489
+ op: {
21490
+ enum: ["set", "append"]
21491
+ }
21492
+ }
21493
+ }
21494
+ ]
21495
+ },
21496
+ then: {
21497
+ properties: {
21498
+ target: {
21499
+ properties: {
21500
+ key: {
21501
+ if: {
21502
+ type: "string"
21503
+ },
21504
+ then: {
21505
+ pattern: "^[a-zA-Z0-9_-]+$"
21506
+ }
21507
+ }
21508
+ }
21509
+ },
21510
+ args: {
21511
+ anyOf: [
21512
+ {
21513
+ type: "string",
21514
+ pattern: "^[a-zA-Z0-9_ :;.,\"'?!(){}\\[\\]@<>=+*#$&`|~\\^%/-]+$"
21515
+ },
21516
+ {
21517
+ type: "array",
21518
+ items: {
21519
+ type: "string",
21520
+ pattern: "^[a-zA-Z0-9_ :;.,\"'?!(){}\\[\\]@<>=+*#$&`|~\\^%/-]+$"
21521
+ }
21522
+ }
21523
+ ]
21524
+ }
21525
+ }
21526
+ }
21527
+ }
21528
+ ]
21529
+ }
21530
+ };
21531
+ var routesSchema = {
21532
+ type: "array",
21533
+ deprecated: true,
21534
+ description: "A list of routes objects used to rewrite paths to point towards other internal or external paths",
21535
+ example: [{ dest: "https://docs.example.com", src: "/docs" }],
21536
+ items: {
21537
+ anyOf: [
21538
+ {
21539
+ type: "object",
21540
+ required: ["src"],
21541
+ additionalProperties: false,
21542
+ properties: {
21543
+ src: {
21544
+ type: "string",
21545
+ maxLength: 4096
21546
+ },
21547
+ dest: {
21548
+ type: "string",
21549
+ maxLength: 4096
21550
+ },
21551
+ headers: {
21552
+ type: "object",
21553
+ additionalProperties: false,
21554
+ minProperties: 1,
21555
+ maxProperties: 100,
21556
+ patternProperties: {
21557
+ "^.{1,256}$": {
21558
+ type: "string",
21559
+ maxLength: 32768
21560
+ }
21561
+ }
21562
+ },
21563
+ methods: {
21564
+ type: "array",
21565
+ maxItems: 10,
21566
+ items: {
21567
+ type: "string",
21568
+ maxLength: 32
21569
+ }
21570
+ },
21571
+ caseSensitive: {
21572
+ type: "boolean"
21573
+ },
21574
+ important: {
21575
+ type: "boolean"
21576
+ },
21577
+ user: {
21578
+ type: "boolean"
21579
+ },
21580
+ continue: {
21581
+ type: "boolean"
21582
+ },
21583
+ override: {
21584
+ type: "boolean"
21585
+ },
21586
+ check: {
21587
+ type: "boolean"
21588
+ },
21589
+ isInternal: {
21590
+ type: "boolean"
21591
+ },
21592
+ status: {
21593
+ type: "integer",
21594
+ minimum: 100,
21595
+ maximum: 999
21596
+ },
21597
+ locale: {
21598
+ type: "object",
21599
+ additionalProperties: false,
21600
+ minProperties: 1,
21601
+ properties: {
21602
+ redirect: {
21603
+ type: "object",
21604
+ additionalProperties: false,
21605
+ minProperties: 1,
21606
+ maxProperties: 100,
21607
+ patternProperties: {
21608
+ "^.{1,256}$": {
21609
+ type: "string",
21610
+ maxLength: 4096
21611
+ }
21612
+ }
21613
+ },
21614
+ value: {
21615
+ type: "string",
21616
+ maxLength: 4096
21617
+ },
21618
+ path: {
21619
+ type: "string",
21620
+ maxLength: 4096
21621
+ },
21622
+ cookie: {
21623
+ type: "string",
21624
+ maxLength: 4096
21625
+ },
21626
+ default: {
21627
+ type: "string",
21628
+ maxLength: 4096
21629
+ }
21630
+ }
21631
+ },
21632
+ middleware: { type: "number" },
21633
+ middlewarePath: { type: "string" },
21634
+ middlewareRawSrc: {
21635
+ type: "array",
21636
+ items: {
21637
+ type: "string"
21638
+ }
21639
+ },
21640
+ has: hasSchema,
21641
+ missing: hasSchema,
21642
+ mitigate: mitigateSchema,
21643
+ transforms: transformsSchema,
21644
+ env: {
21645
+ description: "An array of environment variable names that should be replaced at runtime in the destination or headers",
21646
+ type: "array",
21647
+ minItems: 1,
21648
+ maxItems: 64,
21649
+ items: {
21650
+ type: "string",
21651
+ maxLength: 256
21652
+ }
21653
+ },
21654
+ respectOriginCacheControl: {
21655
+ description: "When set to true (default), external rewrites will respect the Cache-Control header from the origin. When false, caching is disabled for this rewrite.",
21656
+ type: "boolean"
21657
+ }
21658
+ }
21659
+ },
21660
+ {
21661
+ type: "object",
21662
+ required: ["handle"],
21663
+ additionalProperties: false,
21664
+ properties: {
21665
+ handle: {
21666
+ type: "string",
21667
+ maxLength: 32,
21668
+ enum: ["error", "filesystem", "hit", "miss", "resource", "rewrite"]
21669
+ }
21670
+ }
21671
+ }
21672
+ ]
21673
+ }
21674
+ };
21675
+ var rewritesSchema = {
21676
+ type: "array",
21677
+ maxItems: 2048,
21678
+ description: "A list of rewrite definitions.",
21679
+ items: {
21680
+ type: "object",
21681
+ additionalProperties: false,
21682
+ required: ["source", "destination"],
21683
+ properties: {
21684
+ source: {
21685
+ description: "A pattern that matches each incoming pathname (excluding querystring).",
21686
+ type: "string",
21687
+ maxLength: 4096
21688
+ },
21689
+ destination: {
21690
+ description: "An absolute pathname to an existing resource or an external URL.",
21691
+ type: "string",
21692
+ maxLength: 4096
21693
+ },
21694
+ has: hasSchema,
21695
+ missing: hasSchema,
21696
+ statusCode: {
21697
+ description: "An optional integer to override the status code of the response.",
21698
+ type: "integer",
21699
+ minimum: 100,
21700
+ maximum: 999
21701
+ },
21702
+ env: {
21703
+ description: "An array of environment variable names that should be replaced at runtime in the destination",
21704
+ type: "array",
21705
+ minItems: 1,
21706
+ maxItems: 64,
21707
+ items: {
21708
+ type: "string",
21709
+ maxLength: 256
21710
+ }
21711
+ },
21712
+ respectOriginCacheControl: {
21713
+ description: "When set to true (default), external rewrites will respect the Cache-Control header from the origin. When false, caching is disabled for this rewrite.",
21714
+ type: "boolean"
21715
+ }
21716
+ }
21717
+ }
21718
+ };
21719
+ var redirectsSchema = {
21720
+ title: "Redirects",
21721
+ type: "array",
21722
+ maxItems: 2048,
21723
+ description: "A list of redirect definitions.",
21724
+ items: {
21725
+ type: "object",
21726
+ additionalProperties: false,
21727
+ required: ["source", "destination"],
21728
+ properties: {
21729
+ source: {
21730
+ description: "A pattern that matches each incoming pathname (excluding querystring).",
21731
+ type: "string",
21732
+ maxLength: 4096
21733
+ },
21734
+ destination: {
21735
+ description: "A location destination defined as an absolute pathname or external URL.",
21736
+ type: "string",
21737
+ maxLength: 4096
21738
+ },
21739
+ permanent: {
21740
+ description: "A boolean to toggle between permanent and temporary redirect. When `true`, the status code is `308`. When `false` the status code is `307`.",
21741
+ type: "boolean"
21742
+ },
21743
+ statusCode: {
21744
+ description: "An optional integer to define the status code of the redirect.",
21745
+ private: true,
21746
+ type: "integer",
21747
+ minimum: 100,
21748
+ maximum: 999
21749
+ },
21750
+ has: hasSchema,
21751
+ missing: hasSchema,
21752
+ env: {
21753
+ description: "An array of environment variable names that should be replaced at runtime in the destination",
21754
+ type: "array",
21755
+ minItems: 1,
21756
+ maxItems: 64,
21757
+ items: {
21758
+ type: "string",
21759
+ maxLength: 256
21760
+ }
21761
+ }
21762
+ }
21763
+ }
21764
+ };
21765
+ var headersSchema = {
21766
+ type: "array",
21767
+ maxItems: 2048,
21768
+ description: "A list of header definitions.",
21769
+ items: {
21770
+ type: "object",
21771
+ additionalProperties: false,
21772
+ required: ["source", "headers"],
21773
+ properties: {
21774
+ source: {
21775
+ description: "A pattern that matches each incoming pathname (excluding querystring)",
21776
+ type: "string",
21777
+ maxLength: 4096
21778
+ },
21779
+ headers: {
21780
+ description: "An array of key/value pairs representing each response header.",
21781
+ type: "array",
21782
+ maxItems: 1024,
21783
+ items: {
21784
+ type: "object",
21785
+ additionalProperties: false,
21786
+ required: ["key", "value"],
21787
+ properties: {
21788
+ key: {
21789
+ type: "string",
21790
+ maxLength: 4096
21791
+ },
21792
+ value: {
21793
+ type: "string",
21794
+ maxLength: 32768
21795
+ }
21796
+ }
21797
+ }
21798
+ },
21799
+ has: hasSchema,
21800
+ missing: hasSchema
21801
+ }
21802
+ }
21803
+ };
21804
+ var cleanUrlsSchema = {
21805
+ 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.",
21806
+ type: "boolean"
21807
+ };
21808
+ var trailingSlashSchema = {
21809
+ 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.",
21810
+ type: "boolean"
21811
+ };
21812
+ var bulkRedirectsSchema = {
21813
+ type: "array",
21814
+ description: "A list of bulk redirect definitions.",
21815
+ items: {
21816
+ type: "object",
21817
+ additionalProperties: false,
21818
+ required: ["source", "destination"],
21819
+ properties: {
21820
+ source: {
21821
+ description: "The exact URL path or pattern to match.",
21822
+ type: "string",
21823
+ maxLength: 2048
21824
+ },
21825
+ destination: {
21826
+ description: "The target URL path where traffic should be redirected.",
21827
+ type: "string",
21828
+ maxLength: 2048
21829
+ },
21830
+ permanent: {
21831
+ description: "A boolean to toggle between permanent and temporary redirect. When `true`, the status code is `308`. When `false` the status code is `307`.",
21832
+ type: "boolean"
21833
+ },
21834
+ statusCode: {
21835
+ description: "An optional integer to define the status code of the redirect.",
21836
+ type: "integer",
21837
+ enum: [301, 302, 307, 308]
21838
+ },
21839
+ sensitive: {
21840
+ description: "A boolean to toggle between case-sensitive and case-insensitive redirect. When `true`, the redirect is case-sensitive. When `false` the redirect is case-insensitive.",
21841
+ type: "boolean"
21842
+ },
21843
+ query: {
21844
+ description: "Whether the query string should be preserved by the redirect. The default is `false`.",
21845
+ type: "boolean"
21846
+ }
21847
+ }
21848
+ }
21849
+ };
21850
+ }
21851
+ });
21852
+
21853
+ // ../routing-utils/dist/types.js
21854
+ var require_types2 = __commonJS({
21855
+ "../routing-utils/dist/types.js"(exports2, module2) {
21856
+ "use strict";
21857
+ var __defProp2 = Object.defineProperty;
21858
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
21859
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
21860
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
21861
+ var __copyProps2 = (to, from, except, desc) => {
21862
+ if (from && typeof from === "object" || typeof from === "function") {
21863
+ for (let key of __getOwnPropNames2(from))
21864
+ if (!__hasOwnProp2.call(to, key) && key !== except)
21865
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
21866
+ }
21867
+ return to;
21868
+ };
21869
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
21870
+ var types_exports = {};
21871
+ module2.exports = __toCommonJS2(types_exports);
21872
+ }
21873
+ });
21874
+
21875
+ // ../routing-utils/dist/index.js
21876
+ var require_dist6 = __commonJS({
21877
+ "../routing-utils/dist/index.js"(exports2, module2) {
21878
+ "use strict";
21879
+ var __defProp2 = Object.defineProperty;
21880
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
21881
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
21882
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
21883
+ var __export2 = (target, all) => {
21884
+ for (var name in all)
21885
+ __defProp2(target, name, { get: all[name], enumerable: true });
21886
+ };
21887
+ var __copyProps2 = (to, from, except, desc) => {
21888
+ if (from && typeof from === "object" || typeof from === "function") {
21889
+ for (let key of __getOwnPropNames2(from))
21890
+ if (!__hasOwnProp2.call(to, key) && key !== except)
21891
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
21892
+ }
21893
+ return to;
21894
+ };
21895
+ var __reExport = (target, mod, secondTarget) => (__copyProps2(target, mod, "default"), secondTarget && __copyProps2(secondTarget, mod, "default"));
21896
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
21897
+ var src_exports2 = {};
21898
+ __export2(src_exports2, {
21899
+ appendRoutesToPhase: () => import_append.appendRoutesToPhase,
21900
+ getCleanUrls: () => import_superstatic2.getCleanUrls,
21901
+ getOwnershipGuard: () => import_service_route_ownership.getOwnershipGuard,
21902
+ getTransformedRoutes: () => getTransformedRoutes,
21903
+ isHandler: () => isHandler,
21904
+ isValidHandleValue: () => isValidHandleValue,
21905
+ mergeRoutes: () => import_merge.mergeRoutes,
21906
+ normalizeRoutePrefix: () => import_service_route_ownership.normalizeRoutePrefix,
21907
+ normalizeRoutes: () => normalizeRoutes,
21908
+ scopeRouteSourceToOwnership: () => import_service_route_ownership.scopeRouteSourceToOwnership,
21909
+ sourceToRegex: () => import_superstatic2.sourceToRegex
21910
+ });
21911
+ module2.exports = __toCommonJS2(src_exports2);
21912
+ var import_url = require("url");
21913
+ var import_superstatic = require_superstatic();
21914
+ var import_append = require_append();
21915
+ var import_merge = require_merge2();
21916
+ var import_service_route_ownership = require_service_route_ownership();
21917
+ __reExport(src_exports2, require_schemas(), module2.exports);
21918
+ var import_superstatic2 = require_superstatic();
21919
+ __reExport(src_exports2, require_types2(), module2.exports);
21920
+ var VALID_HANDLE_VALUES = [
21921
+ "filesystem",
21922
+ "hit",
21923
+ "miss",
21924
+ "rewrite",
21925
+ "error",
21926
+ "resource"
21927
+ ];
21928
+ var validHandleValues = new Set(VALID_HANDLE_VALUES);
21929
+ function isHandler(route) {
21930
+ return typeof route.handle !== "undefined";
21931
+ }
21932
+ function isValidHandleValue(handle) {
21933
+ return validHandleValues.has(handle);
21934
+ }
21935
+ function normalizeRoutes(inputRoutes) {
21936
+ if (!inputRoutes || inputRoutes.length === 0) {
21937
+ return { routes: inputRoutes, error: null };
21938
+ }
21939
+ const routes = [];
21940
+ const handling = [];
21941
+ const errors = [];
21942
+ inputRoutes.forEach((r, i) => {
21943
+ const route = { ...r };
21944
+ routes.push(route);
21945
+ const keys = Object.keys(route);
21946
+ if (isHandler(route)) {
21947
+ const { handle } = route;
21948
+ if (keys.length !== 1) {
21949
+ const unknownProp = keys.find((prop) => prop !== "handle");
21950
+ errors.push(
21951
+ `Route at index ${i} has unknown property \`${unknownProp}\`.`
21952
+ );
21953
+ } else if (!isValidHandleValue(handle)) {
21954
+ errors.push(
21955
+ `Route at index ${i} has unknown handle value \`handle: ${handle}\`.`
21956
+ );
21957
+ } else if (handling.includes(handle)) {
21958
+ errors.push(
21959
+ `Route at index ${i} is a duplicate. Please use one \`handle: ${handle}\` at most.`
21960
+ );
21961
+ } else {
21962
+ handling.push(handle);
21963
+ }
21964
+ } else if (route.src) {
21965
+ if (!route.src.startsWith("^")) {
21966
+ route.src = `^${route.src}`;
21967
+ }
21968
+ if (!route.src.endsWith("$")) {
21969
+ route.src = `${route.src}$`;
21970
+ }
21971
+ route.src = route.src.replace(/\\\//g, "/");
21972
+ const regError = checkRegexSyntax("Route", i, route.src);
21973
+ if (regError) {
21974
+ errors.push(regError);
21975
+ }
21976
+ const handleValue = handling[handling.length - 1];
21977
+ if (handleValue === "hit") {
21978
+ if (route.dest) {
21979
+ errors.push(
21980
+ `Route at index ${i} cannot define \`dest\` after \`handle: hit\`.`
21981
+ );
21982
+ }
21983
+ if (route.status) {
21984
+ errors.push(
21985
+ `Route at index ${i} cannot define \`status\` after \`handle: hit\`.`
21986
+ );
21987
+ }
21988
+ if (!route.continue) {
21989
+ errors.push(
21990
+ `Route at index ${i} must define \`continue: true\` after \`handle: hit\`.`
21991
+ );
21992
+ }
21993
+ } else if (handleValue === "miss") {
21994
+ if (route.dest && !route.check) {
21995
+ errors.push(
21996
+ `Route at index ${i} must define \`check: true\` after \`handle: miss\`.`
21997
+ );
21998
+ } else if (!route.dest && !route.continue) {
21999
+ errors.push(
22000
+ `Route at index ${i} must define \`continue: true\` after \`handle: miss\`.`
22001
+ );
22002
+ }
22003
+ }
22004
+ } else {
22005
+ errors.push(
22006
+ `Route at index ${i} must define either \`handle\` or \`src\` property.`
22007
+ );
22008
+ }
22009
+ });
22010
+ const error = errors.length > 0 ? createError(
22011
+ "invalid_route",
22012
+ errors,
22013
+ "https://vercel.link/routes-json",
22014
+ "Learn More"
22015
+ ) : null;
22016
+ return { routes, error };
22017
+ }
22018
+ function checkRegexSyntax(type, index, src) {
22019
+ try {
22020
+ new RegExp(src);
22021
+ } catch (err) {
22022
+ const prop = type === "Route" ? "src" : "source";
22023
+ return `${type} at index ${index} has invalid \`${prop}\` regular expression "${src}".`;
22024
+ }
22025
+ return null;
22026
+ }
22027
+ function checkPatternSyntax(type, index, {
22028
+ source,
22029
+ destination,
22030
+ has
22031
+ }) {
22032
+ let sourceSegments = /* @__PURE__ */ new Set();
22033
+ const destinationSegments = /* @__PURE__ */ new Set();
22034
+ try {
22035
+ sourceSegments = new Set((0, import_superstatic.sourceToRegex)(source).segments);
22036
+ } catch (err) {
22037
+ return {
22038
+ message: `${type} at index ${index} has invalid \`source\` pattern "${source}".`,
22039
+ link: "https://vercel.link/invalid-route-source-pattern"
22040
+ };
22041
+ }
22042
+ if (destination) {
22043
+ try {
22044
+ const { hostname, pathname, query } = (0, import_url.parse)(destination, true);
22045
+ (0, import_superstatic.sourceToRegex)(hostname || "").segments.forEach(
22046
+ (name) => destinationSegments.add(name)
22047
+ );
22048
+ (0, import_superstatic.sourceToRegex)(pathname || "").segments.forEach(
22049
+ (name) => destinationSegments.add(name)
22050
+ );
22051
+ for (const strOrArray of Object.values(query)) {
22052
+ const value = Array.isArray(strOrArray) ? strOrArray[0] : strOrArray;
22053
+ (0, import_superstatic.sourceToRegex)(value || "").segments.forEach(
22054
+ (name) => destinationSegments.add(name)
22055
+ );
22056
+ }
22057
+ } catch (err) {
22058
+ }
22059
+ const hasSegments = (0, import_superstatic.collectHasSegments)(has);
22060
+ for (const segment of destinationSegments) {
22061
+ if (!sourceSegments.has(segment) && !hasSegments.includes(segment)) {
22062
+ return {
22063
+ message: `${type} at index ${index} has segment ":${segment}" in \`destination\` property but not in \`source\` or \`has\` property.`,
22064
+ link: "https://vercel.link/invalid-route-destination-segment"
22065
+ };
22066
+ }
22067
+ }
22068
+ }
22069
+ return null;
22070
+ }
22071
+ function checkRedirect(r, index) {
22072
+ if (typeof r.permanent !== "undefined" && typeof r.statusCode !== "undefined") {
22073
+ return `Redirect at index ${index} cannot define both \`permanent\` and \`statusCode\` properties.`;
22074
+ }
22075
+ return null;
22076
+ }
22077
+ function createError(code, allErrors, link, action) {
22078
+ const errors = Array.isArray(allErrors) ? allErrors : [allErrors];
22079
+ const message = errors[0];
22080
+ const error = {
22081
+ name: "RouteApiError",
22082
+ code,
22083
+ message,
22084
+ link,
22085
+ action,
22086
+ errors
22087
+ };
22088
+ return error;
22089
+ }
22090
+ function notEmpty(value) {
22091
+ return value !== null && value !== void 0;
22092
+ }
22093
+ function getTransformedRoutes(vercelConfig) {
22094
+ const { cleanUrls, rewrites, redirects, headers, trailingSlash } = vercelConfig;
22095
+ let { routes = null } = vercelConfig;
22096
+ if (routes) {
22097
+ const hasNewProperties = typeof cleanUrls !== "undefined" || typeof trailingSlash !== "undefined" || typeof redirects !== "undefined" || typeof headers !== "undefined" || typeof rewrites !== "undefined";
22098
+ if (hasNewProperties) {
22099
+ const error = createError(
22100
+ "invalid_mixed_routes",
22101
+ "If `rewrites`, `redirects`, `headers`, `cleanUrls` or `trailingSlash` are used, then `routes` cannot be present.",
22102
+ "https://vercel.link/mix-routing-props",
22103
+ "Learn More"
22104
+ );
22105
+ return { routes, error };
22106
+ }
22107
+ return normalizeRoutes(routes);
22108
+ }
22109
+ if (typeof cleanUrls !== "undefined") {
22110
+ const normalized = normalizeRoutes(
22111
+ (0, import_superstatic.convertCleanUrls)(cleanUrls, trailingSlash)
22112
+ );
22113
+ if (normalized.error) {
22114
+ normalized.error.code = "invalid_clean_urls";
22115
+ return { routes, error: normalized.error };
22116
+ }
22117
+ routes = routes || [];
22118
+ routes.push(...normalized.routes || []);
22119
+ }
22120
+ if (typeof trailingSlash !== "undefined") {
22121
+ const normalized = normalizeRoutes((0, import_superstatic.convertTrailingSlash)(trailingSlash));
22122
+ if (normalized.error) {
22123
+ normalized.error.code = "invalid_trailing_slash";
22124
+ return { routes, error: normalized.error };
22125
+ }
22126
+ routes = routes || [];
22127
+ routes.push(...normalized.routes || []);
22128
+ }
22129
+ if (typeof redirects !== "undefined") {
22130
+ const code = "invalid_redirect";
22131
+ const regexErrorMessage = redirects.map((r, i) => checkRegexSyntax("Redirect", i, r.source)).find(notEmpty);
22132
+ if (regexErrorMessage) {
22133
+ return {
22134
+ routes,
22135
+ error: createError(
22136
+ "invalid_redirect",
22137
+ regexErrorMessage,
22138
+ "https://vercel.link/invalid-route-source-pattern",
22139
+ "Learn More"
22140
+ )
22141
+ };
22142
+ }
22143
+ const patternError = redirects.map((r, i) => checkPatternSyntax("Redirect", i, r)).find(notEmpty);
22144
+ if (patternError) {
22145
+ return {
22146
+ routes,
22147
+ error: createError(
22148
+ code,
22149
+ patternError.message,
22150
+ patternError.link,
22151
+ "Learn More"
22152
+ )
22153
+ };
22154
+ }
22155
+ const redirectErrorMessage = redirects.map(checkRedirect).find(notEmpty);
22156
+ if (redirectErrorMessage) {
22157
+ return {
22158
+ routes,
22159
+ error: createError(
22160
+ code,
22161
+ redirectErrorMessage,
22162
+ "https://vercel.link/redirects-json",
22163
+ "Learn More"
22164
+ )
22165
+ };
22166
+ }
22167
+ const normalized = normalizeRoutes((0, import_superstatic.convertRedirects)(redirects));
22168
+ if (normalized.error) {
22169
+ normalized.error.code = code;
22170
+ return { routes, error: normalized.error };
22171
+ }
22172
+ routes = routes || [];
22173
+ routes.push(...normalized.routes || []);
22174
+ }
22175
+ if (typeof headers !== "undefined") {
22176
+ const code = "invalid_header";
22177
+ const regexErrorMessage = headers.map((r, i) => checkRegexSyntax("Header", i, r.source)).find(notEmpty);
22178
+ if (regexErrorMessage) {
22179
+ return {
22180
+ routes,
22181
+ error: createError(
22182
+ code,
22183
+ regexErrorMessage,
22184
+ "https://vercel.link/invalid-route-source-pattern",
22185
+ "Learn More"
22186
+ )
22187
+ };
22188
+ }
22189
+ const patternError = headers.map((r, i) => checkPatternSyntax("Header", i, r)).find(notEmpty);
22190
+ if (patternError) {
22191
+ return {
22192
+ routes,
22193
+ error: createError(
22194
+ code,
22195
+ patternError.message,
22196
+ patternError.link,
22197
+ "Learn More"
22198
+ )
22199
+ };
22200
+ }
22201
+ const normalized = normalizeRoutes((0, import_superstatic.convertHeaders)(headers));
22202
+ if (normalized.error) {
22203
+ normalized.error.code = code;
22204
+ return { routes, error: normalized.error };
22205
+ }
22206
+ routes = routes || [];
22207
+ routes.push(...normalized.routes || []);
22208
+ }
22209
+ if (typeof rewrites !== "undefined") {
22210
+ const code = "invalid_rewrite";
22211
+ const regexErrorMessage = rewrites.map((r, i) => checkRegexSyntax("Rewrite", i, r.source)).find(notEmpty);
22212
+ if (regexErrorMessage) {
22213
+ return {
22214
+ routes,
22215
+ error: createError(
22216
+ code,
22217
+ regexErrorMessage,
22218
+ "https://vercel.link/invalid-route-source-pattern",
22219
+ "Learn More"
22220
+ )
22221
+ };
22222
+ }
22223
+ const patternError = rewrites.map((r, i) => checkPatternSyntax("Rewrite", i, r)).find(notEmpty);
22224
+ if (patternError) {
22225
+ return {
22226
+ routes,
22227
+ error: createError(
22228
+ code,
22229
+ patternError.message,
22230
+ patternError.link,
22231
+ "Learn More"
22232
+ )
22233
+ };
22234
+ }
22235
+ const normalized = normalizeRoutes((0, import_superstatic.convertRewrites)(rewrites));
22236
+ if (normalized.error) {
22237
+ normalized.error.code = code;
22238
+ return { routes, error: normalized.error };
22239
+ }
22240
+ routes = routes || [];
22241
+ routes.push({ handle: "filesystem" });
22242
+ routes.push(...normalized.routes || []);
22243
+ }
22244
+ return { routes, error: null };
22245
+ }
22246
+ }
22247
+ });
22248
+
22249
+ // ../fs-detectors/dist/services/types.js
22250
+ var require_types3 = __commonJS({
22251
+ "../fs-detectors/dist/services/types.js"(exports2, module2) {
22252
+ "use strict";
22253
+ var __defProp2 = Object.defineProperty;
22254
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
22255
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
22256
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
22257
+ var __export2 = (target, all) => {
22258
+ for (var name in all)
22259
+ __defProp2(target, name, { get: all[name], enumerable: true });
22260
+ };
22261
+ var __copyProps2 = (to, from, except, desc) => {
22262
+ if (from && typeof from === "object" || typeof from === "function") {
22263
+ for (let key of __getOwnPropNames2(from))
22264
+ if (!__hasOwnProp2.call(to, key) && key !== except)
22265
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
22266
+ }
22267
+ return to;
22268
+ };
22269
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
22270
+ var types_exports = {};
22271
+ __export2(types_exports, {
22272
+ ENTRYPOINT_EXTENSIONS: () => ENTRYPOINT_EXTENSIONS,
22273
+ ROUTE_OWNING_BUILDERS: () => ROUTE_OWNING_BUILDERS,
22274
+ RUNTIME_BUILDERS: () => RUNTIME_BUILDERS,
22275
+ RUNTIME_MANIFESTS: () => RUNTIME_MANIFESTS,
22276
+ STATIC_BUILDERS: () => STATIC_BUILDERS
22277
+ });
22278
+ module2.exports = __toCommonJS2(types_exports);
22279
+ var RUNTIME_BUILDERS = {
22280
+ node: "@vercel/node",
22281
+ python: "@vercel/python",
22282
+ go: "@vercel/go",
22283
+ rust: "@vercel/rust",
22284
+ ruby: "@vercel/ruby"
22285
+ };
22286
+ var RUNTIME_MANIFESTS = {
22287
+ node: ["package.json"],
22288
+ python: [
22289
+ "pyproject.toml",
22290
+ "requirements.txt",
22291
+ "Pipfile",
22292
+ "pylock.yml",
22293
+ "uv.lock",
22294
+ "setup.py"
22295
+ ],
22296
+ go: ["go.mod"],
22297
+ ruby: ["Gemfile"],
22298
+ rust: ["Cargo.toml"]
22299
+ };
22300
+ var ENTRYPOINT_EXTENSIONS = {
22301
+ ".ts": "node",
22302
+ ".mts": "node",
22303
+ ".js": "node",
22304
+ ".mjs": "node",
22305
+ ".cjs": "node",
22306
+ ".py": "python",
22307
+ ".go": "go",
22308
+ ".rs": "rust",
22309
+ ".rb": "ruby",
22310
+ ".ru": "ruby"
22311
+ };
22312
+ var STATIC_BUILDERS = /* @__PURE__ */ new Set([
22313
+ "@vercel/static-build",
22314
+ "@vercel/static"
22315
+ ]);
22316
+ var ROUTE_OWNING_BUILDERS = /* @__PURE__ */ new Set([
22317
+ "@vercel/next",
22318
+ "@vercel/backends"
22319
+ ]);
22320
+ }
22321
+ });
22322
+
22323
+ // ../fs-detectors/dist/services/utils.js
22324
+ var require_utils4 = __commonJS({
22325
+ "../fs-detectors/dist/services/utils.js"(exports2, module2) {
22326
+ "use strict";
22327
+ var __defProp2 = Object.defineProperty;
22328
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
22329
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
22330
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
22331
+ var __export2 = (target, all) => {
22332
+ for (var name in all)
22333
+ __defProp2(target, name, { get: all[name], enumerable: true });
22334
+ };
22335
+ var __copyProps2 = (to, from, except, desc) => {
22336
+ if (from && typeof from === "object" || typeof from === "function") {
22337
+ for (let key of __getOwnPropNames2(from))
22338
+ if (!__hasOwnProp2.call(to, key) && key !== except)
22339
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
22340
+ }
22341
+ return to;
22342
+ };
22343
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
22344
+ var utils_exports = {};
22345
+ __export2(utils_exports, {
22346
+ INTERNAL_SERVICE_PREFIX: () => INTERNAL_SERVICE_PREFIX2,
22347
+ getBuilderForRuntime: () => getBuilderForRuntime,
22348
+ getInternalServiceFunctionPath: () => getInternalServiceFunctionPath2,
22349
+ hasFile: () => hasFile,
22350
+ inferServiceRuntime: () => inferServiceRuntime,
22351
+ isRouteOwningBuilder: () => isRouteOwningBuilder2,
22352
+ isStaticBuild: () => isStaticBuild2,
22353
+ readVercelConfig: () => readVercelConfig
22354
+ });
22355
+ module2.exports = __toCommonJS2(utils_exports);
22356
+ var import_framework_helpers = require("@vercel/build-utils/dist/framework-helpers");
22357
+ var import_types = require_types3();
22358
+ async function hasFile(fs5, filePath) {
22359
+ try {
22360
+ return await fs5.isFile(filePath);
22361
+ } catch {
22362
+ return false;
22363
+ }
22364
+ }
22365
+ var INTERNAL_SERVICE_PREFIX2 = "/_svc";
22366
+ function getInternalServiceFunctionPath2(serviceName) {
22367
+ return `${INTERNAL_SERVICE_PREFIX2}/${serviceName}/index`;
22368
+ }
22369
+ function getBuilderForRuntime(runtime) {
22370
+ const builder = import_types.RUNTIME_BUILDERS[runtime];
22371
+ if (!builder) {
22372
+ throw new Error(`Unknown runtime: ${runtime}`);
22373
+ }
22374
+ return builder;
22375
+ }
22376
+ function isStaticBuild2(service) {
22377
+ return import_types.STATIC_BUILDERS.has(service.builder.use);
22378
+ }
22379
+ function isRouteOwningBuilder2(service) {
22380
+ return import_types.ROUTE_OWNING_BUILDERS.has(service.builder.use);
22381
+ }
22382
+ function inferServiceRuntime(config) {
22383
+ if (config.runtime && config.runtime in import_types.RUNTIME_BUILDERS) {
22384
+ return config.runtime;
22385
+ }
22386
+ if ((0, import_framework_helpers.isPythonFramework)(config.framework)) {
22387
+ return "python";
22388
+ }
22389
+ if ((0, import_framework_helpers.isBackendFramework)(config.framework)) {
22390
+ return "node";
22391
+ }
22392
+ if (config.builder) {
22393
+ for (const [runtime, builderName] of Object.entries(import_types.RUNTIME_BUILDERS)) {
22394
+ if (config.builder === builderName) {
22395
+ return runtime;
22396
+ }
22397
+ }
22398
+ }
22399
+ if (config.entrypoint) {
22400
+ for (const [ext, runtime] of Object.entries(import_types.ENTRYPOINT_EXTENSIONS)) {
22401
+ if (config.entrypoint.endsWith(ext)) {
22402
+ return runtime;
22403
+ }
22404
+ }
22405
+ }
22406
+ return void 0;
22407
+ }
22408
+ async function readVercelConfig(fs5) {
22409
+ const hasVercelJson = await fs5.hasPath("vercel.json");
22410
+ if (!hasVercelJson) {
22411
+ return { config: null, error: null };
22412
+ }
22413
+ try {
22414
+ const content = await fs5.readFile("vercel.json");
22415
+ const config = JSON.parse(content.toString());
22416
+ return { config, error: null };
22417
+ } catch {
22418
+ return {
22419
+ config: null,
22420
+ error: {
22421
+ code: "INVALID_VERCEL_JSON",
22422
+ message: "Failed to parse vercel.json. Ensure it contains valid JSON."
22423
+ }
22424
+ };
22425
+ }
22426
+ }
22427
+ }
22428
+ });
22429
+
22430
+ // ../fs-detectors/dist/services/resolve.js
22431
+ var require_resolve = __commonJS({
22432
+ "../fs-detectors/dist/services/resolve.js"(exports2, module2) {
22433
+ "use strict";
22434
+ var __create2 = Object.create;
22435
+ var __defProp2 = Object.defineProperty;
22436
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
22437
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
22438
+ var __getProtoOf2 = Object.getPrototypeOf;
22439
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
22440
+ var __export2 = (target, all) => {
22441
+ for (var name in all)
22442
+ __defProp2(target, name, { get: all[name], enumerable: true });
22443
+ };
22444
+ var __copyProps2 = (to, from, except, desc) => {
22445
+ if (from && typeof from === "object" || typeof from === "function") {
22446
+ for (let key of __getOwnPropNames2(from))
22447
+ if (!__hasOwnProp2.call(to, key) && key !== except)
22448
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
22449
+ }
22450
+ return to;
22451
+ };
22452
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
22453
+ // If the importer is in node compatibility mode or this is not an ESM
22454
+ // file that has been converted to a CommonJS file using a Babel-
22455
+ // compatible transform (i.e. "__esModule" has not been set), then set
22456
+ // "default" to the CommonJS "module.exports" for node compatibility.
19911
22457
  isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
19912
22458
  mod
19913
22459
  ));
@@ -19920,17 +22466,70 @@ var require_resolve = __commonJS({
19920
22466
  });
19921
22467
  module2.exports = __toCommonJS2(resolve_exports);
19922
22468
  var import_path7 = require("path");
19923
- var import_types = require_types2();
22469
+ var import_types = require_types3();
19924
22470
  var import_utils = require_utils4();
19925
22471
  var import_frameworks2 = __toESM2(require_frameworks());
22472
+ var import_routing_utils = require_dist6();
19926
22473
  var frameworksBySlug = new Map(import_frameworks2.default.map((f) => [f.slug, f]));
19927
22474
  var SERVICE_NAME_REGEX = /^[a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$/;
19928
- function normalizeRoutePrefix(routePrefix) {
19929
- let normalized = routePrefix.startsWith("/") ? routePrefix : `/${routePrefix}`;
19930
- if (normalized !== "/" && normalized.endsWith("/")) {
19931
- normalized = normalized.slice(0, -1);
22475
+ function toWorkspaceRelativeEntrypoint(entrypoint, workspace) {
22476
+ const normalizedEntrypoint = import_path7.posix.normalize(entrypoint);
22477
+ if (workspace === ".") {
22478
+ return normalizedEntrypoint;
19932
22479
  }
19933
- return normalized || "/";
22480
+ const workspacePrefix = `${workspace}/`;
22481
+ if (normalizedEntrypoint.startsWith(workspacePrefix)) {
22482
+ return normalizedEntrypoint.slice(workspacePrefix.length);
22483
+ }
22484
+ const relativeEntrypoint = import_path7.posix.relative(
22485
+ workspace,
22486
+ normalizedEntrypoint
22487
+ );
22488
+ if (relativeEntrypoint === "" || relativeEntrypoint.startsWith("..")) {
22489
+ return normalizedEntrypoint;
22490
+ }
22491
+ return relativeEntrypoint;
22492
+ }
22493
+ async function inferWorkspaceFromNearestManifest({
22494
+ fs: fs5,
22495
+ entrypoint,
22496
+ runtime
22497
+ }) {
22498
+ if (!entrypoint || !runtime) {
22499
+ return void 0;
22500
+ }
22501
+ const manifests = import_types.RUNTIME_MANIFESTS[runtime];
22502
+ if (!manifests || manifests.length === 0) {
22503
+ return void 0;
22504
+ }
22505
+ let dir = import_path7.posix.dirname(import_path7.posix.normalize(entrypoint)) || ".";
22506
+ if (dir === "") {
22507
+ dir = ".";
22508
+ }
22509
+ let reachedRoot = false;
22510
+ while (!reachedRoot) {
22511
+ for (const manifest of manifests) {
22512
+ const manifestPath = dir === "." ? manifest : import_path7.posix.join(dir, manifest);
22513
+ if (await (0, import_utils.hasFile)(fs5, manifestPath)) {
22514
+ return dir;
22515
+ }
22516
+ }
22517
+ if (dir === "." || dir === "/") {
22518
+ reachedRoot = true;
22519
+ } else {
22520
+ const parent = import_path7.posix.dirname(dir);
22521
+ if (!parent || parent === dir) {
22522
+ reachedRoot = true;
22523
+ } else {
22524
+ dir = parent;
22525
+ }
22526
+ }
22527
+ }
22528
+ return void 0;
22529
+ }
22530
+ function isReservedServiceRoutePrefix(routePrefix) {
22531
+ const normalized = (0, import_routing_utils.normalizeRoutePrefix)(routePrefix);
22532
+ return normalized === import_utils.INTERNAL_SERVICE_PREFIX || normalized.startsWith(`${import_utils.INTERNAL_SERVICE_PREFIX}/`);
19934
22533
  }
19935
22534
  function validateServiceConfig(name, config) {
19936
22535
  if (!SERVICE_NAME_REGEX.test(name)) {
@@ -19955,6 +22554,13 @@ var require_resolve = __commonJS({
19955
22554
  serviceName: name
19956
22555
  };
19957
22556
  }
22557
+ if (serviceType === "web" && config.routePrefix && isReservedServiceRoutePrefix(config.routePrefix)) {
22558
+ return {
22559
+ code: "RESERVED_ROUTE_PREFIX",
22560
+ message: `Web service "${name}" cannot use routePrefix "${config.routePrefix}". The "${import_utils.INTERNAL_SERVICE_PREFIX}" prefix is reserved for internal services routing.`,
22561
+ serviceName: name
22562
+ };
22563
+ }
19958
22564
  if ((serviceType === "worker" || serviceType === "cron") && config.routePrefix) {
19959
22565
  return {
19960
22566
  code: "INVALID_ROUTE_PREFIX",
@@ -20013,24 +22619,41 @@ var require_resolve = __commonJS({
20013
22619
  }
20014
22620
  return null;
20015
22621
  }
20016
- function resolveConfiguredService(name, config, group) {
22622
+ async function resolveConfiguredService(name, config, fs5, group) {
20017
22623
  const type = config.type || "web";
20018
- const workspace = config.workspace || ".";
22624
+ const inferredRuntime = (0, import_utils.inferServiceRuntime)(config);
22625
+ let workspace = config.workspace || ".";
22626
+ let resolvedEntrypoint = config.entrypoint;
22627
+ if (!config.workspace) {
22628
+ const inferredWorkspace = await inferWorkspaceFromNearestManifest({
22629
+ fs: fs5,
22630
+ entrypoint: resolvedEntrypoint,
22631
+ runtime: inferredRuntime
22632
+ });
22633
+ if (inferredWorkspace) {
22634
+ workspace = inferredWorkspace;
22635
+ if (resolvedEntrypoint) {
22636
+ resolvedEntrypoint = toWorkspaceRelativeEntrypoint(
22637
+ resolvedEntrypoint,
22638
+ inferredWorkspace
22639
+ );
22640
+ }
22641
+ }
22642
+ }
20019
22643
  const topic = type === "worker" ? config.topic || "default" : config.topic;
20020
22644
  const consumer = type === "worker" ? config.consumer || "default" : config.consumer;
20021
- const inferredRuntime = (0, import_utils.inferServiceRuntime)(config);
20022
22645
  let builderUse;
20023
22646
  let builderSrc;
20024
22647
  if (config.framework) {
20025
22648
  const framework = frameworksBySlug.get(config.framework);
20026
22649
  builderUse = framework?.useRuntime?.use || "@vercel/static-build";
20027
- builderSrc = config.entrypoint || framework?.useRuntime?.src || "package.json";
22650
+ builderSrc = resolvedEntrypoint || framework?.useRuntime?.src || "package.json";
20028
22651
  } else if (config.builder) {
20029
22652
  builderUse = config.builder;
20030
- builderSrc = config.entrypoint;
22653
+ builderSrc = resolvedEntrypoint;
20031
22654
  } else {
20032
22655
  builderUse = (0, import_utils.getBuilderForRuntime)(inferredRuntime);
20033
- builderSrc = config.entrypoint;
22656
+ builderSrc = resolvedEntrypoint;
20034
22657
  }
20035
22658
  const routePrefix = type === "web" && config.routePrefix ? config.routePrefix.startsWith("/") ? config.routePrefix : `/${config.routePrefix}` : void 0;
20036
22659
  const isRoot = workspace === ".";
@@ -20063,7 +22686,7 @@ var require_resolve = __commonJS({
20063
22686
  type,
20064
22687
  group,
20065
22688
  workspace,
20066
- entrypoint: config.entrypoint,
22689
+ entrypoint: resolvedEntrypoint,
20067
22690
  routePrefix,
20068
22691
  framework: config.framework,
20069
22692
  builder: {
@@ -20079,7 +22702,7 @@ var require_resolve = __commonJS({
20079
22702
  consumer
20080
22703
  };
20081
22704
  }
20082
- function resolveAllConfiguredServices(services) {
22705
+ async function resolveAllConfiguredServices(services, fs5) {
20083
22706
  const resolved = [];
20084
22707
  const errors = [];
20085
22708
  const webServicesByRoutePrefix = /* @__PURE__ */ new Map();
@@ -20090,9 +22713,9 @@ var require_resolve = __commonJS({
20090
22713
  errors.push(validationError);
20091
22714
  continue;
20092
22715
  }
20093
- const service = resolveConfiguredService(name, serviceConfig);
22716
+ const service = await resolveConfiguredService(name, serviceConfig, fs5);
20094
22717
  if (service.type === "web" && typeof service.routePrefix === "string") {
20095
- const normalizedRoutePrefix = normalizeRoutePrefix(service.routePrefix);
22718
+ const normalizedRoutePrefix = (0, import_routing_utils.normalizeRoutePrefix)(service.routePrefix);
20096
22719
  const existingServiceName = webServicesByRoutePrefix.get(
20097
22720
  normalizedRoutePrefix
20098
22721
  );
@@ -20622,7 +23245,7 @@ var require_detect_services = __commonJS({
20622
23245
  generateServicesRoutes: () => generateServicesRoutes2
20623
23246
  });
20624
23247
  module2.exports = __toCommonJS2(detect_services_exports);
20625
- var import_types = require_types2();
23248
+ var import_routing_utils = require_dist6();
20626
23249
  var import_utils = require_utils4();
20627
23250
  var import_resolve = require_resolve();
20628
23251
  var import_auto_detect = require_auto_detect();
@@ -20651,7 +23274,10 @@ var require_detect_services = __commonJS({
20651
23274
  };
20652
23275
  }
20653
23276
  if (autoResult.services) {
20654
- const result2 = (0, import_resolve.resolveAllConfiguredServices)(autoResult.services);
23277
+ const result2 = await (0, import_resolve.resolveAllConfiguredServices)(
23278
+ autoResult.services,
23279
+ scopedFs
23280
+ );
20655
23281
  const routes2 = generateServicesRoutes2(result2.services);
20656
23282
  return {
20657
23283
  services: result2.services,
@@ -20672,7 +23298,10 @@ var require_detect_services = __commonJS({
20672
23298
  warnings: []
20673
23299
  };
20674
23300
  }
20675
- const result = (0, import_resolve.resolveAllConfiguredServices)(configuredServices);
23301
+ const result = await (0, import_resolve.resolveAllConfiguredServices)(
23302
+ configuredServices,
23303
+ scopedFs
23304
+ );
20676
23305
  const routes = generateServicesRoutes2(result.services);
20677
23306
  return {
20678
23307
  services: result.services,
@@ -20686,45 +23315,47 @@ var require_detect_services = __commonJS({
20686
23315
  const defaults = [];
20687
23316
  const crons = [];
20688
23317
  const workers = [];
20689
- const entrypointExtensions = Object.keys(import_types.ENTRYPOINT_EXTENSIONS).sort(
20690
- (a, b) => b.length - a.length
20691
- );
20692
- const stripEntrypointExtension = (entrypoint) => {
20693
- for (const ext of entrypointExtensions) {
20694
- if (entrypoint.endsWith(ext)) {
20695
- return entrypoint.slice(0, -ext.length);
20696
- }
20697
- }
20698
- return entrypoint;
20699
- };
20700
23318
  const sortedWebServices = services.filter(
20701
23319
  (s) => s.type === "web" && typeof s.routePrefix === "string"
20702
23320
  ).sort((a, b) => b.routePrefix.length - a.routePrefix.length);
23321
+ const allWebPrefixes = getWebRoutePrefixes(sortedWebServices);
20703
23322
  for (const service of sortedWebServices) {
20704
23323
  const { routePrefix } = service;
20705
23324
  const normalizedPrefix = routePrefix.slice(1);
23325
+ const ownershipGuard = (0, import_routing_utils.getOwnershipGuard)(routePrefix, allWebPrefixes);
20706
23326
  if ((0, import_utils.isRouteOwningBuilder)(service)) {
20707
23327
  continue;
20708
23328
  }
20709
23329
  if ((0, import_utils.isStaticBuild)(service)) {
20710
23330
  if (routePrefix === "/") {
20711
23331
  defaults.push({ handle: "filesystem" });
20712
- defaults.push({ src: "/(.*)", dest: "/index.html" });
23332
+ defaults.push({
23333
+ src: (0, import_routing_utils.scopeRouteSourceToOwnership)("/(.*)", ownershipGuard),
23334
+ dest: "/index.html"
23335
+ });
20713
23336
  } else {
20714
23337
  rewrites.push({
20715
- src: `^/${normalizedPrefix}(?:/.*)?$`,
23338
+ src: (0, import_routing_utils.scopeRouteSourceToOwnership)(
23339
+ `^/${normalizedPrefix}(?:/.*)?$`,
23340
+ ownershipGuard
23341
+ ),
20716
23342
  dest: `/${normalizedPrefix}/index.html`
20717
23343
  });
20718
23344
  }
20719
23345
  } else if (service.runtime) {
20720
- const builderSrc = service.builder.src || routePrefix;
20721
- const extensionless = stripEntrypointExtension(builderSrc);
20722
- const functionPath = extensionless.startsWith("/") ? extensionless : `/${extensionless}`;
23346
+ const functionPath = (0, import_utils.getInternalServiceFunctionPath)(service.name);
20723
23347
  if (routePrefix === "/") {
20724
- defaults.push({ src: "^/(.*)$", dest: functionPath, check: true });
23348
+ defaults.push({
23349
+ src: (0, import_routing_utils.scopeRouteSourceToOwnership)("^/(.*)$", ownershipGuard),
23350
+ dest: functionPath,
23351
+ check: true
23352
+ });
20725
23353
  } else {
20726
23354
  rewrites.push({
20727
- src: `^/${normalizedPrefix}(?:/.*)?$`,
23355
+ src: (0, import_routing_utils.scopeRouteSourceToOwnership)(
23356
+ `^/${normalizedPrefix}(?:/.*)?$`,
23357
+ ownershipGuard
23358
+ ),
20728
23359
  dest: functionPath,
20729
23360
  check: true
20730
23361
  });
@@ -20735,6 +23366,16 @@ var require_detect_services = __commonJS({
20735
23366
  }
20736
23367
  return { rewrites, defaults, crons, workers };
20737
23368
  }
23369
+ function getWebRoutePrefixes(services) {
23370
+ const unique = /* @__PURE__ */ new Set();
23371
+ for (const service of services) {
23372
+ if (service.type !== "web" || typeof service.routePrefix !== "string") {
23373
+ continue;
23374
+ }
23375
+ unique.add((0, import_routing_utils.normalizeRoutePrefix)(service.routePrefix));
23376
+ }
23377
+ return Array.from(unique);
23378
+ }
20738
23379
  }
20739
23380
  });
20740
23381
 
@@ -21899,7 +24540,7 @@ var require_detect_file_system_api = __commonJS({
21899
24540
  });
21900
24541
  module2.exports = __toCommonJS2(detect_file_system_api_exports);
21901
24542
  var import_semver2 = __toESM2(require_semver3());
21902
- var import__ = require_dist4();
24543
+ var import__ = require_dist7();
21903
24544
  async function detectFileSystemAPI2({
21904
24545
  files,
21905
24546
  projectSettings,
@@ -23104,7 +25745,7 @@ var require_timestamp2 = __commonJS({
23104
25745
  });
23105
25746
 
23106
25747
  // ../../node_modules/.pnpm/js-yaml@4.1.0/node_modules/js-yaml/lib/type/merge.js
23107
- var require_merge2 = __commonJS({
25748
+ var require_merge3 = __commonJS({
23108
25749
  "../../node_modules/.pnpm/js-yaml@4.1.0/node_modules/js-yaml/lib/type/merge.js"(exports2, module2) {
23109
25750
  "use strict";
23110
25751
  var Type = require_type2();
@@ -23326,7 +25967,7 @@ var require_default = __commonJS({
23326
25967
  module2.exports = require_core2().extend({
23327
25968
  implicit: [
23328
25969
  require_timestamp2(),
23329
- require_merge2()
25970
+ require_merge3()
23330
25971
  ],
23331
25972
  explicit: [
23332
25973
  require_binary2(),
@@ -25177,7 +27818,7 @@ var require_js_yaml3 = __commonJS({
25177
27818
  timestamp: require_timestamp2(),
25178
27819
  bool: require_bool2(),
25179
27820
  int: require_int2(),
25180
- merge: require_merge2(),
27821
+ merge: require_merge3(),
25181
27822
  omap: require_omap2(),
25182
27823
  seq: require_seq2(),
25183
27824
  str: require_str2()
@@ -29262,7 +31903,7 @@ var require_detect_instrumentation = __commonJS({
29262
31903
  });
29263
31904
 
29264
31905
  // ../fs-detectors/dist/index.js
29265
- var require_dist4 = __commonJS({
31906
+ var require_dist7 = __commonJS({
29266
31907
  "../fs-detectors/dist/index.js"(exports2, module2) {
29267
31908
  "use strict";
29268
31909
  var __defProp2 = Object.defineProperty;
@@ -29288,6 +31929,7 @@ var require_dist4 = __commonJS({
29288
31929
  DetectorFilesystem: () => import_filesystem.DetectorFilesystem,
29289
31930
  GetWorkspaceOptions: () => import_get_workspaces.GetWorkspaceOptions,
29290
31931
  GetWorkspacePackagePathsOptions: () => import_get_workspace_package_paths.GetWorkspacePackagePathsOptions,
31932
+ INTERNAL_SERVICE_PREFIX: () => import_utils.INTERNAL_SERVICE_PREFIX,
29291
31933
  LocalFileSystemDetector: () => import_local_file_system_detector.LocalFileSystemDetector,
29292
31934
  REGEX_NON_VERCEL_PLATFORM_FILES: () => import_detect_builders2.REGEX_NON_VERCEL_PLATFORM_FILES,
29293
31935
  Workspace: () => import_get_workspaces.Workspace,
@@ -29305,6 +31947,7 @@ var require_dist4 = __commonJS({
29305
31947
  detectOutputDirectory: () => import_detect_builders.detectOutputDirectory,
29306
31948
  detectServices: () => import_detect_services.detectServices,
29307
31949
  generateServicesRoutes: () => import_detect_services.generateServicesRoutes,
31950
+ getInternalServiceFunctionPath: () => import_utils.getInternalServiceFunctionPath,
29308
31951
  getProjectPaths: () => import_get_project_paths.getProjectPaths,
29309
31952
  getServicesBuilders: () => import_get_services_builders.getServicesBuilders,
29310
31953
  getWorkspacePackagePaths: () => import_get_workspace_package_paths.getWorkspacePackagePaths,
@@ -29562,6 +32205,9 @@ function parseFunctionConfig(data) {
29562
32205
  if (Array.isArray(data.regions) && data.regions.every((r) => typeof r === "string")) {
29563
32206
  config.regions = data.regions;
29564
32207
  }
32208
+ if (Array.isArray(data.functionFailoverRegions) && data.functionFailoverRegions.every((r) => typeof r === "string")) {
32209
+ config.functionFailoverRegions = data.functionFailoverRegions;
32210
+ }
29565
32211
  return config;
29566
32212
  }
29567
32213
  async function readBuildOutputConfig({
@@ -30143,7 +32789,7 @@ async function injectVercelAnalyticsPlugin(dir) {
30143
32789
 
30144
32790
  // src/index.ts
30145
32791
  var import_tree_kill = __toESM(require_tree_kill());
30146
- var import_fs_detectors = __toESM(require_dist4());
32792
+ var import_fs_detectors = __toESM(require_dist7());
30147
32793
 
30148
32794
  // src/utils/hugo.ts
30149
32795
  var import_node_fetch = __toESM(require_lib2());