-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cli] Add support for vc deploy --prebuilt
command with repo link
#10083
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5cb0fcc
[cli] Add support for `vc deploy --prebuilt` command with repo link
TooTallNate 32f384a
Remove console.log
TooTallNate e945958
Fix tests
TooTallNate 4182c72
Merge branch 'main' into update/vc-deploy-prebuilt-repo-link
c5d486f
Merge branch 'main' into update/vc-deploy-prebuilt-repo-link
TooTallNate File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vercel': patch | ||
--- | ||
|
||
Add support for `vc deploy --prebuilt` command with repo link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,56 +203,6 @@ export default async (client: Client): Promise<number> => { | |
return target; | ||
} | ||
|
||
// build `--prebuilt` | ||
if (argv['--prebuilt']) { | ||
const prebuiltExists = await fs.pathExists(join(cwd, '.vercel/output')); | ||
if (!prebuiltExists) { | ||
error( | ||
`The ${param( | ||
'--prebuilt' | ||
)} option was used, but no prebuilt output found in ".vercel/output". Run ${getCommandName( | ||
'build' | ||
)} to generate a local build.` | ||
); | ||
return 1; | ||
} | ||
|
||
const prebuiltBuild = await getPrebuiltJson(cwd); | ||
|
||
// Ensure that there was not a build error | ||
const prebuiltError = | ||
prebuiltBuild?.error || | ||
prebuiltBuild?.builds?.find(build => 'error' in build)?.error; | ||
if (prebuiltError) { | ||
output.log( | ||
`Prebuilt deployment cannot be created because ${getCommandName( | ||
'build' | ||
)} failed with error:\n` | ||
); | ||
prettyError(prebuiltError); | ||
return 1; | ||
} | ||
|
||
// Ensure that the deploy target matches the build target | ||
const assumedTarget = target || 'preview'; | ||
if (prebuiltBuild?.target && prebuiltBuild.target !== assumedTarget) { | ||
let specifyTarget = ''; | ||
if (prebuiltBuild.target === 'production') { | ||
specifyTarget = ` --prod`; | ||
} | ||
|
||
prettyError({ | ||
message: `The ${param( | ||
'--prebuilt' | ||
)} option was used with the target environment "${assumedTarget}", but the prebuilt output found in ".vercel/output" was built with target environment "${ | ||
prebuiltBuild.target | ||
}". Please run ${getCommandName(`--prebuilt${specifyTarget}`)}.`, | ||
link: 'https://vercel.link/prebuilt-environment-mismatch', | ||
}); | ||
return 1; | ||
} | ||
} | ||
|
||
const archive = argv['--archive']; | ||
if (typeof archive === 'string' && !isValidArchive(archive)) { | ||
output.error(`Format must be one of: ${VALID_ARCHIVE_FORMATS.join(', ')}`); | ||
|
@@ -355,6 +305,66 @@ export default async (client: Client): Promise<number> => { | |
throw new Error(`"org" is not defined`); | ||
} | ||
|
||
// build `--prebuilt` | ||
if (argv['--prebuilt']) { | ||
// For repo-style linking, update `cwd` to be the Project | ||
// subdirectory when `rootDirectory` setting is defined | ||
if ( | ||
link.status === 'linked' && | ||
link.repoRoot && | ||
link.project.rootDirectory | ||
) { | ||
cwd = join(cwd, link.project.rootDirectory); | ||
} | ||
Comment on lines
+310
to
+318
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main change. The rest is just a move of the existing code to a point after |
||
|
||
const prebuiltExists = await fs.pathExists(join(cwd, '.vercel/output')); | ||
if (!prebuiltExists) { | ||
error( | ||
`The ${param( | ||
'--prebuilt' | ||
)} option was used, but no prebuilt output found in ".vercel/output". Run ${getCommandName( | ||
'build' | ||
)} to generate a local build.` | ||
); | ||
return 1; | ||
} | ||
|
||
const prebuiltBuild = await getPrebuiltJson(cwd); | ||
|
||
// Ensure that there was not a build error | ||
const prebuiltError = | ||
prebuiltBuild?.error || | ||
prebuiltBuild?.builds?.find(build => 'error' in build)?.error; | ||
if (prebuiltError) { | ||
output.log( | ||
`Prebuilt deployment cannot be created because ${getCommandName( | ||
'build' | ||
)} failed with error:\n` | ||
); | ||
prettyError(prebuiltError); | ||
return 1; | ||
} | ||
|
||
// Ensure that the deploy target matches the build target | ||
const assumedTarget = target || 'preview'; | ||
if (prebuiltBuild?.target && prebuiltBuild.target !== assumedTarget) { | ||
let specifyTarget = ''; | ||
if (prebuiltBuild.target === 'production') { | ||
specifyTarget = ` --prod`; | ||
} | ||
|
||
prettyError({ | ||
message: `The ${param( | ||
'--prebuilt' | ||
)} option was used with the target environment "${assumedTarget}", but the prebuilt output found in ".vercel/output" was built with target environment "${ | ||
prebuiltBuild.target | ||
}". Please run ${getCommandName(`--prebuilt${specifyTarget}`)}.`, | ||
link: 'https://vercel.link/prebuilt-environment-mismatch', | ||
}); | ||
return 1; | ||
} | ||
} | ||
|
||
// Set the `contextName` and `currentTeam` as specified by the | ||
// Project Settings, so that API calls happen with the proper scope | ||
const contextName = org.slug; | ||
|
4 changes: 4 additions & 0 deletions
4
packages/cli/test/fixtures/unit/build-output-api-failed-before-builds/.vercel/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"orgId": "team_dummy", | ||
"projectId": "build-output-api-failed-before-builds" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cli/test/fixtures/unit/build-output-api-failed-within-build/.vercel/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"orgId": "team_dummy", | ||
"projectId": "build-output-api-failed-within-build" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cli/test/fixtures/unit/build-output-api-preview/.vercel/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"orgId": "team_dummy", | ||
"projectId": "build-output-api-preview" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cli/test/fixtures/unit/build-output-api-production/.vercel/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"orgId": "team_dummy", | ||
"projectId": "build-output-api-production" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't test this because I can't get
vc build
to work. When I try it in a project dir:and when I try it in the root, I hit an infinite loop: