@vercel/fs-detectors 7.10.2 → 7.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -233,6 +233,7 @@ var require_framework = __commonJS({
233
233
  DETECTION_FRAMEWORKS: () => DETECTION_FRAMEWORKS,
234
234
  filterFrameworksByRuntime: () => filterFrameworksByRuntime,
235
235
  frameworksBySlug: () => frameworksBySlug,
236
+ getRuntimeFramework: () => getRuntimeFramework,
236
237
  inferBuilderRuntimeFromFramework: () => inferBuilderRuntimeFromFramework2,
237
238
  inferRuntimeFromFramework: () => inferRuntimeFromFramework,
238
239
  inferServerRuntimeFromFramework: () => inferServerRuntimeFromFramework,
@@ -303,6 +304,11 @@ var require_framework = __commonJS({
303
304
  return [...frameworks];
304
305
  return frameworks.filter((f) => inferRuntimeFromFramework(f.slug) === runtime);
305
306
  }
307
+ function getRuntimeFramework(runtime) {
308
+ if (!runtime)
309
+ return void 0;
310
+ return frameworksBySlug.get(runtime)?.runtimeFramework ? runtime : void 0;
311
+ }
306
312
  }
307
313
  });
308
314
 
@@ -483,10 +489,10 @@ async function detectBuilders(files, pkg, options = {}) {
483
489
  usedFunctions.add(key);
484
490
  };
485
491
  const absolutePathCache = /* @__PURE__ */ new Map();
486
- const proxyFile = options.proxy ? parseProxyEntrypoint(options.proxy.entrypoint).file : null;
492
+ const proxy = resolveProxy(files, options);
487
493
  const reservedFunctionFiles = options.reservedFunctionFiles ?? [];
488
494
  const claimedFiles = /* @__PURE__ */ new Set([
489
- ...proxyFile !== null ? [proxyFile] : [],
495
+ ...proxy?.source === "vercel-config" ? [proxy.file] : [],
490
496
  ...reservedFunctionFiles
491
497
  ]);
492
498
  const hasReservedFunctions = reservedFunctionFiles.length > 0;
@@ -497,13 +503,7 @@ async function detectBuilders(files, pkg, options = {}) {
497
503
  rustStaticOutput ? void 0 : frameworkConfig?.ignoreRuntimes
498
504
  );
499
505
  const withTag = options.tag ? `@${options.tag}` : "";
