Skip to content
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 5 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-grapes-whisper.md
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
110 changes: 60 additions & 50 deletions packages/cli/src/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')}`);
Expand Down Expand Up @@ -355,6 +305,66 @@ export default async (client: Client): Promise<number> => {
throw new Error(`"org" is not defined`);
}

// build `--prebuilt`
if (argv['--prebuilt']) {
Copy link
Contributor

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:

$  vc build
Vercel CLI 30.2.1-e945958
? Please select a Project: vercel-cli-monorepo-test-two
? No Project Settings found locally. Run `vercel pull` for retrieving them? [Y/n] y
Error: ENOENT: no such file or directory, chdir '/Users/smassa/source/demo/vercel-cli-monorepo-test/packages/one' -> '/Users/smassa/source/demo/vercel-cli-monorepo-test/packages/one/packages/one'

and when I try it in the root, I hit an infinite loop:

$  vc build
Vercel CLI 30.2.1-e945958
? Please select a Project: vercel-cli-monorepo-test-one
? No Project Settings found locally. Run `vercel pull` for retrieving them? [Y/n] y
? Please select a Project: vercel-cli-monorepo-test-one
> Downloading `preview` Environment Variables for Project vercel-cli-monorepo-test-one
✅  Created .vercel/.env.preview.local file [109ms]

> Downloading project settings
✅  Downloaded project settings to ~/source/demo/vercel-cli-monorepo-test/packages/one/packages/one/.vercel/project.json [0ms]
? No Project Settings found locally. Run `vercel pull` for retrieving them? [Y/n] y
? Please select a Project: vercel-cli-monorepo-test-one
> Overwriting existing .vercel/.env.preview.local file
> Downloading `preview` Environment Variables for Project vercel-cli-monorepo-test-one
> No changes found.
✅  Updated .vercel/.env.preview.local file [113ms]

> Downloading project settings
✅  Downloaded project settings to ~/source/demo/vercel-cli-monorepo-test/packages/one/packages/one/.vercel/project.json [0ms]
? No Project Settings found locally. Run `vercel pull` for retrieving them? [Y/n] y
? Please select a Project:
● vercel-cli-monorepo-test-one
○ vercel-cli-monorepo-test-two

...

// 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
Copy link
Member Author

Choose a reason for hiding this comment

The 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 link is defined.


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;
Expand Down