[next] Fix deploying with cached build (#9555)

This leverages the relative app dir field in the required files manifest when available so that we don't rely on absolute paths from a cached build since the cache can be restored in a separate context where the value no longer applies.

x-ref: https://github.com/vercel/next.js/pull/45864
x-ref: https://github.com/vercel/next.js/pull/46393
x-ref: https://github.com/vercel/next.js/discussions/39432#discussioncomment-4914549
x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1675821643786319)
This commit is contained in:
JJ Kasper
2023-02-24 18:46:06 -08:00
committed by GitHub
parent 3a65acfb32
commit 53cab61e88
18 changed files with 378 additions and 24 deletions

View File

@@ -10,7 +10,7 @@ const ms = require('ms');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
async function nowDeploy(projectName, bodies, randomness, uploadNowJson) {
async function nowDeploy(projectName, bodies, randomness, uploadNowJson, opts) {
const files = Object.keys(bodies)
.filter(n =>
uploadNowJson
@@ -68,7 +68,7 @@ async function nowDeploy(projectName, bodies, randomness, uploadNowJson) {
let deploymentUrl;
{
const json = await deploymentPost(nowDeployPayload);
const json = await deploymentPost(nowDeployPayload, opts);
if (json.error && json.error.code === 'missing_files')
throw new Error('Missing files');
deploymentId = json.id;
@@ -137,8 +137,11 @@ async function filePost(body, digest) {
return json;
}
async function deploymentPost(payload) {
const url = '/v13/deployments?skipAutoDetectionConfirmation=1&forceNew=1';
async function deploymentPost(payload, opts = {}) {
const url = `/v13/deployments?skipAutoDetectionConfirmation=1${
// skipForceNew allows turbo cache to be leveraged
!opts.skipForceNew ? `&forceNew=1` : ''
}`;
const resp = await fetchWithAuth(url, {
method: 'POST',
body: JSON.stringify(payload),