500
- const apiMatches = getApiMatches().filter(
501
- (b) => (
502
- // Root-level middleware is enabled, unless `disableRootMiddleware: true`
503
- b.config?.middleware && !frameworkConfig?.disableRootMiddleware || // "api" dir runtimes are enabled, unless opted-out via `ignoreRuntimes`
504
- !ignoreRuntimes.has(b.use)
505
- )
506
- ).map((b) => {
506
+ const apiMatches = getApiMatches().filter((b) => !ignoreRuntimes.has(b.use)).map((b) => {
507
507
  b.use = `${b.use}${withTag}`;
508
508
  return b;
509
509
  });
@@ -519,8 +519,8 @@ async function detectBuilders(files, pkg, options = {}) {
519
519
  if (claimedFiles.has(fileName)) {
520
520
  continue;
521
521
  }
522
- const apiBuilder = await maybeGetApiBuilder(fileName, apiMatches, options);
523
- if (apiBuilder) {
522
+ const functionBuilder = proxy?.source === "file-convention" && fileName === proxy.file ? proxy.builder : await maybeGetApiBuilder(fileName, apiMatches, options);
523
+ if (functionBuilder) {
524
524
  const { routeError, apiRoute, isDynamic } = getApiRoute(
525
525
  fileName,
526
526
  apiSortedFiles,
@@ -544,8 +544,8 @@ async function detectBuilders(files, pkg, options = {}) {
544
544
  dynamicRoutes.push(apiRoute);
545
545
  }
546
546
  }
547
- addToUsedFunctions(apiBuilder);
548
- apiBuilders.push(apiBuilder);
547
+ addToUsedFunctions(functionBuilder);
548
+ apiBuilders.push(functionBuilder);
549
549
  continue;
550
550
  }
551
551
  if (!hasUsedOutputDirectory && fileName.startsWith(`${usedOutputDirectory}/`)) {
@@ -561,14 +561,9 @@ async function detectBuilders(files, pkg, options = {}) {
561
561
  fallbackEntrypoint = fileName;
562
562
  }
563
563
  }
564
- if (options.proxy) {
565
- const proxyBuilder = getProxyBuilder(
566
- options.proxy,
567
- options.tag,
568
- options.functions
569
- );
570
- addToUsedFunctions(proxyBuilder);
571
- apiBuilders.unshift(proxyBuilder);
564
+ if (proxy?.source === "vercel-config") {
565
+ addToUsedFunctions(proxy.builder);
566
+ apiBuilders.unshift(proxy.builder);
572
567
  }
573
568
  const rustStaticPrebuilt = rustStaticOutput && !pkg && !buildCommand;
574
569
  if (!makeFrontendStatic && !rustStaticPrebuilt && (hasBuildScript(pkg) || buildCommand || framework)) {
@@ -713,11 +708,7 @@ async function detectBuilders(files, pkg, options = {}) {
713
708
  };
714
709
  }
715
710
  async function maybeGetApiBuilder(fileName, apiMatches, options) {
716
- const middleware = !options.proxy && (fileName === "middleware.js" || fileName === "middleware.ts");
717
- if (middleware && options.projectSettings?.framework === "nextjs") {
718
- return null;
719
- }
720
- if (!(fileName.startsWith("api/") || middleware)) {
711
+ if (!fileName.startsWith("api/")) {
721
712
  return null;
722
713
  }
723
714
  if (fileName.includes("/.")) {
@@ -755,10 +746,15 @@ async function maybeGetApiBuilder(fileName, apiMatches, options) {
755
746
  if (!use) {
756
747
  return null;
757
748
  }
749
+ const builder = {
750
+ use,
751
+ src: fileName,
752
+ config: getFunctionConfig(fnPattern, func, options)
753
+ };
754
+ return builder;
755
+ }
756
+ function getFunctionConfig(fnPattern, func, options) {
758
757
  const config = { zeroConfig: true };
759
- if (middleware) {
760
- config.middleware = true;
761
- }
762
758
  if (fnPattern && func) {
763
759
  config.functions = { [fnPattern]: func };
764
760
  if (func.includeFiles) {
@@ -771,12 +767,7 @@ async function maybeGetApiBuilder(fileName, apiMatches, options) {
771
767
  if (options.bunVersion) {
772
768
  config.bunVersion = options.bunVersion;
773
769
  }
774
- const builder = {
775
- use,
776
- src: fileName,
777
- config
778
- };
779
- return builder;
770
+ return config;
780
771
  }
781
772
  function getFunction(fileName, { functions = {} }) {
782
773
  const keys = Object.keys(functions);
@@ -794,6 +785,44 @@ function parseProxyEntrypoint(entrypoint) {
794
785
  }
795
786
  return { file: entrypoint };
796
787
  }
788
+ var ROOT_PROXY_FILES = ["middleware.js", "middleware.ts"];
789
+ function resolveProxy(files, options) {
790
+ const { proxy } = options;
791
+ if (proxy) {
792
+ return {
793
+ source: "vercel-config",
794
+ entrypoint: proxy.entrypoint,
795
+ file: parseProxyEntrypoint(proxy.entrypoint).file,
796
+ builder: getProxyBuilder(proxy, options.tag, options.functions)
797
+ };
798
+ }
799
+ const framework = options.projectSettings?.framework;
800
+ if (framework === "nextjs" || import_framework.frameworksBySlug.get(framework || "")?.disableRootMiddleware) {
801
+ return null;
802
+ }
803
+ const reserved = new Set(options.reservedFunctionFiles ?? []);
804
+ const file = ROOT_PROXY_FILES.find(
805
+ (f) => files.includes(f) && !reserved.has(f)
806
+ );
807
+ if (!file) {
808
+ return null;
809
+ }
810
+ const { fnPattern, func } = getFunction(file, options);
811
+ const withTag = options.tag ? `@${options.tag}` : "";
812
+ return {
813
+ source: "file-convention",
814
+ entrypoint: null,
815
+ file,
816
+ builder: {
817
+ use: func?.runtime || `@vercel/node${withTag}`,
818
+ src: file,
819
+ config: {
820
+ ...getFunctionConfig(fnPattern, func, options),
821
+ middleware: true
822
+ }
823
+ }
824
+ };
825
+ }
797
826
  function getProxyBuilder(proxy, tag, functions = {}) {
798
827
  const { file, variable } = parseProxyEntrypoint(proxy.entrypoint);
799
828
  const isPython = (0, import_path.extname)(file) === ".py";
@@ -825,11 +854,6 @@ function getProxyBuilder(proxy, tag, functions = {}) {
825
854
  function getApiMatches() {
826
855
  const config = { zeroConfig: true };
827
856
  return [
828
- {
829
- src: REGEX_MIDDLEWARE_FILES,
830
- use: `@vercel/node`,
831
- config: { ...config, middleware: true }
832
- },
833
857
  { src: "api/**/*.+(js|mjs|ts|tsx)", use: `@vercel/node`, config },
834
858
  { src: "api/**/!(*_test).go", use: `@vercel/go`, config },
835
859
  { src: "api/**/*.py", use: `@vercel/python`, config },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/fs-detectors",
3
- "version": "7.10.2",
3
+ "version": "7.11.0",
4
4
  "description": "Vercel filesystem detectors",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,10 +20,10 @@
20
20
  "minimatch": "3.1.2",
21
21
  "semver": "6.3.1",
22
22
  "smol-toml": "1.5.2",
23
+ "@vercel/build-utils": "15.0.2",
23
24
  "@vercel/error-utils": "2.2.1",
24
- "@vercel/python-analysis": "0.15.2",
25
25
  "@vercel/frameworks": "3.35.0",
26
- "@vercel/build-utils": "15.0.1",
26
+ "@vercel/python-analysis": "0.15.2",
27
27
  "@vercel/routing-utils": "6.6.0"
28
28
  },
29
29
  "devDependencies": {
@@ -33,7 +33,7 @@
33
33
  "@types/node": "20.11.0",
34
34
  "@types/semver": "7.3.10",
35
35
  "vitest": "4.1.10",
36
- "@vercel-internals/runtimes": "1.2.2"
36
+ "@vercel-internals/runtimes": "1.2.3"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "node build.mjs",