Commit Graph

415 Commits

Author SHA1 Message Date
Austin Merrick
06d2d860e4 [build-utils] Handle case of not having lockfile (#11697)
In the scenario where we don't have a lockfile, cliType was detected by build utils as npm regardless of what's set in corepack. This fixes that.
2024-06-05 20:23:39 +00:00
Nathan Rajlich
9ee7d31957 [cli] Add test for CLI extensions passing through exit code (#11600)
/cc @codybrouwers
2024-05-15 20:02:40 +00:00
Austin Merrick
446ac49e2b [cli] Don't pull system environment vars in dev (#11526)
System environment variables would get set with empty strings in development which breaks some builds. This fixes that by using the v2 of `/env/pull` introduced in https://github.com/vercel/api/pull/27777.
2024-05-15 12:17:47 +00:00
Zack Tanner
5c6f9c0b66 [tests] fix maxDuration integration test (#11578)
Since maxDuration was updated for this tier ([x-ref](https://vercel.com/changelog/vercel-functions-for-hobby-can-now-run-up-to-60-seconds))
2024-05-10 18:39:49 +00:00
Erika Rowland
0f12005a68 [cli] Migrate alias command to use parseArguments and getFlagsSpecification (#11467)
Migrating `vc alias` to use new argument parsing utilities.

Note that our snapshot tests show that our help text was out of sync with what we were actually parsing from the user. 

In particular, we were showing `-n` as the shorthand for both `next` and `limit` and neither of these had this shortflag. `next` was parsing `-N` (capital), so I've updated it to that.

`--json` was parsed, but wasn't mentioned in the help text. I've kept it this way, but it may be worth adding a description. We may want to have a separate discussion about the nature and role of `json` output from our CLI as a whole.
2024-04-24 19:48:04 +00:00
Nathan Rajlich
f4c181a2c2 [static-build] Don't rely on hugo binary existing in build-container (#11455)
* Makes `hugo` framework preset work when Node.js v20.x is selected in
Project Settings.
* Stores the downloaded `hugo` binary in the `.vercel/cache` directory,
so that it does not need to be re-downloaded upon every deployment.
* Makes `vc build` work when run locally for Hugo projects - tested on
macOS arm64.
2024-04-18 12:56:16 -07:00
Jeff See
596b68ce56 Add eslint rule for no-console within the cli package (#11452)
This PR adds a rule to disallow the use of console.log/console.error/etc
from within the CLI package. The aim is to centralize our use of stdio
within the CLI so that everything moves through our client's output
module. It also disables the rule for all of the current console usage,
with the hopes that we will clean things up soon™

Also want to note that the rule only applies to usage from within the
CLI, so dependencies that the CLI pulls in (both external and even
within this monorepo) are unaffected.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2024-04-18 10:54:05 -07:00
Chris
1e6323e2b1 [cli] Ignore VERCEL_ANALYTICS_ID if @vercel/speed-insights is present on the project (#11305)
In the past, we used the `VERCEL_ANALYTICS_ID` environment variable with the previous Speed Insights feature on Vercel to activate specific logic in Next.js, Nuxt and Gatsby for collecting and sending web vitals data.

With the new Speed Insights, that's not required anymore.

We no longer want to set the environment variable when detecting the new `@vercel/speed-insights` package. 
This PR confirms that the variable is not set if the new package is detected.
2024-04-18 15:08:32 +00:00
S. Elliott Johnson
8fd2c0671e [cli] Sort default team to the top of the team selector (#11451)
The user's default team should be sorted to the top of the selector. This is a nice and simple way to do this, though I'm not sure how to test my changes -- would appreciate guidance!
2024-04-18 13:46:22 +00:00
Erika Rowland
027150134f Add snapshot tests for help (#11439)
Adds snapshot tests for the output from help as output by various commands. I expect to be changing some of the `Command` structs to continue the work started in [ [cli] Improve type signature of CommandOption #11394 ](https://github.com/vercel/vercel/pull/11394) especially as I build on work in [ Get flags specification #11433 ](https://github.com/vercel/vercel/pull/11433), and I want to be sure that the associated changes to help output are what we expect.
2024-04-17 20:51:54 +00:00
Erika Rowland
a1dfd90eec Get flags specification (#11433)
Extracting logic for turning a list of `CommandOption`s into a flagsSpecification for `parseArguments`. Builds on the work from #11396 and #11394.
2024-04-16 17:07:55 +00:00
Erika Rowland
0dfb60df83 [cli] Create argument parsing utility with clearer semantics (#11396)
The way that we currently parse arguments throughout the vercel command line is through the `getArgs` function. This function takes three arguments: `argv`, `argOptions`, and `argsOptions`. (Those last two arguments are swapped in order from the real function). This is semantically muddy and likely to create mistakes. We have instances in our code base, such as `deploy/index.ts` which at the time of this pull request creates a variable named `argOptions` and passes it to the `argsOptions` argument of `getArgs`.

Further, the return type of `arg` the library we currently use to parse arguments is unclear as well. It puts positional arguments under an `_` key, instead of a meaningful name.

In this pull request, I create a function called `parseArguments` that takes the same three arguments as `getArgs` with improved names: `args`, `flags`, and `parserOptions`. It also changes the return type to be an object with two keys: `{args, flags}` allowing for clearer access patterns where the argument parser is used.
2024-04-14 08:22:55 +00:00
Erika Rowland
da0ddb83b0 [cli] replace console.log that communicates to user with output.log (#11353)
We have several instances of `console.log` being used with colors or other indicators that they're trying to communicate to the user, and not in a way that makes sense for standard output. These should be migrated to use the `client.output` methods where possible.
2024-04-11 23:40:25 +00:00
Jeff See
a6f1c561a2 Introduce snapshot testing utilities (#11375)
This introduces some additional capabilities on the `MockClient` and `MockStream` classes used in our unit tests. 

The bulk of this code is copied over from https://github.com/SBoudrias/Inquirer.js/tree/master/packages/testing, but uses our existing stdin/stdout mocks instead of what's used there. 

You can now use `client.getScreen()` to see the "last" screen pushed to stdin, which is super handy for snapshot tests. I've added a few as part of this PR, but many more can be written for our client output as well in the near future.

---

The `client.getScreen()` is also a handy debug tool, use it with `raw: true` to see a pretty printed output during tests:


https://github.com/vercel/vercel/assets/5414297/d0be6078-4901-4eb2-a6c9-1b51b576c1ba

---

This also adds an `events` object on the `MockClient` which allows us to write `client.events.keypress("down")` instead of the less readable `client.stdin.write('\x1B[B')` throughout our testing. This could also be moved to so that it's `client.stdin.keypress(...` or something similar. Note that I've only tested that this works in a login test, included in this PR. If we're happy to make this change I will make update the rest of the unit tests to use this syntax for the inputs.
2024-04-11 19:51:34 +00:00
Nathan Rajlich
fd188a396b [tests] Use vercel-deno for "custom-runtime" dev fixture (#11405)
This is related #11133. This `custom-runtime` tests is failing on that branch since the "macos-14" test runner uses arm64 processor, and the `static-binaries` "import" package that the "vercel-bash" runtime is using does not have binaries for arm64. Switch this test fixture to use "vercel-deno" instead, which won't have this problem.
2024-04-11 01:49:13 +00:00
Sean Massa
cddf3fa00c Revert "[cli] Revert "Disallow promoting preview deployments to production (#11363)"" (#11411)
Reverts vercel/vercel#11410 to reinstate #11363
2024-04-10 22:15:33 +00:00
Nathan Rajlich
627b79fb14 [client] Always use v13 of create deployment API endpoint (#11351)
Updates `@vercel/client` to always use the v13 create-deployment endpoint, even when `builds` is present. This allows for `projectSettings.nodeVersion` to be passed when `builds` is present.
2024-04-10 20:55:28 +00:00
Mountain/\Ash
7259a324c2 [cli] optional override of existing environment variables (#11348)
## Why

Closes #11130

## Changelog

Added `--force` argument to upsert existing environment variables (#11130)

## References

- Vercel API `/v10/projects/{idOrName}/env` https://vercel.com/docs/rest-api/endpoints/projects#create-one-or-more-environment-variables
2024-04-10 20:13:53 +00:00
Nathan Rajlich
1088bf2dea [cli] Revert "Disallow promoting preview deployments to production (#11363)" (#11410)
This reverts commit 4e416d7d7b.

It was erroneously merged by Kodiak with failing unit tests.
2024-04-10 07:03:12 +00:00
Trek Glowacki
4e416d7d7b [cli] Disallow promoting preview deployments to production (#11363)
Blocks preview deployments from being directly promoted. This relies on a new API version bump.

Copied the warning text from the UI:
![CleanShot 2024-04-01 at 11 04 00@2x](https://github.com/vercel/vercel/assets/9736/4e93ffdd-32f2-40bc-97e7-6fe98208cd76)

This is a breaking change and will require a major version bump. Please don't merge until we're ready.
2024-04-09 22:02:29 +00:00
Nathan Rajlich
bd100baa16 [tests] Fix tarball URL from deleted project (#11403)
I did some pruning of old projects on my personal account last night, and accidentally broke CI. I've created a new tarball on the `curated-tests` team so that it doesn't happen again.
2024-04-09 19:56:47 +00:00
Austin Merrick
2e6aab01cb [cli] Unify table formatting output (#11387)
This removes 'text-table' as a dependency in favor of using 'cli-table3', and simplifies table formatting logic.
2024-04-09 07:33:04 +00:00
Nathan Rajlich
3e57c4a2de [tests] Remove disableSSO() function (#11380)
The SSO Protection feature is now turned off by default for testing accounts. So this manual logic for disabling the feature on each project test fixture is no longer necessary.
2024-04-06 07:47:56 +00:00
Jeff See
238d6db17a Fix name for integration test (#11393)
I think this was a copy/paste typo from https://github.com/vercel/vercel/pull/11243
2024-04-05 21:50:27 +00:00
Jeff See
76ea6ea2a7 [cli] Replace promptBool with confirm prompts (#11279)
The only changes are from some slightly different punctuation and that typing 'y' or 'n' doesn't process the prompt, it now waits for "Enter". Easiest command to see this is an action is the `init`, if you provided an invalid example to initialize `vercel init astroz` and follow the prompts.
2024-04-04 09:45:02 +00:00
Stefan M
a3fb7e6abe [go] Added support for 1.22 and updated Go minor versions of 1.19, 1.20 and 1.21 (#11156)
Co-authored-by: Nathan Rajlich <n@n8.io>
Co-authored-by: Vedant <83997633+vedantmgoyal9@users.noreply.github.com>
2024-04-04 00:47:57 -07:00
Nathan Rajlich
548afd371a [node] Add import and require ts-node files for TypeScript in vc dev (#11371)
Fixes the case in `vc dev` where importing a `.ts` file from another `.ts` file was failing in `vc dev` when `type: "module"` is not set in `package.json`.

Supersedes https://github.com/vercel/vercel/pull/11364.
2024-04-03 02:14:15 +00:00
Austin Merrick
d0877c1023 [cli] Replace inquirer with @inquirer/prompts (#11321)
# Overview

Changing to `@inquirer/prompts` meant updating all existing usage of `inquirer.prompt`. This removed a lot of code since the `inquirer.prompt` function was extra verbose.

The user experience shouldn't have changed much besides different styling. `patch-inquirer` is incompatible with `@inquirer/prompts`. ~~We probably don't want to merge this until we have a new solution for styling.~~ The new default styling is preferred over our old styling.

There are lots of changes over many files, so I went back and organized the commit history. It will probably be easier to review this PR by commit.

## Tests

~~I had to change tests in ways that aren't great. Tests had a hard time recognizing output with escape codes in them, so I had to make the expected output more generic.~~ Using `strip-ansi` worked nicely to ignore styling changes in unit and integration tests.

I removed the unit test "should list projects running on an soon-to-be-deprecated Node.js version" because that test doing `jest.useFakeTimers().setSystemTime(new Date('2023-12-08'));` would make the "should remove a project" test fail. Really strange stuff! Couldn't think of a better solution than removing this, so looking for suggestions here.
2024-04-02 07:40:32 +00:00
Nathan Rajlich
07d8d11989 Revert "[cli] extract isZeroConfigBuild into utility function (#11316)" (#11350)
This reverts commit 78e2c012f9.

This commit causes a failing test which contains the `zeroConfig: true`
field. It should have not been merged in the first place due to the
failing test, but Kodiak erroneously merged it before the tests were
passing.

When there are `builds` configuration, the v10 create-deployment
endpoint is used instead of the latest v13 endpoint. `projectSettings`
is not allowed in the v10 endpoint, therefore we can not send the
`nodeVersion` when `builds` project exists. Instead, we should look into
moving away from the v10 endpoint so that we can be using the latest
version of the endpoint for all deployments.
2024-03-29 13:53:51 -07:00
Erika Rowland
8a16e8eb65 [cli] Add explicit vitest import to unit test for isZeroConfigBuild utility (#11341) 2024-03-28 13:32:46 -05:00
Erika Rowland
78e2c012f9 [cli] extract isZeroConfigBuild into utility function (#11316)
An additional check was added to make sure that `projectSettings.nodeVersion` is sent when builds property is defined in `vercel.json`
2024-03-28 08:06:10 +00:00
kaifulee
f707f13821 chore: remove repetitive words (#11284) 2024-03-28 08:03:01 +00:00
Jeff See
9ed967034d [cli] Switch unit tests from jest to vitest (#11302) 2024-03-27 17:33:27 -07:00
Nathan Rajlich
c82a55c460 [tests] Use AL2 build container for relevant e2e tests (#11329)
* Forces the AL2 build container image for fixtures that depend on it,
via `engines.node` in package.json for most cases.
* The `testDeployment()` function was updated to send
`projectSettings.nodeVersion` in the POST body, to mimic the behavior in
CLI.
* For Go, Ruby, and Python tests, the `projectSettings.nodeVersion`
property is set "globally" in the Jest setup file, so that individual
fixtures didn't need to be adjusted.
2024-03-27 12:19:30 -07:00
Austin Merrick
6f46b1fc70 [cli][tests] Fix getUpdateCommand for local dev (#11276)
This unit test fails on my machine:
```
Expected: "pnpm i vercel@latest"
Received: "pnpm i -g vercel@latest"
```

This change allows the test to succeed on machines that need the `-g` flag.
2024-03-16 00:31:26 +00:00
Erika Rowland
11218a1798 [cli] Don't send projectSettings.nodeVersion for unsupported versions (#11277)
Previously, we used `semver` which correctly identified the nodeVersion used in `package.json`, but failed in two cases:

1. If the specified `engines` range started too low, it wouldn't correctly identify a later version compatible with Vercel. (`">10"` was detecting as Node `"10.x"` not `"20.x"`)
2. If the specified `engines` version was fixed too low to be compatible with Vercel, we sent it, and then Vercel predictably errored. (`"10"` was detecting as Node `"10.x"` which would lead to an error in the build process)

Now, case 1 should properly use the latest node version. And case 2 will not send a node version override to the API and will print a warning to the user on the CLI, but the deployment will still proceed with the version specified for the project in the web interface.

We chose to keep the error message shown to the user consistent with what shows in the logs for the build container, that is:
> WARN! Node.js Version "10.x" is discontinued and must be upgraded. Please set "engines": { "node": "20.x" } in your `package.json` file to use Node.js 20.
2024-03-14 21:34:51 +00:00
Damien Simonin Feugas
2ad44999dd [cli] stops warning Next.js users about legacy Speed Insights (#11268)
### 🧐 What's in there?

Vercel's Speed Insights legacy injection is deprecated in favor of `@vercel/speed-insights` package.
CLI has a couple places where it warns users running `vc build` locally (or on their CI).

Some users complained about seeing the warning while they are already using the package.

This PR removes the message

###  Note to reviewers

@tobiaslins, @timolins and I had a long discussion on the approach here.

This warning is issued because during `vc pull`, the project API on Vercel returns a legacy analytics.id field, [which is stored](https://github.com/vercel/vercel/blame/main/packages/cli/src/util/projects/project-settings.ts#L35) in `.vercel/project.json`.
While it is legit for users who never used `@vercel/speed-insights` package, it also appear for users who migrated from legacy.

Besides setting the warning, `VERCEL_ANALYTICS_ID` is set, which triggers auto-injection in Next.js, and is useful during self-hosting.

We first considered removing the legacy id from `project.json`, but it would break self-hosting.
We also considered printing the warning only if the application never used the package (which the project API on Vercel knows). 
In the end, we realized that vercel.com Speed Insights dashboard has plenty of disclaimer and incentives to use the new package. Having it in the CLI doesn't worth the annoyance.
2024-03-14 15:00:43 +00:00
Nathan Rajlich
8ea93839cc [cli] Set projectSettings.nodeVersion in vc deploy based on "engines.node" field (#11261)
Read the package.json and use the `engines.node` value to set the
`projectSettings.nodeVersion` property on the create deployment API call
POST body. This allows for the Node 20 build container image to be
properly specified before the deployment is created on the server side.
2024-03-13 15:39:51 -07:00
Nathan Rajlich
b9f3438c2d [cli] Fix framework version detection in monorepos (#11212)
I noticed that the framework version was not being printed on deployments in a monorepo. Turns out the framework detection logic was happening at the root of the monorepo, instead of the project directory.
2024-03-12 22:54:53 +00:00
Sean Massa
33202dec1f fix vc with root dir issues (#11243)
There's an issue with `vc link` and `vc deploy` when using a project
root directory. Framework detection fails because it's looking in the
wrong directory.

---

Manually tested and this fixes the issue. A project with a rootDirectory
was previously not detecting a framework, but now it says:

```
Auto-detected Project Settings (Remix):
```

---------

Co-authored-by: Nathan Rajlich <n@n8.io>
2024-03-08 15:21:18 -06:00
Andy
908e7837d5 [cli][build-utils] Rename variants to flags (#11121)
- Removes all the legacy `flags`
 - Renames the new `variants` to `flags`

Neither the legacy flags, nor the new variants were exposed to anyone, except for the type in build-utils, so there shouldn't be any issues removing/renaming them.
2024-03-08 16:06:23 +00:00
Nathan Rajlich
293770a2f6 [cli] Fix failing test due to npm default change (#11230) 2024-03-05 17:52:19 -08:00
Shohei Maeda
37b193c845 [build-utils] increase max memory limit (#11209)
internal ref. https://github.com/vercel/api/pull/25997

increasing max limit from 3008 -> 3009 MB

---------

Co-authored-by: Nathan Rajlich <n@n8.io>
2024-03-01 08:23:11 +09:00
Ana Trajkovska
77bc00f92e [cli] Add support for sensitive env var (#11033)
This PR updates the `vercel env add` command to support a new option
called `--sensitive` that allows an env var to be created of type
`sensitive`.
2024-01-29 16:48:07 +01:00
Sean Massa
322c88536d add ruby3 to path during build (#11094)
Add ruby to the path plus some debug code. I'll remove the debug code
after we verify this works.
2024-01-25 14:16:53 -06:00
Damien Simonin Feugas
2601257846 [cli, static-builds] deprecation notice for speed insights injection (#11048)
### 🧐 What's in there?

With the recent release of [`@vercel/speed-insights`](https://vercel.com/docs/speed-insights/package) own package (like [`@vercel/analytics`](https://vercel.com/docs/analytics/package)), it's time to encourage users to migrate.

With the availability of `@vercel/speed-insights`, users will have to opt-in explicitly by installing the package. Their benefit is a better and fine-grained control of the reporting (in particular, per-application sample rate).

###  Note to reviewers

I used `console.warn` and hope it will stands out in the build logs. I'm happy to use anything else if you have better suggestions.

There's also a deprecation warning in Next.js, which covers a related but slightly different case, when users explicitly pass analyticsId in their configuration. https://github.com/vercel/next.js/pull/60677
2024-01-19 19:10:31 +00:00
Trek Glowacki
7de754398e [cli] Add documentation string for skip-domain option (#11051)
Text taken directly from https://vercel.com/docs/cli/deploy#skip-domain
2024-01-18 18:10:22 +00:00
Damien Simonin Feugas
72d8604c9d [cli] fix error when @vercel/analytics is a transitive dependency of the deployed application (#10892) 2024-01-11 15:48:20 +01:00
Nathan Rajlich
ab826eb83d [cli] Serialize duplicate EdgeFunction references as symlinks in vc build (#11027)
Enables the symlink optimization that currently exists for `Lambda`
instances, but now for `EdgeFunction` instances as well. This will be
particularly beneficial for Remix applications which use edge functions
for many routes, since they will now all be represented by the same
underling function in production.

---------

Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2024-01-10 13:17:59 -08:00
Chris Barber
21c700aa93 [cli] Display actual deployment's 'target' (#11025)
The CLI renders the deploy URL with the "Preview" label on first deploy because the CLI treats deploys as previews unless `--prod` is set. However the first deploy for a new project is always production, so the CLI needs to render the deploy URL based on the actual deployment's `target`.
2024-01-10 14:05:52 +00:00