Commit Graph

415 Commits

Author SHA1 Message Date
Nathan Rajlich
3468922108 [build-utils] Add getNodeBinPaths() function (#10150)
The `getNodeBinPath()` function is problematic because it assumes that commands are installed in the `node_modules` directory alongside the detected lockfile. This works fine the majority of the time, but ends up not being the case when using a monorepo that uses a package manager in "linked" mode (i.e. pnpm by default).

Consider the following:

```
.
├── pnpm-lock.yaml
├── node_modules
├── blog
│   ├── node_modules
│   │   ├── hexo -> .pnpm/hexo@3.9.0/node_modules/hexo
```

In this setup, adding the root-level `node_modules/.bin` would not make the `hexo` command be visible in the `$PATH`.

To solve this issue, the new `getNodeBinPaths()` function returns an array of all directories up to the specified `root`, which can then be placed into the `$PATH`. It's also more efficient (synchronous) since it does not need to scan for a lockfile anymore (the `root` needs to be specified explicitly).

The new function is being used in `@vercel/next` and `@vercel/static-build`.

The `traverseUpDirectories()` function from CLI was moved to `build-utils` to implement this function. Consequently, that makes the implementations of `walkParentDirs()` and `walkParentDirsMulti()` simpler, since it's using this generator now.
2023-06-28 01:53:34 +00:00
Steven
733ff5ed85 [tests] Add x-vercel-id to test error message (#10149)
Including the `x-vercel-id` header when a e2e test fails will help us
debug issues
2023-06-27 19:05:55 -04:00
Sean Massa
6ec1180798 require --yes flag to promote preview deployment (#10135)
In order to promote a preview deployment, we want to make sure the user knows that this is not typical. Now the `--yes` flag is required to make this work.
2023-06-26 21:43:48 +00:00
Nathan Rajlich
8163a153df [cli] Respond with "Redirecting..." to match production behavior (#10143)
Production was recently changed to make redirect responses return the text "Redirecting..." without the destination nor status code in the text.

This caused some tests to start failing, so update `vc dev` to match this new behavior and update the relevant tests.
2023-06-26 19:41:35 +00:00
Steven
c2f1bebd1f [cli] Fix error message when token is invalid (#10131)
This changes the error when a token is invalid or expired from

```
Error: Could not retrieve Project Settings. To link your Project, remove the `.vercel` directory and deploy again.
Learn More: https://vercel.link/cannot-load-project-settings
```

to a better error

```
Error: The specified token is not valid. Use `vercel login` to generate a new token.
```

- This could be considered a follow up to
https://github.com/vercel/vercel/pull/7794
2023-06-23 11:18:58 -04:00
Nathan Rajlich
f06988d914 [cli] Add debug logging for repo link root lookup (#10112)
Adds some logging during the root directory resolving logic to help debug any cases where that lookup isn't behaving correctly.
2023-06-20 18:09:40 +00:00
Chris Barber
d61a1a7988 [cli] Fix team validation bug where you are apart of a team (#10092)
When consolidating the deployment team validation, a bug was introduced where the command would error if the user was currently using a team. The logic was meant to copy the logic in `getDeploymentByIdOrURL()`: https://github.com/vercel/vercel/blob/main/packages/cli/src/util/deploy/get-deployment-by-id-or-url.ts#L80.
2023-06-12 16:32:01 +00:00
Nathan Rajlich
79dee367cf [cli] Remove findProjectFromPath() (#10093)
Superceded by the `findProjectsFromPath()` function which may return multiple matches, and it was only being used in tests.

The relevant tests have been updated to use the multiple matches version instead, and updated to include the case where multiple matches are returned.

__Note:__ No changeset for this one since it's an internal function being removed, and doesn't need to be referenced in the public changelog.
2023-06-09 22:59:17 +00:00
Nathan Rajlich
dea58dea7e [cli] Add support for vc deploy --prebuilt command with repo link (#10083)
When repo linked, `vc deploy --prebuilt` will change working directory to the Project root directory, instead of the repo root, so that the project's local `.vercel/output` directory is what gets uploaded + deployed.
2023-06-09 09:54:17 +00:00
Steven
fecebfa7fa [cli] vc env pull should add .env*.local to .gitignore (#10085)
This is a follow up to PR #9892 which changed the default to `.env.local`.

Now that we know local files should never be committed to git, we can automatically add `.env*.local` to `.gitignore`. Note that this is the same ignore pattern that ships with create-next-app [as seen here](06abd63489/packages/create-next-app/templates/app/js/gitignore (L28)), so most Next.js users won't see anything change.

See the related [Linear ticket](https://linear.app/vercel/issue/VCCLI-461/)
2023-06-08 00:09:22 +00:00
Nathan Rajlich
e63cf40153 [cli] Add support for vc build command with repo link (#10075)
When the repo is linked to Vercel with `vc link --repo`, the `vc build` command should be invoked from the project subdirectory (otherwise the project selector is displayed). The output directory is at `<projectRoot>/.vercel/output` instead of at the repo root.
2023-06-07 08:26:13 +00:00
Sean Massa
709c9509f4 Revert "Revert "[cli] Add support for vc pull command with repo link"" (#10078)
Reverts vercel/vercel#10076

Restores the original PR: https://github.com/vercel/vercel/pull/10071

With the fix from: https://github.com/vercel/vercel/pull/10073
2023-06-07 07:49:45 +00:00
Sean Massa
7923056bc0 Revert "[cli] Add support for vc pull command with repo link" (#10076) 2023-06-07 00:35:12 -05:00
Nathan Rajlich
71ff193ea3 [cli] Add support for vc pull command with repo link (#10071)
When the repo is linked to Vercel with `vc link --repo`, the `.vercel` directory will be created at the _project root_ instead of the _repo root_, and will still contain the `project.json`.

The difference is that the `orgId` and `projectId` props will not be present in the `project.json` file when repo linked, since that information is available at the root level `repo.json` file.
2023-06-06 22:01:37 +00:00
Kiko Beats
0039c8b5ce [node] Add isomorphic functions (#9947)
This PR allow using Web APIs in Serverless functions

```js
// api/serverless.js
export const GET = () => {
  return new Response(`new Response('👋 Hello from Serverless Web!)`)
}
```

More about that
https://nextjs.org/docs/app/building-your-application/routing/router-handlers

---------

Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-06-06 23:15:10 +02:00
Chris Barber
553c001eb0 [cli] vc build ignore .env* & ignore files for @vercel/static (#10056)
For projects with static files only (e.g. `@vercel/static` builder), do not copy`.env*`, `.vercelignore`, or `.nowignore` into the BOA output dir.
2023-06-02 21:04:03 +00:00
Chris Barber
f6c3a95783 [cli] Ensure .npmrc does not contain use-node-version (#10049)
When a project has a `.npmrc` containing `use-node-version`, package managers (notably `pnpm`) will download the specified Node.js version. This is not the correct way as it can lead to `pnpm` downloading Node.js 18 or newer which depends on a version of GLIBC that is not present in the current AWS image. The proper way is to set the `"engines"` in the `package.json`.

<img width="468" alt="image" src="https://github.com/vercel/vercel/assets/97262/0974cf05-6a11-4d95-88e8-13affc4aad2a">

Discussion: https://github.com/orgs/vercel/discussions/2436
2023-06-02 15:27:28 +00:00
Nathan Rajlich
67e20a6ede [cli] Add repo linking support for deploy command (#10013)
Adds support for `vercel deploy` command when the repository has been linked via `vercel link --repo`.
2023-05-31 18:07:30 +00:00
Nathan Rajlich
57515d2d07 [cli] Fix link subcommand unit tests on Windows (#10033)
Follow-up to #10031 which broke the `link` unit tests on Windows.

For some reason Kodiak was a bad bot and merged the PR with failing tests <picture data-single-emoji=":rarityannoyed:" title=":rarityannoyed:"><img class="emoji" src="https://emoji.slack-edge.com/T0CAQ00TU/rarityannoyed/b62f8c87a5fb7239.png" alt=":rarityannoyed:" width="20" height="auto" align="absmiddle"></picture> 

_Note:_ Probably easier to review with [whitespace hidden](https://github.com/vercel/vercel/pull/10033/files?w=1).
2023-05-26 21:27:19 +00:00
Nathan Rajlich
ef30a46c03 [cli] Add client.cwd to unify all working directory related logic (#10031)
A few commands were still checking on `--cwd` explicitly, which is incorrect since the entrypoint file already handles the directory change.

The new `client.cwd` property is a helper to make writing tests easier. Tests no longer need to `chdir()` explicitly and then revert afterwards.
2023-05-26 20:42:03 +00:00
Nathan Rajlich
00813a3945 [cli] Add expect dev dependency to fix type error in toOutput (#10021)
Also make the timeout print what was buffered to help with debugging failed tests.
2023-05-24 21:35:33 +00:00
Chris Barber
a73ec6343f [cli] Clean up 'vc rollback' (#10019)
This PR removes dependency on the deprecated `lastRollbackTarget` project property and adopts many of the code conventions used in `vc promote`.

Important! Please merge #9984 first!
2023-05-24 19:10:28 +00:00
Chris Barber
4bd70d4b6e [cli] New vc promote command (#9984)
~This PR is blocked by https://github.com/vercel/api/pull/19508.~

Linear: https://linear.app/vercel/issue/VCCLI-262/cli-new-command-to-promote-deployment
2023-05-24 17:22:11 +00:00
Sean Massa
1b18c853c2 [cli] implement vc deploy --prod --skip-domain (#9836)
Adds the `--skip-domain` option to be used like `vc deploy --prod --skip-domain`. This passes along the `autoAliasCustomDomains: false` flag to the API so that the deployment will not auto alias domains for this deployment.

This PR also moves the `commands/deploy/archive` fixture to `commands/deploy/static` to better describe what the fixture is, not how it is sometimes used in a test.

---

Depends on: https://github.com/vercel/api/pull/18730
Card: https://linear.app/vercel/issue/VCCLI-276/cli-allow-creation-of-production-deployment-without-auto-alias
2023-05-23 19:26:47 +00:00
Samuel Bodin
a19edc985b [cli] Fix vercel git connect command when passing a URL parameter (#9967)
Hey team,

I had an error this morning when trying to link my repo using the CLI 
![Screenshot 2023-05-17 at 11 38 01](https://github.com/vercel/vercel/assets/1637651/798d6e4f-8c9e-41b7-b712-0322001fca02)


Seems like a combination of `: any` and a recent refacto introduced an issue here.

~- Removed all `any` that were hiding the error~
- Correctly pass the URL already parsed

~- Removed the second useless parsing~
~- Added missing `--help` flag~
  ~I noticed you never specify them and Typescript screams because of that, not sure if on purpose and how you make the compilation pass with this error. Don't hesitate to tell me.~

The fix could be improved by using `arg.Result<THE_ACTUAL_TYPE>` but that would require to store the dictionnary of flags somewhere else and also create an external type. This is already better so...

--- 

NB: 
I had multiple issues while cloning this repo
- pnpm bootstrap does not work
- missing `constants.ts` file that is not explained in the Contributing guidelines
- maybe due to bootstrap not working, almost nothing else worked and the tests too.
2023-05-23 02:50:42 +00:00
Dan Stowell
1b0d72aba5 [cli] Change vc env pull default output file to .env.local (#9892)
`vc deploy` ignores `.env.local`. To make sure we don't inadvertently
push people's secrets to source control, have all environment pulls
default to writing to `.env.local`.
2023-05-22 15:24:38 -07:00
Chris Barber
cdf55b3b1a [cli] New vc redeploy command (#9956)
This adds a new `vc redeploy <url-or-id>` command. It fetches the requested deployment, then performs a redeploy with similar output to `vc deploy` including the ability to pipe the deployment URL into a file or program.

### Redeploy Example:

<img width="650" alt="image" src="https://github.com/vercel/vercel/assets/97262/b17fc424-558b-415c-8b74-63e450f4b753">

### Bad deployment URL:

<img width="579" alt="image" src="https://github.com/vercel/vercel/assets/97262/0cb53209-396e-4490-b5d0-744d5d870aaf">

### No args:

<img width="622" alt="image" src="https://github.com/vercel/vercel/assets/97262/cb36d625-991b-41fa-bb49-d7d36c1a201b">

Linear: https://linear.app/vercel/issue/VCCLI-558/cli-new-command-to-redeploy
2023-05-22 22:08:49 +00:00
Nathan Rajlich
8de42e0a70 [cli] Remove --platform-version global common arg (#9807)
Removes the unused `--platform-version` flag from the common args.

Technically this is a breaking change, so we should probably hold off on merging until we plan to do a major version bump.
2023-05-22 21:44:52 +00:00
Nathan Rajlich
671e63e7b8 [cli] Add vc link --repo flag (alpha) (#8931)
Adding a new `--repo` flag to `vc link` which is a new linking style to
link to a Git URL rather then directly to a single Vercel Project. This
allows for multiple Projects to be linked simultaneously, which is
useful for monorepo setups.

Utilization of this new linking style in other commands will be done in
a follow-up PR.
2023-05-19 11:53:49 -07:00
Chris Barber
6cdd38d130 [tests] Pin Next.js version in test fixtures (#9910)
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-05-19 09:06:08 -05:00
Nathan Rajlich
14c877e468 [cli] Sort keys in vc env pull (#9949)
Makes sense to have the output be deterministic. Alphabetical sort seems like a logical choice.
2023-05-12 22:08:59 +00:00
Nathan Rajlich
8428632eb1 [cli] Add support for Vercel CLI Extensions (#9800)
# Vercel CLI Extensions

Adds a new mechanism to add additional sub-commands to Vercel CLI, inspired by how Git handles sub-commands:

* Extensions are standalone executables that Vercel CLI will spawn as a child process.
* The name of the executable must begin with `vercel-`. For example, to add a sub-command called `vercel example`, there should exist an executable called `vercel-example`.
* The executable can either be a npm package with a `"bin"` entry installed into the local project's workspace, or be globally available in the `$PATH`.
* Extensions can access the [Vercel REST API](https://vercel.com/docs/rest-api), pre-authenticated, by utilizing the `VERCEL_API` env var. Vercel CLI spawns a local HTTP server that adds the `Authorization` header and then proxies to the Vercel REST API.

## Environment Variables

A few environment variables which provide features and context to the extension:

| Name      | Description |
| ----------- | ----------- |
| `VERCEL_API`      | HTTP URL to access the pre-authenticated Vercel API.       |
| `VERCEL_TEAM_ID`  | Provided when the currently selected scope is a Team. |
| `VERCEL_DEBUG` | Provided when the `--debug` flag is used. The command _may_ output additional debug logging. |
| `VERCEL_HELP` | Provided when the `--help` flag is used. The command _should_ print the help output and then end with exit code **2**. |

## Example

```bash
#!/usr/bin/env bash
set -euo pipefail

echo Hi, from a Vercel CLI Extension!
user="$(curl -s "$VERCEL_API/v2/user" | jq -r .user.username)"
echo "Logged in as: $user"
```

Usage:

```
$ vc example
Vercel CLI 28.18.5
Hi, from a Vercel CLI Extension!
Logged in as: tootallnate
```
2023-05-10 16:36:58 +00:00
Kiko Beats
e3fe368baa [cli][node] upgrade async-listen to 3.0.0 (#9907)
The `async-listen@3.0.0` is ESM ready and always returns a `URL`
instance; That helps us to unify code.
2023-05-05 16:09:10 +02:00
Nathan Rajlich
99832587c5 [cli] Add support for HTTPS_PROXY env var (#9880)
By leveraging the [`proxy-agent`](https://www.npmjs.com/package/proxy-agent) npm module, enable CLI to support making HTTP requests over a proxy, by leveraging the `HTTPS_PROXY` or `ALL_PROXY` env var (same convention as `curl` uses).

Finally closes this ancient issue: https://github.com/vercel/vercel/issues/255
2023-05-05 00:52:18 +00:00
Chris Barber
7a0dacf8bb [cli][fs-detectors][frameworks] Re-add Storybook support (#9891)
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-05-03 14:05:44 -05:00
Chris Barber
678e13af53 [cli][fs-detectors][frameworks] Revert Storybook support (#9890) 2023-05-02 10:03:28 -05:00
Chris Barber
9240cbc022 [cli][fs-detectors][frameworks] Add Storybook support (#9839)
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-05-01 11:25:06 -05:00
Sean Massa
ce597ce0ec [node] validate function runtime and throw when "nodejs" (#9851)
We want to keep the currently unused `runtime: "nodejs"` value clear for future use. This PR effectively makes any unrecognized value fail the build. If the value is "nodejs" specifically, a direct error is thrown suggesting they remove the value.

Only a handful of projects set this value currently. We're reaching out to them to let them know that this value is not currently supported and that they should remove it. Then, we should deploy this PR so that anyone else using this value will know to remove it.
2023-04-27 19:22:47 +00:00
Sean Massa
0490a7733b [tests] install root typescript version 4.9.5 and standardize on that version (#9858)
This add a root-level `typescript` version that matches the one used throughout for VS Code (and other IDEs) to use when browsing the code. After this PR merges, you will be able to set VS Code's TypeScript version to match the project's version.

This will remove issues where the IDE says TypeScript compilation is good to go, but `pnpm build` disagrees.

If there's a better way to allow this, please suggest it!

---

To enable:

<img width="849" alt="Screenshot 2023-04-25 at 4 28 22 PM" src="https://user-images.githubusercontent.com/41545/234408245-205b3260-7b1d-4c43-a531-d616915dbefb.png">

Then:

<img width="1015" alt="Screenshot 2023-04-25 at 4 29 20 PM" src="https://user-images.githubusercontent.com/41545/234408271-4e7b4ec8-0be3-4743-afd7-813a267c0756.png">
2023-04-27 08:13:53 +00:00
Chris Barber
65a6e713c8 [node] Fix ESM dependency support (#9692) 2023-04-26 12:23:43 -05:00
Gary Borton
a5c3cbcd45 Allow passing of local git meta even with no remote. (#9824)
This enables the CLI to pass locally detected git meta data even when there is no available remote. It requires a corresponding internal change, which is blocking the e2e tests.
2023-04-20 13:11:17 +00:00
Kiko Beats
6dded87426 [node] Add streaming support for vc dev (#9745)
Until now, the user code response it's buffered and serialized. This is
mismatching how Vercel works these days.

This PR enables streaming response in `vc dev` for Edge/Serverless.

As part of the implementation, the `node-bridge` which spawns a process
to consume the user code is not necessary anymore.

Some necessary files (like HTTP server helpers) have been moved to live
in node builder package instead.

---------

Co-authored-by: Ethan Arrowood <ethan.arrowood@vercel.com>
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-04-19 23:56:41 +02:00
Chris Barber
b52df7a533 [cli] Add vc deploy --no-wait and vc inspect --wait (#9802)
There's a need to allow `vc deploy` to not block and not wait for the deployment to finish, yet return the URL.

```
$ vc deploy --no-wait
Vercel CLI 28.18.5
🔍  Inspect: https://vercel.com/chrisbarber/next13fun/L8X4oxp5LGcmy51yVptXwMK7n4wt [1s]
📝  Note: Deployment is still processing...
  Production: https://next13fun-kecpx6za2-chrisbarber.vercel.app [1s]
```

Normally this deployment takes around 30 seconds, but the `--no-wait` flag causes the command to exit in less than 2 seconds.

The next step is to add the ability for `vc inspect` to wait as well as specify the maximum time to wait (defaults to 3 minutes, same as `vc rollback`).

```
$ vc inspect --wait --timeout 1m https://next13fun-kecpx6za2-chrisbarber.vercel.app
Vercel CLI 28.18.5
> Fetched deployment "next13fun-ov2r4pvdz-chrisbarber.vercel.app" in chrisbarber [23s]

  General

    id		dpl_9VUuV23EGeoqWf7akEeL8rP1c8cb
    name	next13fun
    status	● Ready
    url		https://next13fun-ov2r4pvdz-chrisbarber.vercel.app
    created	Thu Apr 13 2023 12:25:07 GMT-0500 (Central Daylight Time) [24s ago]
<snip>
```

Also added the ability to pipe the URL into `vc inspect`:

```
echo https://next13fun-ov2r4pvdz-chrisbarber.vercel.app | vc inspect
```

Combined, it allows us to support cool things like:

```
$ vc inspect $(vc deploy --prod --no-wait) --wait
```
2023-04-17 15:43:05 +00:00
Nathan Rajlich
993a404311 [cli] Support pnpm in getUpdateCommand() (#9813)
We're currently showing bad instructions when CLI was installed via pnpm:

![image](https://user-images.githubusercontent.com/71256/232131890-ecc1c2c1-ace6-48b3-bd6f-8631cf7be087.png)

This adds support for it by leveraging our existing `scanParentDirs()` logic from build-utils.
2023-04-14 21:45:35 +00:00
Nathan Rajlich
3e7bcb2073 [cli] Remove a bunch of isCanary checks (#9806)
We no longer publish versions that include `-canary` in the package.json `version` field, so these are dead code. Just doing a little bit of cleanup.
2023-04-14 20:35:56 +00:00
Ethan Arrowood
ed119d6a33 [internals] Refactor @vercel-internals/types enums into constants (#9789)
- Creates new internals package, `@vercel-internals/constants`
- Refactors the `enum`s from `@vercel-internals/types` into `as const` objects, and moves them to `@vercel-intenrals/constants`
- Updates all relevant code within `packages/cli`, including `@vercel-internals/types` imports to be `import type`
2023-04-14 18:08:12 +00:00
Chris Barber
38eb0bca04 [go] Support 'go.work' file and resolve shared deps relative to work path (#9708)
This PR fixes a few issues related to `vc dev`.

1. Create a default `go.work` file in the cache dir when building the `vercel-dev-server-go` executable
2. Copy the existing `go.mod` file into the cache dir and update any "replace" relative paths
3. Split the "build" logic into separate functions for the legacy "main" package build and the `go.mod` build

Additionally, it fixes:

1. `vc build`: pass in `build.env` from `vercel.json`
2. Fix several tests to work with `vc dev` and `vc build`

Linear: https://linear.app/vercel/issue/VCCLI-638/vc-dev-go-builder-cant-resolve-workspace-dependencies

The user that reported the issue has tested this build and seems to fix their use case: https://github.com/vercel/vercel/issues/9393#issuecomment-1490726785.
2023-04-13 17:59:47 +00:00
Chris Barber
732ac2072c [tests] Update Typescript, Jest, and ts-jest (#9782)
Co-authored-by: Nathan Rajlich <n@n8.io>
Co-authored-by: Swarnava Sengupta <swarnavasengupta@gmail.com>
2023-04-12 08:38:03 -05:00
Nathan Rajlich
6b9e274bc7 [cli] Simplify parseRepoUrl() and fix edge case (#9796)
Fixes an edge case in `parseRepoUrl()` when there is a `.com` in the repo name. The code was hard to refactor in its previous form so I refactored it to be simpler as well.
2023-04-12 04:29:29 +00:00
Espen Hovlandsdal
52b2892b80 [build-utils][cli][fs-detectors] Upgrade minimatch to 3.1.2 (#9762)
Minimatch 3.0.4 has a [ReDoS
vulnerability](https://security.snyk.io/vuln/SNYK-JS-MINIMATCH-3050818).
While not likely to be an issue for the packages that use it here, a
simple version bump should prevent the issue and reduce vulnerability
noise on audits. 3.1.2 is the latest version within the 3.x range, so
prevents breaking changes.
2023-04-06 16:18:07 -07:00