Compare commits

..

155 Commits

Author SHA1 Message Date
JJ Kasper
dce9a89407 Publish Stable
- @vercel/next@2.6.14
2020-07-29 08:55:06 -05:00
Steven
c1cdddd974 Publish Canary
- vercel@20.0.0-canary.6
2020-07-28 17:29:59 -04:00
Steven
4bce77dd4b [cli] Fix vercel link command when vercel.json contains builds (#4940)
This PR fixes a bug when running `vercel link` command in a directory with `vercel.json` that contains `builds` property. The problem is that framework auto-detection doesn't run when `builds` is used, only for zero config. So we skip the API and instead create the project without auto-detection during `vc link`.
2020-07-28 17:28:53 -04:00
Steven
3a79810944 Publish Canary
- @vercel/frameworks@0.0.18-canary.1
 - vercel@20.0.0-canary.5
 - @vercel/client@8.2.2-canary.4
 - @vercel/next@2.6.14-canary.2
 - @vercel/node@1.7.4-canary.1
2020-07-27 20:53:09 -04:00
Steven
5b3fbdddb3 [node][next] Bump node-file-trace to 0.8.1 (#4933)
This PR bumps `node-file-trace` to [0.8.1](https://github.com/vercel/node-file-trace/releases/tag/0.8.1) to fix ESM packages used with `require()`.

Fixes https://github.com/vercel/node-file-trace/issues/141
2020-07-27 20:50:45 -04:00
JJ Kasper
25e9ecb5a2 [next] Update test fixtures to latest canary (#4935)
This updates our Next.js test fixtures to run against canary. 

It looks like the mono-repo fixtures will need to be updated to run against canary separately since there may be a conflict with legacy routes and the trailing slash redirect
2020-07-27 19:39:25 -04:00
Nathan Rajlich
415515840c [frameworks] Update "Other" build command placeholder to use "vercel-build" (#4934) 2020-07-27 14:03:16 -07:00
Nathan Rajlich
9ba14be12e [client] Export buildFileTree() and return the ignore list (#4917)
* [client] Export `buildFileTree()` and return the ignore list

The ignore list from this function will be used in production to
render a warning if there are files listed in the `.vercelignore` file
that are being comitted to the project's git repo.

* Tests for `ignoreList`

* Update packages/now-client/src/utils/index.ts

Co-authored-by: Steven <steven@ceriously.com>

Co-authored-by: Steven <steven@ceriously.com>
2020-07-24 17:11:44 -07:00
Steven
f1321946c5 [frameworks] Add link to demo for RedwoodJS (#4921) 2020-07-24 16:22:19 -07:00
Max Leiter
230b69abf4 [cli] Fix external rewrites/redirects in dev (#4914)
Co-authored-by: Steven <steven@ceriously.com>
2020-07-24 16:21:52 -07:00
Igor Klopov
0d96f80ac8 [cli] Print build error message instead of 'Build failed' (#4908)
This PR fixes the `lambda-with-invalid-runtime` CLI test
2020-07-24 12:38:24 -04:00
Steven
178f5e7f00 Publish Canary
- @vercel/build-utils@2.4.3-canary.2
 - vercel@20.0.0-canary.4
 - @vercel/client@8.2.2-canary.3
2020-07-23 21:00:25 -04:00
Steven
dbfdf20c9d [build-utils] Fix redwood /api detection (#4916)
Previously, the zero detection would see js files in the `/api` directory and attempt to use `@vercel/node`. However, this doesn't work with RedwoodJS which uses a different format for [`/api`](https://github.com/vercel/vercel/tree/master/examples/redwoodjs/api) so we must only use `@vercel/redwood` when RedwoodJS is detected.
2020-07-24 00:33:06 +00:00
Juan Campa
a80ed4ec9b [api] Fix api-framework cache header (#4913)
## Problem

`api-frameworks` is not being cached by our edge when used via the fallback-to-front mechanism. That's because the headers are only applied to `/api/frameworks` but not `/api/v1/frameworks` which is the actual path being used.

## Solution

Also apply the caching headers to `/api/<version>/frameworks`
2020-07-23 23:48:47 +00:00
Steven
833c3d7c01 Publish Canary
- @vercel/frameworks@0.0.18-canary.0
 - @vercel/build-utils@2.4.3-canary.1
 - vercel@20.0.0-canary.3
 - @vercel/client@8.2.2-canary.2
 - @vercel/redwood@0.0.2-canary.1
2020-07-23 18:29:16 -04:00
Steven
19d0db7270 [frameworks] Add autodetection for RedwoodJS (#4915)
- Supersedes #4539
- Related to #4676

Co-authored-by: Lachlan Campbell <lachlan@hackclub.com>
2020-07-23 18:02:50 -04:00
Steven
041e8cc601 Publish Canary
- @vercel/build-utils@2.4.3-canary.0
 - vercel@20.0.0-canary.2
 - @vercel/client@8.2.2-canary.1
 - @vercel/static-build@0.17.7-canary.1
 - @vercel/redwood@0.0.2-canary.0
2020-07-23 16:28:44 -04:00
Steven
b118e461b1 [redwoood] Add runtime @vercel/redwood (#4676)
### Changes
- Add new Runtime: `@vercel/redwood`
- Update `run.js` script to sort packages properly

### Related
- Related to #4539 
- Related to #4535
- Depends on https://github.com/apollographql/apollo-server/pull/4311
2020-07-23 16:22:48 -04:00
Andy Bitz
e519d49d7b Publish Canary
- vercel@20.0.0-canary.1
2020-07-23 15:42:46 +02:00
Andy Bitz
27683818ba Bump vercel to 20.0.0-canary.0 2020-07-23 15:42:30 +02:00
Andy
e016e38229 [cli] (Major) Change vc domains add workflow to match the dashboard (#3325)
* [now-cli] Change `now domains add` workflow to match dashboard

* Fix error throwing and add --force

* Remove `now domains verify`

* Count projects when removing a domain

* Include projects for `now inspect`

* Updated `now domains ls`

* Fix `now domains ls`

* Use Finally

* Add tests

* Use --force for domain tests

* Adjust tests

* Adjust test and fix output

* Fix padding

* Adjust more tests

* Ensure the project exists

* Log the deployment

* Fix tests again

* Remove project after test

* Fix command

* Fix test

* Change user after a couple of tests

* Add check

* Use random name for domain

* More logging

* Add more logging

* Remove logging

* Remove .now/project.json every time

* Skip test

* Add test to change user

* More logging

* Use now login

* Remove duplicated test

* Consider linked project for `domains add`

* Fix linting

* Remove unused docs

* Undo changes

* Undo more changes

* Fix typo

* Do not sort projects when there is only one record

* Fix loop

* Deploy with `-V 2`

* Remove verification

* Remove outdated link

* Update packages/now-cli/src/commands/domains/add.ts

Co-authored-by: Steven <steven@ceriously.com>

* Update packages/now-cli/src/commands/domains/add.ts

Co-authored-by: Steven <steven@ceriously.com>

* Use utils for public suffix and service type

* Update packages/now-cli/src/commands/domains/ls.ts

Co-authored-by: Steven <steven@ceriously.com>

* Update packages/now-cli/src/commands/domains/add.ts

Co-authored-by: Steven <steven@ceriously.com>

* Change link

* Undo test changes

* Fix type issues

* Update packages/now-cli/src/commands/domains/add.ts

Co-authored-by: Steven <steven@ceriously.com>

* Use domain config to print info

* Check apex domain when removing a domain

* Remove psl

* List projects when removing a domain

* Do not list projects

* Change user earlier

* Update packages/now-cli/src/commands/domains/inspect.ts

Co-authored-by: Steven <steven@ceriously.com>

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

Co-authored-by: Mark Glagola <mark.glagola@gmail.com>
Co-authored-by: Steven <steven@ceriously.com>
2020-07-23 15:41:25 +02:00
Max Leiter
5db1c5e610 [tests] Skip try to purchase a domain CLI test if a VERCEL_TOKEN is provided (#4909)
I placed the check inside the test because otherwise `test.only` and other test functions break with this test.
2020-07-23 01:39:05 +00:00
Steven
24c228569f Publish Canary
- vercel@19.2.1-canary.2
 - @vercel/next@2.6.14-canary.1
2020-07-22 16:09:26 -04:00
Steven
963de9b64f [cli] Update "set up" message (#4907)
Follow up to #4897 

* `vc link` - Update message to say `Set up ~/proj`
* `vc dev` - Update message  to say `Set up and develop ~/proj`
* `vc link --help` - Updated example message to include `vc link ~/proj` usage
2020-07-22 19:13:41 +00:00
JJ Kasper
ab7fd52305 [next] Don't trace pages for lambdas when not needed (#4841)
When pages are fully static and don't leverage preview mode or revalidation we can skip tracing the pages for generating the lambdas since lambdas aren't needed in this case
2020-07-22 18:14:47 +00:00
Nathan Rajlich
0fdb0dac91 [cli] Send the Vercel platform proxy request headers to frontend dev server (#4874)
This is a follow up to #4850 that does the same thing when
proxying to the frontend dev server.
2020-07-22 14:36:15 +00:00
Andy Bitz
bb0b632dcf Publish Canary
- vercel@19.2.1-canary.1
 - @vercel/go@1.1.5-canary.0
 - @vercel/next@2.6.14-canary.0
 - @vercel/node@1.7.4-canary.0
 - @vercel/static-build@0.17.7-canary.0
2020-07-22 13:34:40 +02:00
Andy
ced9495143 Revert "Revert "[go] Implement startDevServer() function (#4662)" (#4899)" (#4906)
This reverts commit 8d1afc026f.
2020-07-22 13:33:36 +02:00
Nathan Rajlich
fadc3f2588 [next][node][static-build] Execute "vercel-build" script if defined (#4863)
* [build-utils] Make `runPackageJsonScript()` run the `vercel-` or `now-` if defined in `package.json`

* [build-utils] Export `getScriptName()`

* [next] Use `getScriptName()` and `remove()`

* [node] Update for `vercel-`

* [static-build] Update for `vercel-`

* Remove debug

* Add `getScriptName()` unit tests

* Test for `vercel-build` in e2e

* Make platform name behavior be opt-in

So that it's not a breaking behavior change.

* Check for only "vercel-build" or "now-build", but not "build"

* Simplify `getScriptName()` to return the first existing script in a possible set

* Revert change

* Fix test

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-07-21 20:04:24 -07:00
Steven
a1d548dfef Publish Canary
- vercel@19.2.1-canary.0
 - @vercel/client@8.2.2-canary.0
2020-07-21 18:56:21 -04:00
Steven
754090a8ab [cli] Add vercel link command (#4897)
- [x] Add `vercel link` command
- [x] Update `vercel dev` to automatically link 
- [x] Updated `vercel env` error message to mention `vercel link`
- [x] Test `vercel link`
- [x] Test `vercel dev`
- [x] Add `--confirm` flag

### Related

- Fixes #3767
- Fixes #4889 
- Fixes #3991 
- Fixes #4534 
- Related to #3989
2020-07-21 18:52:46 -04:00
dependabot[bot]
8269a48ee0 Bump codecov from 3.6.5 to 3.7.1 (#4900)
Bumps [codecov](https://github.com/codecov/codecov-node) from 3.6.5 to 3.7.1.
<details>
<summary>Commits</summary>
<ul>
<li><a href="29dd5b6b03"><code>29dd5b6</code></a> 3.7.1</li>
<li><a href="c0711c6566"><code>c0711c6</code></a> Switch from execSync to execFileSync (<a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/180">#180</a>)</li>
<li><a href="5f6cc62d4f"><code>5f6cc62</code></a> Bump lodash from 4.17.15 to 4.17.19 (<a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/183">#183</a>)</li>
<li><a href="0c4d7f3c6f"><code>0c4d7f3</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/182">#182</a> from codecov/update-readme-badges</li>
<li><a href="cc5e121842"><code>cc5e121</code></a> Update depstat image and urls</li>
<li><a href="b44b44e1f8"><code>b44b44e</code></a> Update readme with 400 error info (<a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/181">#181</a>)</li>
<li><a href="bb79335719"><code>bb79335</code></a> V3.7.0 (<a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/179">#179</a>)</li>
<li><a href="0d7b9b01cb"><code>0d7b9b0</code></a> Remove <code>'x-amz-acl': 'public-read'</code> header (<a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/178">#178</a>)</li>
<li><a href="eeff4e1953"><code>eeff4e1</code></a> Bump acorn from 5.7.3 to 5.7.4 (<a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/174">#174</a>)</li>
<li><a href="eb8a527470"><code>eb8a527</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/codecov/codecov-node/issues/172">#172</a> from RoboCafaz/bugfix/codebuild-pr-parser</li>
<li>Additional commits viewable in <a href="https://github.com/codecov/codecov-node/compare/v3.6.5...v3.7.1">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=codecov&package-manager=npm_and_yarn&previous-version=3.6.5&new-version=3.7.1)](https://help.github.com/articles/configuring-automated-security-fixes)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/vercel/vercel/network/alerts).

</details>
2020-07-21 17:25:56 +00:00
Andy Bitz
9f05a1865c Publish Stable
- @vercel/frameworks@0.0.17
 - @vercel/build-utils@2.4.2
 - vercel@19.2.0
 - @vercel/client@8.2.1
 - @vercel/go@1.1.4
 - @vercel/next@2.6.13
 - @vercel/node@1.7.3
 - @vercel/static-build@0.17.6
2020-07-21 14:58:27 +02:00
Andy
8d1afc026f Revert "[go] Implement startDevServer() function (#4662)" (#4899)
This reverts commit 04bea1e3cd.
2020-07-21 14:55:59 +02:00
Nathan Rajlich
130f36aad6 Publish Canary
- vercel@19.1.3-canary.6
2020-07-20 23:11:46 -07:00
Nathan Rajlich
dd87c9b0c6 Publish Canary
- vercel@19.1.3-canary.5
 - @vercel/next@2.6.13-canary.2
2020-07-20 19:51:15 -07:00
Max Leiter
f813b3340b [cli] Fetch environment variables from Project Settings if .env file is not present (#4562)
Previously, users would have to run `vc env pull` to fetch cloud environment
variables into `.env`. After this PR, if no `.env` or `.build.env` file is present,
environment variables will be pulled by `vc dev` from your Vercel Environment
Variables settings, no file necessary.
2020-07-20 19:47:13 -07:00
Joe Haddad
976b02e895 [next] Add tests for trailing slash behavior (#4894) 2020-07-20 22:29:09 -04:00
Nathan Rajlich
843be9658c [cli] Use update-notifier instead of update-check (#4896)
This makes the updating logic be asynchronous instead of synchronous, and as such will make boot-up of CLI be faster.

The actual update notification display is identical to previous, we are not using `update-notifier`'s default boxen rendering.
2020-07-20 22:31:15 +00:00
dependabot[bot]
ad501a4cd0 Bump lodash from 4.17.15 to 4.17.19 (#4877)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-20 14:00:32 -04:00
Steven
727ae587db Publish Canary
- @vercel/frameworks@0.0.17-canary.2
 - @vercel/build-utils@2.4.2-canary.1
 - vercel@19.1.3-canary.4
 - @vercel/client@8.2.1-canary.1
 - @vercel/next@2.6.13-canary.1
 - @vercel/node@1.7.3-canary.0
2020-07-20 10:27:10 -04:00
Steven
536b15079b [node][next] Bump node-file-trace to 0.8.0 (#4814)
Bump `node-file-trace` to version [0.7.0](https://github.com/vercel/node-file-trace/releases/tag/0.7.0) and then [0.8.0](https://github.com/vercel/node-file-trace/releases/tag/0.8.0)

- Add support for `exports`, dynamic import from CJS support, package boundary emission
- Fix trailing slash in `require()`
- Import named instead of default
2020-07-20 10:24:05 -04:00
Nathan Rajlich
887882697b [cli] Remove "npm pack" logic from output-is-source dev test (#4870)
Now that `@vercel/static-build` is being symlinked to CLI due to the
yarn workspace, `vc dev` will always use the latest code for
zero-config, so this "npm pack" logic is no longer necessary.

The `vercel.json` also no longer gets created in this test so that
zero-config is used.
2020-07-16 16:44:28 -07:00
Nathan Rajlich
e2db7c7734 [build-utils] Add getScriptName() function (#4869)
And allow a set of possible script names to use in `runPackageJsonScript()`.

These are only the changes to `@vercel/build-utils` from #4863.
2020-07-16 16:42:55 -07:00
Steven
022504787c [frameworks][examples] Update blitz new command (#4868)
Updated description per @leo
2020-07-16 22:16:03 +00:00
Nathan Rajlich
0f424de406 [cli] Set server: Vercel header and remove x-now response headers in vercel dev (#4867)
This matches production.
2020-07-16 20:23:44 +00:00
Nathan Rajlich
4819c3ac61 Publish Canary
- vercel@19.1.3-canary.3
2020-07-15 11:04:16 -07:00
Nathan Rajlich
c28ca7ef2d [cli] Set Vercel platform env vars for startDevServer() invocations (#4855)
Ensures that `VERCEL_REGION` is set for API calls when the runtime
implements `startDevServer()`.

Also adds `VERCEL_URL` which was previously not defined.
2020-07-15 10:34:27 -07:00
Nathan Rajlich
068ea00615 [cli] Set Vercel proxy request headers in startDevServer() (#4850)
The Vercel proxy request headers (`x-vercel-deployment-url` for example)
were not being sent to the dev server when the Runtime defines
`startDevServer()`. This is now fixed.

Also updates the header names to match production:

 - `now` -> `vercel`
 - 'x-now-trace', 'x-now-id', and 'x-now-log-id' are removed

Fixes #4729.
2020-07-14 14:48:46 -07:00
Paco
7f8145ab40 [cli] Minor text changes to wrong config error message (#4848)
CH-3242

From review:
- Capitalize "Project"
- Highlight ".vercel" in code snippet style

Thanks to @styfle for pointing me to output/code.
2020-07-14 13:53:23 +00:00
Steven
1a12715096 Publish Canary
- @vercel/build-utils@2.4.2-canary.0
 - vercel@19.1.3-canary.2
 - @vercel/client@8.2.1-canary.0
 - @vercel/next@2.6.13-canary.0
2020-07-13 18:57:39 -04:00
Steven
5b6d565360 [build-utils] Update error message for unmatched function pattern (#4849)
- [x] Depends on https://github.com/vercel/docs/pull/1985
2020-07-13 22:55:15 +00:00
JJ Kasper
0794158906 Publish Stable
- @vercel/next@2.6.12
2020-07-12 10:30:51 -05:00
JJ Kasper
02cdb88d3b Publish Canary
- vercel@19.1.3-canary.1
 - @vercel/next@2.6.12-canary.0
2020-07-12 10:25:27 -05:00
Paco
fa58855114 [cli] Show helpful error when using unauthorized .vercel config (#4807)
CH-3242

When a user has project configuration in `.vercel` that corresponds to a team that they are not a part of, we currently throw a 403 error. This adds special handling so that we can show a specific message when this happens.

I didn't want to update the return type of `getProjectByIdOrName` because we only want to handle this 403 in a special case, so I `throw` it instead.

Other changes are linter.
2020-07-11 03:52:02 +00:00
JJ Kasper
1fac11792f [next] Fix nested public files being renamed incorrectly (#4817)
This corrects the file rename for public files to not incorrectly rename nested `public` files

x-ref: https://github.com/vercel-support/next-nested-public-dir
2020-07-10 23:52:54 +00:00
Nathan Rajlich
05ffc9ce2b Publish Canary
- @vercel/frameworks@0.0.17-canary.1
 - vercel@19.1.3-canary.0
 - @vercel/go@1.1.4-canary.0
 - @vercel/static-build@0.17.6-canary.1
2020-07-10 15:51:19 -07:00
Nathan Rajlich
f848551043 [cli] Pin @vercel/static-build to "0.17.6-canary.0" (#4837)
It got de-synced in c68e83f972.
2020-07-10 22:49:35 +00:00
Steven
9712abc5bf [frameworks][api] Move dependency to devdependency (#4836)
Follow up to #4829
2020-07-10 16:38:19 -04:00
Nathan Rajlich
a9ef3cc726 [go] Add filesystem write fallback for startDevServer() (#4830)
This is for `@vercel/go` to work on Windows, which currently fails with
this error:

```
panic: write pipe: The handle is invalid.

goroutine 1 [running]:
main.main()
	C:/Users/Nathan/Code/casca/vercel-go-test/.vercel/cache/go/2flefmhra8o/api/vercel-dev-server-main.go:25 +0x1ec
exit status 2
```

So this fallback writes the port number to a temp file that
`startDevServer()` polls for in order to figure out the port number.
2020-07-10 19:55:53 +00:00
Steven
e5cc1d643a [frameworks][api] Add sort order (#4829)
This PR adds an optional property called `sort` to each framework so that we can change the order returned in the API. 
The reason this is necessary is because the order of the original array determines the precedence of framework detection. So we need another way to indicate the order of templates/examples returned from the API.

In particular, we need "Next.js" to be first and "Other" to be last.

I also updated the deprecated `@now/node` usage to `@vercel/node` in the API.
2020-07-10 18:09:14 +00:00
Andy Bitz
c68e83f972 Publish Canary
- @vercel/frameworks@0.0.17-canary.0
 - @vercel/static-build@0.17.6-canary.0
2020-07-10 18:45:47 +02:00
Sébastien Chopin
80118de040 [build-utils] Add Nuxt cache and default routes (#4755)
* [@vercel/build-utils] Improve Nuxt build

Need review from @pi0 and @danielroe

* Update packages/now-static-build/src/frameworks.ts

Co-authored-by: Daniel Roe <daniel@roe.dev>

Co-authored-by: Daniel Roe <daniel@roe.dev>
Co-authored-by: Andy <AndyBitz@users.noreply.github.com>
2020-07-10 18:41:02 +02:00
Sébastien Chopin
c69da18e9c fix: Also handle nuxt-edge detection (#4756)
Co-authored-by: Andy <AndyBitz@users.noreply.github.com>
2020-07-10 17:55:29 +02:00
Steven
e19446f89c Publish Stable
- @vercel/frameworks@0.0.16
 - @vercel/build-utils@2.4.1
 - vercel@19.1.2
 - @vercel/client@8.2.0
 - @vercel/go@1.1.3
 - @vercel/next@2.6.11
 - @vercel/node@1.7.2
 - @vercel/ruby@1.2.3
 - @vercel/static-build@0.17.5
2020-07-10 08:20:44 -07:00
JJ Kasper
ea3233502d Publish Stable
- @vercel/next@2.6.10
2020-07-09 21:30:31 -05:00
JJ Kasper
0a8810b64f Publish Canary
- vercel@19.1.2-canary.22
 - @vercel/next@2.6.10-canary.2
2020-07-09 21:29:18 -05:00
JJ Kasper
f6b373f0f4 [next] Fix preview mode with dynamic routes in shared lambdas (#4812)
This fixes dynamic routes missing inside of shared lambdas for non-revalidate pages that leverage preview mode which causes them to not be able to render. Additional tests have also been added to ensure preview mode is working properly
2020-07-10 02:22:17 +00:00
Steven
7ad2a99cd7 Publish Canary
- @vercel/frameworks@0.0.16-canary.2
 - @vercel/build-utils@2.4.1-canary.3
 - vercel@19.1.2-canary.21
 - @vercel/client@8.1.1-canary.3
 - @vercel/next@2.6.10-canary.1
 - @vercel/static-build@0.17.5-canary.1
2020-07-09 16:42:50 -07:00
JJ Kasper
0349eea494 [next] Add pages with invalid route regexes (#4813)
This adds failing page names to our tests which should be resolved once the correct regexes is being generated for the routes-manifest in Next.js

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
Co-authored-by: Steven <steven@ceriously.com>
2020-07-09 19:37:13 -04:00
Luc
ed4d006fb7 replace "more details" with "learn more" (#4828)
Follow up to PR #4825. Replace more "More details" with "Learn More".
2020-07-09 19:31:04 -04:00
Steven
12a9d203e9 [cli] Handle 400 errors as user errors (#4827)
When a user performs an action such as trying to add a domain they don't own, the API returns a 400-499 response code.

Previously, we would save this error in Sentry but this PR changes the behavior so that the error is printed locally for the user but not saved in Sentry.
2020-07-09 21:57:18 +00:00
Luc
ac1f4cf789 [cli] Handle API Error action property (#4825)
* handle error action

* fix test
2020-07-09 22:14:30 +02:00
Steven
b284ca350a Revert "[frameworks] Remove blitz demo (#4816)" (#4826)
This reverts commit f11eb32b2c.

Reverts PR #4816

This PR adds back the Blitz.js demo now that we confirmed the example works and is deployed to the correct account.
2020-07-09 13:28:38 -04:00
Steven
a43bf6c912 [cli][static-build] Use titlecase for "Project Settings" (#4820)
"project settings" should be "Project Settings"
2020-07-09 11:56:11 -04:00
Nathan Rajlich
62410806bb Publish Canary
- vercel@19.1.2-canary.20
 - @vercel/next@2.6.10-canary.0
2020-07-08 16:24:18 -07:00
Steven
47e3111cab [all] Change prettier config arrowParens: avoid (#4819)
In PR #4760, Prettier was upgraded to 2.0 which changed the default configuration for `arrowParens` from `avoid` to `always`. This PR changes it back to `avoid` so we don't have PRs changing unnecessary lines during in the commit hook.

See the [Prettier 2.0 Announcement](https://prettier.io/blog/2020/03/21/2.0.0.html#change-default-value-for-arrowparens-to-always-7430httpsgithubcomprettierprettierpull7430-by-kachkaevhttpsgithubcomkachkaev) for more.
2020-07-08 18:46:48 -04:00
Nathan Rajlich
135f35002f [cli] Remove caching of vercel.json config in vc dev (#4808)
This is a re-introduction of #4697, which was reverted for performance
resons. But now that #4760 and #4793 have landed, we can enable this
behavior again.
2020-07-08 22:37:55 +00:00
Steven
ee40052cee Publish Stable
- @vercel/next@2.6.9
2020-07-08 13:53:18 -07:00
JJ Kasper
86b730c1cd Publish Canary
- vercel@19.1.2-canary.19
 - @vercel/next@2.6.9-canary.1
2020-07-08 15:08:29 -05:00
JJ Kasper
b440249c26 [next] Don't use potentially invalid routeKeys/regexes (#4803)
The first version of `routeKeys` which was Array based could contain invalid named regexes which would break the build during route validation so this disables using them in that version of the manifest instead of trying to leverage them still. It also adds an additional test fixture with this version of the manifest to ensure it is still working properly
2020-07-08 20:05:00 +00:00
Steven
5380c12569 Publish Canary
- @vercel/frameworks@0.0.16-canary.1
 - @vercel/build-utils@2.4.1-canary.2
 - vercel@19.1.2-canary.18
 - @vercel/client@8.1.1-canary.2
 - @vercel/next@2.6.9-canary.0
2020-07-08 11:27:30 -07:00
Steven
f11eb32b2c [frameworks] Remove blitz demo (#4816)
This is not ready yet. We need to confirm Blitz is working before we deploy the demo.
2020-07-08 14:19:55 -04:00
Brandon Bayer
3d40e343ac [frameworks][examples] Add Blitz.js (#4465)
This adds [Blitz.js](https://github.com/blitz-js/blitz) to the zero-config frameworks.

Blitz compiles to a Next.js app, so it uses the same `@vercel/next` builder.

The change in `packages/now-build-utils/src/detect-builders.ts` was made according to @styfle's suggestion in Slack.

---

**This is a rerun of #4219 which had to be reverted because of this:**

> It looks like the @vercel/next package still requires next in the dependencies.
>
> When I've deployed the example I've got only a file listing, but when I added next to the dependencies it worked. I'll revert for now.

This new PR fixes that problem with a small refactor to `@vercel/next`.

`@vercel/next` was getting the Next version two different ways:

1. By checking project root package.json for `next` in deps or devDeps
2. By trying to resolve the installed next version and get `version` from its package.json

My refactor consolidates those two approaches by changing the existing `getNextVersion()` function to first try and resolve the real next version. If that fails, fall back to checking the project root.

Blitz bundles Next, so the real next package version should always be resolved.
2020-07-08 13:18:01 -04:00
Nathan Rajlich
80f525796f [cli] Make filesystem globbing faster in vercel dev (#4793)
The current code uses `getAllProjectFiles()` which globs for every file
in the project, not considering the `.vercelignore` file and default
ignore list. For example, every file in the `node_modules` directory is
selected, just for `vercel dev` to manually ignore them afterwards,
which is very slow and wasteful. For a simple Next.js project, this
globbing was taking over 3 seconds on my machine 🤯!

Solution is to use the `staticFiles()` function which is the same as
`vercel dev` uses at boot-up time. This function properly considers the
ignore list and thus is much faster, and the manual filtering is no
longer necessary by `vercel dev`. For the same simple Next.js project,
this function takes on average 10 milliseconds.

Also did a bit of cleanup and removed the `getAllProjectFiles()`
function since it is no longer used anywhere.
2020-07-07 20:30:21 +00:00
Nathan Rajlich
af4ad358f2 [cli] Print a warning if both "functions" and "builds" are defined in vercel.json in vercel dev (#4795)
This matches the error message that is used in production when using the
`vercel dev` command.
2020-07-07 19:41:29 +00:00
Nathan Rajlich
e6033d7a2d [client] Add @vercel/build-utils as a "dependency" (#4804)
Fixes: https://github.com/philcockfield/sample.vercel.client-error
2020-07-07 18:56:31 +00:00
JJ Kasper
d3148dffaa Publish Stable
- @vercel/next@2.6.8
2020-07-06 08:40:44 -05:00
JJ Kasper
30048cf4ff Publish Canary
- vercel@19.1.2-canary.17
 - @vercel/next@2.6.8-canary.7
2020-07-06 08:31:35 -05:00
JJ Kasper
07c65fa5c8 [next] Use correct data route regex (#4778)
For `getServerSideProps` routes the non-named data route was being used for routes causing dynamic route params that were being trusted from the proxy to be incorrect. Our tests weren't failing after trusting the values from the proxy was landed in Next.js on canary due to the `21-server-props` test suite not running against the latest canary which is updated in this PR. 

Note: the below Next.js PR is not needed or can be reverted if this PR is landed

x-ref: https://github.com/vercel/next.js/pull/14829
2020-07-05 21:13:01 +00:00
Nathan Rajlich
411ec64986 [cli] Reduce number of times getNowConfig() is invoked in vercel dev (#4760)
* [cli] Reduce number of times `getNowConfig()` is invoked in `vercel dev`

When using the `vercel dev` command, the `getNowConfig()` function was
being invoked many times per HTTP-request. It should only be read _once_
per HTTP request as it may be an expensive function depending on the
project size.

This change reduces the number of times the function is called to once
per HTTP request, and passes around the resulting `nowConfig` object to
the functions that require it.

* Fix default values

* Remove unnecessary type narrowing

* Remove one more `getNowConfig()` invocation

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-07-02 17:25:07 -07:00
Joe Haddad
e4d2cc704c Add Lockfile to Fix Gatsby Example (#4771)
This adds the Lockfile from Gatsby's official starter to fix deployments.

```
❯ npx gatsby-cli new ~/Desktop/scratch/test-default
❯ cp ~/Desktop/scratch/test-default/yarn.lock examples/gatsby
❯ cd examples/gatsby
❯ yarn
❯ git add examples/gatsby/yarn.lock
```
2020-07-02 21:06:44 +00:00
Joe Haddad
38db720586 Regenerate yarn.lock file (#4769) 2020-07-02 11:20:35 -07:00
Joe Haddad
c26c7886be [next] Skip Lambda Deployment for Static Sites (#4748) 2020-07-02 11:51:02 -04:00
JJ Kasper
b0e5d308ca [next] Add additiontal test cases for basePath support (#4747)
This adds some additional test cases for `basePath` support in Next.js to ensure it is working properly with `@vercel/next`
2020-07-02 09:40:15 +00:00
JJ Kasper
609b98cc73 Publish Canary
- vercel@19.1.2-canary.16
 - @vercel/next@2.6.8-canary.6
2020-07-01 14:46:28 -05:00
JJ Kasper
e0ec6c792b [next] Re-enable shared lambdas by default (#4757)
This re-enables the shared lambdas optimization by default and also adds additional tests to ensure that when a `now.json` or `vercel.json` contains either `routes` or `functions` configs the shared lambda optimization is disabled. 

Additional test deployments done:

- minimal `now.json` with `builds` config [deploy](https://shared-lambdas-tests-d646fsqju.vercel.app)
- `now.json` with `functions` config [deploy](https://shared-lambdas-tests-ahnuosp4s.vercel.app)
- `now.json` with `routes` config [deploy](https://shared-lambdas-tests-gulam3jda.vercel.app)
- minimal `vercel.json` with `builds` config [deploy](https://shared-lambdas-tests-7ic7wzirs.vercel.app)
- `vercel.json` with `functions` config [deploy](https://shared-lambdas-tests-7ic7wzirs.vercel.app)
- `vercel.json` with `routes` config [deploy](https://shared-lambdas-tests-rja2391tq.vercel.app)
2020-07-01 19:44:09 +00:00
Nathan Rajlich
b29db2fd1d [cli] Pin @vercel/static-build to v0.17.5-canary.0 (#4751)
It got de-synced in fa0f1b90b4.
2020-07-01 10:59:22 -07:00
JJ Kasper
b604ced99d Publish Canary
- vercel@19.1.2-canary.15
 - @vercel/next@2.6.8-canary.5
2020-07-01 10:53:18 -05:00
JJ Kasper
b7fd69517e [next] Fix dynamic route mapping with shared lambdas (#4740)
This fixes mapping dynamic routes to their shared lambdas failing from the `dynamicPageLambdaRoute` not being injected directly after the dynamic route due to dynamic routes now containing a `query` which caused the route lookup to fail. 

This is resolved by making sure to parse the pathname while injecting the `dynamicPageLambdaRoute` so the route can be looked up correctly. This also adds additional test cases to prevent regressing on this along with updating existing fixtures for custom routes being de-experimentalized
2020-07-01 07:30:41 +00:00
Nathan Rajlich
4c821a6fb5 Publish Canary
- vercel@19.1.2-canary.14
 - @vercel/node@1.7.2-canary.1
 - @vercel/static-build@0.17.5-canary.0
2020-06-30 16:27:46 -07:00
Nathan Rajlich
5c4fb319af [cli] Revert "Remove caching of vercel.json config in vc dev" (#4749)
This reverts commit ffb98781f1 (#4697),
because it was realized that `vc dev` reads this configuration file many
times per HTTP request, causing the server to feel extremely slow.

Reverting this optimization for now until the over-reading issue is
addressed.
2020-06-30 16:26:56 -07:00
Nathan Rajlich
fbe9ea0750 [node] Set the TypeScript "target" in vc dev (#4728)
Fixes: https://github.com/vercel/vercel/discussions/4724
2020-06-30 16:07:04 -07:00
Andy Bitz
fa0f1b90b4 Publish Stable 2020-06-30 23:33:47 +02:00
Andy Bitz
2daa0e28d3 Publish Canary
- @vercel/frameworks@0.0.16-canary.0
 - vercel@19.1.2-canary.13
 - @vercel/static-build@0.17.4-canary.1
2020-06-30 13:21:02 +02:00
Andy
48358b4986 [@vercel/build-utils] Cache .cache for Eleventy (#4743) 2020-06-30 12:54:44 +02:00
Steven
c59f44a63b [frameworks] Fix build command placeholder nuxt generate (#4737)
The Nuxt placeholder was wrong, it should be `nuxt generate` like the build command here: ca27864201/packages/now-static-build/src/frameworks.ts (L516)
2020-06-29 11:59:34 -04:00
Joe Haddad
ca27864201 Update "description" in package.json for Vercel (#4735) 2020-06-28 22:05:30 -07:00
Steven
6c81a87338 Publish Canary
- vercel@19.1.2-canary.12
 - @vercel/static-build@0.17.4-canary.0
2020-06-27 01:02:10 -04:00
Steven
a7bef9387b [static-build] Fix error handling for unexpected output directory (#4727)
This PR improves the error handling when a zero config framework has an unexpected output directory.

Previously, setting a Docusaurus 2.0 build command to `docusaurus build && mv build foo` would fail with the following:

```
Error: ENOENT: no such file or directory, scandir '/vercel/514ce14b/build'
```

With this PR, the error message will show the expected:

```
Error: No Output Directory named "build" found after the Build completed. You can configure the Output Directory in your project settings. Learn more: https://vercel.com/docs/v2/platform/frequently-asked-questions#missing-public-directory
```

I also changed the usage of [`promisify(fs)`](https://nodejs.org/docs/latest-v10.x/api/util.html#util_util_promisify_original) to [`fs.promises`](https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_promises_api) which is available in Node 10 or newer.

Lastly, I updated the test suite to check if the correct error message is returned for builds we expect to fail.
2020-06-26 23:56:45 -04:00
Nathan Rajlich
65d6c5e1f4 [cli] Use the configured "Output Directory" from project's settings in vc dev (#4715)
Previously, when a project has a specific "Output Directory" configured
in the project settings page, it was not being correctly considered when
using `vercel dev`.

The main fix here is passing in the full project settings object
(including the `outputDirectory`) to the `detectBuilders()` function.

Also cleaned up a few types and updated the error message that was
previously being rendered to use a short link.
2020-06-26 16:07:07 -07:00
Steven
c09355fdb3 Publish Canary
- vercel@19.1.2-canary.11
 - @vercel/client@8.1.1-canary.1
2020-06-26 13:11:05 -04:00
Steven
d9ac4c45e1 [cli] Fix vc dev serving pure static dot files (#4714)
Fixes ch1233 and discussion #4475
2020-06-26 17:10:11 +00:00
nkzawa
c2ff95714f Publish Canary
- @vercel/build-utils@2.4.1-canary.1
 - vercel@19.1.2-canary.10
 - @vercel/client@8.1.1-canary.0
 - @vercel/go@1.1.3-canary.1
 - @vercel/next@2.6.8-canary.4
2020-06-26 13:47:50 +09:00
Naoyuki Kanezawa
a51feb7a62 add source prop when deploying (#4701) 2020-06-26 13:44:31 +09:00
JJ Kasper
ff10918230 [next] Memoize lstating files (#4712)
Closes: https://github.com/vercel/next.js/issues/14429
2020-06-25 22:55:09 +00:00
Nathan Rajlich
04bea1e3cd [go] Implement startDevServer() function (#4662)
Due to Go's peculiar package importing structure, there's unfortunately no way to _directly_ invoke a Go serverless file, so the approach for this `startDevServer()` function is:

 * Create a temp directory in `.vercel/cache`
 * Run the `analyze` Go program on the entrypoint file to determine the `functionName`
 * Copy the entrypoint file into the temp directory, while modifying it to use `package main`
 * Copy the `dev-server.go` file into the temp directory, replacing the placeholder function name with the `functionName` retrieved from the analysis step from before
 * Execute `go run $tmp_dir` to spawn the Go HTTP server on an ephemeral port
 * Return the Go process id and port number for `vercel dev` to proxy to
 * After the Go process has exited, delete the temp directory
2020-06-24 19:50:00 +00:00
Milan Felix Šulc
bc5e5e8a9c [tests] Change now-php to vercel-php (#4710) 2020-06-24 11:58:17 -07:00
JJ Kasper
2e647175f5 Publish Canary
- vercel@19.1.2-canary.9
 - @vercel/next@2.6.8-canary.3
2020-06-24 10:20:04 -05:00
JJ Kasper
1a4e1d2fdd [next] Update revalidate tests and correct shared lambdas revalidate (#4704)
This adds more fine grained tests for our revalidate behavior to ensure pages are actually being updated instead of only checking the headers, it also corrects page lookups failing with shared lambdas enabled for dynamic pages using revalidate. 

Closes: https://github.com/vercel/next.js/issues/14497
2020-06-24 14:53:43 +00:00
Steven
49e2274d81 Publish Canary
- @vercel/build-utils@2.4.1-canary.0
 - vercel@19.1.2-canary.8
2020-06-24 09:24:46 -04:00
Steven
9af3938544 [cli][build-utils] Refactor ajv error message (#4705)
This PR is a follow up to #4694 so we can use this same helper function in the API.

I tried to follow the existing error message format so that the API can use a different prefix than the CLI.

The API currently returns a 400 with `Invalid request` when a Git deploy fails validation:

![api-comment](https://user-images.githubusercontent.com/229881/85466548-1c140b00-b578-11ea-9bed-1eb14df2685a.png)
2020-06-24 13:23:51 +00:00
Nathan Rajlich
7b5bf061c2 Publish Canary
- vercel@19.1.2-canary.7
 - @vercel/go@1.1.3-canary.0
2020-06-22 19:12:28 -07:00
Nathan Rajlich
ffb98781f1 [cli] Remove caching of vercel.json config in vc dev (#4697)
Since the filesystem watcher may be slow, it's actually faster and more
reliable to simply re-read the `vercel.json` configuration for every
HTTP request. This also simplifies the logic as an added benefit.

Some `sleep()` calls are removed from relevant tests that were
previously necessary due to the lag in the filesystem watcher.
2020-06-22 23:45:23 +00:00
Steven
3411fcbb68 Publish Canary
- vercel@19.1.2-canary.6
2020-06-22 18:42:23 -04:00
Steven
55cfd33338 [cli] Improve validation error message for vercel.json (#4694)
This PR improves the validation error message when the user has an invalid `vercel.json` file.

Previously, the error message did not account for nested properties so `{"foo": "will error"}` looked fine because it would mention there is an additional property `foo`. However, the error message for `{ "routes": [{ "foo": "will error" }] }` did not mention anything about `routes` when it explaining there was an additional property `foo`. This became more apparent as we added nested properties for `rewrites` and `redirects` (see tests in this PR).

This PR also adds suggestions for common mistakes such as `src` vs `source`.
2020-06-22 22:38:13 +00:00
JJ Kasper
93a9e5bed3 Publish Canary
- vercel@19.1.2-canary.5
 - @vercel/next@2.6.8-canary.2
2020-06-22 16:38:23 -05:00
JJ Kasper
b454021234 [next] Update tests to run against latest canary (#4682)
In the latest canary of Next.js pages are no longer nested under the `BUILD_ID` folder and instead are nested under a hash for the page bundle content. To prevent these tests from breaking too often from changes in canary this updates to locate the page bundle using the `buildManifest`. This also updates our latest SSG fixture to test against the latest canary to help ensure the feature doesn't break with a new canary release
2020-06-22 21:31:37 +00:00
Nathan Rajlich
bb705cd091 [docs] Refactor "Developing a Runtime" docs and add startDevServer() (#4675)
Co-authored-by: Steven <steven@ceriously.com>
2020-06-22 13:41:10 -07:00
Naoyuki Kanezawa
0986f4bcb6 [cli] Do not confirm vc env pull overwrite if created by CLI (#4678)
Append `# Created by Vercel CLI` to the head of `.env` file and automatically overwrite the file if it's there next time without confirmation.

https://app.clubhouse.io/vercel/story/316
2020-06-22 18:47:34 +00:00
Steven
83f77223aa Publish Canary
- vercel@19.1.2-canary.4
2020-06-19 16:23:32 -04:00
Steven
effda1fa6c [cli] Fix error message when no internet connectivity (#4687)
This PR fixes the error message when the client does not have internet connectivity or perhaps DNS is misconfigured such that the hostname cannot be resolved.
2020-06-19 15:57:26 -04:00
Steven
2ab6a7ef0c Publish Canary
- vercel@19.1.2-canary.3
 - @vercel/next@2.6.8-canary.1
2020-06-18 19:57:28 -04:00
Jean Helou
200bf5e996 [next] Fix nextjs routes in vercel dev (#4510)
This PR fixes #4239 where using `vercel dev` to work on monorepos where
the Next.js app is not in the topmost directory fails to correctly route
to dynamic pages.
After investigating the devServer router, @styfle prompted me to
investigate the @vercel/next builder. He also suggested restricting
`check` to be false only when running in `now dev`.

Co-authored-by: Steven <steven@ceriously.com>
2020-06-18 19:28:53 -04:00
Steven
94ab2512e9 Publish Canary
- vercel@19.1.2-canary.2
 - @vercel/ruby@1.2.3-canary.0
2020-06-18 17:19:29 -04:00
Jared White
da3207278e [ruby] Fix for UTF-8 responses in Ruby functions (#4593)
There's an unexpected string encoding issue with `Net::HTTP`, so this is a workaround. Further details:
https://bugs.ruby-lang.org/issues/15517

Co-authored-by: Steven <steven@ceriously.com>
2020-06-18 17:12:28 -04:00
nkzawa
8e10a82b43 Publish Canary
- vercel@19.1.2-canary.1
2020-06-18 20:24:49 +09:00
Naoyuki Kanezawa
d7731d191b Fix to not render no token error, prompt login instead (#4659)
When `auth.json` exists but no `token` property exists in it, we currently render error like the following screenshot.
<img width="488" alt="Screen Shot 2020-06-15 at 21 32 55" src="https://user-images.githubusercontent.com/775227/84657782-cd4eeb80-af4f-11ea-901d-2ad4b52b6667.png">

This PR fixes to prompt login instead.
<img width="994" alt="Screen Shot 2020-06-15 at 21 28 09" src="https://user-images.githubusercontent.com/775227/84657706-aa243c00-af4f-11ea-915e-4ada7de9c467.png">
2020-06-17 17:20:08 +00:00
Steven
0f5f99e667 Publish Canary
- vercel@19.1.2-canary.0
 - @vercel/next@2.6.8-canary.0
 - @vercel/node@1.7.2-canary.0
2020-06-16 17:41:45 -04:00
Steven
93a7831943 [node][next] Bump node-file-trace to 0.6.5 (#4667)
Bump `node-file-trace` to version [0.6.5](https://github.com/vercel/node-file-trace/releases/tag/0.6.5) to fix a webpack wrappers bug
2020-06-16 21:41:13 +00:00
Steven
0eacbeae11 Publish Stable
- vercel@19.1.1
 - @vercel/next@2.6.7
 - @vercel/node@1.7.1
 - @vercel/static-build@0.17.3
2020-06-16 13:09:42 -04:00
Steven
e50417dc47 Publish Canary
- vercel@19.1.1-canary.4
 - @vercel/static-build@0.17.3-canary.0
2020-06-16 08:55:29 -04:00
Paco
4840a25d30 [static-build] Apply Gatsby default caching routes automatically (#4645)
CH-702
Fixes #3331

If the file generated by `gatsby-plugin-now` does not exist, we'll set up these routes automatically.
2020-06-15 22:15:14 +00:00
Steven
785e91979d Publish Canary
- vercel@19.1.1-canary.3
 - @vercel/next@2.6.7-canary.1
 - @vercel/node@1.7.1-canary.1
2020-06-15 16:46:03 -04:00
Steven
7a776c54b8 [node][next] Bump node-file-trace to 0.6.4 (#4617)
Bump node-file-trace to fix a webpack tracing bug that looks like the following:


```
TypeError: Cannot read property 'type' of null
    at handleWrappers (/vercel/e77875438c1cd74b/.build-utils/.builder/node_modules/@vercel/next/dist/index.js:12763:58)
    at module.exports.447.module.exports (/vercel/e77875438c1cd74b/.build-utils/.builder/node_modules/@vercel/next/dist/index.js:14674:3)
    at Job.emitDependency (/vercel/e77875438c1cd74b/.build-utils/.builder/node_modules/@vercel/next/dist/index.js:11730:40)
    at /vercel/e77875438c1cd74b/.build-utils/.builder/node_modules/@vercel/next/dist/index.js:11755:20
    at async Promise.all (index 9)
    at async Job.emitDependency (/vercel/e77875438c1cd74b/.build-utils/.builder/node_modules/@vercel/next/dist/index.js:11736:5)
    at async Promise.all (index 1)
    at async Object.module.exports.328.module.exports [as default] (/vercel/e77875438c1cd74b/.build-utils/.builder/node_modules/@vercel/next/dist/index.js:11514:3)
    at async Object.module.exports.178.exports.build (/vercel/e77875438c1cd74b/.build-utils/.builder/node_modules/@vercel/next/dist/index.js:6076:69)
    at async buildStep (/var/task/sandbox-worker.js:20407:20)
```

- [0.6.2](https://github.com/vercel/node-file-trace/releases/tag/0.6.2)
- [0.6.3](https://github.com/vercel/node-file-trace/releases/tag/0.6.3) 
- [0.6.4](https://github.com/vercel/node-file-trace/releases/tag/0.6.4)

Depends on #4355
2020-06-15 20:45:15 +00:00
JJ Kasper
997031c53b [next] Update handling experimental basePath (#3791)
As mentioned by @dav-is we can prefix the outputs with the `basePath` instead of using a rewrite so that we make sure to 404 when the basePath isn't prefixed on the output. This behavior is also matched in Next.js with [this PR](https://github.com/zeit/next.js/pull/9988). 

x-ref: https://github.com/zeit/now/pull/3478
2020-06-15 17:43:37 +00:00
Steven
fdee03a599 Publish Canary
- vercel@19.1.1-canary.2
2020-06-15 12:38:11 -04:00
Steven
c5a93ecdad [cli] Fix vc dev proxy to upstream frontend dev server (#4644)
This PR fixes a longstanding issue introduced in #3673 that prevents routing properties from applying to the framework's upstream dev server.

This mimic's the older proxy logic used in build matches here: 5035fa537f/packages/now-cli/src/util/dev/server.ts (L1535-L1539)

- Related to #3777
- Related to #4510
2020-06-15 16:37:08 +00:00
JJ Kasper
5a9391b7ce Publish Canary
- vercel@19.1.1-canary.1
 - @vercel/next@2.6.7-canary.0
2020-06-15 10:20:38 -05:00
JJ Kasper
99e49473b8 [next] Update dynamic route named regexes and route keys (#4355)
This updates to leverage changes from https://github.com/zeit/next.js/pull/12801 which resolves invalid named regexes being used when the segments contain non-word characters e.g. `/[hello-world]`. 

Failing page names have also been added to the `23-custom-routes-verbose` fixture. Since the routeKeys aren't applied for dynamic routes in this PR until the routes-manifest version is bumped in the latest canary of Next.js the added test cases will be passing now and should be re-run to ensure passing after a new canary of Next.js is released with the routes-manifest version bump
2020-06-15 15:15:38 +00:00
Nathan Rajlich
de1cc6f9a7 [cli] Add a test case for resolving default "typescript" version in @vercel/node (#4656)
Adds a test case for #4655 (it got auto-merged too quickly).
2020-06-14 21:52:33 +00:00
Nathan Rajlich
08eedd8f34 Publish Canary
- vercel@19.1.1-canary.0
 - @vercel/node@1.7.1-canary.0
2020-06-14 14:00:04 -07:00
Nathan Rajlich
5021a71a8e [node] Don't resolve "typescript" from the dist dir (#4655)
On Node 10, the `require.resolve()` with "paths" does not return the
proper value relative to the `node_modules` directory. To wit:

```
$ node -v
v10.16.3

$ node -p "require.resolve('typescript', { paths: [process.cwd()] })"
/Users/nrajlich/Code/vercel/vercel/packages/now-node/dist/typescript.js

$ node -v
v14.4.0

$ node -p "require.resolve('typescript', { paths: [process.cwd()] })"
/Users/nrajlich/Code/vercel/vercel/node_modules/typescript/lib/typescript.js
```

(**Note:** cwd when running these commands is the `dist` dir of `@vercel/node`)

So the solution is to just let `require.resolve()` throw an error so the
default string "typescript" is used instead of a resolved absolute path.
2020-06-14 20:47:23 +00:00
Max Leiter
56671d7c2f [tests] Don't revoke VERCEL_TOKEN after tests run (#4643)
`VERCEL_TOKEN` will no longer be invalidated during tests

Story: https://app.clubhouse.io/vercel/story/2281
2020-06-12 22:49:37 +00:00
Steven
5035fa537f [cli] Add test for gatsby cache (#4447)
This PR adds a E2E CLI test to ensure that the Gatsby example deploys correctly and that the second deployment has the proper cached directories.

Co-authored-by: Nathan Rajlich <n@n8.io>
Co-authored-by: Andy <AndyBitz@users.noreply.github.com>
2020-06-12 16:51:55 -04:00
407 changed files with 51366 additions and 2456 deletions

View File

@@ -19,6 +19,11 @@ indent_style = space
[*.py]
indent_size = 4
[*.go]
indent_style = tab
indent_size = 4
tab_width = 4
[*.asm]
indent_size = 8

View File

@@ -34,3 +34,6 @@ packages/now-node-bridge/bridge.*
# now-static-build
packages/now-static-build/test/fixtures
# redwood
packages/redwood/test/fixtures

View File

@@ -1,10 +1,33 @@
# Runtime Developer Reference
The following page is a reference for how to create a Runtime using the available Runtime API.
The following page is a reference for how to create a Runtime by implementing
the Runtime API interface.
A Runtime is an npm module that exposes a `build` function and optionally an `analyze` function and `prepareCache` function.
Official Runtimes are published to [npmjs.com](https://npmjs.com) as a package and referenced in the `use` property of the `vercel.json` configuration file.
However, the `use` property will work with any [npm install argument](https://docs.npmjs.com/cli/install) such as a git repo url which is useful for testing your Runtime.
A Runtime is an npm module that implements the following interface:
```typescript
interface Runtime {
version: number;
build: (options: BuildOptions) => Promise<BuildResult>;
analyze?: (options: AnalyzeOptions) => Promise<string>;
prepareCache?: (options: PrepareCacheOptions) => Promise<CacheOutputs>;
shouldServe?: (options: ShouldServeOptions) => Promise<boolean>;
startDevServer?: (
options: StartDevServerOptions
) => Promise<StartDevServerResult>;
}
```
The `version` property and the `build()` function are the only _required_ fields.
The rest are optional extensions that a Runtime _may_ implement in order to
enhance functionality. These functions are documented in more detail below.
Official Runtimes are published to [the npm registry](https://npmjs.com) as a package and referenced in the `use` property of the `vercel.json` configuration file.
> **Note:** The `use` property in the `builds` array will work with any [npm
> install argument](https://docs.npmjs.com/cli/install) such as a git repo URL,
> which is useful for testing your Runtime. Alternatively, the `functions` property
> requires that you specify a specifc tag published to npm, for stability purposes.
See the [Runtimes Documentation](https://vercel.com/docs/runtimes) to view example usage.
@@ -16,146 +39,170 @@ A **required** exported constant that decides which version of the Runtime API t
The latest and suggested version is `3`.
### `analyze`
**Example:**
An **optional** exported function that returns a unique fingerprint used for the purpose of [build de-duplication](https://vercel.com/docs/v2/platform/deployments#deduplication). If the `analyze` function is not supplied, a random fingerprint is assigned to each build.
```js
export analyze({
files: Files,
entrypoint: String,
workPath: String,
config: Object
}) : String fingerprint
```typescript
export const version = 3;
```
If you are using TypeScript, you should use the following types:
### `build()`
```ts
import { AnalyzeOptions } from '@vercel/build-utils'
A **required** exported function that returns a Serverless Function.
export analyze(options: AnalyzeOptions) {
return 'fingerprint goes here'
> What's a Serverless Function? Read about [Serverless Functions](https://vercel.com/docs/v2/serverless-functions/introduction) to learn more.
**Example:**
```typescript
import { BuildOptions, createLambda } from '@vercel/build-utils';
export async function build(options: BuildOptions) {
// Build the code here…
const lambda = createLambda(/* … */);
return {
output: lambda,
watch: [
// Dependent files to trigger a rebuild in `vercel dev` go here…
],
routes: [
// If your Runtime needs to define additional routing, define it here…
],
};
}
```
### `build`
### `analyze()`
A **required** exported function that returns a [Serverless Function](#serverless-function).
An **optional** exported function that returns a unique fingerprint used for the
purpose of [build
de-duplication](https://vercel.com/docs/v2/platform/deployments#deduplication).
If the `analyze()` function is not supplied, then a random fingerprint is
assigned to each build.
What's a Serverless Function? Read about [Serverless Functions](https://vercel.com/docs/v2/serverless-functions/introduction) to learn more.
**Example:**
```js
build({
files: Files,
entrypoint: String,
workPath: String,
config: Object,
meta?: {
isDev?: Boolean,
requestPath?: String,
filesChanged?: Array<String>,
filesRemoved?: Array<String>
}
}) : {
watch?: Array<String>,
output: Lambda,
routes?: Object
```typescript
import { AnalyzeOptions } from '@vercel/build-utils';
export async function analyze(options: AnalyzeOptions) {
// Do calculations to generate a fingerprint based off the source code here…
return 'fingerprint goes here';
}
```
If you are using TypeScript, you should use the following types:
### `prepareCache()`
```ts
import { BuildOptions } from '@vercel/build-utils'
An **optional** exported function that is executed after [`build()`](#build) is
completed. The implementation should return an object of `File`s that will be
pre-populated in the working directory for the next build run in the user's
project. An example use-case is that `@vercel/node` uses this function to cache
the `node_modules` directory, making it faster to install npm dependencies for
future builds.
export build(options: BuildOptions) {
// Build the code here
**Example:**
```typescript
import { PrepareCacheOptions } from '@vercel/build-utils';
export async function prepareCache(options: PrepareCacheOptions) {
// Create a mapping of file names and `File` object instances to cache here…
return {
output: {
'path-to-file': File,
'path-to-lambda': Lambda
},
watch: [],
routes: {}
}
'path-to-file': File,
};
}
```
### `prepareCache`
### `shouldServe()`
An **optional** exported function that is equivalent to [`build`](#build), but it executes the instructions necessary to prepare a cache for the next run.
An **optional** exported function that is only used by `vercel dev` in [Vercel
CLI](https://vercel.com/download) and indicates whether a
[Runtime](https://vercel.com/docs/runtimes) wants to be responsible for responding
to a certain request path.
```js
prepareCache({
files: Files,
entrypoint: String,
workPath: String,
cachePath: String,
config: Object
}) : Files cacheOutput
```
**Example:**
If you are using TypeScript, you can import the types for each of these functions by using the following:
```typescript
import { ShouldServeOptions } from '@vercel/build-utils';
```ts
import { PrepareCacheOptions } from '@vercel/build-utils'
export async function shouldServe(options: ShouldServeOptions) {
// Determine whether or not the Runtime should respond to the request path here…
export prepareCache(options: PrepareCacheOptions) {
return { 'path-to-file': File }
return options.requestPath === options.entrypoint;
}
```
### `shouldServe`
If this function is not defined, Vercel CLI will use the [default implementation](https://github.com/vercel/vercel/blob/52994bfe26c5f4f179bdb49783ee57ce19334631/packages/now-build-utils/src/should-serve.ts).
An **optional** exported function that is only used by `vercel dev` in [Vercel CLI](https:///download) and indicates whether a [Runtime](https://vercel.com/docs/runtimes) wants to be responsible for building a certain request path.
### `startDevServer()`
```js
shouldServe({
entrypoint: String,
files: Files,
config: Object,
requestPath: String,
workPath: String
}) : Boolean
```
An **optional** exported function that is only used by `vercel dev` in [Vercel
CLI](https://vercel.com/download). If this function is defined, Vercel CLI will
**not** invoke the `build()` function, and instead invoke this function for every
HTTP request. It is an opportunity to provide an optimized development experience
rather than going through the entire `build()` process that is used in production.
If you are using TypeScript, you can import the types for each of these functions by using the following:
This function is invoked _once per HTTP request_ and is expected to spawn a child
process which creates an HTTP server that will execute the entrypoint code when
an HTTP request is received. This child process is _single-serve_ (only used for
a single HTTP request). After the HTTP response is complete, `vercel dev` sends
a shut down signal to the child process.
```ts
import { ShouldServeOptions } from '@vercel/build-utils'
The `startDevServer()` function returns an object with the `port` number that the
child process' HTTP server is listening on (which should be an [ephemeral
port](https://stackoverflow.com/a/28050404/376773)) as well as the child process'
Process ID, which `vercel dev` uses to send the shut down signal to.
export shouldServe(options: ShouldServeOptions) {
return Boolean
> **Hint:** To determine which ephemeral port the child process is listening on,
> some form of [IPC](https://en.wikipedia.org/wiki/Inter-process_communication) is
> required. For example, in `@vercel/go` the child process writes the port number
> to [_file descriptor 3_](https://en.wikipedia.org/wiki/File_descriptor), which is read by the `startDevServer()` function
> implementation.
It may also return `null` to opt-out of this behavior for a particular request
path or entrypoint.
**Example:**
```typescript
import { spawn } from 'child_process';
import { StartDevServerOptions } from '@vercel/build-utils';
export async function startDevServer(options: StartDevServerOptions) {
// Create a child process which will create an HTTP server.
//
// Note: `my-runtime-dev-server` is an example dev server program name.
// Your implementation will spawn a different program specific to your runtime.
const child = spawn('my-runtime-dev-server', [options.entrypoint], {
stdio: ['ignore', 'inherit', 'inherit', 'pipe'],
});
// In this example, the child process will write the port number to FD 3…
const portPipe = child.stdio[3];
const childPort = await new Promise(resolve => {
portPipe.setEncoding('utf8');
portPipe.once('data', data => {
resolve(Number(data));
});
});
return { pid: child.pid, port: childPort };
}
```
If this method is not defined, Vercel CLI will default to [this function](https://github.com/vercel/vercel/blob/52994bfe26c5f4f179bdb49783ee57ce19334631/packages/now-build-utils/src/should-serve.ts).
### Runtime Options
The exported functions [`analyze`](#analyze), [`build`](#build), and [`prepareCache`](#preparecache) receive one argument with the following properties.
**Properties:**
- `files`: All source files of the project as a [Files](#files) data structure.
- `entrypoint`: Name of entrypoint file for this particular build job. Value `files[entrypoint]` is guaranteed to exist and be a valid [File](#files) reference. `entrypoint` is always a discrete file and never a glob, since globs are expanded into separate builds at deployment time.
- `workPath`: A writable temporary directory where you are encouraged to perform your build process. This directory will be populated with the restored cache from the previous run (if any) for [`analyze`](#analyze) and [`build`](#build).
- `cachePath`: A writable temporary directory where you can build a cache for the next run. This is only passed to `prepareCache`.
- `config`: An arbitrary object passed from by the user in the [Build definition](#defining-the-build-step) in `vercel.json`.
## Examples
Check out our [Node.js Runtime](https://github.com/vercel/vercel/tree/master/packages/now-node), [Go Runtime](https://github.com/vercel/vercel/tree/master/packages/now-go), [Python Runtime](https://github.com/vercel/vercel/tree/master/packages/now-python) or [Ruby Runtime](https://github.com/vercel/vercel/tree/master/packages/now-ruby) for examples of how to build one.
## Technical Details
### Execution Context
A [Serverless Function](https://vercel.com/docs/v2/serverless-functions/introduction) is created where the Runtime logic is executed. The lambda is run using the Node.js 8 runtime. A brand new sandbox is created for each deployment, for security reasons. The sandbox is cleaned up between executions to ensure no lingering temporary files are shared from build to build.
- Runtimes are executed in a Linux container that closely matches the Servereless Function runtime environment.
- The Runtime code is executed using Node.js version **12.x**.
- A brand new sandbox is created for each deployment, for security reasons.
- The sandbox is cleaned up between executions to ensure no lingering temporary files are shared from build to build.
All the APIs you export ([`analyze`](#analyze), [`build`](#build) and [`prepareCache`](#preparecache)) are not guaranteed to be run in the same process, but the filesystem we expose (e.g.: `workPath` and the results of calling [`getWriteableDirectory`](#getWriteableDirectory) ) is retained.
All the APIs you export ([`analyze()`](#analyze), [`build()`](#build),
[`prepareCache()`](#preparecache), etc.) are not guaranteed to be run in the
same process, but the filesystem we expose (e.g.: `workPath` and the results
of calling [`getWritableDirectory`](#getWritableDirectory) ) is retained.
If you need to share state between those steps, use the filesystem.
@@ -173,11 +220,11 @@ The env and secrets specified by the user as `build.env` are passed to the Runti
When you publish your Runtime to npm, make sure to not specify `@vercel/build-utils` (as seen below in the API definitions) as a dependency, but rather as part of `peerDependencies`.
## Types
## `@vercel/build-utils` Types
### `Files`
```ts
```typescript
import { File } from '@vercel/build-utils';
type Files = { [filePath: string]: File };
```
@@ -188,7 +235,7 @@ When used as an input, the `Files` object will only contain `FileRefs`. When `Fi
An example of a valid output `Files` object is:
```json
```javascript
{
"index.html": FileRef,
"api/index.js": Lambda
@@ -199,7 +246,7 @@ An example of a valid output `Files` object is:
This is an abstract type that can be imported if you are using TypeScript.
```ts
```typescript
import { File } from '@vercel/build-utils';
```
@@ -211,71 +258,71 @@ Valid `File` types include:
### `FileRef`
```ts
```typescript
import { FileRef } from '@vercel/build-utils';
```
This is a [JavaScript class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) that represents an abstract file instance stored in our platform, based on the file identifier string (its checksum). When a `Files` object is passed as an input to `analyze` or `build`, all its values will be instances of `FileRef`.
This is a [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) that represents an abstract file instance stored in our platform, based on the file identifier string (its checksum). When a `Files` object is passed as an input to `analyze` or `build`, all its values will be instances of `FileRef`.
**Properties:**
- `mode : Number` file mode
- `digest : String` a checksum that represents the file
- `mode: Number` file mode
- `digest: String` a checksum that represents the file
**Methods:**
- `toStream() : Stream` creates a [Stream](https://nodejs.org/api/stream.html) of the file body
- `toStream(): Stream` creates a [Stream](https://nodejs.org/api/stream.html) of the file body
### `FileFsRef`
```ts
```typescript
import { FileFsRef } from '@vercel/build-utils';
```
This is a [JavaScript class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) that represents an abstract instance of a file present in the filesystem that the build process is executing in.
This is a [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) that represents an abstract instance of a file present in the filesystem that the build process is executing in.
**Properties:**
- `mode : Number` file mode
- `fsPath : String` the absolute path of the file in file system
- `mode: Number` file mode
- `fsPath: String` the absolute path of the file in file system
**Methods:**
- `static async fromStream({ mode : Number, stream : Stream, fsPath : String }) : FileFsRef` creates an instance of a [FileFsRef](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) from `Stream`, placing file at `fsPath` with `mode`
- `toStream() : Stream` creates a [Stream](https://nodejs.org/api/stream.html) of the file body
- `static async fromStream({ mode: Number, stream: Stream, fsPath: String }): FileFsRef` creates an instance of a [FileFsRef](#FileFsRef) from `Stream`, placing file at `fsPath` with `mode`
- `toStream(): Stream` creates a [Stream](https://nodejs.org/api/stream.html) of the file body
### `FileBlob`
```ts
```typescript
import { FileBlob } from '@vercel/build-utils';
```
This is a [JavaScript class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) that represents an abstract instance of a file present in memory.
This is a [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) that represents an abstract instance of a file present in memory.
**Properties:**
- `mode : Number` file mode
- `data : String | Buffer` the body of the file
- `mode: Number` file mode
- `data: String | Buffer` the body of the file
**Methods:**
- `static async fromStream({ mode : Number, stream : Stream }) :FileBlob` creates an instance of a [FileBlob](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) from [`Stream`](https://nodejs.org/api/stream.html) with `mode`
- `toStream() : Stream` creates a [Stream](https://nodejs.org/api/stream.html) of the file body
- `static async fromStream({ mode: Number, stream: Stream }): FileBlob` creates an instance of a [FileBlob](#FileBlob) from [`Stream`](https://nodejs.org/api/stream.html) with `mode`
- `toStream(): Stream` creates a [Stream](https://nodejs.org/api/stream.html) of the file body
### `Lambda`
```ts
```typescript
import { Lambda } from '@vercel/build-utils';
```
This is a [JavaScript class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes), called a Serverless Function, that can be created by supplying `files`, `handler`, `runtime`, and `environment` as an object to the [`createLambda`](#createlambda) helper. The instances of this class should not be created directly. Instead, invoke the [`createLambda`](#createlambda) helper function.
This is a [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) that represents a Serverless Function. An instance can be created by supplying `files`, `handler`, `runtime`, and `environment` as an object to the [`createLambda`](#createlambda) helper. The instances of this class should not be created directly. Instead, invoke the [`createLambda`](#createlambda) helper function.
**Properties:**
- `files : Files` the internal filesystem of the lambda
- `handler : String` path to handler file and (optionally) a function name it exports
- `runtime : LambdaRuntime` the name of the lambda runtime
- `environment : Object` key-value map of handler-related (aside of those passed by user) environment variables
- `files: Files` the internal filesystem of the lambda
- `handler: String` path to handler file and (optionally) a function name it exports
- `runtime: LambdaRuntime` the name of the lambda runtime
- `environment: Object` key-value map of handler-related (aside of those passed by user) environment variables
### `LambdaRuntime`
@@ -291,15 +338,15 @@ This is an abstract enumeration type that is implemented by one of the following
- `ruby2.5`
- `provided`
## JavaScript API
## `@vercel/build-utils` Helper Functions
The following is exposed by `@vercel/build-utils` to simplify the process of writing Runtimes, manipulating the file system, using the above types, etc.
### `createLambda`
### `createLambda()`
Signature: `createLambda(Object spec) : Lambda`
Signature: `createLambda(Object spec): Lambda`
```ts
```typescript
import { createLambda } from '@vercel/build-utils';
```
@@ -316,29 +363,33 @@ await createLambda({
});
```
### `download`
### `download()`
Signature: `download() : Files`
Signature: `download(): Files`
```ts
```typescript
import { download } from '@vercel/build-utils';
```
This utility allows you to download the contents of a [`Files`](#files) data structure, therefore creating the filesystem represented in it.
This utility allows you to download the contents of a [`Files`](#files) data
structure, therefore creating the filesystem represented in it.
Since `Files` is an abstract way of representing files, you can think of `download` as a way of making that virtual filesystem _real_.
Since `Files` is an abstract way of representing files, you can think of
`download()` as a way of making that virtual filesystem _real_.
If the **optional** `meta` property is passed (the argument for [build](#build)), only the files that have changed are downloaded. This is decided using `filesRemoved` and `filesChanged` inside that object.
If the **optional** `meta` property is passed (the argument for
[`build()`](#build)), only the files that have changed are downloaded.
This is decided using `filesRemoved` and `filesChanged` inside that object.
```js
await download(files, workPath, meta);
```
### `glob`
### `glob()`
Signature: `glob() : Files`
Signature: `glob(): Files`
```ts
```typescript
import { glob } from '@vercel/build-utils';
```
@@ -355,21 +406,21 @@ exports.build = ({ files, workPath }) => {
}
```
### `getWriteableDirectory`
### `getWritableDirectory()`
Signature: `getWriteableDirectory() : String`
Signature: `getWritableDirectory(): String`
```ts
import { getWriteableDirectory } from '@vercel/build-utils';
```typescript
import { getWritableDirectory } from '@vercel/build-utils';
```
In some occasions, you might want to write to a temporary directory.
### `rename`
### `rename()`
Signature: `rename(Files) : Files`
Signature: `rename(Files, Function): Files`
```ts
```typescript
import { rename } from '@vercel/build-utils';
```

View File

@@ -1,4 +1,4 @@
import { NowRequest, NowResponse } from '@now/node';
import { NowRequest, NowResponse } from '@vercel/node';
import { errorHandler } from './error-handler';
type Handler = (req: NowRequest, res: NowResponse) => Promise<any>;

View File

@@ -2,7 +2,7 @@ import fs from 'fs';
// @ts-ignore
import tar from 'tar-fs';
import { extract } from '../../_lib/examples/extract';
import { NowRequest, NowResponse } from '@now/node';
import { NowRequest, NowResponse } from '@vercel/node';
import { withApiHandler } from '../../_lib/util/with-api-handler';
const TMP_DIR = '/tmp';
@@ -15,8 +15,8 @@ function notFound(res: NowResponse, message: string) {
return res.status(404).send({
error: {
code: 'not_found',
message
}
message,
},
});
}
@@ -35,7 +35,10 @@ function streamToBuffer(stream: any) {
});
}
export default withApiHandler(async function(req: NowRequest, res: NowResponse) {
export default withApiHandler(async function (
req: NowRequest,
res: NowResponse
) {
const ext = '.tar.gz';
const { segment = '' } = req.query;

View File

@@ -3,12 +3,12 @@
// @ts-ignore
import parseGitUrl from 'parse-github-url';
import { NowRequest, NowResponse } from '@now/node';
import { NowRequest, NowResponse } from '@vercel/node';
import { withApiHandler } from '../_lib/util/with-api-handler';
import { getGitHubRepoInfo } from '../_lib/examples/github-repo-info';
import { getGitLabRepoInfo } from '../_lib/examples/gitlab-repo-info';
export default withApiHandler(async function(
export default withApiHandler(async function (
req: NowRequest,
res: NowResponse
) {

View File

@@ -1,8 +1,8 @@
import { NowRequest, NowResponse } from '@now/node';
import { NowRequest, NowResponse } from '@vercel/node';
import { getExampleList } from '../_lib/examples/example-list';
import { withApiHandler } from '../_lib/util/with-api-handler';
export default withApiHandler(async function(
export default withApiHandler(async function (
req: NowRequest,
res: NowResponse
) {

View File

@@ -1,10 +1,10 @@
import { extract } from '../_lib/examples/extract';
import { summary } from '../_lib/examples/summary';
import { NowRequest, NowResponse } from '@now/node';
import { NowRequest, NowResponse } from '@vercel/node';
import { mapOldToNew } from '../_lib/examples/map-old-to-new';
import { withApiHandler } from '../_lib/util/with-api-handler';
export default withApiHandler(async function(
export default withApiHandler(async function (
req: NowRequest,
res: NowResponse
) {

View File

@@ -1,21 +1,27 @@
import { NowRequest, NowResponse } from '@now/node';
import { NowRequest, NowResponse } from '@vercel/node';
import { withApiHandler } from './_lib/util/with-api-handler';
import frameworkList, { Framework } from '../packages/frameworks';
import _frameworks, { Framework } from '../packages/frameworks';
const frameworks = (frameworkList as Framework[]).map(frameworkItem => {
const framework = {
...frameworkItem,
detectors: undefined,
};
const frameworks = (_frameworks as Framework[])
.sort(
(a, b) =>
(a.sort || Number.MAX_SAFE_INTEGER) - (b.sort || Number.MAX_SAFE_INTEGER)
)
.map(frameworkItem => {
const framework = {
...frameworkItem,
detectors: undefined,
sort: undefined,
};
if (framework.logo) {
framework.logo = `https://res.cloudinary.com/zeit-inc/image/fetch/${framework.logo}`;
}
if (framework.logo) {
framework.logo = `https://res.cloudinary.com/zeit-inc/image/fetch/${framework.logo}`;
}
return framework;
});
return framework;
});
export default withApiHandler(async function(
export default withApiHandler(async function (
req: NowRequest,
res: NowResponse
) {

View File

@@ -13,12 +13,12 @@
"node-fetch": "2.6.0",
"parse-github-url": "1.0.2",
"tar-fs": "2.0.0",
"typescript": "3.7.4",
"unzip-stream": "0.3.0"
},
"devDependencies": {
"@now/node": "1.3.3",
"@types/node": "13.1.4",
"@types/node-fetch": "2.5.4"
"@types/node-fetch": "2.5.4",
"@vercel/node": "1.7.2",
"typescript": "3.9.6"
}
}

View File

@@ -2,13 +2,6 @@
# yarn lockfile v1
"@now/node@1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@now/node/-/node-1.3.3.tgz#5407cb6a730d4dd9b6b6b0bc4a316f29086c9feb"
integrity sha512-s1qajtQttWhhSs1k6FX0/6eTFYFUplzultrQeKfOPMoYzzz6OxDq5qrQ3elpsGlZlDVmO+x+JOJ7yad+3yBgpg==
dependencies:
"@types/node" "*"
"@sentry/apm@5.11.1":
version "5.11.1"
resolved "https://registry.yarnpkg.com/@sentry/apm/-/apm-5.11.1.tgz#cc89fa4150056fbf009f92eca94fccc3980db34e"
@@ -141,11 +134,25 @@
dependencies:
"@types/node" "*"
"@vercel/node@1.7.2":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@vercel/node/-/node-1.7.2.tgz#85cb8aac661c02dfef6fe752740f5b162e90767b"
integrity sha512-XV5lrLC+K/cxsaFj8H2OoGu1zliOqnxcrOnPInI8HmQjR/Tztt+0nzgpt+7sx8wXcrib0Nu7lK303jP7VjSETw==
dependencies:
"@types/node" "*"
ts-node "8.9.1"
typescript "3.9.3"
agent-base@5:
version "5.1.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-5.1.1.tgz#e8fb3f242959db44d63be665db7a8e739537a32c"
integrity sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g==
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
binary@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/binary/-/binary-0.3.0.tgz#9f60553bc5ce8c3386f3b553cff47462adecaa79"
@@ -161,6 +168,11 @@ bl@^3.0.0:
dependencies:
readable-stream "^3.0.1"
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
buffers@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/buffers/-/buffers-0.1.1.tgz#b24579c3bed4d6d396aeee6d9a8ae7f5482ab7bb"
@@ -229,6 +241,11 @@ defer-to-connect@^1.1.1:
resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-1.1.1.tgz#88ae694b93f67b81815a2c8c769aef6574ac8f2f"
integrity sha512-J7thop4u3mRTkYRQ+Vpfwy2G5Ehoy82I14+14W4YMDLKdWloI9gSzRbV30s/NckQGVJtPkWNcW4oMAUigTdqiQ==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
duplexer3@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
@@ -313,6 +330,11 @@ lru_map@^0.3.3:
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=
make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
mimic-response@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b"
@@ -396,6 +418,19 @@ safe-buffer@~5.2.0:
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==
source-map-support@^0.5.17:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
string_decoder@^1.1.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
@@ -434,6 +469,17 @@ to-readable-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9"
integrity sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk=
ts-node@8.9.1:
version "8.9.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.9.1.tgz#2f857f46c47e91dcd28a14e052482eb14cfd65a5"
integrity sha512-yrq6ODsxEFTLz0R3BX2myf0WBCSQh9A+py8PBo1dCzWIOcvisbyH6akNKqDHMgXePF2kir5mm5JXJTH3OUJYOQ==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"
tslib@^1.9.3:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
@@ -444,10 +490,15 @@ type-fest@^0.8.0:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==
typescript@3.7.4:
version "3.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==
typescript@3.9.3:
version "3.9.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.3.tgz#d3ac8883a97c26139e42df5e93eeece33d610b8a"
integrity sha512-D/wqnB2xzNFIcoBG9FG8cXRDjiqSTbG2wd8DMZeQyJlP1vfTkIxH4GKveWaEBYySKIg+USu+E+EDIR47SqnaMQ==
typescript@3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==
unzip-stream@0.3.0:
version "0.3.0"
@@ -466,3 +517,8 @@ wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

View File

@@ -2,16 +2,14 @@
#### Why This Error Occurred
The domain you supplied cannot be verified using either the intended set of nameservers or the given verification TXT record.
The domain you supplied cannot be verified using the intended nameservers.
#### Possible Ways to Fix It
#### Possible Way to Fix It
Apply the intended set of nameservers to your domain or add the given TXT verification record through your domain provider.
Apply the intended set of nameservers to your domain.
You can retrieve both the intended nameservers and TXT verification record for the domain you wish to verify by running `vercel domains inspect <domain>`.
When you have added either verification method to your domain, you can run `vercel domains verify <domain>` again to complete verification for your domain.
Vercel will also automatically check periodically that your domain has been verified and automatically mark it as such if we detect either verification method on the domain.
If you would not like to verify your domain, you can remove it from your account using `vercel domains rm <domain>`.

View File

@@ -0,0 +1,4 @@
module.exports = {
presets: ["next/babel"],
plugins: [],
}

View File

@@ -0,0 +1,10 @@
module.exports = {
extends: ["react-app", "plugin:jsx-a11y/recommended"],
plugins: ["jsx-a11y"],
rules: {
"import/no-anonymous-default-export": "error",
"import/no-webpack-loader-syntax": "off",
"react/react-in-jsx-scope": "off", // React is always in scope with Blitz
"jsx-a11y/anchor-is-valid": "off", //Doesn't play well with Blitz/Next <Link> usage
},
}

56
examples/blitzjs/.gitignore vendored Normal file
View File

@@ -0,0 +1,56 @@
# dependencies
node_modules
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*
.npm
web_modules/
# blitz
/.blitz/
/.next/
*.sqlite
.now
.vercel
.blitz-console-history
blitz-log.log
# misc
.DS_Store
# local env files
.env
.envrc
.env.local
.env.development.local
.env.test.local
.env.production.local
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Testing
coverage
*.lcov
.nyc_output
lib-cov
# Caches
*.tsbuildinfo
.eslintcache
.node_repl_history
.yarn-integrity
# Serverless directories
.serverless/
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

1
examples/blitzjs/.npmrc Normal file
View File

@@ -0,0 +1 @@
save-exact=true

View File

@@ -0,0 +1,6 @@
.gitkeep
.env
*.ico
*.lock
db/migrations

View File

@@ -0,0 +1,21 @@
![Blitz Logo](https://github.com/vercel/vercel/blob/master/packages/frameworks/logos/blitz.svg)
This is a [Blitz.js](https://blitzjs.com/) project bootstrapped with `npx blitz new`.
## Getting Started
First, run the development server:
```bash
npx blitz start
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
## Learn More
To learn more about Blitz.js, view [Blitzjs.com](https://blitzjs.com)
## Deploy on Vercel
View the [documentation on deploying to Vercel](https://blitzjs.com/docs/deploy-vercel)

View File

View File

@@ -0,0 +1,21 @@
import React from "react"
export default class ErrorBoundary extends React.Component<{
fallback: (error: any) => React.ReactNode
}> {
state = { hasError: false, error: null }
static getDerivedStateFromError(error: any) {
return {
hasError: true,
error,
}
}
render() {
if (this.state.hasError) {
return this.props.fallback(this.state.error)
}
return this.props.children
}
}

View File

View File

@@ -0,0 +1,5 @@
import { AppProps } from "blitz"
export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}

View File

@@ -0,0 +1,23 @@
import { Document, Html, DocumentHead, Main, BlitzScript /*DocumentContext*/ } from "blitz"
class MyDocument extends Document {
// Only uncomment if you need to customize this behaviour
// static async getInitialProps(ctx: DocumentContext) {
// const initialProps = await Document.getInitialProps(ctx)
// return {...initialProps}
// }
render() {
return (
<Html lang="en">
<DocumentHead />
<body>
<Main />
<BlitzScript />
</body>
</Html>
)
}
}
export default MyDocument

View File

@@ -0,0 +1,197 @@
import { Head, Link } from "blitz"
const Home = () => (
<div className="container">
<Head>
<title>blitzjs</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<div className="logo">
<img src="/logo.png" alt="blitz.js" />
</div>
<p>1. Run this command in your terminal:</p>
<pre>
<code>blitz generate all project name:string</code>
</pre>
<p>2. Then run this command:</p>
<pre>
<code>blitz db migrate</code>
</pre>
<p>
3. Go to{" "}
<Link href="/projects">
<a>/projects</a>
</Link>
</p>
<div className="buttons">
<a
className="button"
href="https://github.com/blitz-js/blitz/blob/master/USER_GUIDE.md?utm_source=blitz-new&utm_medium=app-template&utm_campaign=blitz-new"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
<a
className="button-outline"
href="https://github.com/blitz-js/blitz"
target="_blank"
rel="noopener noreferrer"
>
Github Repo
</a>
<a
className="button-outline"
href="https://slack.blitzjs.com"
target="_blank"
rel="noopener noreferrer"
>
Slack Community
</a>
</div>
</main>
<footer>
<a
href="https://blitzjs.com?utm_source=blitz-new&utm_medium=app-template&utm_campaign=blitz-new"
target="_blank"
rel="noopener noreferrer"
>
Powered by Blitz.js
</a>
</footer>
<style jsx>{`
.container {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main {
padding: 5rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main p {
font-size: 1.2rem;
}
footer {
width: 100%;
height: 60px;
border-top: 1px solid #eaeaea;
display: flex;
justify-content: center;
align-items: center;
background-color: #45009d;
}
footer a {
display: flex;
justify-content: center;
align-items: center;
}
footer a {
color: #f4f4f4;
text-decoration: none;
}
.logo {
margin-bottom: 2rem;
}
.logo img {
width: 300px;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 0.5rem;
margin-top: 6rem;
}
a.button {
background-color: #6700eb;
padding: 1rem 2rem;
color: #f4f4f4;
text-align: center;
}
a.button:hover {
background-color: #45009d;
}
a.button-outline {
border: 2px solid #6700eb;
padding: 1rem 2rem;
color: #6700eb;
text-align: center;
}
a.button-outline:hover {
border-color: #45009d;
color: #45009d;
}
pre {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
}
code {
font-size: 0.9rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}
.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
margin-top: 3rem;
}
@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}
`}</style>
<style jsx global>{`
@import url("https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@300;700&display=swap");
html,
body {
padding: 0;
margin: 0;
font-family: "Libre Franklin", -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
* {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
box-sizing: border-box;
}
`}</style>
</div>
)
export default Home

View File

@@ -0,0 +1,15 @@
module.exports = {
/*
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
return config
},
webpackDevMiddleware: (config) => {
// Perform customizations to webpack dev middleware config
// Important: return the modified config
return config
},
*/
}

View File

@@ -0,0 +1,15 @@
import { PrismaClient } from "@prisma/client"
export * from "@prisma/client"
let prisma: PrismaClient
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient()
} else {
// Ensure the prisma instance is re-used during hot-reloading
// Otherwise, a new client will be created on every reload
global["prisma"] = global["prisma"] || new PrismaClient()
prisma = global["prisma"]
}
export default prisma

View File

View File

@@ -0,0 +1,27 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource sqlite {
provider = "sqlite"
url = "file:./db.sqlite"
}
// SQLite is easy to start with, but if you use Postgres in production
// you should also use it in development with the following:
//datasource postgresql {
// provider = "postgresql"
// url = env("DATABASE_URL")
//}
generator client {
provider = "prisma-client-js"
}
// --------------------------------------
//model Project {
// id Int @default(autoincrement()) @id
// name String
//}

View File

View File

@@ -0,0 +1,55 @@
{
"name": "blitzjs",
"version": "1.0.0",
"scripts": {
"start": "blitz start",
"studio": "blitz db studio",
"build": "blitz build",
"lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx .",
"test": "echo \"No tests yet\""
},
"browserslist": [
"defaults"
],
"prettier": {
"semi": false,
"printWidth": 100
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && pretty-quick --staged",
"pre-push": "blitz test"
}
},
"lint-staged": {
"*.{js,ts,tsx}": [
"eslint --fix"
]
},
"dependencies": {
"@prisma/cli": "latest",
"@prisma/client": "latest",
"blitz": "latest",
"react": "experimental",
"react-dom": "experimental"
},
"devDependencies": {
"@types/react": "16.9.36",
"@typescript-eslint/eslint-plugin": "2.x",
"@typescript-eslint/parser": "2.x",
"babel-eslint": "10.1.0",
"eslint": "6.8.0",
"eslint-config-react-app": "5.2.1",
"eslint-plugin-flowtype": "4.7.0",
"eslint-plugin-import": "2.21.2",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-react": "7.20.0",
"eslint-plugin-react-hooks": "3.0.0",
"husky": "4.2.5",
"lint-staged": "10.2.10",
"prettier": "2.0.5",
"pretty-quick": "2.0.1",
"typescript": "3.9.5"
},
"private": true
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": "./",
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

View File

11913
examples/gatsby/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

View File

@@ -0,0 +1,7 @@
# These environment variables will be used by default if you do not create any
# yourself in .env. This file should be safe to check into your version control
# system. Any custom values should go in .env and .env should *not* be checked
# into version control.
DATABASE_URL=file:./dev.db
BINARY_TARGET=native

10
examples/redwoodjs/.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
.DS_Store
.env
.netlify
dev.db
dist
dist-babel
node_modules
yarn-error.log
.vercel

View File

@@ -0,0 +1 @@
lts/*

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Redwood
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,29 @@
![RedwoodJS Logo](https://github.com/vercel/vercel/blob/master/packages/frameworks/logos/redwood.svg)
# RedwoodJS Example
This directory is a brief example of a [RedwoodJS](https://redwoodjs.com) app with [Serverless Functions](https://vercel.com/docs/v2/serverless-functions/introduction) that can be deployed with Vercel and zero configuration.
## Deploy Your Own
Deploy your own RedwoodJS project, along with Serverless Functions, with Vercel.
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/vercel/tree/master/examples/redwoodjs)
_Live Example: https://redwoodjs.now-examples.now.sh_
### How We Created This Example
To get started with RedwoodJS on Vercel, you can [use Yarn to initialize](https://redwoodjs.com/tutorial/installation-starting-development) the project:
```shell
$ yarn create redwood-app ./my-redwood-app
```
### Deploying From Your Terminal
You can deploy your new RedwoodJS project, along with [Serverless Functions](https://vercel.com/docs/v2/serverless-functions/introduction), with a single command from your terminal using [Vercel CLI](https://vercel.com/download):
```shell
$ vercel
```

View File

@@ -0,0 +1 @@
module.exports = { extends: '../babel.config.js' }

View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
}
},
"include": ["src/**/*"]
}

View File

@@ -0,0 +1,8 @@
{
"name": "api",
"version": "0.0.0",
"private": true,
"dependencies": {
"@redwoodjs/api": "0.14.0"
}
}

View File

@@ -0,0 +1,18 @@
datasource DS {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = env("BINARY_TARGET")
}
// Define your own datamodels here and run `yarn redwood db save` to create
// migrations for them.
// TODO: Please remove the following example:
model UserExample {
id Int @id @default(autoincrement())
email String @unique
name String?
}

View File

@@ -0,0 +1,26 @@
/* eslint-disable no-console */
const { PrismaClient } = require('@prisma/client')
const dotenv = require('dotenv')
dotenv.config()
const db = new PrismaClient()
async function main() {
// Seed data is database data that needs to exist for your app to run.
// Ideally this file should be idempotent: running it multiple times
// will result in the same database state (usually by checking for the
// existence of a record before trying to create it). For example:
//
// const existing = await db.user.findMany({ where: { email: 'admin@email.com' }})
// if (!existing.length) {
// await db.user.create({ data: { name: 'Admin', email: 'admin@email.com' }})
// }
console.info('No data to seed. See api/prisma/seeds.js for info.')
}
main()
.catch((e) => console.error(e))
.finally(async () => {
await db.disconnect()
})

View File

@@ -0,0 +1,19 @@
import {
createGraphQLHandler,
makeMergedSchema,
makeServices,
} from '@redwoodjs/api'
import importAll from '@redwoodjs/api/importAll.macro'
import { db } from 'src/lib/db'
const schemas = importAll('api', 'graphql')
const services = importAll('api', 'services')
export const handler = createGraphQLHandler({
schema: makeMergedSchema({
schemas,
services: makeServices({ services }),
}),
db,
})

View File

View File

@@ -0,0 +1,6 @@
// See https://github.com/prisma/prisma2/blob/master/docs/prisma-client-js/api.md#constructor
// for options.
import { PrismaClient } from '@prisma/client'
export const db = new PrismaClient()

View File

@@ -0,0 +1,3 @@
module.exports = {
presets: ['@redwoodjs/core/config/babel-preset'],
}

View File

@@ -0,0 +1,19 @@
{
"private": true,
"workspaces": {
"packages": [
"api",
"web"
]
},
"devDependencies": {
"@redwoodjs/core": "0.14.0"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config"
},
"engines": {
"node": ">=12",
"yarn": ">=1.15"
}
}

View File

@@ -0,0 +1,9 @@
// https://prettier.io/docs/en/options.html
module.exports = {
trailingComma: 'es5',
bracketSpacing: true,
tabWidth: 2,
semi: false,
singleQuote: true,
arrowParens: 'always',
}

View File

@@ -0,0 +1,7 @@
[web]
port = 8910
apiProxyPath = "/api"
[api]
port = 8911
[browser]
open = false

View File

@@ -0,0 +1 @@
module.exports = { extends: '../babel.config.js' }

View File

@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
},
"jsx": "preserve"
},
"include": ["src/**/*"]
}

View File

@@ -0,0 +1,15 @@
{
"name": "web",
"version": "0.0.0",
"private": true,
"browserslist": [
"defaults"
],
"dependencies": {
"@redwoodjs/router": "0.14.0",
"@redwoodjs/web": "0.14.0",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}

View File

@@ -0,0 +1,36 @@
# Static Assets
Use this folder to add static files directly to your app. All included files and folders will be copied directly into the `/dist` folder (created when Webpack builds for production). They will also be available during development when you run `yarn rw dev`.
>Note: files will *not* hot reload while the development server is running. You'll need to manually stop/start to access file changes.
### Example Use
A file like `favicon.png` will be copied to `/dist/favicon.png`. A folder containing a file such as `static-files/my-logo.jpg` will be copied to `/dist/static-files/my-logo.jpg`. These can be referenced in your code directly without any special handling, e.g.
```
<link rel="icon" type="image/png" href="/favicon.png" />
```
and
```
<img src="/static-files/my-logo.jpg"> alt="Logo" />
```
Behind the scenes, we are using Webpack's ["copy-webpack-plugin"](https://github.com/webpack-contrib/copy-webpack-plugin).
## Best Practices
Because assets in this folder are bypassing the javascript module system, **this folder should be used sparingly** for assets such as favicons, robots.txt, manifests, libraries incompatible with Webpack, etc.
In general, it's best to import files directly into a template, page, or component. This allows Webpack to include that file in the bundle, which ensures Webpack will correctly process and move assets into the distribution folder, providing error checks and correct paths along the way.
### Example Asset Import with Webpack
Instead of handling our logo image as a static file per the example above, we can do the following:
```
import React from "react"
import logo from "./my-logo.jpg"
function Header() {
return <img src={logo} alt="Logo" />
}
export default Header
```
Behind the scenes, we are using Webpack's ["file-loader"](https://webpack.js.org/loaders/file-loader/) and ["url-loader](https://webpack.js.org/loaders/url-loader/) (for files smaller than 10kb).

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,2 @@
User-agent: *
Disallow:

View File

@@ -0,0 +1,22 @@
// In this file, all Page components from 'src/pages` are auto-imported. Nested
// directories are supported, and should be uppercase. Each subdirectory will be
// prepended onto the component name.
//
// Examples:
//
// 'src/pages/HomePage/HomePage.js' -> HomePage
// 'src/pages/Admin/BooksPage/BooksPage.js' -> AdminBooksPage
import { Router, Route } from '@redwoodjs/router'
const Routes = () => {
return (
<Router>
<Route path="/" page={HomePage} name="home" />
<Route path="/about" page={AboutPage} name="about" />
<Route notfound page={NotFoundPage} />
</Router>
)
}
export default Routes

View File

View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="/favicon.png" />
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<div id="redwood-app"></div>
</body>
</html>

View File

@@ -0,0 +1,16 @@
import ReactDOM from 'react-dom'
import { RedwoodProvider, FatalErrorBoundary } from '@redwoodjs/web'
import FatalErrorPage from 'src/pages/FatalErrorPage'
import Routes from 'src/Routes'
import './index.css'
ReactDOM.render(
<FatalErrorBoundary page={FatalErrorPage}>
<RedwoodProvider>
<Routes />
</RedwoodProvider>
</FatalErrorBoundary>,
document.getElementById('redwood-app')
)

View File

View File

@@ -0,0 +1,44 @@
export default () => (
<main>
<style
dangerouslySetInnerHTML={{
__html: `
html, body {
margin: 0;
}
html * {
box-sizing: border-box;
}
main {
display: flex;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
text-align: center;
background-color: #E2E8F0;
height: 100vh;
}
section {
background-color: white;
border-radius: 0.25rem;
width: 32rem;
padding: 1rem;
margin: 0 auto;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
h1 {
font-size: 2rem;
margin: 0;
font-weight: 500;
line-height: 1;
color: #2D3748;
}
`,
}}
/>
<section>
<h1>
<span>About RedwoodJS</span>
</h1>
</section>
</main>
)

View File

@@ -0,0 +1,53 @@
// This page will be rendered when an error makes it all the way to the top of the
// application without being handled by a Javascript catch statement or React error
// boundary.
//
// You can modify this page as you wish, but it is important to keep things simple to
// avoid the possibility that it will cause its own error. If it does, Redwood will
// still render a generic error page, but your users will prefer something a bit more
// thoughtful. =)
export default () => (
<main>
<style
dangerouslySetInnerHTML={{
__html: `
html, body {
margin: 0;
}
html * {
box-sizing: border-box;
}
main {
display: flex;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
text-align: center;
background-color: #E2E8F0;
height: 100vh;
}
section {
background-color: white;
border-radius: 0.25rem;
width: 32rem;
padding: 1rem;
margin: 0 auto;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
h1 {
font-size: 2rem;
margin: 0;
font-weight: 500;
line-height: 1;
color: #2D3748;
}
`,
}}
/>
<section>
<h1>
<span>Something went wrong</span>
</h1>
</section>
</main>
)

View File

@@ -0,0 +1,44 @@
export default () => (
<main>
<style
dangerouslySetInnerHTML={{
__html: `
html, body {
margin: 0;
}
html * {
box-sizing: border-box;
}
main {
display: flex;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
text-align: center;
background-color: #E2E8F0;
height: 100vh;
}
section {
background-color: white;
border-radius: 0.25rem;
width: 32rem;
padding: 1rem;
margin: 0 auto;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
h1 {
font-size: 2rem;
margin: 0;
font-weight: 500;
line-height: 1;
color: #2D3748;
}
`,
}}
/>
<section>
<h1>
<span>Welcome to RedwoodJS!</span>
</h1>
</section>
</main>
)

View File

@@ -0,0 +1,44 @@
export default () => (
<main>
<style
dangerouslySetInnerHTML={{
__html: `
html, body {
margin: 0;
}
html * {
box-sizing: border-box;
}
main {
display: flex;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
text-align: center;
background-color: #E2E8F0;
height: 100vh;
}
section {
background-color: white;
border-radius: 0.25rem;
width: 32rem;
padding: 1rem;
margin: 0 auto;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
h1 {
font-size: 2rem;
margin: 0;
font-weight: 500;
line-height: 1;
color: #2D3748;
}
`,
}}
/>
<section>
<h1>
<span>404 Page Not Found</span>
</h1>
</section>
</main>
)

View File

@@ -20,6 +20,7 @@
"@zeit/ncc": "0.20.4",
"async-retry": "1.2.3",
"buffer-replace": "1.0.0",
"cheerio": "1.0.0-rc.3",
"eslint": "6.2.2",
"eslint-config-prettier": "6.1.0",
"eslint-plugin-jest": "23.8.2",
@@ -28,7 +29,7 @@
"lint-staged": "9.2.5",
"node-fetch": "2.6.0",
"npm-package-arg": "6.1.0",
"prettier": "1.18.2"
"prettier": "2.0.5"
},
"scripts": {
"lerna": "lerna",
@@ -63,7 +64,8 @@
},
"prettier": {
"trailingComma": "es5",
"singleQuote": true
"singleQuote": true,
"arrowParens": "avoid"
},
"eslintConfig": {
"root": true,

View File

@@ -1,12 +1,41 @@
[
{
"name": "Blitz.js",
"slug": "blitzjs",
"demo": "https://blitzjs.now-examples.now.sh",
"logo": "https://raw.githubusercontent.com/vercel/vercel/master/packages/frameworks/logos/blitz.svg",
"tagline": "Blitz.js: The Fullstack React Framework",
"description": "A brand new Blitz.js app - the result of running `npx blitz new`.",
"website": "https://blitzjs.com",
"detectors": {
"every": [
{
"path": "package.json",
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"blitz\":\\s*\".+?\"[^}]*}"
}
]
},
"settings": {
"buildCommand": {
"placeholder": "`npm run build` or `blitz build`"
},
"devCommand": {
"value": "blitz start"
},
"outputDirectory": {
"placeholder": "Next.js default"
}
}
},
{
"name": "Next.js",
"slug": "nextjs",
"demo": "https://nextjs.now-examples.now.sh",
"logo": "https://raw.githubusercontent.com/vercel/vercel/master/packages/frameworks/logos/next.svg",
"tagline": "Next.js makes you productive with React instantly — whether you want to build static or dynamic sites. ",
"tagline": "Next.js makes you productive with React instantly — whether you want to build static or dynamic sites.",
"description": "A Next.js app and a Serverless Function API.",
"website": "https://nextjs.org",
"sort": 1,
"detectors": {
"every": [
{
@@ -35,6 +64,7 @@
"tagline": "Gatsby helps developers build blazing fast websites and apps with React.",
"description": "A Gatsby app, using the default starter theme and a Serverless Function API.",
"website": "https://gatsbyjs.org",
"sort": 2,
"detectors": {
"every": [
{
@@ -62,7 +92,8 @@
"logo": "https://raw.githubusercontent.com/vercel/vercel/master/packages/frameworks/logos/hexo.svg",
"tagline": "Hexo is a fast, simple & powerful blog framework powered by Node.js.",
"description": "A Hexo site, created with the Hexo CLI.",
"website": "https://hexo.io/",
"website": "https://hexo.io",
"sort": 3,
"detectors": {
"every": [
{
@@ -90,7 +121,8 @@
"logo": "https://raw.githubusercontent.com/vercel/vercel/master/packages/frameworks/logos/eleventy.svg",
"tagline": "11ty is a simpler static site generator written in JavaScript, created to be an alternative to Jekyll.",
"description": "An Eleventy site, created with npm init.",
"website": "https://www.11ty.dev/",
"website": "https://www.11ty.dev",
"sort": 4,
"detectors": {
"every": [
{
@@ -634,13 +666,13 @@
"every": [
{
"path": "package.json",
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"nuxt\":\\s*\".+?\"[^}]*}"
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"nuxt(-edge)?\":\\s*\".+?\"[^}]*}"
}
]
},
"settings": {
"buildCommand": {
"placeholder": "`npm run build` or `nuxt build`"
"placeholder": "`npm run build` or `nuxt generate`"
},
"devCommand": {
"value": "nuxt"
@@ -650,6 +682,34 @@
}
}
},
{
"name": "RedwoodJS",
"slug": "redwoodjs",
"demo": "https://redwoodjs.now-examples.now.sh",
"logo": "https://raw.githubusercontent.com/vercel/vercel/master/packages/frameworks/logos/redwood.svg",
"tagline": "RedwoodJS is a full-stack framework for the Jamstack.",
"description": "A RedwoodJS app, bootstraped with create-redwood-app.",
"website": "https://redwoodjs.com",
"detectors": {
"every": [
{
"path": "package.json",
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"@redwoodjs\\/core\":\\s*\".+?\"[^}]*}"
}
]
},
"settings": {
"buildCommand": {
"value": "yarn rw db up --no-db-client --auto-approve && yarn rw build"
},
"devCommand": {
"value": "yarn rw dev"
},
"outputDirectory": {
"value": "RedwoodJS default"
}
}
},
{
"name": "Hugo",
"slug": "hugo",
@@ -658,6 +718,7 @@
"tagline": "Hugo is the worlds fastest framework for building websites, written in Go.",
"description": "A Hugo site, created with the Hugo CLI.",
"website": "https://gohugo.io",
"sort": 5,
"detectors": {
"some": [
{
@@ -771,7 +832,7 @@
"description": "No framework or a unoptimized framework.",
"settings": {
"buildCommand": {
"placeholder": "`npm run now-build` or `npm run build`"
"placeholder": "`npm run vercel-build` or `npm run build`"
},
"devCommand": {
"placeholder": "None"

View File

@@ -19,6 +19,7 @@ export interface Framework {
tagline?: string;
website?: string;
description: string;
sort?: number;
detectors?: {
every?: FrameworkDetectionItem[];
some?: FrameworkDetectionItem[];

View File

@@ -0,0 +1,30 @@
<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0)">
<path d="M95.4242 249.857H173.991C203.89 249.857 232.049 263.909 250.026 287.799L327.526 390.789C328.991 392.736 329.212 395.349 328.095 397.513L283.421 484.069C281.278 488.221 275.532 488.71 272.719 484.978L95.4242 249.857Z" fill="url(#paint0_linear)"/>
<g filter="url(#filter0_d)">
<path d="M404.558 249.991H325.991C296.093 249.991 267.933 235.939 249.956 212.049L172.456 109.059C170.991 107.112 170.771 104.499 171.888 102.335L216.561 15.7794C218.705 11.6267 224.45 11.1382 227.264 14.8695L404.558 249.991Z" fill="url(#paint1_linear)"/>
</g>
</g>
<defs>
<filter id="filter0_d" x="71.1812" y="-39.6553" width="433.377" height="437.646" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
<feOffset dy="48"/>
<feGaussianBlur stdDeviation="50"/>
<feColorMatrix type="matrix" values="0 0 0 0 0.270588 0 0 0 0 0 0 0 0 0 0.615686 0 0 0 0.2 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>
</filter>
<linearGradient id="paint0_linear" x1="163.936" y1="392.775" x2="316.429" y2="155.244" gradientUnits="userSpaceOnUse">
<stop stop-color="#6700EB"/>
<stop offset="1" stop-color="#45009D"/>
</linearGradient>
<linearGradient id="paint1_linear" x1="336.047" y1="107.073" x2="183.554" y2="344.604" gradientUnits="userSpaceOnUse">
<stop stop-color="#6700EB"/>
<stop offset="1" stop-color="#45009D"/>
</linearGradient>
<clipPath id="clip0">
<rect width="500" height="500" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1 @@
<svg fill="none" height="1000" viewBox="0 0 917 1000" width="917" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="m249.557 144.582 194.171 132.54c4.383 2.918 9.502 4.516 14.755 4.606 5.261-.038 10.394-1.641 14.755-4.606l194.319-132.986c7.55-5.406 11.714-14.418 10.957-23.717-.757-9.298-6.322-17.507-14.646-21.6024l-194.171-96.13614c-7.366-3.573948-15.947-3.573948-23.313 0l-193.581 96.13614c-8.474 4.1174-14.113 12.4854-14.783 21.9354-.67 9.451 3.73 18.541 11.537 23.83zm274.879 174.144c.016 8.789 4.318 17.01 11.509 21.991l155.662 106.389c9.965 6.87 23.298 6.012 32.313-2.081l130.579-116.789c5.819-5.199 9.051-12.729 8.823-20.56s-3.892-15.158-10.004-20.005l-124.677-99.702c-9.062-7.199-21.704-7.68-31.28-1.189l-161.416 110.401c-7.064 4.89-11.35 12.914-11.509 21.545zm-387.163 144.724c6.292 5.652 9.526 13.988 8.706 22.437-.817 8.499-5.726 16.052-13.132 20.208l-92.9545 55.72c-9.4227 5.633-21.32 4.82-29.90183-2.041-8.5818-6.861-12.06543-18.346-8.75546-28.865l34.37839-108.172c2.6969-8.57 9.5328-15.175 18.1483-17.533 8.609-2.505 17.8924-.309 24.4928 5.795zm504.168 11.293-168.056-115.007c-8.931-6.01-20.578-6.01-29.509 0l-168.056 115.007c-6.684 4.626-10.919 12.061-11.509 20.208-.435 8.203 2.816 16.169 8.853 21.693l167.909 150.222c4.842 4.319 11.089 6.698 17.558 6.687 6.465-.002 12.708-2.38 17.558-6.687l167.908-150.222c6.056-5.501 9.265-13.5 8.705-21.693-.469-8.146-4.666-15.612-11.361-20.208zm-448.247-29.718-130.4316-116.79c-5.8687-5.331-9.1073-12.995-8.8528-20.95.1419-7.841 3.7705-15.204 9.8856-20.06l124.6768-100.296c9.126-7.179 21.793-7.658 31.428-1.189l161.269 110.401c7.484 4.908 11.998 13.293 11.998 22.288 0 8.994-4.514 17.38-11.998 22.288l-155.515 106.388c-10.025 6.841-23.376 5.985-32.46-2.08zm669.715 167.756-132.792-79.495c-9.862-5.943-22.415-4.739-30.985 2.972l-162.301 144.873c-6.846 6.114-10.062 15.362-8.499 24.441 1.563 9.08 7.681 16.698 16.171 20.135l225.157 91.233c3.088 1.283 6.397 1.939 9.738 1.932 10.449.033 19.936-6.142 24.197-15.751l69.79-156.314c5.68-12.37 1.157-27.062-10.476-34.026zm18.443-190.043 34.379 108.171h-.295c2.542 8.091 1.097 16.919-3.889 23.761-4.986 6.841-12.915 10.876-21.342 10.86-4.728.016-9.37-1.269-13.427-3.715l-93.102-55.72c-7.254-4.243-11.992-11.789-12.689-20.208-.87-8.456 2.373-16.814 8.705-22.436l59.019-52.6c6.668-5.976 15.881-8.156 24.493-5.795 8.609 2.459 15.423 9.098 18.148 17.682zm-492.511 282.761c1.587-9.042-1.597-18.266-8.41-24.368l-162.302-144.873c-8.57-7.711-21.123-8.915-30.985-2.972l-132.7921 79.495c-11.4977 6.995-16.0467 21.502-10.6233 33.878l69.9374 156.314c5.794 13.034 20.774 19.134 33.936 13.818l225.009-91.232c8.492-3.407 14.632-10.995 16.23-20.06zm79.675 44.577 180.598 73.105c8.83 3.779 14.93 12.084 15.935 21.694 1.143 9.729-3.178 19.291-11.214 24.814l-180.745 125.556c-4.331 3.043-9.473 4.7-14.754 4.755-5.277-.082-10.411-1.737-14.755-4.755l-180.597-125.556c-8.066-5.508-12.439-15.061-11.362-24.814 1.206-9.71 7.526-18.006 16.526-21.694l180.597-73.105c6.351-2.532 13.421-2.532 19.771 0z" fill="#bf4722" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/frameworks",
"version": "0.0.15",
"version": "0.0.18-canary.1",
"main": "frameworks.json",
"license": "UNLICENSED",
"scripts": {

View File

@@ -1,11 +1,9 @@
import Ajv from 'ajv';
import path from 'path';
import { join } from 'path';
import { existsSync } from 'fs';
import { isString } from 'util';
import { Framework } from '../';
function isString(arg: any): arg is string {
return typeof arg === 'string';
}
const frameworkList = require('../frameworks.json') as Framework[];
const SchemaFrameworkDetectionItem = {
type: 'array',
@@ -60,6 +58,7 @@ const Schema = {
properties: {
name: { type: 'string' },
slug: { type: ['string', 'null'] },
sort: { type: 'number' },
logo: { type: 'string' },
demo: { type: 'string' },
tagline: { type: 'string' },
@@ -89,12 +88,10 @@ const Schema = {
describe('frameworks', () => {
it('ensure there is an example for every framework', async () => {
const root = path.join(__dirname, '..', '..', '..');
const getExample = (name: string) => path.join(root, 'examples', name);
const root = join(__dirname, '..', '..', '..');
const getExample = (name: string) => join(root, 'examples', name);
const frameworks = require('../frameworks.json') as Framework[];
const result = frameworks
const result = frameworkList
.map(f => f.slug)
.filter(isString)
.filter(f => existsSync(getExample(f)) === false);
@@ -103,10 +100,8 @@ describe('frameworks', () => {
});
it('ensure schema', async () => {
const frameworks = require('../frameworks.json') as Framework[];
const ajv = new Ajv();
const result = ajv.validate(Schema, frameworks);
const result = ajv.validate(Schema, frameworkList);
if (ajv.errors) {
console.error(ajv.errors);
@@ -116,17 +111,26 @@ describe('frameworks', () => {
});
it('ensure logo', async () => {
const frameworks = require('../frameworks.json') as Framework[];
const missing = frameworks
const missing = frameworkList
.map(f => f.logo)
.filter(url => {
const prefix =
'https://raw.githubusercontent.com/vercel/vercel/master/packages/frameworks/logos/';
const name = url.replace(prefix, '');
return existsSync(path.join(__dirname, '..', 'logos', name)) === false;
return existsSync(join(__dirname, '..', 'logos', name)) === false;
});
expect(missing).toEqual([]);
});
it('ensure unique sort number', async () => {
const sortNumToSlug = new Map<number, string | null>();
frameworkList.forEach(f => {
if (f.sort) {
const duplicateSlug = sortNumToSlug.get(f.sort);
expect(duplicateSlug).toStrictEqual(undefined);
sortNumToSlug.set(f.sort, f.slug);
}
});
});
});

View File

@@ -1,5 +1,6 @@
#!/bin/sh
set -eu
#!/bin/bash
set -euo pipefail
out="dist"
rm -rf "$out"

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/build-utils",
"version": "2.4.0",
"version": "2.4.3-canary.2",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.js",

View File

@@ -8,6 +8,8 @@ import { isOfficialRuntime } from './';
interface ErrorResponse {
code: string;
message: string;
action?: string;
link?: string;
}
interface Options {
@@ -307,6 +309,13 @@ export async function detectBuilders(
options
);
if (frontendBuilder && framework === 'redwoodjs') {
// RedwoodJS uses the /api directory differently so we must
// clear any existing builders and only use `@vercel/redwood`.
builders.length = 0;
builders.push(frontendBuilder);
}
return {
warnings,
builders: builders.length ? builders : null,
@@ -462,10 +471,14 @@ function detectFrontBuilder(
});
}
if (framework === 'nextjs') {
if (framework === 'nextjs' || framework === 'blitzjs') {
return { src: 'package.json', use: `@vercel/next${withTag}`, config };
}
if (framework === 'redwoodjs') {
return { src: 'package.json', use: `@vercel/redwood${withTag}`, config };
}
// Entrypoints for other frameworks
// TODO - What if just a build script is provided, but no entrypoint.
const entrypoints = new Set([
@@ -496,7 +509,7 @@ function getMissingBuildScriptError() {
code: 'missing_build_script',
message:
'Your `package.json` file is missing a `build` property inside the `scripts` property.' +
'\nMore details: https://vercel.com/docs/v2/platform/frequently-asked-questions#missing-build-script',
'\nLearn More: https://vercel.com/docs/v2/platform/frequently-asked-questions#missing-build-script',
};
}
@@ -608,20 +621,22 @@ function checkUnusedFunctions(
} else {
return {
code: 'unused_function',
message: `The function for ${fnKey} can't be handled by any builder`,
message: `The pattern "${fnKey}" defined in \`functions\` doesn't match any Serverless Functions.`,
action: 'Learn More',
link: 'https://vercel.link/unmatched-function-pattern',
};
}
}
}
if (unusedFunctions.size) {
const [unusedFunction] = Array.from(unusedFunctions);
const [fnKey] = Array.from(unusedFunctions);
return {
code: 'unused_function',
message:
`The function for ${unusedFunction} can't be handled by any builder. ` +
`Make sure it is inside the api/ directory.`,
message: `The pattern "${fnKey}" defined in \`functions\` doesn't match any Serverless Functions inside the \`api\` directory.`,
action: 'Learn More',
link: 'https://vercel.link/unmatched-function-pattern',
};
}

View File

@@ -34,7 +34,82 @@ interface Props {
*/
link?: string;
/**
* Optional "action" to display before the `link`, such as "More details".
* Optional "action" to display before the `link`, such as "Learn More".
*/
action?: string;
}
export function getPrettyError(obj: {
dataPath?: string;
message?: string;
params: any;
}): NowBuildError {
const docsUrl = 'https://vercel.com/docs/configuration';
try {
const { dataPath, params, message: ajvMessage } = obj;
const prop = getTopLevelPropertyName(dataPath);
let message =
dataPath && dataPath.startsWith('.') ? `\`${dataPath.slice(1)}\` ` : '';
if (params && typeof params.additionalProperty === 'string') {
const suggestion = getSuggestion(prop, params.additionalProperty);
message += `should NOT have additional property \`${params.additionalProperty}\`. ${suggestion}`;
} else if (params && typeof params.missingProperty === 'string') {
message += `missing required property \`${params.missingProperty}\`.`;
} else {
message += `${ajvMessage}.`;
}
return new NowBuildError({
code: 'DEV_VALIDATE_CONFIG',
message: message,
link: prop ? `${docsUrl}#project/${prop.toLowerCase()}` : docsUrl,
action: 'View Documentation',
});
} catch (e) {
return new NowBuildError({
code: 'DEV_VALIDATE_CONFIG',
message: `Failed to validate configuration.`,
link: docsUrl,
action: 'View Documentation',
});
}
}
/**
* Get the top level property from the dataPath.
* `.cleanUrls` => `cleanUrls`
* `.headers[0].source` => `headers`
* `.headers[0].headers[0]` => `headers`
* `` => ``
*/
function getTopLevelPropertyName(dataPath?: string): string {
if (dataPath && dataPath.startsWith('.')) {
const lastIndex = dataPath.indexOf('[');
return lastIndex > -1 ? dataPath.slice(1, lastIndex) : dataPath.slice(1);
}
return '';
}
const mapTypoToSuggestion: { [key: string]: { [key: string]: string } } = {
'': {
builder: 'builds',
'build.env': '{ "build": { "env": {"name": "value"} } }',
'builds.env': '{ "build": { "env": {"name": "value"} } }',
},
rewrites: { src: 'source', dest: 'destination' },
redirects: { src: 'source', dest: 'destination', status: 'statusCode' },
headers: { src: 'source', header: 'headers' },
routes: {
source: 'src',
destination: 'dest',
header: 'headers',
method: 'methods',
},
};
function getSuggestion(topLevelProp: string, additionalProperty: string) {
const choices = mapTypoToSuggestion[topLevelProp];
const choice = choices ? choices[additionalProperty] : undefined;
return choice ? `Did you mean \`${choice}\`?` : 'Please remove it.';
}

View File

@@ -15,7 +15,9 @@ async function readFileOrNull(file: string) {
return null;
}
export async function readConfigFile<T>(files: string | string[]) {
export async function readConfigFile<T>(
files: string | string[]
): Promise<T | null> {
files = Array.isArray(files) ? files : [files];
for (const name of files) {
@@ -24,11 +26,11 @@ export async function readConfigFile<T>(files: string | string[]) {
if (data) {
const str = data.toString('utf8');
if (name.endsWith('.json')) {
return JSON.parse(str);
return JSON.parse(str) as T;
} else if (name.endsWith('.toml')) {
return (toml.parse(str) as unknown) as T;
} else if (name.endsWith('.yaml') || name.endsWith('.yml')) {
return yaml.safeLoad(str, { filename: name });
return yaml.safeLoad(str, { filename: name }) as T;
}
}
}

View File

@@ -349,20 +349,35 @@ export async function runPipInstall(
);
}
export function getScriptName(
pkg: Pick<PackageJson, 'scripts'> | null | undefined,
possibleNames: Iterable<string>
): string | null {
if (pkg && pkg.scripts) {
for (const name of possibleNames) {
if (name in pkg.scripts) {
return name;
}
}
}
return null;
}
export async function runPackageJsonScript(
destPath: string,
scriptName: string,
scriptNames: string | Iterable<string>,
spawnOpts?: SpawnOptions
) {
assert(path.isAbsolute(destPath));
const { packageJson, cliType } = await scanParentDirs(destPath, true);
const hasScript = Boolean(
packageJson &&
packageJson.scripts &&
scriptName &&
packageJson.scripts[scriptName]
const scriptName = getScriptName(
packageJson,
typeof scriptNames === 'string' ? [scriptNames] : scriptNames
);
if (!hasScript) return false;
if (!scriptName) return false;
debug('Running user script...');
const runScriptTime = Date.now();
if (cliType === 'npm') {
const prettyCommand = `npm run ${scriptName}`;
@@ -382,6 +397,7 @@ export async function runPackageJsonScript(
});
}
debug(`Script complete [${Date.now() - runScriptTime}ms]`);
return true;
}

View File

@@ -13,6 +13,7 @@ import {
execCommand,
spawnCommand,
walkParentDirs,
getScriptName,
installDependencies,
runPackageJsonScript,
runNpmInstall,
@@ -47,6 +48,7 @@ export {
rename,
execAsync,
spawnAsync,
getScriptName,
installDependencies,
runPackageJsonScript,
execCommand,

View File

@@ -493,7 +493,7 @@ describe('Test `detectBuilders`', () => {
});
it('use a custom runtime', async () => {
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/user.php'];
const { builders, errors } = await detectBuilders(files, null, {
functions,
@@ -501,11 +501,11 @@ describe('Test `detectBuilders`', () => {
expect(errors).toBe(null);
expect(builders!.length).toBe(1);
expect(builders![0].use).toBe('now-php@0.0.8');
expect(builders![0].use).toBe('vercel-php@0.1.0');
});
it('use a custom runtime but without a source', async () => {
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/team.js'];
const { errors } = await detectBuilders(files, null, {
functions,
@@ -775,8 +775,9 @@ describe('Test `detectBuilders`', () => {
expect(errors).toEqual([
{
code: 'unused_function',
message:
"The function for server/**/*.ts can't be handled by any builder. Make sure it is inside the api/ directory.",
message: `The pattern "server/**/*.ts" defined in \`functions\` doesn't match any Serverless Functions inside the \`api\` directory.`,
action: 'Learn More',
link: 'https://vercel.link/unmatched-function-pattern',
},
]);
});
@@ -1538,7 +1539,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
});
it('use a custom runtime', async () => {
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/user.php'];
const { builders, errors } = await detectBuilders(files, null, {
functions,
@@ -1547,11 +1548,11 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
expect(errors).toBe(null);
expect(builders!.length).toBe(1);
expect(builders![0].use).toBe('now-php@0.0.8');
expect(builders![0].use).toBe('vercel-php@0.1.0');
});
it('use a custom runtime but without a source', async () => {
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/team.js'];
const { errors } = await detectBuilders(files, null, {
functions,
@@ -1807,6 +1808,36 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
expect((errorRoutes![0] as Source).status).toBe(404);
});
it('RedwoodJS should only use redwood builder', async () => {
const files = [
'package.json',
'web/index.html',
'api/one.js',
'api/two.js',
];
const projectSettings = {
framework: 'redwoodjs',
};
const { builders, errorRoutes } = await detectBuilders(files, null, {
projectSettings,
featHandleMiss,
});
expect(builders).toEqual([
{
use: '@vercel/redwood',
src: 'package.json',
config: {
zeroConfig: true,
framework: 'redwoodjs',
},
},
]);
expect(errorRoutes!.length).toBe(1);
expect((errorRoutes![0] as Source).status).toBe(404);
});
it('No framework, only package.json', async () => {
const files = ['package.json'];
const pkg = {
@@ -1878,8 +1909,9 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
expect(errors).toEqual([
{
code: 'unused_function',
message:
"The function for server/**/*.ts can't be handled by any builder. Make sure it is inside the api/ directory.",
message: `The pattern "server/**/*.ts" defined in \`functions\` doesn't match any Serverless Functions inside the \`api\` directory.`,
action: 'Learn More',
link: 'https://vercel.link/unmatched-function-pattern',
},
]);
});
@@ -2081,7 +2113,7 @@ it('Test `detectRoutes`', async () => {
{
// use a custom runtime
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/user.php'];
const { defaultRoutes } = await detectBuilders(files, null, { functions });
@@ -2393,7 +2425,7 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
{
// use a custom runtime
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/user.php'];
const { defaultRoutes, rewriteRoutes } = await detectBuilders(files, null, {
@@ -2692,7 +2724,7 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
{
// use a custom runtime
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/user.php'];
const {
@@ -2941,7 +2973,7 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
{
// use a custom runtime
const functions = { 'api/user.php': { runtime: 'now-php@0.0.8' } };
const functions = { 'api/user.php': { runtime: 'vercel-php@0.1.0' } };
const files = ['api/user.php'];
const {

View File

@@ -0,0 +1,72 @@
import assert from 'assert';
import { getScriptName } from '../src';
describe('Test `getScriptName()`', () => {
it('should return "vercel-*"', () => {
const pkg = {
scripts: {
'vercel-dev': '',
'vercel-build': '',
dev: '',
build: '',
},
};
assert.equal(
getScriptName(pkg, ['vercel-dev', 'now-dev', 'dev']),
'vercel-dev'
);
assert.equal(
getScriptName(pkg, ['vercel-build', 'now-build', 'build']),
'vercel-build'
);
assert.equal(getScriptName(pkg, ['dev']), 'dev');
assert.equal(getScriptName(pkg, ['build']), 'build');
});
it('should return "now-*"', () => {
const pkg = {
scripts: {
'now-dev': '',
'now-build': '',
dev: '',
build: '',
},
};
assert.equal(
getScriptName(pkg, ['vercel-dev', 'now-dev', 'dev']),
'now-dev'
);
assert.equal(
getScriptName(pkg, ['vercel-build', 'now-build', 'build']),
'now-build'
);
assert.equal(getScriptName(pkg, ['dev']), 'dev');
assert.equal(getScriptName(pkg, ['build']), 'build');
});
it('should return base script name', () => {
const pkg = {
scripts: {
dev: '',
build: '',
},
};
assert.equal(getScriptName(pkg, ['dev']), 'dev');
assert.equal(getScriptName(pkg, ['build']), 'build');
});
it('should return `null`', () => {
assert.equal(getScriptName(undefined, ['build']), null);
assert.equal(getScriptName({}, ['build']), null);
assert.equal(getScriptName({ scripts: {} }, ['build']), null);
const pkg = {
scripts: {
dev: '',
build: '',
},
};
assert.equal(getScriptName(pkg, ['vercel-dev', 'now-dev']), null);
assert.equal(getScriptName(pkg, ['vercel-build', 'now-build']), null);
});
});

View File

@@ -1,9 +1,9 @@
{
"name": "vercel",
"version": "19.1.0",
"version": "20.0.0-canary.6",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Now",
"description": "The command-line interface for Vercel",
"homepage": "https://vercel.com",
"repository": {
"type": "git",
@@ -12,7 +12,7 @@
},
"scripts": {
"preinstall": "node ./scripts/preinstall.js",
"test-unit": "nyc ava test/unit.js test/dev-builder.unit.js test/dev-router.unit.js test/dev-server.unit.js --serial --fail-fast --verbose",
"test-unit": "nyc ava test/unit.js test/dev-builder.unit.js test/dev-router.unit.js test/dev-server.unit.js test/dev-validate.unit.js --serial --fail-fast --verbose",
"test-integration-cli": "ava test/integration.js --serial --fail-fast --verbose",
"test-integration-v1": "ava test/integration-v1.js --serial --fail-fast",
"test-integration-dev": "ava test/dev/integration.js --serial --fail-fast --verbose",
@@ -62,13 +62,15 @@
"node": ">= 10"
},
"dependencies": {
"@vercel/build-utils": "2.4.0",
"@vercel/go": "1.1.2",
"@vercel/next": "2.6.6",
"@vercel/node": "1.7.0",
"@vercel/build-utils": "2.4.3-canary.2",
"@vercel/go": "1.1.5-canary.0",
"@vercel/next": "2.6.14",
"@vercel/node": "1.7.4-canary.1",
"@vercel/python": "1.2.2",
"@vercel/ruby": "1.2.2",
"@vercel/static-build": "0.17.2"
"@vercel/redwood": "0.0.2-canary.1",
"@vercel/ruby": "1.2.3",
"@vercel/static-build": "0.17.7-canary.1",
"update-notifier": "4.1.0"
},
"devDependencies": {
"@sentry/node": "5.5.0",
@@ -119,7 +121,7 @@
"chalk": "2.4.2",
"chokidar": "3.3.1",
"clipboardy": "2.1.0",
"codecov": "3.6.5",
"codecov": "3.7.1",
"cpy": "7.2.0",
"credit-card": "3.0.1",
"date-fns": "1.29.0",
@@ -185,7 +187,6 @@
"ts-node": "8.3.0",
"typescript": "3.9.3",
"universal-analytics": "0.4.20",
"update-check": "1.5.3",
"utility-types": "2.1.0",
"which": "2.0.2",
"which-promise": "1.0.0",

View File

@@ -49,7 +49,13 @@ async function main() {
// Do the initial `ncc` build
console.log();
const src = join(dirRoot, 'src');
const args = ['@zeit/ncc', 'build', '--source-map'];
const args = [
'@zeit/ncc',
'build',
'--source-map',
'--external',
'update-notifier',
];
if (!isDev) {
args.push('--minify');
}
@@ -86,7 +92,7 @@ async function main() {
// A bunch of source `.ts` files from CLI's `util` directory
await remove(join(dirRoot, 'dist', 'util'));
console.log('Finished building `now-cli`');
console.log('Finished building Vercel CLI');
}
process.on('unhandledRejection', (reason: any, promise: Promise<any>) => {

View File

@@ -3,8 +3,8 @@ import bytes from 'bytes';
import { join } from 'path';
import { write as copy } from 'clipboardy';
import chalk from 'chalk';
import title from 'title';
import { fileNameSymbol } from '@vercel/client';
import { getPrettyError } from '@vercel/build-utils';
import Client from '../../util/client';
import { handleError } from '../../util/error';
import getArgs from '../../util/get-args';
@@ -354,7 +354,7 @@ export default async function main(
path,
sourcePath,
project
? `To change your project settings, go to https://vercel.com/${org.slug}/${project.name}/settings`
? `To change your Project Settings, go to https://vercel.com/${org.slug}/${project.name}/settings`
: ''
)) === false
) {
@@ -669,7 +669,7 @@ export default async function main(
}
if (err instanceof BuildError) {
output.error('Build failed');
output.error(err.message || 'Build failed');
output.error(
`Check your logs at https://${now.url}/_logs or run ${getCommandName(
`logs ${now.url}`,
@@ -738,53 +738,10 @@ function handleCreateDeployError(output, error, localConfig) {
return 1;
}
if (error instanceof SchemaValidationFailed) {
const { message, params, keyword, dataPath } = error.meta;
if (params && params.additionalProperty) {
const prop = params.additionalProperty;
output.error(
`The property ${code(prop)} is not allowed in ${highlight(
localConfig[fileNameSymbol]
)} please remove it.`
);
if (prop === 'build.env' || prop === 'builds.env') {
output.note(
`Do you mean ${code('build')} (object) with a property ${code(
'env'
)} (object) instead of ${code(prop)}?`
);
}
return 1;
}
if (dataPath === '.name') {
output.error(message);
return 1;
}
if (keyword === 'type') {
const prop = dataPath.substr(1, dataPath.length);
output.error(
`The property ${code(prop)} in ${highlight(
localConfig[fileNameSymbol]
)} can only be of type ${code(title(params.type))}.`
);
return 1;
}
const link = 'https://vercel.com/docs/configuration';
output.error(
`Failed to validate ${highlight(
localConfig[fileNameSymbol]
)}: ${message}\nDocumentation: ${link}`
);
const niceError = getPrettyError(error.meta);
const fileName = localConfig[fileNameSymbol] || 'vercel.json';
niceError.message = `Invalid ${fileName} - ${niceError.message}`;
output.prettyError(niceError);
return 1;
}
if (error instanceof TooManyRequests) {

View File

@@ -8,11 +8,15 @@ import Client from '../../util/client';
import { getLinkedProject } from '../../util/projects/link';
import { getFrameworks } from '../../util/get-frameworks';
import { isSettingValue } from '../../util/is-setting-value';
import { getCommandName } from '../../util/pkg-name';
import { ProjectSettings, ProjectEnvTarget } from '../../types';
import getDecryptedEnvRecords from '../../util/get-decrypted-env-records';
import { Env } from '@vercel/build-utils';
import setupAndLink from '../../util/link/setup-and-link';
type Options = {
'--debug'?: boolean;
'--listen'?: string;
'--confirm': boolean;
};
export default async function dev(
@@ -34,37 +38,56 @@ export default async function dev(
});
// retrieve dev command
const [link, frameworks] = await Promise.all([
let [link, frameworks] = await Promise.all([
getLinkedProject(output, client, cwd),
getFrameworks(client),
]);
if (link.status === 'not_linked' && !process.env.__VERCEL_SKIP_DEV_CMD) {
const autoConfirm = opts['--confirm'];
const forceDelete = false;
link = await setupAndLink(
ctx,
output,
cwd,
forceDelete,
autoConfirm,
'link',
'Set up and develop'
);
if (link.status === 'not_linked') {
// User aborted project linking questions
return 0;
}
}
if (link.status === 'error') {
return link.exitCode;
}
if (link.status === 'not_linked' && !process.env.__VERCEL_SKIP_DEV_CMD) {
output.error(
`Your codebase isnt linked to a project on Vercel. Run ${getCommandName()} to link it.`
);
return 1;
}
let devCommand: undefined | string;
let frameworkSlug: null | string = null;
let devCommand: string | undefined;
let frameworkSlug: string | undefined;
let projectSettings: ProjectSettings | undefined;
let environmentVars: Env | undefined;
if (link.status === 'linked') {
const { project, org } = link;
client.currentTeam = org.type === 'team' ? org.id : undefined;
projectSettings = project;
if (project.devCommand) {
devCommand = project.devCommand;
} else if (project.framework) {
const framework = frameworks.find(f => f.slug === project.framework);
if (framework) {
frameworkSlug = framework.slug;
const defaults = framework.settings.devCommand;
if (framework.slug) {
frameworkSlug = framework.slug;
}
const defaults = framework.settings.devCommand;
if (isSettingValue(defaults)) {
devCommand = defaults.value;
}
@@ -74,6 +97,13 @@ export default async function dev(
if (project.rootDirectory) {
cwd = join(cwd, project.rootDirectory);
}
environmentVars = await getDecryptedEnvRecords(
output,
client,
project,
ProjectEnvTarget.Development
);
}
const devServer = new DevServer(cwd, {
@@ -81,6 +111,8 @@ export default async function dev(
debug,
devCommand,
frameworkSlug,
projectSettings,
environmentVars,
});
process.once('SIGINT', () => devServer.stop());

View File

@@ -10,6 +10,7 @@ import handleError from '../../util/handle-error';
import createOutput from '../../util/output/create-output';
import logo from '../../util/output/logo';
import cmd from '../../util/output/cmd';
import highlight from '../../util/output/highlight';
import dev from './dev';
import readPackage from '../../util/read-package';
import readConfig from '../../util/config/read-config';
@@ -31,6 +32,7 @@ const help = () => {
-d, --debug Debug mode [off]
-l, --listen [uri] Specify a URI endpoint on which to listen [0.0.0.0:3000]
-t, --token [token] Specify an Authorization Token
--confirm Skip questions and use defaults when setting up a new project
${chalk.dim('Examples:')}
@@ -55,6 +57,7 @@ export default async function main(ctx: NowContext) {
argv = getArgs(ctx.argv.slice(2), {
'--listen': String,
'-l': '--listen',
'--confirm': Boolean,
// Deprecated
'--port': Number,
@@ -96,7 +99,7 @@ export default async function main(ctx: NowContext) {
'package.json'
)} must not contain ${cmd('now dev')}`
);
output.error(`More details: http://err.sh/now/now-dev-as-dev-script`);
output.error(`Learn More: http://err.sh/now/now-dev-as-dev-script`);
return 1;
}
if (scripts && scripts.dev && /\bvercel\b\W+\bdev\b/.test(scripts.dev)) {
@@ -105,7 +108,7 @@ export default async function main(ctx: NowContext) {
'package.json'
)} must not contain ${cmd('vercel dev')}`
);
output.error(`More details: http://err.sh/now/now-dev-as-dev-script`);
output.error(`Learn More: http://err.sh/now/now-dev-as-dev-script`);
return 1;
}
}
@@ -119,6 +122,21 @@ export default async function main(ctx: NowContext) {
try {
return await dev(ctx, argv, args, output);
} catch (err) {
if (err.code === 'ENOTFOUND') {
// Error message will look like the following:
// "request to https://api.vercel.com/www/user failed, reason: getaddrinfo ENOTFOUND api.vercel.com"
const matches = /getaddrinfo ENOTFOUND (.*)$/.exec(err.message || '');
if (matches && matches[1]) {
const hostname = matches[1];
output.error(
`The hostname ${highlight(
hostname
)} could not be resolved. Please verify your internet connectivity and DNS configuration.`
);
}
output.debug(err.stack);
return 1;
}
output.prettyError(err);
output.debug(stringifyError(err));
return 1;

View File

@@ -1,23 +1,24 @@
import chalk from 'chalk';
import psl from 'psl';
import { NowContext } from '../../types';
import { Output } from '../../util/output';
import * as ERRORS from '../../util/errors-ts';
import addDomain from '../../util/domains/add-domain';
import Client from '../../util/client';
import cmd from '../../util/output/cmd';
import formatDnsTable from '../../util/format-dns-table';
import formatNSTable from '../../util/format-ns-table';
import getScope from '../../util/get-scope';
import stamp from '../../util/output/stamp';
import param from '../../util/output/param';
import { getCommandName, getTitleName } from '../../util/pkg-name';
import { getCommandName } from '../../util/pkg-name';
import { getDomain } from '../../util/domains/get-domain';
import { getLinkedProject } from '../../util/projects/link';
import { isPublicSuffix } from '../../util/domains/is-public-suffix';
import { getDomainConfig } from '../../util/domains/get-domain-config';
import { addDomainToProject } from '../../util/projects/add-domain-to-project';
import { removeDomainFromProject } from '../../util/projects/remove-domain-from-project';
import code from '../../util/output/code';
type Options = {
'--cdn': boolean;
'--debug': boolean;
'--no-cdn': boolean;
'--force': boolean;
};
export default async function add(
@@ -33,6 +34,7 @@ export default async function add(
const { currentTeam } = config;
const { apiUrl } = ctx;
const debug = opts['--debug'];
const force = opts['--force'];
const client = new Client({ apiUrl, token, currentTeam, debug });
let contextName = null;
@@ -47,105 +49,116 @@ export default async function add(
throw err;
}
if (opts['--cdn'] !== undefined || opts['--no-cdn'] !== undefined) {
output.error(`Toggling CF from ${getTitleName()} CLI is deprecated.`);
return 1;
}
const project = await getLinkedProject(output, client).then(result => {
if (result.status === 'linked') {
return result.project;
}
if (args.length !== 1) {
return null;
});
if (project && args.length !== 1) {
output.error(
`${getCommandName('domains add <domain>')} expects one argument`
`${getCommandName('domains add <domain>')} expects one argument.`
);
return 1;
} else if (!project && args.length !== 2) {
output.error(
`${getCommandName(
'domains add <domain> <project>'
)} expects two arguments.`
);
return 1;
}
const domainName = String(args[0]);
const parsedDomain = psl.parse(domainName);
if (parsedDomain.error) {
output.error(`The provided domain name ${param(domainName)} is invalid`);
return 1;
}
const { domain, subdomain } = parsedDomain;
if (!domain) {
output.error(`The provided domain '${param(domainName)}' is not valid.`);
return 1;
}
if (subdomain) {
output.error(
`You are adding '${domainName}' as a domain name containing a subdomain part '${subdomain}'\n` +
` This feature is deprecated, please add just the root domain: ${chalk.cyan(
`${getCommandName(`domain add ${domain}`)}`
)}`
);
return 1;
}
const projectName = project ? project.name : String(args[1]);
const addStamp = stamp();
const addedDomain = await addDomain(client, domainName, contextName);
if (addedDomain instanceof ERRORS.InvalidDomain) {
output.error(
`The provided domain name "${addedDomain.meta.domain}" is invalid`
);
return 1;
}
let aliasTarget = await addDomainToProject(client, projectName, domainName);
if (addedDomain instanceof ERRORS.DomainAlreadyExists) {
output.error(
`The domain ${chalk.underline(
addedDomain.meta.domain
)} is already registered by a different account.\n` +
` If this seems like a mistake, please contact us at support@vercel.com`
);
return 1;
if (aliasTarget instanceof Error) {
if (
aliasTarget instanceof ERRORS.APIError &&
aliasTarget.code === 'ALIAS_DOMAIN_EXIST' &&
aliasTarget.project &&
aliasTarget.project.id
) {
if (force) {
const removeResponse = await removeDomainFromProject(
client,
aliasTarget.project.id,
domainName
);
if (removeResponse instanceof Error) {
output.prettyError(removeResponse);
return 1;
}
aliasTarget = await addDomainToProject(client, projectName, domainName);
}
}
if (aliasTarget instanceof Error) {
output.prettyError(aliasTarget);
return 1;
}
}
// We can cast the information because we've just added the domain and it should be there
console.log(
`${chalk.cyan('> Success!')} Domain ${chalk.bold(
addedDomain.name
)} added correctly. ${addStamp()}\n`
domainName
)} added to project ${chalk.bold(projectName)}. ${addStamp()}`
);
if (!addedDomain.verified) {
if (isPublicSuffix(domainName)) {
output.log(
`The domain will automatically get assigned to your latest production deployment.`
);
return 0;
}
const domainResponse = await getDomain(client, contextName, domainName);
if (domainResponse instanceof Error) {
output.prettyError(domainResponse);
return 1;
}
const domainConfig = await getDomainConfig(client, contextName, domainName);
if (domainConfig.misconfigured) {
output.warn(
`The domain was added but it is not verified. To verify it, you should either:`
`This domain is not configured properly. To configure it you should either:`
);
output.print(
` ${chalk.gray(
'a)'
)} Change your domain nameservers to the following intended set: ${chalk.gray(
'[recommended]'
)}\n`
` ${chalk.grey('a)')} ` +
`Set the following record on your DNS provider to continue: ` +
`${code(`A ${domainName} 76.76.21.21`)} ` +
`${chalk.grey('[recommended]')}\n`
);
output.print(
` ${chalk.grey('b)')} ` +
`Change your domain nameservers to the intended set`
);
output.print(
`\n${formatNSTable(
addedDomain.intendedNameservers,
addedDomain.nameservers,
domainResponse.intendedNameservers,
domainResponse.nameservers,
{ extraSpace: ' ' }
)}\n\n`
);
output.print(
` ${chalk.gray(
'b)'
)} Add a DNS TXT record with the name and value shown below.\n`
);
output.print(
`\n${formatDnsTable([['_now', 'TXT', addedDomain.verificationRecord]], {
extraSpace: ' ',
})}\n\n`
);
output.print(
` We will run a verification for you and you will receive an email upon completion.\n`
);
output.print(
` If you want to force running a verification, you can run ${cmd(
`${getCommandName('domains verify <domain>')}`
)}\n`
output.print(' Read more: https://vercel.link/domain-configuration\n\n');
} else {
output.log(
`The domain will automatically get assigned to your latest production deployment.`
);
output.print(' Read more: https://err.sh/now/domain-verification\n\n');
}
return 0;

View File

@@ -13,7 +13,6 @@ import transferIn from './transfer-in';
import inspect from './inspect';
import ls from './ls';
import rm from './rm';
import verify from './verify';
import move from './move';
import { getPkgName } from '../../util/pkg-name';
@@ -25,17 +24,17 @@ const help = () => {
ls Show all domains in a list
inspect [name] Displays information related to a domain
add [name] Add a new domain that you already own
add [name] [project] Add a new domain that you already own
rm [name] Remove a domain
buy [name] Buy a domain that you don't yet own
move [name] [destination] Move a domain to another user or team.
transfer-in [name] Transfer in a domain to Vercel
verify [name] Run a verification for a domain
${chalk.dim('Options:')}
-h, --help Output usage information
-d, --debug Debug mode [off]
-f, --force Force a domain on a project and remove it from an existing one
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
'FILE'
)} Path to the local ${'`vercel.json`'} file
@@ -82,7 +81,6 @@ const COMMAND_CONFIG = {
move: ['move'],
rm: ['rm', 'remove'],
transferIn: ['transfer-in'],
verify: ['verify'],
};
export default async function main(ctx: NowContext) {
@@ -90,10 +88,9 @@ export default async function main(ctx: NowContext) {
try {
argv = getArgs(ctx.argv.slice(2), {
'--cdn': Boolean,
'--code': String,
'--no-cdn': Boolean,
'--yes': Boolean,
'--force': Boolean,
'--next': Number,
'-N': '--next',
});
@@ -122,8 +119,6 @@ export default async function main(ctx: NowContext) {
return rm(ctx, argv, args, output);
case 'transferIn':
return transferIn(ctx, argv, args, output);
case 'verify':
return verify(ctx, argv, args, output);
default:
return ls(ctx, argv, args, output);
}

View File

@@ -4,13 +4,16 @@ import { NowContext } from '../../types';
import { Output } from '../../util/output';
import Client from '../../util/client';
import stamp from '../../util/output/stamp';
import dnsTable from '../../util/format-dns-table';
import formatDate from '../../util/format-date';
import formatNSTable from '../../util/format-ns-table';
import getDomainByName from '../../util/domains/get-domain-by-name';
import getScope from '../../util/get-scope';
import formatTable from '../../util/format-table';
import { findProjectsForDomain } from '../../util/projects/find-projects-for-domain';
import getDomainPrice from '../../util/domains/get-domain-price';
import { getCommandName } from '../../util/pkg-name';
import { getDomainConfig } from '../../util/domains/get-domain-config';
import code from '../../util/output/code';
type Options = {
'--debug': boolean;
@@ -70,7 +73,7 @@ export default async function inspect(
.then(res => (res instanceof Error ? null : res.price))
.catch(() => null),
]);
if (domain instanceof DomainNotFound) {
if (!domain || domain instanceof DomainNotFound) {
output.error(
`Domain not found by "${domainName}" under ${chalk.bold(contextName)}`
);
@@ -88,6 +91,15 @@ export default async function inspect(
return 1;
}
const projects = await findProjectsForDomain(client, domainName);
if (projects instanceof Error) {
output.prettyError(projects);
return 1;
}
const domainConfig = await getDomainConfig(client, contextName, domainName);
output.log(
`Domain ${domainName} found under ${chalk.bold(contextName)} ${chalk.gray(
inspectStamp()
@@ -129,6 +141,7 @@ export default async function inspect(
domain.txtVerifiedAt
)}\n`
);
if (renewalPrice && domain.boughtAt) {
output.print(
` ${chalk.cyan('Renewal Price')}\t\t$${renewalPrice} USD\n`
@@ -145,37 +158,57 @@ export default async function inspect(
);
output.print('\n');
output.print(chalk.bold(' Verification Record\n\n'));
output.print(
`${dnsTable([['_now', 'TXT', domain.verificationRecord]], {
extraSpace: ' ',
})}\n`
);
output.print('\n');
if (!domain.verified) {
output.warn(`This domain is not verified. To verify it you should either:`);
output.print(
` ${chalk.gray(
'a)'
)} Change your domain nameservers to the intended set detailed above. ${chalk.gray(
'[recommended]'
)}\n`
if (domainConfig.misconfigured) {
output.warn(
`This domain is not configured properly. To configure it you should either:`
);
output.print(
` ${chalk.gray(
'b)'
)} Add a DNS TXT record with the name and value shown above.\n\n`
` ${chalk.grey('a)')} ` +
`Set the following record on your DNS provider to continue: ` +
`${code(`A ${domainName} 76.76.21.21`)} ` +
`${chalk.grey('[recommended]')}\n`
);
output.print(
` ${chalk.grey('b)')} ` +
`Change your domain nameservers to the intended set detailed above.\n\n`
);
output.print(
` We will run a verification for you and you will receive an email upon completion.\n`
);
output.print(
` If you want to force running a verification, you can run ${getCommandName(
`domains verify <domain>`
)}\n`
output.print(' Read more: https://vercel.link/domain-configuration\n\n');
}
if (Array.isArray(projects) && projects.length > 0) {
output.print(chalk.bold(' Projects\n'));
const table = formatTable(
['Project', 'Domains'],
['l', 'l'],
[
{
rows: projects.map(project => {
const name = project.name;
const domains = (project.alias || [])
.map(target => target.domain)
.filter(alias => alias.endsWith(domainName));
const cols = domains.length ? domains.join(', ') : '-';
return [name, cols];
}),
},
]
);
output.print(' Read more: https://err.sh/now/domain-verification\n\n');
output.print(
table
.split('\n')
.map(line => ` ${line}`)
.join('\n')
);
output.print('\n\n');
}
return null;

View File

@@ -1,22 +1,37 @@
import ms from 'ms';
import psl from 'psl';
import chalk from 'chalk';
import table from 'text-table';
import plural from 'pluralize';
import Client from '../../util/client';
import getDomains from '../../util/domains/get-domains';
import getScope from '../../util/get-scope';
import stamp from '../../util/output/stamp';
import strlen from '../../util/strlen';
import { Output } from '../../util/output';
import { Domain, NowContext } from '../../types';
import formatTable from '../../util/format-table';
import { formatDateWithoutTime } from '../../util/format-date';
import { Domain, Project, NowContext } from '../../types';
import { getProjectsWithDomains } from '../../util/projects/get-projects-with-domains';
import getCommandFlags from '../../util/get-command-flags';
import { getCommandName } from '../../util/pkg-name';
import isDomainExternal from '../../util/domains/is-domain-external';
import { isPublicSuffix } from '../../util/domains/is-public-suffix';
type Options = {
'--debug': boolean;
'--next': number;
};
interface DomainInfo {
domain: string;
apexDomain: string;
projectName: string | null;
dns: 'Vercel' | 'External';
configured: boolean;
expiresAt: number | null;
createdAt: number | null;
}
export default async function ls(
ctx: NowContext,
opts: Options,
@@ -60,16 +75,31 @@ export default async function ls(
return 1;
}
const { domains, pagination } = await getDomains(
client,
contextName,
nextTimestamp
);
const [{ domains, pagination }, projects] = await Promise.all([
getDomains(client, contextName),
getProjectsWithDomains(client),
] as const);
if (projects instanceof Error) {
output.prettyError(projects);
return 1;
}
const domainsInfo = createDomainsInfo(domains, projects);
output.log(
`Domains found under ${chalk.bold(contextName)} ${chalk.gray(lsStamp())}\n`
`${plural(
'project domain',
domainsInfo.length,
true
)} found under ${chalk.bold(contextName)} ${chalk.gray(lsStamp())}`
);
if (domains.length > 0) {
console.log(`${formatDomainsTable(domains)}\n`);
if (domainsInfo.length > 0) {
output.print(
formatDomainsTable(domainsInfo).replace(/^(.*)/gm, `${' '.repeat(3)}$1`)
);
output.print('\n\n');
}
if (pagination && pagination.count === 20) {
@@ -84,28 +114,92 @@ export default async function ls(
return 0;
}
function formatDomainsTable(domains: Domain[]) {
const current = new Date();
return table(
[
[
'',
chalk.gray('domain'),
chalk.gray('serviceType'),
chalk.gray('verified'),
chalk.gray('cdn'),
chalk.gray('age'),
].map(s => chalk.dim(s)),
...domains.map(domain => {
const url = chalk.bold(domain.name);
const time = chalk.gray(ms(current.getTime() - domain.createdAt));
return ['', url, domain.serviceType, domain.verified, true, time];
}),
],
{
align: ['l', 'l', 'l', 'l', 'l'],
hsep: ' '.repeat(4),
stringLength: strlen,
function createDomainsInfo(domains: Domain[], projects: Project[]) {
const info = new Map<string, DomainInfo>();
domains.forEach(domain => {
info.set(domain.name, {
domain: domain.name,
apexDomain: domain.name,
projectName: null,
expiresAt: domain.expiresAt || null,
createdAt: domain.createdAt,
configured: Boolean(domain.verified),
dns: isDomainExternal(domain) ? 'External' : 'Vercel',
});
projects.forEach(project => {
(project.alias || []).forEach(target => {
if (!target.domain.endsWith(domain.name)) return;
info.set(target.domain, {
domain: target.domain,
apexDomain: domain.name,
projectName: project.name,
expiresAt: domain.expiresAt || null,
createdAt: domain.createdAt || target.createdAt || null,
configured: Boolean(domain.verified),
dns: isDomainExternal(domain) ? 'External' : 'Vercel',
});
});
});
});
projects.forEach(project => {
(project.alias || []).forEach(target => {
if (info.has(target.domain)) return;
const { domain: apexDomain } = psl.parse(
target.domain
) as psl.ParsedDomain;
info.set(target.domain, {
domain: target.domain,
apexDomain: apexDomain || target.domain,
projectName: project.name,
expiresAt: null,
createdAt: target.createdAt || null,
configured: isPublicSuffix(target.domain),
dns: isPublicSuffix(target.domain) ? 'Vercel' : 'External',
});
});
});
const list = Array.from(info.values());
return list.sort((a, b) => {
if (a.apexDomain === b.apexDomain) {
if (a.apexDomain === a.domain) return -1;
if (b.apexDomain === b.domain) return 1;
return a.domain.localeCompare(b.domain);
}
);
return a.apexDomain.localeCompare(b.apexDomain);
});
}
function formatDomainsTable(domainsInfo: DomainInfo[]) {
const current = Date.now();
const rows: string[][] = domainsInfo.map(info => {
const expiration = formatDateWithoutTime(info.expiresAt);
const age = info.createdAt ? ms(current - info.createdAt) : '-';
return [
info.domain,
info.projectName || '-',
info.dns,
expiration,
info.configured.toString(),
chalk.gray(age),
];
});
const table = formatTable(
['domain', 'project', 'dns', 'expiration', 'configured', 'age'],
['l', 'l', 'l', 'l', 'l', 'l'],
[{ rows }]
);
return table;
}

View File

@@ -15,6 +15,7 @@ import * as ERRORS from '../../util/errors-ts';
import param from '../../util/output/param';
import promptBool from '../../util/input/prompt-bool';
import setCustomSuffix from '../../util/domains/set-custom-suffix';
import { findProjectsForDomain } from '../../util/projects/find-projects-for-domain';
import { getCommandName } from '../../util/pkg-name';
type Options = {
@@ -67,7 +68,7 @@ export default async function rm(
}
const domain = await getDomainByName(client, contextName, domainName);
if (domain instanceof DomainNotFound) {
if (domain instanceof DomainNotFound || domain.name !== domainName) {
output.error(
`Domain not found by "${domainName}" under ${chalk.bold(contextName)}`
);
@@ -85,6 +86,18 @@ export default async function rm(
return 1;
}
const projects = await findProjectsForDomain(client, domain.name);
if (Array.isArray(projects) && projects.length > 0) {
output.warn(
`The domain is currently used by ${plural(
'project',
projects.length,
true
)}.`
);
}
const skipConfirmation = opts['--yes'];
if (
!skipConfirmation &&

View File

@@ -1,147 +0,0 @@
import chalk from 'chalk';
import { NowContext } from '../../types';
import { Output } from '../../util/output';
import * as ERRORS from '../../util/errors-ts';
import Client from '../../util/client';
import formatDnsTable from '../../util/format-dns-table';
import formatNSTable from '../../util/format-ns-table';
import getDomainByName from '../../util/domains/get-domain-by-name';
import getScope from '../../util/get-scope';
import stamp from '../../util/output/stamp';
import verifyDomain from '../../util/domains/verify-domain';
import { getCommandName } from '../../util/pkg-name';
type Options = {
'--debug': boolean;
};
export default async function verify(
ctx: NowContext,
opts: Options,
args: string[],
output: Output
) {
const {
authConfig: { token },
config,
} = ctx;
const { currentTeam } = config;
const { apiUrl } = ctx;
const debug = opts['--debug'];
const client = new Client({ apiUrl, token, currentTeam, debug });
let contextName = null;
try {
({ contextName } = await getScope(client));
} catch (err) {
if (err.code === 'NOT_AUTHORIZED' || err.code === 'TEAM_DELETED') {
output.error(err.message);
return 1;
}
throw err;
}
const [domainName] = args;
if (!domainName) {
output.error(
`${getCommandName(`domains verify <domain>`)} expects one argument`
);
return 1;
}
if (args.length !== 1) {
output.error(
`Invalid number of arguments. Usage: ${chalk.cyan(
`${getCommandName('domains verify <domain>')}`
)}`
);
return 1;
}
const domain = await getDomainByName(client, contextName, domainName);
if (domain instanceof ERRORS.DomainNotFound) {
output.error(
`Domain not found by "${domainName}" under ${chalk.bold(contextName)}`
);
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
return 1;
}
if (domain instanceof ERRORS.DomainPermissionDenied) {
output.error(
`You don't have access to the domain ${domainName} under ${chalk.bold(
contextName
)}`
);
output.log(`Run ${getCommandName(`domains ls`)} to see your domains.`);
return 1;
}
const verifyStamp = stamp();
const result = await verifyDomain(client, domain.name, contextName);
if (result instanceof ERRORS.DomainVerificationFailed) {
const { nsVerification, txtVerification } = result.meta;
output.error(
`The domain ${
domain.name
} could not be verified due to the following reasons: ${verifyStamp()}\n`
);
output.print(
` ${chalk.gray(
'a)'
)} Nameservers verification failed since we see a different set than the intended set:`
);
output.print(
`\n${formatNSTable(
nsVerification.intendedNameservers,
nsVerification.nameservers,
{ extraSpace: ' ' }
)}\n\n`
);
output.print(
` ${chalk.gray(
'b)'
)} DNS TXT verification failed since found no matching records.`
);
output.print(
`\n${formatDnsTable(
[['_now', 'TXT', txtVerification.verificationRecord]],
{ extraSpace: ' ' }
)}\n\n`
);
output.print(
` Once your domain uses either the nameservers or the TXT DNS record from above, run again ${getCommandName(
`domains verify <domain>`
)}.\n`
);
output.print(
` We will also periodically run a verification check for you and you will receive an email once your domain is verified.\n`
);
output.print(' Read more: https://err.sh/now/domain-verification\n\n');
return 1;
}
if (result.nsVerifiedAt) {
console.log(
`${chalk.cyan('> Success!')} Domain ${chalk.bold(
domain.name
)} was verified using nameservers. ${verifyStamp()}`
);
return 0;
}
console.log(
`${chalk.cyan('> Success!')} Domain ${chalk.bold(
domain.name
)} was verified using DNS TXT record. ${verifyStamp()}`
);
output.print(
` You can verify with nameservers too. Run ${getCommandName(
`domains inspect ${domain.name}`
)} to find out the intended set.\n`
);
return 0;
}

View File

@@ -124,7 +124,9 @@ export default async function main(ctx: NowContext) {
return link.exitCode;
} else if (link.status === 'not_linked') {
output.error(
`Your codebase isnt linked to a project on Vercel. Run ${getCommandName()} to link it.`
`Your codebase isnt linked to a project on Vercel. Run ${getCommandName(
'link'
)} to begin.`
);
return 1;
} else {

View File

@@ -4,21 +4,44 @@ import { Output } from '../../util/output';
import promptBool from '../../util/prompt-bool';
import Client from '../../util/client';
import stamp from '../../util/output/stamp';
import getEnvVariables from '../../util/env/get-env-records';
import getDecryptedSecret from '../../util/env/get-decrypted-secret';
import getDecryptedEnvRecords from '../../util/get-decrypted-env-records';
import param from '../../util/output/param';
import withSpinner from '../../util/with-spinner';
import { join } from 'path';
import { promises, existsSync } from 'fs';
import { promises, openSync, closeSync, readSync } from 'fs';
import { emoji, prependEmoji } from '../../util/emoji';
import { getCommandName } from '../../util/pkg-name';
const { writeFile } = promises;
import { Env } from '@vercel/build-utils';
const CONTENTS_PREFIX = '# Created by Vercel CLI\n';
type Options = {
'--debug': boolean;
'--yes': boolean;
};
function readHeadSync(path: string, length: number) {
const buffer = Buffer.alloc(length);
const fd = openSync(path, 'r');
try {
readSync(fd, buffer, 0, buffer.length, null);
} finally {
closeSync(fd);
}
return buffer.toString();
}
function tryReadHeadSync(path: string, length: number) {
try {
return readHeadSync(path, length);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
}
export default async function pull(
client: Client,
project: Project,
@@ -35,10 +58,14 @@ export default async function pull(
const [filename = '.env'] = args;
const fullPath = join(process.cwd(), filename);
const exists = existsSync(fullPath);
const skipConfirmation = opts['--yes'];
if (
const head = tryReadHeadSync(fullPath, Buffer.byteLength(CONTENTS_PREFIX));
const exists = typeof head !== 'undefined';
if (head === CONTENTS_PREFIX) {
output.print(`Overwriting existing ${chalk.bold(filename)} file\n`);
} else if (
exists &&
!skipConfirmation &&
!(await promptBool(
@@ -57,45 +84,23 @@ export default async function pull(
);
const pullStamp = stamp();
const records = await withSpinner('Downloading', async () => {
const dev = ProjectEnvTarget.Development;
const envs = await getEnvVariables(output, client, project.id, 4, dev);
const decryptedValues = await Promise.all(
envs.map(async env => {
try {
const value = await getDecryptedSecret(output, client, env.value);
return { value, found: true };
} catch (error) {
if (error && error.status === 404) {
return { value: '', found: false };
}
throw error;
}
})
);
const results: { key: string; value: string; found: boolean }[] = [];
for (let i = 0; i < decryptedValues.length; i++) {
const { key } = envs[i];
const { value, found } = decryptedValues[i];
results.push({ key, value, found });
}
return results;
});
const records: Env = await withSpinner(
'Downloading',
async () =>
await getDecryptedEnvRecords(
output,
client,
project,
ProjectEnvTarget.Development
)
);
const contents =
records
.filter(obj => {
if (!obj.found) {
output.print('');
output.warn(
`Unable to download variable ${obj.key} because associated secret was deleted`
);
return false;
}
return true;
})
.map(({ key, value }) => `${key}="${escapeValue(value)}"`)
.join('\n') + '\n';
CONTENTS_PREFIX +
Object.entries(records)
.map(([key, value]) => `${key}="${escapeValue(value)}"`)
.join('\n') +
'\n';
await writeFile(fullPath, contents, 'utf8');
@@ -110,8 +115,10 @@ export default async function pull(
return 0;
}
function escapeValue(value: string) {
function escapeValue(value: string | undefined) {
return value
.replace(new RegExp('\n', 'g'), '\\n') // combine newlines (unix) into one line
.replace(new RegExp('\r', 'g'), '\\r'); // combine newlines (windows) into one line
? value
.replace(new RegExp('\n', 'g'), '\\n') // combine newlines (unix) into one line
.replace(new RegExp('\r', 'g'), '\\r') // combine newlines (windows) into one line
: '';
}

View File

@@ -17,6 +17,7 @@ export default new Map([
['help', 'help'],
['init', 'init'],
['inspect', 'inspect'],
['link', 'link'],
['list', 'list'],
['ln', 'alias'],
['log', 'logs'],

Some files were not shown because too many files have changed in this diff Show More