MCPcopy Create free account
hub / github.com/vercel/vercel / maybeExecBuildCommand

Function maybeExecBuildCommand

packages/backends/src/utils.ts:78–119  ·  view source on GitHub ↗
(
  args: Parameters<BuildV2>[0],
  {
    spawnEnv,
  }: {
    spawnEnv: {
      [x: string]: string | undefined;
    };
  }
)

Source from the content-addressed store, hash-verified

76}
77
78export async function maybeExecBuildCommand(
79 args: Parameters<BuildV2>[0],
80 {
81 spawnEnv,
82 }: {
83 spawnEnv: {
84 [x: string]: string | undefined;
85 };
86 }
87) {
88 const projectBuildCommand = args.config.projectSettings?.buildCommand;
89 if (projectBuildCommand) {
90 // Add node_modules/.bin to PATH so commands like 'cervel' can be found
91 const repoRoot = args.repoRootPath || args.workPath;
92 const nodeBinPaths = getNodeBinPaths({
93 base: repoRoot,
94 start: args.workPath,
95 });
96 const nodeBinPath = nodeBinPaths.join(delimiter);
97 const env = {
98 ...spawnEnv,
99 PATH: `${nodeBinPath}${delimiter}${spawnEnv?.PATH || process.env.PATH}`,
100 };
101
102 return execCommand(projectBuildCommand, {
103 env,
104 cwd: args.workPath,
105 });
106 }
107
108 // I don't think we actually want to support vercel-build or now-build because those are hacks for controlling api folder builds
109 const possibleScripts = ['build'];
110
111 // Run from the app root (workPath), not dirname(entrypoint), so `turbo build` /
112 // monorepo scripts match what users run locally and align with explicit buildCommand.
113 return runPackageJsonScript(
114 args.workPath,
115 possibleScripts,
116 { env: spawnEnv },
117 args.config.projectSettings?.createdAt
118 );
119}

Callers 1

maybeDoBuildCommandFunction · 0.85

Calls 4

getNodeBinPathsFunction · 0.90
execCommandFunction · 0.90
runPackageJsonScriptFunction · 0.90
joinMethod · 0.45

Tested by

no test coverage detected