@vercel/static-build 2.8.29 → 2.8.31

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 +548 -281
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -19753,6 +19753,7 @@ var require_utils4 = __commonJS({
19753
19753
  __export2(utils_exports, {
19754
19754
  getBuilderForRuntime: () => getBuilderForRuntime,
19755
19755
  inferServiceRuntime: () => inferServiceRuntime,
19756
+ isStaticBuild: () => isStaticBuild2,
19756
19757
  readVercelConfig: () => readVercelConfig
19757
19758
  });
19758
19759
  module2.exports = __toCommonJS2(utils_exports);
@@ -19765,6 +19766,9 @@ var require_utils4 = __commonJS({
19765
19766
  }
19766
19767
  return builder;
19767
19768
  }
19769
+ function isStaticBuild2(service) {
19770
+ return import_types.STATIC_BUILDERS.has(service.builder.use);
19771
+ }
19768
19772
  function inferServiceRuntime(config) {
19769
19773
  if (config.runtime && config.runtime in import_types.RUNTIME_BUILDERS) {
19770
19774
  return config.runtime;
@@ -19949,7 +19953,7 @@ var require_resolve = __commonJS({
19949
19953
  builderUse = (0, import_utils.getBuilderForRuntime)(inferredRuntime);
19950
19954
  builderSrc = config.entrypoint;
19951
19955
  }
19952
- const routePrefix = type === "web" ? config.routePrefix : void 0;
19956
+ const routePrefix = type === "web" && config.routePrefix ? config.routePrefix.startsWith("/") ? config.routePrefix : `/${config.routePrefix}` : void 0;
19953
19957
  const isRoot = workspace === ".";
19954
19958
  if (!isRoot && !builderSrc.startsWith(workspace + "/")) {
19955
19959
  builderSrc = import_path7.posix.join(workspace, builderSrc);
@@ -19963,8 +19967,15 @@ var require_resolve = __commonJS({
19963
19967
  builderConfig.includeFiles = config.includeFiles;
19964
19968
  if (config.excludeFiles)
19965
19969
  builderConfig.excludeFiles = config.excludeFiles;
19966
- const isStaticBuild = import_types.STATIC_BUILDERS.has(builderUse);
19967
- const runtime = isStaticBuild ? void 0 : inferredRuntime;
19970
+ const isStaticBuild2 = import_types.STATIC_BUILDERS.has(builderUse);
19971
+ const runtime = isStaticBuild2 ? void 0 : inferredRuntime;
19972
+ if (routePrefix) {
19973
+ const stripped = routePrefix.startsWith("/") ? routePrefix.slice(1) : routePrefix;
19974
+ builderConfig.routePrefix = stripped || ".";
19975
+ }
19976
+ if (config.framework) {
19977
+ builderConfig.framework = config.framework;
19978
+ }
19968
19979
  return {
19969
19980
  name,
19970
19981
  type,
@@ -20004,6 +20015,488 @@ var require_resolve = __commonJS({
20004
20015
  }
20005
20016
  });
20006
20017
 
20018
+ // ../fs-detectors/dist/detect-framework.js
20019
+ var require_detect_framework = __commonJS({
20020
+ "../fs-detectors/dist/detect-framework.js"(exports2, module2) {
20021
+ "use strict";
20022
+ var __defProp2 = Object.defineProperty;
20023
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
20024
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
20025
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
20026
+ var __export2 = (target, all) => {
20027
+ for (var name in all)
20028
+ __defProp2(target, name, { get: all[name], enumerable: true });
20029
+ };
20030
+ var __copyProps2 = (to, from, except, desc) => {
20031
+ if (from && typeof from === "object" || typeof from === "function") {
20032
+ for (let key of __getOwnPropNames2(from))
20033
+ if (!__hasOwnProp2.call(to, key) && key !== except)
20034
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
20035
+ }
20036
+ return to;
20037
+ };
20038
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
20039
+ var detect_framework_exports = {};
20040
+ __export2(detect_framework_exports, {
20041
+ detectFramework: () => detectFramework2,
20042
+ detectFrameworkRecord: () => detectFrameworkRecord3,
20043
+ detectFrameworkVersion: () => detectFrameworkVersion2,
20044
+ detectFrameworks: () => detectFrameworks2,
20045
+ removeSupersededFrameworks: () => removeSupersededFrameworks
20046
+ });
20047
+ module2.exports = __toCommonJS2(detect_framework_exports);
20048
+ var import_child_process2 = require("child_process");
20049
+ function shouldIncludeExperimentalFrameworks(useExperimentalFrameworks) {
20050
+ if (typeof useExperimentalFrameworks === "boolean") {
20051
+ return useExperimentalFrameworks;
20052
+ }
20053
+ const experimentalEnv = process.env.VERCEL_USE_EXPERIMENTAL_FRAMEWORKS;
20054
+ const isEnabled = (val) => val === "1" || typeof val === "string" && val.toLowerCase() === "true";
20055
+ return isEnabled(experimentalEnv);
20056
+ }
20057
+ function filterFrameworkList(frameworkList, useExperimentalFrameworks) {
20058
+ if (shouldIncludeExperimentalFrameworks(useExperimentalFrameworks)) {
20059
+ return frameworkList;
20060
+ }
20061
+ return frameworkList.filter((f) => {
20062
+ const experimental = f.experimental;
20063
+ return !experimental;
20064
+ });
20065
+ }
20066
+ async function matches(fs5, framework) {
20067
+ const { detectors } = framework;
20068
+ if (!detectors) {
20069
+ return;
20070
+ }
20071
+ const { every, some } = detectors;
20072
+ if (every !== void 0 && !Array.isArray(every)) {
20073
+ return;
20074
+ }
20075
+ if (some !== void 0 && !Array.isArray(some)) {
20076
+ return;
20077
+ }
20078
+ const check = async ({
20079
+ path: path6,
20080
+ matchContent,
20081
+ matchPackage
20082
+ }) => {
20083
+ if (matchPackage && matchContent) {
20084
+ throw new Error(
20085
+ `Cannot specify "matchPackage" and "matchContent" in the same detector for "${framework.slug}"`
20086
+ );
20087
+ }
20088
+ if (matchPackage && path6) {
20089
+ throw new Error(
20090
+ `Cannot specify "matchPackage" and "path" in the same detector for "${framework.slug}" because "path" is assumed to be "package.json".`
20091
+ );
20092
+ }
20093
+ if (!path6 && !matchPackage) {
20094
+ throw new Error(
20095
+ `Must specify either "path" or "matchPackage" in detector for "${framework.slug}".`
20096
+ );
20097
+ }
20098
+ if (!path6) {
20099
+ path6 = "package.json";
20100
+ }
20101
+ if (matchPackage) {
20102
+ matchContent = `"(dev)?(d|D)ependencies":\\s*{[^}]*"${matchPackage}":\\s*"(.+?)"[^}]*}`;
20103
+ }
20104
+ if (await fs5.hasPath(path6) === false) {
20105
+ return;
20106
+ }
20107
+ if (matchContent) {
20108
+ if (await fs5.isFile(path6) === false) {
20109
+ return;
20110
+ }
20111
+ const regex = new RegExp(matchContent, "m");
20112
+ const content = await fs5.readFile(path6);
20113
+ const match = content.toString().match(regex);
20114
+ if (!match) {
20115
+ return;
20116
+ }
20117
+ if (matchPackage && match[3]) {
20118
+ return {
20119
+ framework,
20120
+ detectedVersion: match[3]
20121
+ };
20122
+ }
20123
+ }
20124
+ return {
20125
+ framework
20126
+ };
20127
+ };
20128
+ const result = [];
20129
+ if (every) {
20130
+ const everyResult = await Promise.all(every.map((item) => check(item)));
20131
+ result.push(...everyResult);
20132
+ }
20133
+ if (some) {
20134
+ let someResult;
20135
+ for (const item of some) {
20136
+ const itemResult = await check(item);
20137
+ if (itemResult) {
20138
+ someResult = itemResult;
20139
+ break;
20140
+ }
20141
+ }
20142
+ result.push(someResult);
20143
+ }
20144
+ if (!result.every((res) => !!res)) {
20145
+ return;
20146
+ }
20147
+ const detectedVersion = result.find(
20148
+ (r) => typeof r === "object" && r.detectedVersion
20149
+ )?.detectedVersion;
20150
+ return {
20151
+ framework,
20152
+ detectedVersion
20153
+ };
20154
+ }
20155
+ function removeSupersededFramework(matches2, slug) {
20156
+ const index = matches2.findIndex((f) => f?.slug === slug);
20157
+ const framework = matches2[index];
20158
+ if (framework) {
20159
+ if (framework.supersedes) {
20160
+ for (const slug2 of framework.supersedes) {
20161
+ removeSupersededFramework(matches2, slug2);
20162
+ }
20163
+ }
20164
+ matches2.splice(index, 1);
20165
+ }
20166
+ }
20167
+ function removeSupersededFrameworks(matches2) {
20168
+ for (const match of matches2.slice()) {
20169
+ if (match?.supersedes) {
20170
+ for (const slug of match.supersedes) {
20171
+ removeSupersededFramework(matches2, slug);
20172
+ }
20173
+ }
20174
+ }
20175
+ }
20176
+ async function detectFramework2({
20177
+ fs: fs5,
20178
+ frameworkList,
20179
+ useExperimentalFrameworks
20180
+ }) {
20181
+ const filteredList = filterFrameworkList(
20182
+ frameworkList,
20183
+ useExperimentalFrameworks
20184
+ );
20185
+ const result = await Promise.all(
20186
+ filteredList.map(async (frameworkMatch) => {
20187
+ if (await matches(fs5, frameworkMatch)) {
20188
+ return frameworkMatch;
20189
+ }
20190
+ return null;
20191
+ })
20192
+ );
20193
+ removeSupersededFrameworks(result);
20194
+ return result.find((res) => res !== null)?.slug ?? null;
20195
+ }
20196
+ async function detectFrameworks2({
20197
+ fs: fs5,
20198
+ frameworkList,
20199
+ useExperimentalFrameworks
20200
+ }) {
20201
+ const filteredList = filterFrameworkList(
20202
+ frameworkList,
20203
+ useExperimentalFrameworks
20204
+ );
20205
+ const result = await Promise.all(
20206
+ filteredList.map(async (frameworkMatch) => {
20207
+ if (await matches(fs5, frameworkMatch)) {
20208
+ return frameworkMatch;
20209
+ }
20210
+ return null;
20211
+ })
20212
+ );
20213
+ removeSupersededFrameworks(result);
20214
+ return result.filter((res) => res !== null);
20215
+ }
20216
+ async function detectFrameworkRecord3({
20217
+ fs: fs5,
20218
+ frameworkList,
20219
+ useExperimentalFrameworks
20220
+ }) {
20221
+ const filteredList = filterFrameworkList(
20222
+ frameworkList,
20223
+ useExperimentalFrameworks
20224
+ );
20225
+ const result = await Promise.all(
20226
+ filteredList.map(async (frameworkMatch) => {
20227
+ const matchResult = await matches(fs5, frameworkMatch);
20228
+ if (matchResult) {
20229
+ return {
20230
+ ...frameworkMatch,
20231
+ detectedVersion: matchResult?.detectedVersion
20232
+ };
20233
+ }
20234
+ return null;
20235
+ })
20236
+ );
20237
+ removeSupersededFrameworks(result);
20238
+ return result.find((res) => res !== null) ?? null;
20239
+ }
20240
+ function detectFrameworkVersion2(frameworkRecord) {
20241
+ const allDetectors = [
20242
+ ...frameworkRecord.detectors?.every || [],
20243
+ ...frameworkRecord.detectors?.some || []
20244
+ ];
20245
+ const firstMatchPackage = allDetectors.find((d) => d.matchPackage);
20246
+ if (!firstMatchPackage?.matchPackage) {
20247
+ return;
20248
+ }
20249
+ return lookupInstalledVersion(
20250
+ process.execPath,
20251
+ firstMatchPackage.matchPackage
20252
+ );
20253
+ }
20254
+ function lookupInstalledVersion(cwd, packageName) {
20255
+ try {
20256
+ const script = `require('${packageName}/package.json').version`;
20257
+ return (0, import_child_process2.spawnSync)(cwd, ["-p", script], {
20258
+ encoding: "utf-8"
20259
+ }).stdout.trim();
20260
+ } catch (error) {
20261
+ console.debug(
20262
+ `Error looking up version of installed package "${packageName}": ${error}`
20263
+ );
20264
+ }
20265
+ return;
20266
+ }
20267
+ }
20268
+ });
20269
+
20270
+ // ../fs-detectors/dist/services/auto-detect.js
20271
+ var require_auto_detect = __commonJS({
20272
+ "../fs-detectors/dist/services/auto-detect.js"(exports2, module2) {
20273
+ "use strict";
20274
+ var __create2 = Object.create;
20275
+ var __defProp2 = Object.defineProperty;
20276
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
20277
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
20278
+ var __getProtoOf2 = Object.getPrototypeOf;
20279
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
20280
+ var __export2 = (target, all) => {
20281
+ for (var name in all)
20282
+ __defProp2(target, name, { get: all[name], enumerable: true });
20283
+ };
20284
+ var __copyProps2 = (to, from, except, desc) => {
20285
+ if (from && typeof from === "object" || typeof from === "function") {
20286
+ for (let key of __getOwnPropNames2(from))
20287
+ if (!__hasOwnProp2.call(to, key) && key !== except)
20288
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
20289
+ }
20290
+ return to;
20291
+ };
20292
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
20293
+ // If the importer is in node compatibility mode or this is not an ESM
20294
+ // file that has been converted to a CommonJS file using a Babel-
20295
+ // compatible transform (i.e. "__esModule" has not been set), then set
20296
+ // "default" to the CommonJS "module.exports" for node compatibility.
20297
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
20298
+ mod
20299
+ ));
20300
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
20301
+ var auto_detect_exports = {};
20302
+ __export2(auto_detect_exports, {
20303
+ autoDetectServices: () => autoDetectServices2
20304
+ });
20305
+ module2.exports = __toCommonJS2(auto_detect_exports);
20306
+ var import_detect_framework = require_detect_framework();
20307
+ var import_frameworks2 = __toESM2(require_frameworks());
20308
+ var FRONTEND_DIR = "frontend";
20309
+ var APPS_WEB_DIR = "apps/web";
20310
+ var BACKEND_DIR = "backend";
20311
+ var SERVICES_DIR = "services";
20312
+ var FRONTEND_LOCATIONS = [FRONTEND_DIR, APPS_WEB_DIR];
20313
+ async function autoDetectServices2(options) {
20314
+ const { fs: fs5 } = options;
20315
+ const rootFrameworks = await (0, import_detect_framework.detectFrameworks)({
20316
+ fs: fs5,
20317
+ frameworkList: import_frameworks2.default
20318
+ });
20319
+ if (rootFrameworks.length > 1) {
20320
+ const frameworkNames = rootFrameworks.map((f) => f.name).join(", ");
20321
+ return {
20322
+ services: null,
20323
+ errors: [
20324
+ {
20325
+ code: "MULTIPLE_FRAMEWORKS_ROOT",
20326
+ message: `Multiple frameworks detected at root: ${frameworkNames}. Use explicit experimentalServices config.`
20327
+ }
20328
+ ]
20329
+ };
20330
+ }
20331
+ if (rootFrameworks.length === 1) {
20332
+ return detectServicesAtRoot(fs5, rootFrameworks[0]);
20333
+ }
20334
+ for (const frontendLocation of FRONTEND_LOCATIONS) {
20335
+ const hasFrontendDir = await fs5.hasPath(frontendLocation);
20336
+ if (!hasFrontendDir) {
20337
+ continue;
20338
+ }
20339
+ const frontendFs = fs5.chdir(frontendLocation);
20340
+ const frontendFrameworks = await (0, import_detect_framework.detectFrameworks)({
20341
+ fs: frontendFs,
20342
+ frameworkList: import_frameworks2.default
20343
+ });
20344
+ if (frontendFrameworks.length > 1) {
20345
+ const frameworkNames = frontendFrameworks.map((f) => f.name).join(", ");
20346
+ return {
20347
+ services: null,
20348
+ errors: [
20349
+ {
20350
+ code: "MULTIPLE_FRAMEWORKS_SERVICE",
20351
+ message: `Multiple frameworks detected in ${frontendLocation}/: ${frameworkNames}. Use explicit experimentalServices config.`
20352
+ }
20353
+ ]
20354
+ };
20355
+ }
20356
+ if (frontendFrameworks.length === 1) {
20357
+ return detectServicesFrontendSubdir(
20358
+ fs5,
20359
+ frontendFrameworks[0],
20360
+ frontendLocation
20361
+ );
20362
+ }
20363
+ }
20364
+ return {
20365
+ services: null,
20366
+ errors: [
20367
+ {
20368
+ code: "NO_SERVICES_CONFIGURED",
20369
+ message: "No services detected. Configure experimentalServices in vercel.json or ensure a framework exists at project root, frontend/, or apps/web/."
20370
+ }
20371
+ ]
20372
+ };
20373
+ }
20374
+ async function detectServicesAtRoot(fs5, rootFramework) {
20375
+ const services = {};
20376
+ services.frontend = {
20377
+ framework: rootFramework.slug ?? void 0,
20378
+ routePrefix: "/"
20379
+ };
20380
+ const backendResult = await detectBackendServices(fs5);
20381
+ if (backendResult.error) {
20382
+ return { services: null, errors: [backendResult.error] };
20383
+ }
20384
+ Object.assign(services, backendResult.services);
20385
+ return { services, errors: [] };
20386
+ }
20387
+ async function detectServicesFrontendSubdir(fs5, frontendFramework, frontendLocation) {
20388
+ const services = {};
20389
+ const serviceName = frontendLocation.split("/").pop() || "frontend";
20390
+ services[serviceName] = {
20391
+ framework: frontendFramework.slug ?? void 0,
20392
+ workspace: frontendLocation,
20393
+ routePrefix: "/"
20394
+ };
20395
+ const backendResult = await detectBackendServices(fs5);
20396
+ if (backendResult.error) {
20397
+ return { services: null, errors: [backendResult.error] };
20398
+ }
20399
+ if (Object.keys(backendResult.services).length === 0) {
20400
+ return {
20401
+ services: null,
20402
+ errors: [
20403
+ {
20404
+ code: "NO_BACKEND_SERVICES",
20405
+ message: `Frontend detected in ${frontendLocation}/ but no backend services found. Add a backend/ or services/ directory with a supported framework.`
20406
+ }
20407
+ ]
20408
+ };
20409
+ }
20410
+ Object.assign(services, backendResult.services);
20411
+ return { services, errors: [] };
20412
+ }
20413
+ async function detectBackendServices(fs5) {
20414
+ const services = {};
20415
+ const backendResult = await detectServiceInDir(fs5, BACKEND_DIR, "backend");
20416
+ if (backendResult.error) {
20417
+ return { services: {}, error: backendResult.error };
20418
+ }
20419
+ if (backendResult.service) {
20420
+ services.backend = backendResult.service;
20421
+ }
20422
+ const multiServicesResult = await detectServicesDirectory(fs5);
20423
+ if (multiServicesResult.error) {
20424
+ return { services: {}, error: multiServicesResult.error };
20425
+ }
20426
+ for (const serviceName of Object.keys(multiServicesResult.services)) {
20427
+ if (services[serviceName]) {
20428
+ return {
20429
+ services: {},
20430
+ error: {
20431
+ code: "SERVICE_NAME_CONFLICT",
20432
+ message: `Service name conflict: "${serviceName}" exists in both ${BACKEND_DIR}/ and ${SERVICES_DIR}/${serviceName}/. Rename one of the directories or use explicit experimentalServices config.`,
20433
+ serviceName
20434
+ }
20435
+ };
20436
+ }
20437
+ }
20438
+ Object.assign(services, multiServicesResult.services);
20439
+ return { services };
20440
+ }
20441
+ async function detectServicesDirectory(fs5) {
20442
+ const services = {};
20443
+ const hasServicesDir = await fs5.hasPath(SERVICES_DIR);
20444
+ if (!hasServicesDir) {
20445
+ return { services };
20446
+ }
20447
+ const servicesFs = fs5.chdir(SERVICES_DIR);
20448
+ const entries = await servicesFs.readdir("/");
20449
+ for (const entry of entries) {
20450
+ if (entry.type !== "dir") {
20451
+ continue;
20452
+ }
20453
+ const serviceName = entry.name;
20454
+ const serviceDir = `${SERVICES_DIR}/${serviceName}`;
20455
+ const result = await detectServiceInDir(fs5, serviceDir, serviceName);
20456
+ if (result.error) {
20457
+ return { services: {}, error: result.error };
20458
+ }
20459
+ if (result.service) {
20460
+ services[serviceName] = result.service;
20461
+ }
20462
+ }
20463
+ return { services };
20464
+ }
20465
+ async function detectServiceInDir(fs5, dirPath, serviceName) {
20466
+ const hasDirPath = await fs5.hasPath(dirPath);
20467
+ if (!hasDirPath) {
20468
+ return {};
20469
+ }
20470
+ const serviceFs = fs5.chdir(dirPath);
20471
+ const frameworks2 = await (0, import_detect_framework.detectFrameworks)({
20472
+ fs: serviceFs,
20473
+ frameworkList: import_frameworks2.default
20474
+ });
20475
+ if (frameworks2.length > 1) {
20476
+ const frameworkNames = frameworks2.map((f) => f.name).join(", ");
20477
+ return {
20478
+ error: {
20479
+ code: "MULTIPLE_FRAMEWORKS_SERVICE",
20480
+ message: `Multiple frameworks detected in ${dirPath}/: ${frameworkNames}. Use explicit experimentalServices config.`,
20481
+ serviceName
20482
+ }
20483
+ };
20484
+ }
20485
+ if (frameworks2.length === 1) {
20486
+ const framework = frameworks2[0];
20487
+ return {
20488
+ service: {
20489
+ framework: framework.slug ?? void 0,
20490
+ workspace: dirPath,
20491
+ routePrefix: `/_/${serviceName}`
20492
+ }
20493
+ };
20494
+ }
20495
+ return {};
20496
+ }
20497
+ }
20498
+ });
20499
+
20007
20500
  // ../fs-detectors/dist/services/detect-services.js
20008
20501
  var require_detect_services = __commonJS({
20009
20502
  "../fs-detectors/dist/services/detect-services.js"(exports2, module2) {
@@ -20033,6 +20526,7 @@ var require_detect_services = __commonJS({
20033
20526
  module2.exports = __toCommonJS2(detect_services_exports);
20034
20527
  var import_utils = require_utils4();
20035
20528
  var import_resolve = require_resolve();
20529
+ var import_auto_detect = require_auto_detect();
20036
20530
  async function detectServices2(options) {
20037
20531
  const { fs: fs5, workPath } = options;
20038
20532
  const scopedFs = workPath ? fs5.chdir(workPath) : fs5;
@@ -20048,6 +20542,25 @@ var require_detect_services = __commonJS({
20048
20542
  const configuredServices = vercelConfig?.experimentalServices;
20049
20543
  const hasConfiguredServices = configuredServices && Object.keys(configuredServices).length > 0;
20050
20544
  if (!hasConfiguredServices) {
20545
+ const autoResult = await (0, import_auto_detect.autoDetectServices)({ fs: scopedFs });
20546
+ if (autoResult.errors.length > 0) {
20547
+ return {
20548
+ services: [],
20549
+ routes: { rewrites: [], defaults: [], crons: [], workers: [] },
20550
+ errors: autoResult.errors,
20551
+ warnings: []
20552
+ };
20553
+ }
20554
+ if (autoResult.services) {
20555
+ const result2 = (0, import_resolve.resolveAllConfiguredServices)(autoResult.services);
20556
+ const routes2 = generateServicesRoutes2(result2.services);
20557
+ return {
20558
+ services: result2.services,
20559
+ routes: routes2,
20560
+ errors: result2.errors,
20561
+ warnings: []
20562
+ };
20563
+ }
20051
20564
  return {
20052
20565
  services: [],
20053
20566
  routes: { rewrites: [], defaults: [], crons: [], workers: [] },
@@ -20074,33 +20587,34 @@ var require_detect_services = __commonJS({
20074
20587
  const defaults = [];
20075
20588
  const crons = [];
20076
20589
  const workers = [];
20077
- const webServices = services.filter(
20590
+ const sortedWebServices = services.filter(
20078
20591
  (s) => s.type === "web" && typeof s.routePrefix === "string"
20079
- );
20080
- const sortedWebServices = [...webServices].sort((a, b) => {
20081
- if (a.routePrefix === "/")
20082
- return 1;
20083
- if (b.routePrefix === "/")
20084
- return -1;
20085
- return b.routePrefix.length - a.routePrefix.length;
20086
- });
20592
+ ).sort((a, b) => b.routePrefix.length - a.routePrefix.length);
20087
20593
  for (const service of sortedWebServices) {
20088
- const { routePrefix, builder } = service;
20089
- const builderSrc = builder.src || routePrefix;
20090
- const functionPath = builderSrc.startsWith("/") ? builderSrc : `/${builderSrc}`;
20091
- if (routePrefix === "/") {
20092
- defaults.push({
20093
- src: "^/(.*)$",
20094
- dest: functionPath,
20095
- check: true
20096
- });
20594
+ const { routePrefix } = service;
20595
+ const normalizedPrefix = routePrefix.slice(1);
20596
+ if ((0, import_utils.isStaticBuild)(service)) {
20597
+ if (routePrefix === "/") {
20598
+ defaults.push({ handle: "filesystem" });
20599
+ defaults.push({ src: "/(.*)", dest: "/index.html" });
20600
+ } else {
20601
+ rewrites.push({
20602
+ src: `^/${normalizedPrefix}(?:/.*)?$`,
20603
+ dest: `/${normalizedPrefix}/index.html`
20604
+ });
20605
+ }
20097
20606
  } else {
20098
- const normalizedPrefix = routePrefix.startsWith("/") ? routePrefix.slice(1) : routePrefix;
20099
- rewrites.push({
20100
- src: `^/${normalizedPrefix}(?:/.*)?$`,
20101
- dest: functionPath,
20102
- check: true
20103
- });
20607
+ const builderSrc = service.builder.src || routePrefix;
20608
+ const functionPath = builderSrc.startsWith("/") ? builderSrc : `/${builderSrc}`;
20609
+ if (routePrefix === "/") {
20610
+ defaults.push({ src: "^/(.*)$", dest: functionPath, check: true });
20611
+ } else {
20612
+ rewrites.push({
20613
+ src: `^/${normalizedPrefix}(?:/.*)?$`,
20614
+ dest: functionPath,
20615
+ check: true
20616
+ });
20617
+ }
20104
20618
  }
20105
20619
  }
20106
20620
  return { rewrites, defaults, crons, workers };
@@ -21426,258 +21940,6 @@ var require_detect_file_system_api = __commonJS({
21426
21940
  }
21427
21941
  });
21428
21942
 
21429
- // ../fs-detectors/dist/detect-framework.js
21430
- var require_detect_framework = __commonJS({
21431
- "../fs-detectors/dist/detect-framework.js"(exports2, module2) {
21432
- "use strict";
21433
- var __defProp2 = Object.defineProperty;
21434
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
21435
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
21436
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
21437
- var __export2 = (target, all) => {
21438
- for (var name in all)
21439
- __defProp2(target, name, { get: all[name], enumerable: true });
21440
- };
21441
- var __copyProps2 = (to, from, except, desc) => {
21442
- if (from && typeof from === "object" || typeof from === "function") {
21443
- for (let key of __getOwnPropNames2(from))
21444
- if (!__hasOwnProp2.call(to, key) && key !== except)
21445
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
21446
- }
21447
- return to;
21448
- };
21449
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
21450
- var detect_framework_exports = {};
21451
- __export2(detect_framework_exports, {
21452
- detectFramework: () => detectFramework2,
21453
- detectFrameworkRecord: () => detectFrameworkRecord3,
21454
- detectFrameworkVersion: () => detectFrameworkVersion2,
21455
- detectFrameworks: () => detectFrameworks2,
21456
- removeSupersededFrameworks: () => removeSupersededFrameworks
21457
- });
21458
- module2.exports = __toCommonJS2(detect_framework_exports);
21459
- var import_child_process2 = require("child_process");
21460
- function shouldIncludeExperimentalFrameworks(useExperimentalFrameworks) {
21461
- if (typeof useExperimentalFrameworks === "boolean") {
21462
- return useExperimentalFrameworks;
21463
- }
21464
- const experimentalEnv = process.env.VERCEL_USE_EXPERIMENTAL_FRAMEWORKS;
21465
- const isEnabled = (val) => val === "1" || typeof val === "string" && val.toLowerCase() === "true";
21466
- return isEnabled(experimentalEnv);
21467
- }
21468
- function filterFrameworkList(frameworkList, useExperimentalFrameworks) {
21469
- if (shouldIncludeExperimentalFrameworks(useExperimentalFrameworks)) {
21470
- return frameworkList;
21471
- }
21472
- return frameworkList.filter((f) => {
21473
- const experimental = f.experimental;
21474
- return !experimental;
21475
- });
21476
- }
21477
- async function matches(fs5, framework) {
21478
- const { detectors } = framework;
21479
- if (!detectors) {
21480
- return;
21481
- }
21482
- const { every, some } = detectors;
21483
- if (every !== void 0 && !Array.isArray(every)) {
21484
- return;
21485
- }
21486
- if (some !== void 0 && !Array.isArray(some)) {
21487
- return;
21488
- }
21489
- const check = async ({
21490
- path: path6,
21491
- matchContent,
21492
- matchPackage
21493
- }) => {
21494
- if (matchPackage && matchContent) {
21495
- throw new Error(
21496
- `Cannot specify "matchPackage" and "matchContent" in the same detector for "${framework.slug}"`
21497
- );
21498
- }
21499
- if (matchPackage && path6) {
21500
- throw new Error(
21501
- `Cannot specify "matchPackage" and "path" in the same detector for "${framework.slug}" because "path" is assumed to be "package.json".`
21502
- );
21503
- }
21504
- if (!path6 && !matchPackage) {
21505
- throw new Error(
21506
- `Must specify either "path" or "matchPackage" in detector for "${framework.slug}".`
21507
- );
21508
- }
21509
- if (!path6) {
21510
- path6 = "package.json";
21511
- }
21512
- if (matchPackage) {
21513
- matchContent = `"(dev)?(d|D)ependencies":\\s*{[^}]*"${matchPackage}":\\s*"(.+?)"[^}]*}`;
21514
- }
21515
- if (await fs5.hasPath(path6) === false) {
21516
- return;
21517
- }
21518
- if (matchContent) {
21519
- if (await fs5.isFile(path6) === false) {
21520
- return;
21521
- }
21522
- const regex = new RegExp(matchContent, "m");
21523
- const content = await fs5.readFile(path6);
21524
- const match = content.toString().match(regex);
21525
- if (!match) {
21526
- return;
21527
- }
21528
- if (matchPackage && match[3]) {
21529
- return {
21530
- framework,
21531
- detectedVersion: match[3]
21532
- };
21533
- }
21534
- }
21535
- return {
21536
- framework
21537
- };
21538
- };
21539
- const result = [];
21540
- if (every) {
21541
- const everyResult = await Promise.all(every.map((item) => check(item)));
21542
- result.push(...everyResult);
21543
- }
21544
- if (some) {
21545
- let someResult;
21546
- for (const item of some) {
21547
- const itemResult = await check(item);
21548
- if (itemResult) {
21549
- someResult = itemResult;
21550
- break;
21551
- }
21552
- }
21553
- result.push(someResult);
21554
- }
21555
- if (!result.every((res) => !!res)) {
21556
- return;
21557
- }
21558
- const detectedVersion = result.find(
21559
- (r) => typeof r === "object" && r.detectedVersion
21560
- )?.detectedVersion;
21561
- return {
21562
- framework,
21563
- detectedVersion
21564
- };
21565
- }
21566
- function removeSupersededFramework(matches2, slug) {
21567
- const index = matches2.findIndex((f) => f?.slug === slug);
21568
- const framework = matches2[index];
21569
- if (framework) {
21570
- if (framework.supersedes) {
21571
- for (const slug2 of framework.supersedes) {
21572
- removeSupersededFramework(matches2, slug2);
21573
- }
21574
- }
21575
- matches2.splice(index, 1);
21576
- }
21577
- }
21578
- function removeSupersededFrameworks(matches2) {
21579
- for (const match of matches2.slice()) {
21580
- if (match?.supersedes) {
21581
- for (const slug of match.supersedes) {
21582
- removeSupersededFramework(matches2, slug);
21583
- }
21584
- }
21585
- }
21586
- }
21587
- async function detectFramework2({
21588
- fs: fs5,
21589
- frameworkList,
21590
- useExperimentalFrameworks
21591
- }) {
21592
- const filteredList = filterFrameworkList(
21593
- frameworkList,
21594
- useExperimentalFrameworks
21595
- );
21596
- const result = await Promise.all(
21597
- filteredList.map(async (frameworkMatch) => {
21598
- if (await matches(fs5, frameworkMatch)) {
21599
- return frameworkMatch;
21600
- }
21601
- return null;
21602
- })
21603
- );
21604
- removeSupersededFrameworks(result);
21605
- return result.find((res) => res !== null)?.slug ?? null;
21606
- }
21607
- async function detectFrameworks2({
21608
- fs: fs5,
21609
- frameworkList,
21610
- useExperimentalFrameworks
21611
- }) {
21612
- const filteredList = filterFrameworkList(
21613
- frameworkList,
21614
- useExperimentalFrameworks
21615
- );
21616
- const result = await Promise.all(
21617
- filteredList.map(async (frameworkMatch) => {
21618
- if (await matches(fs5, frameworkMatch)) {
21619
- return frameworkMatch;
21620
- }
21621
- return null;
21622
- })
21623
- );
21624
- removeSupersededFrameworks(result);
21625
- return result.filter((res) => res !== null);
21626
- }
21627
- async function detectFrameworkRecord3({
21628
- fs: fs5,
21629
- frameworkList,
21630
- useExperimentalFrameworks
21631
- }) {
21632
- const filteredList = filterFrameworkList(
21633
- frameworkList,
21634
- useExperimentalFrameworks
21635
- );
21636
- const result = await Promise.all(
21637
- filteredList.map(async (frameworkMatch) => {
21638
- const matchResult = await matches(fs5, frameworkMatch);
21639
- if (matchResult) {
21640
- return {
21641
- ...frameworkMatch,
21642
- detectedVersion: matchResult?.detectedVersion
21643
- };
21644
- }
21645
- return null;
21646
- })
21647
- );
21648
- removeSupersededFrameworks(result);
21649
- return result.find((res) => res !== null) ?? null;
21650
- }
21651
- function detectFrameworkVersion2(frameworkRecord) {
21652
- const allDetectors = [
21653
- ...frameworkRecord.detectors?.every || [],
21654
- ...frameworkRecord.detectors?.some || []
21655
- ];
21656
- const firstMatchPackage = allDetectors.find((d) => d.matchPackage);
21657
- if (!firstMatchPackage?.matchPackage) {
21658
- return;
21659
- }
21660
- return lookupInstalledVersion(
21661
- process.execPath,
21662
- firstMatchPackage.matchPackage
21663
- );
21664
- }
21665
- function lookupInstalledVersion(cwd, packageName) {
21666
- try {
21667
- const script = `require('${packageName}/package.json').version`;
21668
- return (0, import_child_process2.spawnSync)(cwd, ["-p", script], {
21669
- encoding: "utf-8"
21670
- }).stdout.trim();
21671
- } catch (error) {
21672
- console.debug(
21673
- `Error looking up version of installed package "${packageName}": ${error}`
21674
- );
21675
- }
21676
- return;
21677
- }
21678
- }
21679
- });
21680
-
21681
21943
  // ../fs-detectors/dist/get-project-paths.js
21682
21944
  var require_get_project_paths = __commonJS({
21683
21945
  "../fs-detectors/dist/get-project-paths.js"(exports2, module2) {
@@ -28914,6 +29176,7 @@ var require_dist4 = __commonJS({
28914
29176
  REGEX_NON_VERCEL_PLATFORM_FILES: () => import_detect_builders2.REGEX_NON_VERCEL_PLATFORM_FILES,
28915
29177
  Workspace: () => import_get_workspaces.Workspace,
28916
29178
  WorkspaceType: () => import_get_workspaces.WorkspaceType,
29179
+ autoDetectServices: () => import_auto_detect.autoDetectServices,
28917
29180
  detectApiDirectory: () => import_detect_builders.detectApiDirectory,
28918
29181
  detectApiExtensions: () => import_detect_builders.detectApiExtensions,
28919
29182
  detectBuilders: () => import_detect_builders.detectBuilders,
@@ -28931,6 +29194,7 @@ var require_dist4 = __commonJS({
28931
29194
  getWorkspacePackagePaths: () => import_get_workspace_package_paths.getWorkspacePackagePaths,
28932
29195
  getWorkspaces: () => import_get_workspaces.getWorkspaces,
28933
29196
  isOfficialRuntime: () => import_is_official_runtime.isOfficialRuntime,
29197
+ isStaticBuild: () => import_utils.isStaticBuild,
28934
29198
  isStaticRuntime: () => import_is_official_runtime.isStaticRuntime,
28935
29199
  monorepoManagers: () => import_monorepo_managers.monorepoManagers,
28936
29200
  packageManagers: () => import_package_managers.packageManagers,
@@ -28939,6 +29203,8 @@ var require_dist4 = __commonJS({
28939
29203
  module2.exports = __toCommonJS2(src_exports2);
28940
29204
  var import_detect_builders = require_detect_builders();
28941
29205
  var import_detect_services = require_detect_services();
29206
+ var import_auto_detect = require_auto_detect();
29207
+ var import_utils = require_utils4();
28942
29208
  var import_get_services_builders = require_get_services_builders();
28943
29209
  var import_detect_file_system_api = require_detect_file_system_api();
28944
29210
  var import_detect_framework = require_detect_framework();
@@ -30044,8 +30310,9 @@ var build = async ({
30044
30310
  meta = {}
30045
30311
  }) => {
30046
30312
  await (0, import_build_utils4.download)(files, workPath, meta);
30047
- const mountpoint = import_path6.default.dirname(entrypoint);
30048
- const entrypointDir = import_path6.default.join(workPath, mountpoint);
30313
+ const routePrefix = config.routePrefix;
30314
+ const mountpoint = routePrefix ? routePrefix.replace(/^\//, "") || "." : import_path6.default.dirname(entrypoint);
30315
+ const entrypointDir = import_path6.default.join(workPath, import_path6.default.dirname(entrypoint));
30049
30316
  let distPath = import_path6.default.join(
30050
30317
  workPath,
30051
30318
  import_path6.default.dirname(entrypoint),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/static-build",
3
- "version": "2.8.29",
3
+ "version": "2.8.31",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/build-step",
@@ -15,8 +15,8 @@
15
15
  "dependencies": {
16
16
  "ts-morph": "12.0.0",
17
17
  "@vercel/gatsby-plugin-vercel-analytics": "1.0.11",
18
- "@vercel/gatsby-plugin-vercel-builder": "2.0.128",
19
- "@vercel/static-config": "3.1.2"
18
+ "@vercel/static-config": "3.1.2",
19
+ "@vercel/gatsby-plugin-vercel-builder": "2.0.129"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/aws-lambda": "8.10.64",
@@ -38,10 +38,10 @@
38
38
  "rc9": "1.2.0",
39
39
  "semver": "7.5.2",
40
40
  "tree-kill": "1.2.2",
41
- "@vercel/build-utils": "13.2.17",
42
41
  "@vercel/frameworks": "3.16.1",
43
42
  "@vercel/error-utils": "2.0.3",
44
- "@vercel/fs-detectors": "5.7.21",
43
+ "@vercel/build-utils": "13.3.0",
44
+ "@vercel/fs-detectors": "5.8.0",
45
45
  "@vercel/routing-utils": "5.3.2"
46
46
  },
47
47
  "scripts": {