| 212 | } |
| 213 | |
| 214 | export const build: BuildV2 = async buildOptions => { |
| 215 | let { workPath, repoRootPath } = buildOptions; |
| 216 | const builderSpan = buildOptions.span ?? new Span({ name: 'vc.builder' }); |
| 217 | |
| 218 | const { |
| 219 | files, |
| 220 | entrypoint, |
| 221 | config = {}, |
| 222 | meta = {}, |
| 223 | buildCallback, |
| 224 | } = buildOptions; |
| 225 | |
| 226 | validateEntrypoint(entrypoint); |
| 227 | |
| 228 | let entryDirectory = path.dirname(entrypoint); |
| 229 | let entryPath = path.join(workPath, entryDirectory); |
| 230 | |
| 231 | // allow testing root directory setting with vercel.json |
| 232 | if (config.rootDirectory) { |
| 233 | repoRootPath = entryPath; |
| 234 | entryPath = path.join(entryPath, config.rootDirectory as string); |
| 235 | } |
| 236 | const outputDirectory = path.join('./', config.outputDirectory || '.next'); |
| 237 | const dotNextStatic = path.join(entryPath, outputDirectory, 'static'); |
| 238 | // TODO: remove after testing used for simulating root directory monorepo |
| 239 | // setting that can't be triggered with vercel.json |
| 240 | const baseDir = repoRootPath || workPath; |
| 241 | |
| 242 | debug( |
| 243 | JSON.stringify( |
| 244 | { |
| 245 | repoRootPath, |
| 246 | baseDir, |
| 247 | workPath, |
| 248 | entryPath, |
| 249 | entryDirectory, |
| 250 | outputDirectory, |
| 251 | }, |
| 252 | null, |
| 253 | 2 |
| 254 | ) |
| 255 | ); |
| 256 | |
| 257 | const prefixedEnvs = getPrefixedEnvVars({ |
| 258 | envPrefix: 'NEXT_PUBLIC_', |
| 259 | envs: process.env, |
| 260 | }); |
| 261 | |
| 262 | for (const [key, value] of Object.entries(prefixedEnvs)) { |
| 263 | process.env[key] = value; |
| 264 | } |
| 265 | |
| 266 | await download(files, workPath, meta); |
| 267 | |
| 268 | if (config.rootDirectory) { |
| 269 | // this must come after the download step since files outside |
| 270 | // the root directory will be excluded if we update workPath first. |
| 271 | // This should not be used when the actual root directory setting |
no test coverage detected