Compare commits

..

58 Commits

Author SHA1 Message Date
IgorKlopov
bc49bc335b print the url of the image file 2020-07-21 19:22:43 +03:00
IgorKlopov
58d3502f5b now break a test for sure 2020-07-21 18:27:40 +03:00
IgorKlopov
29775f8e05 break a test 2020-07-21 18:00:29 +03: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
173 changed files with 2506 additions and 1010 deletions

View File

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

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

@@ -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

View File

@@ -64,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,7 +666,7 @@
"every": [
{
"path": "package.json",
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"nuxt\":\\s*\".+?\"[^}]*}"
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"nuxt(-edge)?\":\\s*\".+?\"[^}]*}"
}
]
},
@@ -658,6 +690,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": [
{

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

@@ -1,6 +1,6 @@
{
"name": "@vercel/frameworks",
"version": "0.0.16-canary.0",
"version": "0.0.17",
"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.1-canary.1",
"version": "2.4.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 {
@@ -462,7 +464,7 @@ function detectFrontBuilder(
});
}
if (framework === 'nextjs') {
if (framework === 'nextjs' || framework === 'blitzjs') {
return { src: 'package.json', use: `@vercel/next${withTag}`, config };
}
@@ -496,7 +498,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 +610,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,7 @@ 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;
}

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

@@ -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',
},
]);
});
@@ -1878,8 +1879,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',
},
]);
});

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,6 +1,6 @@
{
"name": "vercel",
"version": "19.1.2-canary.17",
"version": "19.2.0",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Vercel",
@@ -62,13 +62,14 @@
"node": ">= 10"
},
"dependencies": {
"@vercel/build-utils": "2.4.1-canary.1",
"@vercel/go": "1.1.3-canary.1",
"@vercel/next": "2.6.8",
"@vercel/node": "1.7.2-canary.1",
"@vercel/build-utils": "2.4.2",
"@vercel/go": "1.1.4",
"@vercel/next": "2.6.13",
"@vercel/node": "1.7.3",
"@vercel/python": "1.2.2",
"@vercel/ruby": "1.2.3-canary.0",
"@vercel/static-build": "0.17.5-canary.0"
"@vercel/ruby": "1.2.3",
"@vercel/static-build": "0.17.6",
"update-notifier": "4.1.0"
},
"devDependencies": {
"@sentry/node": "5.5.0",
@@ -185,7 +186,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

@@ -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
) {

View File

@@ -9,7 +9,9 @@ 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 } from '../../types';
import { ProjectSettings, ProjectEnvTarget } from '../../types';
import getDecryptedEnvRecords from '../../util/get-decrypted-env-records';
import { Env } from '@vercel/build-utils';
type Options = {
'--debug'?: boolean;
@@ -54,6 +56,7 @@ export default async function dev(
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;
@@ -80,6 +83,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, {
@@ -88,6 +98,7 @@ export default async function dev(
devCommand,
frameworkSlug,
projectSettings,
environmentVars,
});
process.once('SIGINT', () => devServer.stop());

View File

@@ -97,7 +97,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)) {
@@ -106,7 +106,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;
}
}

View File

@@ -4,8 +4,7 @@ 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';
@@ -13,6 +12,7 @@ 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';
@@ -84,45 +84,21 @@ 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 =
CONTENTS_PREFIX +
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)}"`)
Object.entries(records)
.map(([key, value]) => `${key}="${escapeValue(value)}"`)
.join('\n') +
'\n';
@@ -139,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

@@ -20,8 +20,7 @@ import sourceMap from '@zeit/source-map-support';
import { mkdirp } from 'fs-extra';
import chalk from 'chalk';
import epipebomb from 'epipebomb';
import checkForUpdate from 'update-check';
import ms from 'ms';
import updateNotifier from 'update-notifier';
import { URL } from 'url';
import * as Sentry from '@sentry/node';
import { NowBuildError } from '@vercel/build-utils';
@@ -46,11 +45,20 @@ import reportError from './util/report-error';
import getConfig from './util/get-config';
import * as ERRORS from './util/errors-ts';
import { NowError } from './util/now-error';
import { APIError } from './util/errors-ts.ts';
import { SENTRY_DSN } from './util/constants.ts';
import getUpdateCommand from './util/get-update-command';
import { metrics, shouldCollectMetrics } from './util/metrics.ts';
import { getCommandName, getTitleName } from './util/pkg-name.ts';
const isCanary = pkg.version.includes('canary');
// Checks for available update and returns an instance
const notifier = updateNotifier({
pkg,
distTag: isCanary ? 'canary' : 'latest',
});
const VERCEL_DIR = getGlobalPathConfig();
const VERCEL_CONFIG_PATH = configFiles.getConfigFilePath();
const VERCEL_AUTH_CONFIG_PATH = configFiles.getAuthConfigFilePath();
@@ -65,7 +73,7 @@ sourceMap.install();
Sentry.init({
dsn: SENTRY_DSN,
release: `vercel-cli@${pkg.version}`,
environment: pkg.version.includes('canary') ? 'canary' : 'stable',
environment: isCanary ? 'canary' : 'stable',
});
let debug = () => {};
@@ -127,38 +135,20 @@ const main = async argv_ => {
// (as in: `vercel ls`)
const targetOrSubcommand = argv._[2];
let update = null;
try {
if (targetOrSubcommand !== 'update') {
update = await checkForUpdate(pkg, {
interval: ms('1d'),
distTag: pkg.version.includes('canary') ? 'canary' : 'latest',
});
}
} catch (err) {
console.error(
error(`Checking for updates failed${isDebugging ? ':' : ''}`)
);
if (isDebugging) {
console.error(err);
}
}
if (update && isTTY) {
if (notifier.update && isTTY) {
const { latest } = notifier.update;
console.log(
info(
`${chalk.bgRed('UPDATE AVAILABLE')} ` +
`Run ${cmd(
await getUpdateCommand()
)} to install ${getTitleName()} CLI ${update.latest}`
)} to install ${getTitleName()} CLI ${latest}`
)
);
console.log(
info(
`Changelog: https://github.com/vercel/vercel/releases/tag/vercel@${update.latest}`
`Changelog: https://github.com/vercel/vercel/releases/tag/vercel@${latest}`
)
);
}
@@ -168,7 +158,7 @@ const main = async argv_ => {
`${getTitleName()} CLI ${pkg.version}${
targetOrSubcommand === 'dev' ? ' dev (beta)' : ''
}${
pkg.version.includes('canary') || targetOrSubcommand === 'dev'
isCanary || targetOrSubcommand === 'dev'
? ' — https://vercel.com/feedback'
: ''
}`
@@ -190,8 +180,7 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to find the ' +
'global directory: '}${err.message}`
`An unexpected error occurred while trying to find the global directory: ${err.message}`
)
);
@@ -204,8 +193,10 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to create the ' +
`global directory "${hp(VERCEL_DIR)}" `}${err.message}`
`${
'An unexpected error occurred while trying to create the ' +
`global directory "${hp(VERCEL_DIR)}" `
}${err.message}`
)
);
}
@@ -219,8 +210,10 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to find the ' +
`config file "${hp(VERCEL_CONFIG_PATH)}" `}${err.message}`
`${
'An unexpected error occurred while trying to find the ' +
`config file "${hp(VERCEL_CONFIG_PATH)}" `
}${err.message}`
)
);
@@ -235,8 +228,10 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to read the ' +
`config in "${hp(VERCEL_CONFIG_PATH)}" `}${err.message}`
`${
'An unexpected error occurred while trying to read the ' +
`config in "${hp(VERCEL_CONFIG_PATH)}" `
}${err.message}`
)
);
@@ -267,8 +262,10 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to write the ' +
`default config to "${hp(VERCEL_CONFIG_PATH)}" `}${err.message}`
`${
'An unexpected error occurred while trying to write the ' +
`default config to "${hp(VERCEL_CONFIG_PATH)}" `
}${err.message}`
)
);
@@ -283,8 +280,10 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to find the ' +
`auth file "${hp(VERCEL_AUTH_CONFIG_PATH)}" `}${err.message}`
`${
'An unexpected error occurred while trying to find the ' +
`auth file "${hp(VERCEL_AUTH_CONFIG_PATH)}" `
}${err.message}`
)
);
@@ -301,8 +300,10 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to read the ' +
`auth config in "${hp(VERCEL_AUTH_CONFIG_PATH)}" `}${err.message}`
`${
'An unexpected error occurred while trying to read the ' +
`auth config in "${hp(VERCEL_AUTH_CONFIG_PATH)}" `
}${err.message}`
)
);
@@ -326,10 +327,10 @@ const main = async argv_ => {
} catch (err) {
console.error(
error(
`${'An unexpected error occurred while trying to write the ' +
`default config to "${hp(VERCEL_AUTH_CONFIG_PATH)}" `}${
err.message
}`
`${
'An unexpected error occurred while trying to write the ' +
`default config to "${hp(VERCEL_AUTH_CONFIG_PATH)}" `
}${err.message}`
)
);
return 1;
@@ -639,6 +640,12 @@ const main = async argv_ => {
return 1;
}
if (err instanceof APIError && 400 <= err.status && err.status <= 499) {
err.message = err.serverMessage;
output.prettyError(err);
return 1;
}
if (shouldCollectMetrics) {
metric
.event(eventCategory, '1', pkg.version)

View File

@@ -67,8 +67,6 @@ async function createBuildProcess(
...process.env,
PATH,
...envConfigs.allEnv,
NOW_REGION: 'dev1',
VERCEL_REGION: 'dev1',
};
const buildProcess = fork(builderWorkerPath, [], {
@@ -365,8 +363,6 @@ export async function executeBuild(
...nowConfig.env,
...asset.environment,
...envConfigs.runEnv,
NOW_REGION: 'dev1',
VERCEL_REGION: 'dev1',
},
},
});

View File

@@ -29,7 +29,7 @@ export function resolveRouteParameters(
export function getRoutesTypes(routes: Route[] = []) {
const handleMap = new Map<HandleValue | null, Route[]>();
let prevHandle: HandleValue | null = null;
routes.forEach((route) => {
routes.forEach(route => {
if (isHandler(route)) {
prevHandle = route.handle;
} else {

View File

@@ -49,7 +49,7 @@ import getNowConfigPath from '../config/local-path';
import { MissingDotenvVarsError } from '../errors-ts';
import cliPkg from '../pkg';
import { getVercelDirectory } from '../projects/link';
import { staticFiles as getFiles, getAllProjectFiles } from '../get-files';
import { staticFiles as getFiles } from '../get-files';
import { validateConfig } from './validate';
import { devRouter, getRoutesTypes } from './router';
import getMimeType from './mime-type';
@@ -90,6 +90,10 @@ interface FSEvent {
path: string;
}
type WithFileNameSymbol<T> = T & {
[fileNameSymbol]: string;
};
function sortBuilders(buildA: Builder, buildB: Builder) {
if (buildA && buildA.use && isOfficialRuntime('static-build', buildA.use)) {
return 1;
@@ -113,7 +117,6 @@ export default class DevServer {
public address: string;
public devCacheDir: string;
private cachedNowConfig: NowConfig | null;
private caseSensitive: boolean;
private apiDir: string | null;
private apiExtensions: Set<string>;
@@ -137,18 +140,21 @@ export default class DevServer {
private blockingBuildsPromise: Promise<void> | null;
private updateBuildersPromise: Promise<void> | null;
private updateBuildersTimeout: NodeJS.Timeout | undefined;
private startPromise: Promise<void> | null;
private environmentVars: Env | undefined;
constructor(cwd: string, options: DevServerOptions) {
this.cwd = cwd;
this.debug = options.debug;
this.output = options.output;
this.envConfigs = { buildEnv: {}, runEnv: {}, allEnv: {} };
this.environmentVars = options.environmentVars;
this.files = {};
this.address = '';
this.devCommand = options.devCommand;
this.projectSettings = options.projectSettings;
this.frameworkSlug = options.frameworkSlug;
this.cachedNowConfig = null;
this.caseSensitive = false;
this.apiDir = null;
this.apiExtensions = new Set();
@@ -167,12 +173,13 @@ export default class DevServer {
this.getNowConfigPromise = null;
this.blockingBuildsPromise = null;
this.updateBuildersPromise = null;
this.startPromise = null;
this.watchAggregationId = null;
this.watchAggregationEvents = [];
this.watchAggregationTimeout = 500;
this.filter = (path) => Boolean(path);
this.filter = path => Boolean(path);
this.podId = Math.random().toString(32).slice(-5);
this.devServerPids = new Set();
@@ -211,8 +218,8 @@ export default class DevServer {
}
}
events = events.filter((event) =>
distPaths.every((distPath) => !event.path.startsWith(distPath))
events = events.filter(event =>
distPaths.every(distPath => !event.path.startsWith(distPath))
);
// First, update the `files` mapping of source files
@@ -226,15 +233,7 @@ export default class DevServer {
}
}
const nowConfig = await this.getNowConfig(false);
// Update the env vars configuration
const [runEnv, buildEnv] = await Promise.all([
this.getLocalEnv('.env', nowConfig.env),
this.getLocalEnv('.env.build', nowConfig.build?.env),
]);
const allEnv = { ...buildEnv, ...runEnv };
this.envConfigs = { buildEnv, runEnv, allEnv };
const nowConfig = await this.getNowConfig();
// Update the build matches in case an entrypoint was created or deleted
await this.updateBuildMatches(nowConfig);
@@ -292,7 +291,7 @@ export default class DevServer {
filesRemovedArray
).catch((err: Error) => {
this.output.warn(
`An error occurred while rebuilding ${match.src}:`
`An error occurred while rebuilding \`${match.src}\`:`
);
console.error(err.stack);
});
@@ -376,7 +375,7 @@ export default class DevServer {
this,
fileList
);
const sources = matches.map((m) => m.src);
const sources = matches.map(m => m.src);
if (isInitial && fileList.length === 0) {
this.output.warn('There are no files inside your deployment.');
@@ -485,13 +484,16 @@ export default class DevServer {
const dotenv = await fs.readFile(filePath, 'utf8');
this.output.debug(`Using local env: ${filePath}`);
env = parseDotenv(dotenv);
env = this.populateVercelEnvVars(env);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
try {
return this.validateEnvConfig(fileName, base || {}, env);
return {
...this.validateEnvConfig(fileName, base || {}, env),
};
} catch (err) {
if (err instanceof MissingDotenvVarsError) {
this.output.error(err.message);
@@ -503,23 +505,24 @@ export default class DevServer {
return {};
}
async getNowConfig(canUseCache: boolean = true): Promise<NowConfig> {
clearNowConfigPromise = () => {
this.getNowConfigPromise = null;
};
getNowConfig(): Promise<NowConfig> {
if (this.getNowConfigPromise) {
return this.getNowConfigPromise;
}
this.getNowConfigPromise = this._getNowConfig(canUseCache);
try {
return await this.getNowConfigPromise;
} finally {
this.getNowConfigPromise = null;
}
this.getNowConfigPromise = this._getNowConfig();
// Clean up the promise once it has resolved
const clear = this.clearNowConfigPromise;
this.getNowConfigPromise.finally(clear);
return this.getNowConfigPromise;
}
async _getNowConfig(canUseCache: boolean = true): Promise<NowConfig> {
if (canUseCache && this.cachedNowConfig) {
return this.cachedNowConfig;
}
async _getNowConfig(): Promise<NowConfig> {
const configPath = getNowConfigPath(this.cwd);
const [
@@ -532,14 +535,6 @@ export default class DevServer {
this.readJsonFile<NowConfig>(configPath),
]);
const allFiles = await getAllProjectFiles(this.cwd, this.output);
const files = allFiles.filter(this.filter);
this.output.debug(
`Found ${allFiles.length} and ` +
`filtered out ${allFiles.length - files.length} files`
);
await this.validateNowConfig(config);
const { error: routeError, routes: maybeRoutes } = getTransformedRoutes({
nowConfig: config,
@@ -555,6 +550,11 @@ export default class DevServer {
const featHandleMiss = true; // enable for zero config
const { projectSettings, cleanUrls, trailingSlash } = config;
const opts = { output: this.output, isBuilds: true };
const files = (await getFiles(this.cwd, config, opts)).map(f =>
relative(this.cwd, f)
);
let {
builders,
warnings,
@@ -578,7 +578,7 @@ export default class DevServer {
}
if (warnings && warnings.length > 0) {
warnings.forEach((warning) => this.output.warn(warning.message));
warnings.forEach(warning => this.output.warn(warning.message));
}
if (builders) {
@@ -588,6 +588,8 @@ export default class DevServer {
config.builds = config.builds || [];
config.builds.push(...builders);
delete config.functions;
}
let routes: Route[] = [];
@@ -621,14 +623,31 @@ export default class DevServer {
await this.validateNowConfig(config);
this.cachedNowConfig = config;
this.caseSensitive = hasNewRoutingProperties(config);
this.apiDir = detectApiDirectory(config.builds || []);
this.apiExtensions = detectApiExtensions(config.builds || []);
// Update the env vars configuration
let [runEnv, buildEnv] = await Promise.all([
this.getLocalEnv('.env', config.env),
this.getLocalEnv('.env.build', config.build?.env),
]);
let allEnv = { ...buildEnv, ...runEnv };
// If no .env/.build.env is present, fetch and use cloud environment variables
if (Object.keys(allEnv).length === 0) {
const cloudEnv = this.populateVercelEnvVars(this.environmentVars);
allEnv = runEnv = buildEnv = cloudEnv;
}
this.envConfigs = { buildEnv, runEnv, allEnv };
return config;
}
async readJsonFile<T>(filePath: string): Promise<T | void> {
async readJsonFile<T>(
filePath: string
): Promise<WithFileNameSymbol<T> | void> {
let rel, abs;
if (isAbsolute(filePath)) {
rel = path.relative(this.cwd, filePath);
@@ -640,7 +659,10 @@ export default class DevServer {
this.output.debug(`Reading \`${rel}\` file`);
try {
return JSON.parse(await fs.readFile(abs, 'utf8'));
const raw = await fs.readFile(abs, 'utf8');
const parsed: WithFileNameSymbol<T> = JSON.parse(raw);
parsed[fileNameSymbol] = rel;
return parsed;
} catch (err) {
if (err.code === 'ENOENT') {
this.output.debug(`No \`${rel}\` file present`);
@@ -724,6 +746,26 @@ export default class DevServer {
return merged;
}
populateVercelEnvVars(env: Env | undefined): Env {
if (!env) {
return {};
}
for (const name of Object.keys(env)) {
if (name === 'VERCEL_URL') {
const host = new URL(this.address).host;
env['VERCEL_URL'] = host;
} else if (name === 'VERCEL_REGION') {
env['VERCEL_REGION'] = 'dev1';
}
}
// Always set NOW_REGION to match production
env['NOW_REGION'] = 'dev1';
return env;
}
/**
* Create an array of from builder inputs
* and filter them
@@ -732,10 +774,20 @@ export default class DevServer {
return Object.keys(files).filter(this.filter);
}
start(...listenSpec: ListenSpec): Promise<void> {
if (!this.startPromise) {
this.startPromise = this._start(...listenSpec).catch(err => {
this.stop();
throw err;
});
}
return this.startPromise;
}
/**
* Launches the `vercel dev` server.
*/
async start(...listenSpec: ListenSpec): Promise<void> {
async _start(...listenSpec: ListenSpec): Promise<void> {
if (!fs.existsSync(this.cwd)) {
throw new Error(`${chalk.bold(this.cwd)} doesn't exist`);
}
@@ -747,14 +799,39 @@ export default class DevServer {
const { ig } = await getVercelIgnore(this.cwd);
this.filter = ig.createFilter();
// Retrieve the path of the native module
const nowConfig = await this.getNowConfig(false);
const [runEnv, buildEnv] = await Promise.all([
this.getLocalEnv('.env', nowConfig.env),
this.getLocalEnv('.env.build', nowConfig.build?.env),
]);
const allEnv = { ...buildEnv, ...runEnv };
this.envConfigs = { buildEnv, runEnv, allEnv };
let address: string | null = null;
while (typeof address !== 'string') {
try {
address = await listen(this.server, ...listenSpec);
} catch (err) {
this.output.debug(`Got listen error: ${err.code}`);
if (err.code === 'EADDRINUSE') {
if (typeof listenSpec[0] === 'number') {
// Increase port and try again
this.output.note(
`Requested port ${chalk.yellow(
String(listenSpec[0])
)} is already in use`
);
listenSpec[0]++;
} else {
this.output.error(
`Requested socket ${chalk.cyan(listenSpec[0])} is already in use`
);
process.exit(1);
}
} else {
throw err;
}
}
}
this.address = address
.replace('[::]', 'localhost')
.replace('127.0.0.1', 'localhost');
const nowConfig = await this.getNowConfig();
const devCommandPromise = this.runDevCommand();
const opts = { output: this.output, isBuilds: true };
const files = await getFiles(this.cwd, nowConfig, opts);
@@ -782,11 +859,11 @@ export default class DevServer {
// get their "build matches" invalidated so that the new version is used.
this.updateBuildersTimeout = setTimeout(() => {
this.updateBuildersPromise = updateBuilders(builders, this.output)
.then((updatedBuilders) => {
.then(updatedBuilders => {
this.updateBuildersPromise = null;
this.invalidateBuildMatches(nowConfig, updatedBuilders);
})
.catch((err) => {
.catch(err => {
this.updateBuildersPromise = null;
this.output.error(`Failed to update builders: ${err.message}`);
this.output.debug(err.stack);
@@ -846,39 +923,6 @@ export default class DevServer {
this.proxy.ws(req, socket, head, { target });
});
const devCommandPromise = this.runDevCommand();
let address: string | null = null;
while (typeof address !== 'string') {
try {
address = await listen(this.server, ...listenSpec);
} catch (err) {
this.output.debug(`Got listen error: ${err.code}`);
if (err.code === 'EADDRINUSE') {
if (typeof listenSpec[0] === 'number') {
// Increase port and try again
this.output.note(
`Requested port ${chalk.yellow(
String(listenSpec[0])
)} is already in use`
);
listenSpec[0]++;
} else {
this.output.error(
`Requested socket ${chalk.cyan(listenSpec[0])} is already in use`
);
process.exit(1);
}
} else {
throw err;
}
}
}
this.address = address
.replace('[::]', 'localhost')
.replace('127.0.0.1', 'localhost');
await devCommandPromise;
this.output.ready(`Available at ${link(this.address)}`);
@@ -1087,10 +1131,7 @@ export default class DevServer {
const allHeaders = {
'cache-control': 'public, max-age=0, must-revalidate',
...headers,
server: 'now',
'x-now-trace': 'dev1',
'x-now-id': nowRequestId,
'x-now-cache': 'MISS',
server: 'Vercel',
'x-vercel-id': nowRequestId,
'x-vercel-cache': 'MISS',
};
@@ -1104,23 +1145,24 @@ export default class DevServer {
*/
getNowProxyHeaders(
req: http.IncomingMessage,
nowRequestId: string
nowRequestId: string,
xfwd: boolean
): http.IncomingHttpHeaders {
const ip = this.getRequestIp(req);
const { host } = req.headers;
return {
...req.headers,
Connection: 'close',
'x-forwarded-host': host,
'x-forwarded-proto': 'http',
'x-forwarded-for': ip,
const headers: http.IncomingHttpHeaders = {
connection: 'close',
'x-real-ip': ip,
'x-now-trace': 'dev1',
'x-now-deployment-url': host,
'x-now-id': nowRequestId,
'x-now-log-id': nowRequestId.split('-')[2],
'x-zeit-co-forwarded-for': ip,
'x-vercel-deployment-url': host,
'x-vercel-forwarded-for': ip,
'x-vercel-id': nowRequestId,
};
if (xfwd) {
headers['x-forwarded-host'] = host;
headers['x-forwarded-proto'] = 'http';
headers['x-forwarded-for'] = ip;
}
return headers;
}
async triggerBuild(
@@ -1202,6 +1244,8 @@ export default class DevServer {
req: http.IncomingMessage,
res: http.ServerResponse
) => {
await this.startPromise;
let nowRequestId = generateRequestId(this.podId);
if (this.stopping) {
@@ -1612,6 +1656,12 @@ export default class DevServer {
query: parsed.query,
});
// Add the Vercel platform proxy request headers
const headers = this.getNowProxyHeaders(req, nowRequestId, false);
for (const [name, value] of Object.entries(headers)) {
req.headers[name] = value;
}
this.setResponseHeaders(res, nowRequestId);
return proxyPass(
req,
@@ -1724,7 +1774,10 @@ export default class DevServer {
method: req.method || 'GET',
host: req.headers.host,
path,
headers: this.getNowProxyHeaders(req, nowRequestId),
headers: {
...req.headers,
...this.getNowProxyHeaders(req, nowRequestId, true),
},
encoding: 'base64',
body: body.toString('base64'),
};
@@ -1781,7 +1834,7 @@ export default class DevServer {
const dirs: Set<string> = new Set();
const files = Array.from(this.buildMatches.keys())
.filter((p) => {
.filter(p => {
const base = basename(p);
if (
base === 'now.json' ||
@@ -1802,7 +1855,7 @@ export default class DevServer {
}
return true;
})
.map((p) => {
.map(p => {
let base = basename(p);
let ext = '';
let type = 'file';
@@ -1894,8 +1947,6 @@ export default class DevServer {
...(this.frameworkSlug === 'create-react-app' ? { BROWSER: 'none' } : {}),
...process.env,
...this.envConfigs.allEnv,
NOW_REGION: 'dev1',
VERCEL_REGION: 'dev1',
PORT: `${port}`,
};
@@ -2214,7 +2265,7 @@ function isIndex(path: string): boolean {
function minimatches(files: string[], pattern: string): boolean {
return files.some(
(file) => file === pattern || minimatch(file, pattern, { dot: true })
file => file === pattern || minimatch(file, pattern, { dot: true })
);
}
@@ -2244,7 +2295,7 @@ function needsBlockingBuild(buildMatch: BuildMatch): boolean {
}
async function sleep(n: number) {
return new Promise((resolve) => setTimeout(resolve, n));
return new Promise(resolve => setTimeout(resolve, n));
}
async function checkForPort(

View File

@@ -27,11 +27,12 @@ export interface DevServerOptions {
devCommand?: string;
frameworkSlug?: string;
projectSettings?: ProjectSettings;
environmentVars?: Env;
}
export interface EnvConfigs {
/**
* environment variables from `.env.build` file (deprecated)
* environment variables from `.env.build` file
*/
buildEnv: Env;

View File

@@ -47,5 +47,14 @@ export function validateConfig(config: NowConfig): NowBuildError | null {
}
}
if (config.functions && config.builds) {
return new NowBuildError({
code: 'FUNCTIONS_AND_BUILDS',
message:
'The `functions` property cannot be used in conjunction with the `builds` property. Please remove one of them.',
link: 'https://vercel.link/functions-and-builds',
});
}
return null;
}

View File

@@ -14,6 +14,7 @@ export class APIError extends Error {
status: number;
serverMessage: string;
link?: string;
action?: string;
retryAfter: number | null | 'never';
[key: string]: any;

View File

@@ -0,0 +1,46 @@
import getEnvVariables from './env/get-env-records';
import getDecryptedSecret from './env/get-decrypted-secret';
import Client from './client';
import { Output } from './output/create-output';
import { ProjectEnvTarget, Project } from '../types';
import { Env } from '@vercel/build-utils';
export default async function getDecryptedEnvRecords(
output: Output,
client: Client,
project: Project,
target: ProjectEnvTarget
): Promise<Env> {
const envs = await getEnvVariables(output, client, project.id, 4, target);
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: Env = {};
for (let i = 0; i < decryptedValues.length; i++) {
const { key } = envs[i];
const { value, found } = decryptedValues[i];
if (!found) {
output.print('');
output.warn(
`Unable to download variable ${key} because associated secret was deleted`
);
continue;
}
results[key] = value ? value : '';
}
return results;
}

View File

@@ -1,7 +1,7 @@
import { resolve, join } from 'path';
import { resolve } from 'path';
import ignore from 'ignore';
import dockerignore from '@zeit/dockerignore';
import _glob, { IOptions } from 'glob';
import _glob, { IOptions as GlobOptions } from 'glob';
import fs from 'fs-extra';
import { getVercelIgnore } from '@vercel/client';
import IGNORED from './ignored';
@@ -12,11 +12,11 @@ import { NowConfig } from './dev/types';
type NullableString = string | null;
const flatten = (
function flatten(
arr: NullableString[] | NullableString[][],
res: NullableString[] = []
) => {
for (let cur of arr) {
): NullableString[] {
for (const cur of arr) {
if (Array.isArray(cur)) {
flatten(cur, res);
} else {
@@ -24,21 +24,17 @@ const flatten = (
}
}
return res;
};
}
const glob = async function(pattern: string, options: IOptions) {
return new Promise<string[]>((resolve, reject) => {
_glob(pattern, options, (error, files) => {
if (error) {
reject(error);
} else {
resolve(files);
}
async function glob(pattern: string, options: GlobOptions): Promise<string[]> {
return new Promise((resolve, reject) => {
_glob(pattern, options, (err, files) => {
err ? reject(err) : resolve(files);
});
});
};
}
interface WalkSyncOptions {
interface WalkOptions {
output: Output;
}
@@ -51,27 +47,27 @@ interface WalkSyncOptions {
* - `output` {Object} "output" helper object
* @returns {Array}
*/
const walkSync = async (
async function walk(
dir: string,
path: string,
filelist: string[] = [],
opts: WalkSyncOptions
) => {
opts: WalkOptions
) {
const { debug } = opts.output;
const dirc = await fs.readdir(asAbsolute(dir, path));
for (let file of dirc) {
file = asAbsolute(file, dir);
try {
const file_stat = await fs.stat(file);
filelist = file_stat.isDirectory()
? await walkSync(file, path, filelist, opts)
const fileStat = await fs.stat(file);
filelist = fileStat.isDirectory()
? await walk(file, path, filelist, opts)
: filelist.concat(file);
} catch (e) {
debug(`Ignoring invalid file ${file}`);
}
}
return filelist;
};
}
interface FilesInWhitelistOptions {
output: Output;
@@ -85,7 +81,7 @@ interface FilesInWhitelistOptions {
* - `output` {Object} "output" helper object
* @returns {Array} the expanded list of whitelisted files.
*/
const getFilesInWhitelist = async function(
const getFilesInWhitelist = async function (
whitelist: string[],
path: string,
opts: FilesInWhitelistOptions
@@ -97,10 +93,10 @@ const getFilesInWhitelist = async function(
whitelist.map(async (file: string) => {
file = asAbsolute(file, path);
try {
const file_stat = await fs.stat(file);
if (file_stat.isDirectory()) {
const dir_files = await walkSync(file, path, [], opts);
files.push(...dir_files);
const fileStat = await fs.stat(file);
if (fileStat.isDirectory()) {
const dirFiles = await walk(file, path, [], opts);
files.push(...dirFiles);
} else {
files.push(file);
}
@@ -117,7 +113,7 @@ const getFilesInWhitelist = async function(
* because ignore doesn't like them :|
*/
const clearRelative = function(str: string) {
const clearRelative = function (str: string) {
return str.replace(/(\n|^)\.\//g, '$1');
};
@@ -127,7 +123,7 @@ const clearRelative = function(str: string) {
* @return {String} results or `''`
*/
const maybeRead = async function<T>(path: string, default_: T) {
const maybeRead = async function <T>(path: string, default_: T) {
try {
return await fs.readFile(path, 'utf8');
} catch (err) {
@@ -143,7 +139,7 @@ const maybeRead = async function<T>(path: string, default_: T) {
* @param {String} parent full path
*/
const asAbsolute = function(path: string, parent: string) {
const asAbsolute = function (path: string, parent: string) {
if (path[0] === '/') {
return path;
}
@@ -272,7 +268,7 @@ export async function npm(
const search = Array.prototype.concat.apply(
[],
await Promise.all(
search_.map(file =>
search_.map((file) =>
glob(file, { cwd: path, absolute: true, dot: true })
)
)
@@ -364,7 +360,7 @@ export async function docker(
const search_ = ['.'];
// Convert all filenames into absolute paths
const search = search_.map(file => asAbsolute(file, path));
const search = search_.map((file) => asAbsolute(file, path));
// Compile list of ignored patterns and files
const dockerIgnore = await maybeRead(resolve(path, '.dockerignore'), null);
@@ -382,7 +378,7 @@ export async function docker(
.createFilter();
const prefixLength = path.length + 1;
const accepts = function(file: string) {
const accepts = function (file: string) {
const relativePath = file.substr(prefixLength);
if (relativePath === '') {
@@ -415,24 +411,6 @@ export async function docker(
return uniqueStrings(files);
}
/**
* Get a list of all files inside the project folder
*
* @param {String} of the current working directory
* @param {Object} output instance
* @return {Array} of {String}s with the found files
*/
export async function getAllProjectFiles(cwd: string, { debug }: Output) {
// We need a slash at the end to remove it later on from the matched files
const current = join(resolve(cwd), '/');
debug(`Searching files inside of ${current}`);
const list = await glob('**', { cwd: current, absolute: true, nodir: true });
// We need to replace \ with / for windows
return list.map(file => file.replace(current.replace(/\\/g, '/'), ''));
}
interface ExplodeOptions {
accepts: (file: string) => boolean;
output: Output;
@@ -482,7 +460,7 @@ async function explode(
if (s.isDirectory()) {
const all = await fs.readdir(file);
/* eslint-disable no-use-before-define */
const recursive = many(all.map(subdir => asAbsolute(subdir, file)));
const recursive = many(all.map((subdir) => asAbsolute(subdir, file)));
return (recursive as any) as Promise<string | null>;
/* eslint-enable no-use-before-define */
}
@@ -494,7 +472,7 @@ async function explode(
return path;
};
const many = (all: string[]) => Promise.all(all.map(file => list(file)));
const many = (all: string[]) => Promise.all(all.map((file) => list(file)));
const arrayOfArrays = await many(paths);
return flatten(arrayOfArrays).filter(notNull);
}

View File

@@ -44,8 +44,8 @@ export default async function editProjectSettings(
output.print(
!framework.slug
? `No framework detected. Default project settings:\n`
: `Auto-detected project settings (${chalk.bold(framework.name)}):\n`
? `No framework detected. Default Project Settings:\n`
: `Auto-detected Project Settings (${chalk.bold(framework.name)}):\n`
);
settings.framework = framework.slug;

View File

@@ -27,7 +27,8 @@ export default function createOutput({ debug: debugEnabled = false } = {}) {
function warn(
str: string,
slug: string | null = null,
link: string | null = null
link: string | null = null,
action: string = 'Learn More'
) {
const prevTerm = process.env.TERM;
@@ -42,7 +43,7 @@ export default function createOutput({ debug: debugEnabled = false } = {}) {
boxen(
chalk.bold.yellow('WARN! ') +
str +
(details ? `\nMore details: ${renderLink(details)}` : ''),
(details ? `\n${action}: ${renderLink(details)}` : ''),
{
padding: {
top: 0,
@@ -67,7 +68,7 @@ export default function createOutput({ debug: debugEnabled = false } = {}) {
str: string,
slug?: string,
link?: string,
action = 'More details'
action = 'Learn More'
) {
print(`${chalk.red(`Error!`)} ${str}\n`);
const details = slug ? `https://err.sh/now/${slug}` : link;

View File

@@ -8,11 +8,11 @@ const metric = metrics();
export default function error(...input: string[] | [APIError]) {
let messages = input;
if (typeof input[0] === 'object') {
const { slug, message, link } = input[0];
const { slug, message, link, action = 'Learn More' } = input[0];
messages = [message];
const details = slug ? `https://err.sh/now/${slug}` : link;
if (details) {
messages.push(`${chalk.bold('More details')}: ${renderLink(details)}`);
messages.push(`${chalk.bold(action)}: ${renderLink(details)}`);
}
}

View File

@@ -15,6 +15,7 @@ import { prependEmoji, emoji } from '../emoji';
import AJV from 'ajv';
import { isDirectory } from '../config/global-path';
import { NowBuildError, getPlatformEnv } from '@vercel/build-utils';
import outputCode from '../output/code';
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
@@ -73,7 +74,7 @@ async function getLinkFromDir(dir: string): Promise<ProjectLink | null> {
if (!ajv.validate(linkSchema, link)) {
throw new Error(
`Project settings are invalid. To link your project again, remove the ${dir} directory.`
`Project Settings are invalid. To link your project again, remove the ${dir} directory.`
);
}
@@ -87,7 +88,7 @@ async function getLinkFromDir(dir: string): Promise<ProjectLink | null> {
// link file can't be read
if (error.name === 'SyntaxError') {
throw new Error(
`Project settings could not be retrieved. To link your project again, remove the ${dir} directory.`
`Project Settings could not be retrieved. To link your project again, remove the ${dir} directory.`
);
}
@@ -141,13 +142,27 @@ export async function getLinkedProject(
}
const spinner = output.spinner('Retrieving project…', 1000);
let org: Org | null;
let project: Project | ProjectNotFound | null;
let org: Org | null = null;
let project: Project | ProjectNotFound | null = null;
try {
[org, project] = await Promise.all([
getOrgById(client, link.orgId),
getProjectByIdOrName(client, link.projectId, link.orgId),
]);
} catch (err) {
if (err?.status === 403) {
spinner();
throw new NowBuildError({
message: `Could not retrieve Project Settings. To link your Project, remove the ${outputCode(
'.vercel'
)} directory and deploy again.`,
code: 'PROJECT_UNAUTHORIZED',
link: 'https://vercel.link/cannot-load-project-settings',
});
}
// Not a special case 403, we should still throw it
throw err;
} finally {
spinner();
}

View File

@@ -6,7 +6,6 @@ export default async function responseError(
fallbackMessage = null,
parsedBody = {}
) {
let message;
let bodyError;
if (res.status >= 400 && res.status < 500) {
@@ -20,12 +19,9 @@ export default async function responseError(
// Some APIs wrongly return `err` instead of `error`
bodyError = body.error || body.err || body;
message = bodyError.message;
}
if (message == null) {
message = fallbackMessage === null ? 'Response Error' : fallbackMessage;
}
const msg = bodyError?.message || fallbackMessage || 'Response Error';
return new APIError(message, res, bodyError);
return new APIError(msg, res, bodyError);
}

View File

@@ -71,7 +71,7 @@ function testFixture(name, fn) {
}
function validateResponseHeaders(t, res, podId = null) {
t.is(res.headers.get('server'), 'now');
t.is(res.headers.get('server'), 'Vercel');
t.truthy(res.headers.get('cache-control').length > 0);
t.truthy(
/^dev1::(dev1::)?[0-9a-z]{5}-[1-9][0-9]+-[a-f0-9]{12}$/.test(

View File

@@ -1,18 +1,17 @@
import test from 'ava';
import { validateConfig } from '../src/util/dev/validate';
test('[dev-validate] should not error with empty config', async t => {
test('[dev-validate] should not error with empty config', async (t) => {
const config = {};
const error = validateConfig(config);
t.deepEqual(error, null);
});
test('[dev-validate] should not error with complete config', async t => {
test('[dev-validate] should not error with complete config', async (t) => {
const config = {
version: 2,
public: true,
regions: ['sfo1', 'iad1'],
builds: [{ src: 'package.json', use: '@vercel/next' }],
cleanUrls: true,
headers: [{ source: '/', headers: [{ key: 'x-id', value: '123' }] }],
rewrites: [{ source: '/help', destination: '/support' }],
@@ -24,7 +23,7 @@ test('[dev-validate] should not error with complete config', async t => {
t.deepEqual(error, null);
});
test('[dev-validate] should not error with builds and routes', async t => {
test('[dev-validate] should not error with builds and routes', async (t) => {
const config = {
builds: [{ src: 'api/index.js', use: '@vercel/node' }],
routes: [{ src: '/(.*)', dest: '/api/index.js' }],
@@ -33,7 +32,7 @@ test('[dev-validate] should not error with builds and routes', async t => {
t.deepEqual(error, null);
});
test('[dev-validate] should error with invalid rewrites due to additional property and offer suggestion', async t => {
test('[dev-validate] should error with invalid rewrites due to additional property and offer suggestion', async (t) => {
const config = {
rewrites: [{ src: '/(.*)', dest: '/api/index.js' }],
};
@@ -48,7 +47,7 @@ test('[dev-validate] should error with invalid rewrites due to additional proper
);
});
test('[dev-validate] should error with invalid routes due to additional property and offer suggestion', async t => {
test('[dev-validate] should error with invalid routes due to additional property and offer suggestion', async (t) => {
const config = {
routes: [{ source: '/(.*)', destination: '/api/index.js' }],
};
@@ -63,7 +62,7 @@ test('[dev-validate] should error with invalid routes due to additional property
);
});
test('[dev-validate] should error with invalid routes array type', async t => {
test('[dev-validate] should error with invalid routes array type', async (t) => {
const config = {
routes: { src: '/(.*)', dest: '/api/index.js' },
};
@@ -75,7 +74,7 @@ test('[dev-validate] should error with invalid routes array type', async t => {
);
});
test('[dev-validate] should error with invalid redirects array object', async t => {
test('[dev-validate] should error with invalid redirects array object', async (t) => {
const config = {
redirects: [
{
@@ -94,7 +93,7 @@ test('[dev-validate] should error with invalid redirects array object', async t
);
});
test('[dev-validate] should error with invalid redirects.permanent poperty', async t => {
test('[dev-validate] should error with invalid redirects.permanent poperty', async (t) => {
const config = {
redirects: [{ source: '/', destination: '/go', permanent: 'yes' }],
};
@@ -109,7 +108,7 @@ test('[dev-validate] should error with invalid redirects.permanent poperty', asy
);
});
test('[dev-validate] should error with invalid cleanUrls type', async t => {
test('[dev-validate] should error with invalid cleanUrls type', async (t) => {
const config = {
cleanUrls: 'true',
};
@@ -124,7 +123,7 @@ test('[dev-validate] should error with invalid cleanUrls type', async t => {
);
});
test('[dev-validate] should error with invalid trailingSlash type', async t => {
test('[dev-validate] should error with invalid trailingSlash type', async (t) => {
const config = {
trailingSlash: [true],
};
@@ -139,7 +138,7 @@ test('[dev-validate] should error with invalid trailingSlash type', async t => {
);
});
test('[dev-validate] should error with invalid headers property', async t => {
test('[dev-validate] should error with invalid headers property', async (t) => {
const config = {
headers: [{ 'Content-Type': 'text/html' }],
};
@@ -154,7 +153,7 @@ test('[dev-validate] should error with invalid headers property', async t => {
);
});
test('[dev-validate] should error with invalid headers.source type', async t => {
test('[dev-validate] should error with invalid headers.source type', async (t) => {
const config = {
headers: [{ source: [{ 'Content-Type': 'text/html' }] }],
};
@@ -169,7 +168,7 @@ test('[dev-validate] should error with invalid headers.source type', async t =>
);
});
test('[dev-validate] should error with invalid headers additional property', async t => {
test('[dev-validate] should error with invalid headers additional property', async (t) => {
const config = {
headers: [{ source: '/', stuff: [{ 'Content-Type': 'text/html' }] }],
};
@@ -184,7 +183,7 @@ test('[dev-validate] should error with invalid headers additional property', asy
);
});
test('[dev-validate] should error with invalid headers wrong nested headers type', async t => {
test('[dev-validate] should error with invalid headers wrong nested headers type', async (t) => {
const config = {
headers: [{ source: '/', headers: [{ 'Content-Type': 'text/html' }] }],
};
@@ -199,7 +198,7 @@ test('[dev-validate] should error with invalid headers wrong nested headers type
);
});
test('[dev-validate] should error with invalid headers wrong nested headers additional property', async t => {
test('[dev-validate] should error with invalid headers wrong nested headers additional property', async (t) => {
const config = {
headers: [
{ source: '/', headers: [{ key: 'Content-Type', val: 'text/html' }] },
@@ -216,7 +215,7 @@ test('[dev-validate] should error with invalid headers wrong nested headers addi
);
});
test('[dev-validate] should error with too many redirects', async t => {
test('[dev-validate] should error with too many redirects', async (t) => {
const config = {
redirects: Array.from({ length: 5000 }).map((_, i) => ({
source: `/${i}`,
@@ -234,7 +233,7 @@ test('[dev-validate] should error with too many redirects', async t => {
);
});
test('[dev-validate] should error with too many nested headers', async t => {
test('[dev-validate] should error with too many nested headers', async (t) => {
const config = {
headers: [
{
@@ -260,3 +259,25 @@ test('[dev-validate] should error with too many nested headers', async t => {
'https://vercel.com/docs/configuration#project/headers'
);
});
test('[dev-validate] should error with "functions" and "builds"', async (t) => {
const config = {
builds: [
{
src: 'index.html',
use: '@vercel/static',
},
],
functions: {
'api/test.js': {
memory: 1024,
},
},
};
const error = validateConfig(config);
t.deepEqual(
error.message,
'The `functions` property cannot be used in conjunction with the `builds` property. Please remove one of them.'
);
t.deepEqual(error.link, 'https://vercel.link/functions-and-builds');
});

View File

@@ -1,7 +1,7 @@
{
"functions": {
"api/user.sh": {
"runtime": "vercel-bash@3.0.7"
"runtime": "vercel-bash@3.0.8"
}
}
}

View File

@@ -1 +0,0 @@
.vercel

View File

@@ -1,10 +0,0 @@
package handler
import (
"fmt"
"net/http"
)
func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Req Path: %s", r.URL.Path)
}

View File

@@ -1,10 +0,0 @@
package another
import (
"fmt"
"net/http"
)
func Another(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "This is another page")
}

View File

@@ -1,10 +0,0 @@
package handler
import (
"fmt"
"net/http"
)
func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "This is the index page")
}

View File

@@ -1 +1 @@
{ "env": { "FOO": "bar" } }
{"env":{"FOO":"bar"}}

View File

@@ -1 +1 @@
{ "builds": [{ "src": "index.js", "use": "@vercel/node@canary" }] }
{"builds":[{"src":"index.js","use":"@vercel/node@canary"}]}

View File

@@ -0,0 +1,3 @@
# Created by Vercel CLI
VERCEL_REGION=""
VERCEL_URL=""

View File

@@ -0,0 +1,6 @@
module.exports = (req, res) => {
res.send({
env: process.env,
headers: req.headers,
});
};

View File

@@ -1 +1,2 @@
!public
.vercel

View File

@@ -0,0 +1,8 @@
from flask import Flask, Response, request
app = Flask(__name__)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def headers(path):
url = request.headers.get('x-vercel-deployment-url')
return Response(url, mimetype='text/plain')

View File

@@ -118,24 +118,9 @@ async function runNpmInstall(fixturePath) {
}
}
async function getPackedBuilderPath(builderDirName) {
const packagePath = join(__dirname, '..', '..', '..', builderDirName);
const output = await execa('npm', ['pack'], {
cwd: packagePath,
shell: true,
});
if (output.exitCode !== 0 || output.stdout.trim() === '') {
throw new Error(
`Failed to pack ${builderDirName}: ${formatOutput(output)}`
);
}
return join(packagePath, output.stdout.trim());
}
async function testPath(
t,
isDev,
origin,
status,
path,
@@ -153,6 +138,9 @@ async function testPath(
if (typeof expectedText === 'string') {
const actualText = await res.text();
t.is(actualText.trim(), expectedText.trim(), msg);
} else if (typeof expectedText === 'function') {
const actualText = await res.text();
await expectedText(t, actualText, res, isDev);
} else if (expectedText instanceof RegExp) {
const actualText = await res.text();
expectedText.lastIndex = 0; // reset since we test twice
@@ -342,9 +330,9 @@ function testFixtureStdio(
const helperTestPath = async (...args) => {
if (!skipDeploy) {
await testPath(t, `https://${deploymentUrl}`, ...args);
await testPath(t, false, `https://${deploymentUrl}`, ...args);
}
await testPath(t, `http://localhost:${port}`, ...args);
await testPath(t, true, `http://localhost:${port}`, ...args);
};
await fn(helperTestPath, t, port);
} finally {
@@ -411,7 +399,6 @@ test('[vercel dev] `vercel.json` should be invalidated if deleted', async t => {
{
// Env var should not be set after `vercel.json` is deleted
await fs.remove(configPath);
await sleep(1000);
const res = await fetch(`http://localhost:${port}/api`);
const body = await res.json();
@@ -454,7 +441,6 @@ test('[vercel dev] reflects changes to config and env without restart', async t
],
};
await fs.writeJSON(configPath, config);
await sleep(1000);
const res = await fetch(`http://localhost:${port}/?foo=bar`);
const body = await res.json();
@@ -476,7 +462,6 @@ test('[vercel dev] reflects changes to config and env without restart', async t
],
};
await fs.writeJSON(configPath, config);
await sleep(1000);
const res = await fetch(`http://localhost:${port}/?foo=baz`);
const body = await res.json();
@@ -495,7 +480,6 @@ test('[vercel dev] reflects changes to config and env without restart', async t
},
};
await fs.writeJSON(configPath, config);
await sleep(1000);
const res = await fetch(`http://localhost:${port}/?foo=baz`);
const body = await res.json();
@@ -514,7 +498,6 @@ test('[vercel dev] reflects changes to config and env without restart', async t
},
};
await fs.writeJSON(configPath, config);
await sleep(1000);
const res = await fetch(`http://localhost:${port}/?foo=boo`);
const body = await res.json();
@@ -1485,22 +1468,6 @@ test('[vercel dev] render warning for empty cwd dir', async t => {
test('[vercel dev] do not rebuild for changes in the output directory', async t => {
const directory = fixture('output-is-source');
// Pack the builder and set it in the `vercel.json`
const builder = await getPackedBuilderPath('now-static-build');
await fs.writeFile(
join(directory, 'vercel.json'),
JSON.stringify({
builds: [
{
src: 'package.json',
use: `file://${builder}`,
config: { zeroConfig: true },
},
],
})
);
const { dev, port } = await testFixture(directory, {
stdio: ['ignore', 'pipe', 'pipe'],
});
@@ -1586,6 +1553,10 @@ test(
await testPath(200, `/api/user?name=${name}`, new RegExp(`Hello ${name}`));
await testPath(200, `/api/date`, new RegExp(`Current date is ${year}`));
await testPath(200, `/api/date.py`, new RegExp(`Current date is ${year}`));
await testPath(200, `/api/headers`, (t, body, res) => {
const { host } = new URL(res.url);
t.is(body, host);
});
})
);
@@ -1629,28 +1600,3 @@ test(
await testPath(200, '/index.css', 'This is index.css');
})
);
test(
'[vercel dev] Should support `*.go` API serverless functions',
testFixtureStdio('go', async testPath => {
await testPath(200, `/api`, 'This is the index page');
await testPath(200, `/api/index`, 'This is the index page');
await testPath(200, `/api/index.go`, 'This is the index page');
await testPath(200, `/api/another`, 'This is another page');
await testPath(200, '/api/another.go', 'This is another page');
await testPath(200, `/api/foo`, 'Req Path: /api/foo');
await testPath(200, `/api/bar`, 'Req Path: /api/bar');
})
);
test(
'[vercel dev] Should set the `ts-node` "target" to match Node.js version',
testFixtureStdio('node-ts-node-target', async testPath => {
await testPath(200, `/api/subclass`, '{"ok":true}');
await testPath(
200,
`/api/array`,
'{"months":[1,2,3,4,5,6,7,8,9,10,11,12]}'
);
})
);

View File

@@ -365,7 +365,7 @@ CMD ["node", "index.js"]`,
'package.json': JSON.stringify({
private: true,
scripts: {
build: 'mkdir public && node print.js > public/index.json',
build: 'mkdir -p public && node print.js > public/index.json',
},
}),
},
@@ -519,6 +519,13 @@ CMD ["node", "index.js"]`,
'vercel.json': getConfigFile(true),
'now.json': getConfigFile(true),
},
'unauthorized-vercel-config': {
// This project is under the testing-internal team
'.vercel/project.json': JSON.stringify({
orgId: 'team_JgimPl9u9uauL7E4MjMLt605',
projectId: 'QmRoBYhejkkmssotLZr8tWgewPdPcjYucYUNERFbhJrRNi',
}),
},
};
for (const typeName of Object.keys(spec)) {

View File

@@ -219,9 +219,7 @@ const createUser = async () => {
email = user.email;
contextName = user.username;
session = Math.random()
.toString(36)
.split('.')[1];
session = Math.random().toString(36).split('.')[1];
},
{ retries: 3, factor: 1 }
);
@@ -595,7 +593,86 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
t.is(homeRes.status, 200, formatOutput({ stderr, stdout }));
const homeJson = await homeRes.json();
t.is(homeJson['MY_ENV_VAR'], 'MY_VALUE');
t.is(apiJson['VERCEL_URL'], host);
t.is(homeJson['VERCEL_URL'], host);
}
async function nowDevWithEnv() {
const vc = execa(binaryPath, ['dev', ...defaultArgs], {
reject: false,
cwd: target,
});
let localhost = undefined;
await waitForPrompt(vc, chunk => {
if (chunk.includes('Ready! Available at')) {
localhost = /(https?:[^\s]+)/g.exec(chunk);
return true;
}
return false;
});
const localhostNoProtocol = localhost[0].slice('http://'.length);
const apiUrl = `${localhost[0]}/api/get-env`;
const apiRes = await fetch(apiUrl);
t.is(apiRes.status, 200);
const apiJson = await apiRes.json();
t.is(apiJson['MY_ENV_VAR'], 'MY_VALUE');
t.is(apiJson['VERCEL_URL'], localhostNoProtocol);
const homeUrl = localhost[0];
const homeRes = await fetch(homeUrl);
const homeJson = await homeRes.json();
t.is(homeJson['MY_ENV_VAR'], 'MY_VALUE');
t.is(homeJson['VERCEL_URL'], localhostNoProtocol);
vc.kill('SIGTERM', { forceKillAfterTimeout: 2000 });
const { exitCode, stderr, stdout } = await vc;
t.is(exitCode, 0, formatOutput({ stderr, stdout }));
}
async function nowDevAndFetchCloudVars() {
const vc = execa(binaryPath, ['dev', ...defaultArgs], {
reject: false,
cwd: target,
});
let localhost = undefined;
await waitForPrompt(vc, chunk => {
if (chunk.includes('Ready! Available at')) {
localhost = /(https?:[^\s]+)/g.exec(chunk);
return true;
}
return false;
});
const apiUrl = `${localhost[0]}/api/get-env`;
const apiRes = await fetch(apiUrl);
const localhostNoProtocol = localhost[0].slice('http://'.length);
t.is(apiRes.status, 200);
const apiJson = await apiRes.json();
t.is(apiJson['VERCEL_URL'], localhostNoProtocol);
t.is(apiJson['MY_ENV_VAR'], 'MY_VALUE');
const homeUrl = localhost[0];
const homeRes = await fetch(homeUrl);
const homeJson = await homeRes.json();
t.is(homeJson['MY_ENV_VAR'], 'MY_VALUE');
t.is(homeJson['VERCEL_URL'], localhostNoProtocol);
vc.kill('SIGTERM', { forceKillAfterTimeout: 2000 });
const { exitCode, stderr, stdout } = await vc;
t.is(exitCode, 0, formatOutput({ stderr, stdout }));
}
async function nowEnvRemove() {
@@ -664,11 +741,13 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
await nowEnvPullOverwrite();
await nowEnvPullConfirm();
await nowDeployWithVar();
await nowDevWithEnv();
fs.unlinkSync(path.join(target, '.env'));
await nowDevAndFetchCloudVars();
await nowEnvRemove();
await nowEnvRemoveWithArgs();
await nowEnvRemoveWithNameOnly();
await nowEnvLsIsEmpty();
fs.unlinkSync(path.join(target, '.env'));
});
test('deploy with metadata containing "=" in the value', async t => {
@@ -1763,6 +1842,7 @@ test('deploying a file should not show prompts and display deprecation', async t
t.is(contentType, 'image/png');
t.deepEqual(await readFile(file), await response.buffer());
console.log('>>>>>', stdout);
});
test('deploying more than 1 path should fail', async t => {
@@ -2365,7 +2445,7 @@ test('fail to deploy a Lambda with an incorrect value for of memory', async t =>
t.is(output.exitCode, 1, formatOutput(output));
t.regex(output.stderr, /steps of 64/gm, formatOutput(output));
t.regex(output.stderr, /More details/gm, formatOutput(output));
t.regex(output.stderr, /Learn More/gm, formatOutput(output));
});
test('deploy a Lambda with 3 seconds of maxDuration', async t => {
@@ -2470,9 +2550,7 @@ test('change user', async t => {
test('should show prompts to set up project', async t => {
const directory = fixture('project-link');
const projectName = `project-link-${
Math.random()
.toString(36)
.split('.')[1]
Math.random().toString(36).split('.')[1]
}`;
// remove previously linked project if it exists
@@ -2598,9 +2676,7 @@ test('should show prompts to set up project', async t => {
test('should prefill "project name" prompt with folder name', async t => {
const projectName = `static-deployment-${
Math.random()
.toString(36)
.split('.')[1]
Math.random().toString(36).split('.')[1]
}`;
const src = fixture('static-deployment');
@@ -2648,9 +2724,7 @@ test('should prefill "project name" prompt with folder name', async t => {
test('should prefill "project name" prompt with --name', async t => {
const directory = fixture('static-deployment');
const projectName = `static-deployment-${
Math.random()
.toString(36)
.split('.')[1]
Math.random().toString(36).split('.')[1]
}`;
// remove previously linked project if it exists
@@ -2708,9 +2782,7 @@ test('should prefill "project name" prompt with --name', async t => {
test('should prefill "project name" prompt with now.json `name`', async t => {
const directory = fixture('static-deployment');
const projectName = `static-deployment-${
Math.random()
.toString(36)
.split('.')[1]
Math.random().toString(36).split('.')[1]
}`;
// remove previously linked project if it exists
@@ -3077,3 +3149,24 @@ test('deploy gatsby twice and print cached directories', async t => {
await writeFile(packageJsonPath, packageJsonOriginal);
}
});
test('reject deploying with wrong team .vercel config', async t => {
const directory = fixture('unauthorized-vercel-config');
const { exitCode, stderr, stdout } = await execa(
binaryPath,
[...defaultArgs, '--confirm'],
{
cwd: directory,
reject: false,
}
);
t.is(exitCode, 1, formatOutput({ stderr, stdout }));
t.true(
stderr.includes(
'Could not retrieve Project Settings. To link your Project, remove the `.vercel` directory and deploy again.'
),
formatOutput({ stderr, stdout })
);
});

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/client",
"version": "8.1.1-canary.1",
"version": "8.2.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"homepage": "https://vercel.com",
@@ -38,6 +38,7 @@
]
},
"dependencies": {
"@vercel/build-utils": "2.4.2",
"@zeit/fetch": "5.2.0",
"async-retry": "1.2.3",
"async-sema": "3.0.0",

View File

@@ -1,13 +1,4 @@
#!/bin/bash
set -euo pipefail
# Start fresh
rm -rf dist
# Build with `ncc`
ncc build index.ts -e @vercel/build-utils -e @now/build-utils -o dist
ncc build install.ts -e @vercel/build-utils -e @now/build-utils -o dist/install
# Move `install.js` to dist
mv dist/install/index.js dist/install.js
rm -rf dist/install

View File

@@ -1,6 +1,7 @@
package main
import (
"io/ioutil"
"net"
"net/http"
"os"
@@ -12,17 +13,23 @@ func main() {
handler := http.HandlerFunc(__HANDLER_FUNC_NAME)
// https://stackoverflow.com/a/43425461/376773
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
}
port := listener.Addr().(*net.TCPAddr).Port
portBytes := []byte(strconv.Itoa(port))
file := os.NewFile(3, "pipe")
_, err2 := file.Write([]byte(strconv.Itoa(port)))
_, err2 := file.Write(portBytes)
if err2 != nil {
panic(err2)
portFile := os.Getenv("VERCEL_DEV_PORT_FILE")
os.Unsetenv("VERCEL_DEV_PORT_FILE")
err3 := ioutil.WriteFile(portFile, portBytes, 0644)
if err3 != nil {
panic(err3)
}
}
panic(http.Serve(listener, handler))

View File

@@ -3,10 +3,14 @@ import execa from 'execa';
import fetch from 'node-fetch';
import { mkdirp, pathExists } from 'fs-extra';
import { dirname, join } from 'path';
import { homedir } from 'os';
import buildUtils from './build-utils';
import stringArgv from 'string-argv';
const { debug } = buildUtils;
const archMap = new Map([['x64', 'amd64'], ['x86', '386']]);
const archMap = new Map([
['x64', 'amd64'],
['x86', '386'],
]);
const platformMap = new Map([['win32', 'windows']]);
// Location where the `go` binary will be installed after `postinstall`
@@ -126,35 +130,50 @@ export async function downloadGo(
platform = process.platform,
arch = process.arch
) {
// Check if `go` is already installed in user's `$PATH`
const { failed, stdout } = await execa('go', ['version'], { reject: false });
// Check default `Go` in user machine
const isUserGo = await pathExists(join(homedir(), 'go'));
if (!failed && parseInt(stdout.split('.')[1]) >= 11) {
debug('Using system installed version of `go`: %o', stdout.trim());
return createGo(dir, platform, arch);
}
// If we found GOPATH in ENV, or default `Go` path exists
// asssume that user have `Go` installed
if (isUserGo || process.env.GOPATH !== undefined) {
const { stdout } = await execa('go', ['version']);
// Check `go` bin in builder CWD
const isGoExist = await pathExists(join(dir, 'bin'));
if (!isGoExist) {
debug('Installing `go` v%s to %o for %s %s', version, dir, platform, arch);
const url = getGoUrl(version, platform, arch);
debug('Downloading `go` URL: %o', url);
const res = await fetch(url);
if (!res.ok) {
throw new Error(`Failed to download: ${url} (${res.status})`);
if (parseInt(stdout.split('.')[1]) >= 11) {
return createGo(dir, platform, arch);
}
// TODO: use a zip extractor when `ext === "zip"`
await mkdirp(dir);
await new Promise((resolve, reject) => {
res.body
.on('error', reject)
.pipe(tar.extract({ cwd: dir, strip: 1 }))
.on('error', reject)
.on('finish', resolve);
});
throw new Error(
`Your current ${stdout} doesn't support Go Modules. Please update.`
);
} else {
// Check `Go` bin in builder CWD
const isGoExist = await pathExists(join(dir, 'bin'));
if (!isGoExist) {
debug(
'Installing `go` v%s to %o for %s %s',
version,
dir,
platform,
arch
);
const url = getGoUrl(version, platform, arch);
debug('Downloading `go` URL: %o', url);
const res = await fetch(url);
if (!res.ok) {
throw new Error(`Failed to download: ${url} (${res.status})`);
}
// TODO: use a zip extractor when `ext === "zip"`
await mkdirp(dir);
await new Promise((resolve, reject) => {
res.body
.on('error', reject)
.pipe(tar.extract({ cwd: dir, strip: 1 }))
.on('error', reject)
.on('finish', resolve);
});
}
return createGo(dir, platform, arch);
}
return createGo(dir, platform, arch);
}

View File

@@ -1,24 +1,8 @@
import execa from 'execa';
import { join, sep, dirname, basename, normalize } from 'path';
import { readFile, writeFile, pathExists, move } from 'fs-extra';
import { homedir } from 'os';
import { spawn } from 'child_process';
import { Readable } from 'stream';
import once from '@tootallnate/once';
import { join, dirname, basename, normalize, sep } from 'path';
import {
readFile,
writeFile,
pathExists,
mkdirp,
move,
remove,
} from 'fs-extra';
import {
BuildOptions,
Meta,
Files,
StartDevServerOptions,
StartDevServerResult,
} from '@vercel/build-utils';
import execa from 'execa';
import { BuildOptions, Meta, Files, shouldServe } from '@vercel/build-utils';
import buildUtils from './build-utils';
const {
@@ -26,15 +10,12 @@ const {
download,
createLambda,
getWriteableDirectory,
shouldServe,
debug,
} = buildUtils;
import { createGo, getAnalyzedEntrypoint, OUT_EXTENSION } from './go-helpers';
const handlerFileName = `handler${OUT_EXTENSION}`;
export { shouldServe };
interface Analyzed {
found?: boolean;
packageName: string;
@@ -42,22 +23,16 @@ interface Analyzed {
watch: string[];
}
interface PortInfo {
port: number;
}
// Initialize private git repo for Go Modules
async function initPrivateGit(credentials: string) {
const gitCredentialsPath = join(homedir(), '.git-credentials');
await execa('git', [
'config',
'--global',
'credential.helper',
`store --file ${gitCredentialsPath}`,
`store --file ${join(homedir(), '.git-credentials')}`,
]);
await writeFile(gitCredentialsPath, credentials);
await writeFile(join(homedir(), '.git-credentials'), credentials);
}
/**
@@ -460,121 +435,4 @@ Learn more: https://vercel.com/docs/runtimes#official-runtimes/go
};
}
function isPortInfo(v: any): v is PortInfo {
return v && typeof v.port === 'number';
}
function isReadable(v: any): v is Readable {
return v && v.readable === true;
}
async function copyEntrypoint(entrypoint: string, dest: string): Promise<void> {
const data = await readFile(entrypoint, 'utf8');
// Modify package to `package main`
const patched = data.replace(/\bpackage\W+\S+\b/, 'package main');
await writeFile(join(dest, 'entrypoint.go'), patched);
}
async function copyDevServer(
functionName: string,
dest: string
): Promise<void> {
const data = await readFile(join(__dirname, 'dev-server.go'), 'utf8');
// Populate the handler function name
const patched = data.replace('__HANDLER_FUNC_NAME', functionName);
await writeFile(join(dest, 'vercel-dev-server-main.go'), patched);
}
export async function startDevServer(
opts: StartDevServerOptions
): Promise<StartDevServerResult> {
const { entrypoint, workPath, meta = {} } = opts;
const { devCacheDir = join(workPath, '.vercel', 'cache') } = meta;
const entrypointDir = dirname(entrypoint);
// For some reason, if `entrypoint` is a path segment (filename contains `[]`
// brackets) then the `.go` suffix on the entrypoint is missing. Fix that here…
let entrypointWithExt = entrypoint;
if (!entrypoint.endsWith('.go')) {
entrypointWithExt += '.go';
}
const tmp = join(
devCacheDir,
'go',
Math.random()
.toString(32)
.substring(2)
);
const tmpPackage = join(tmp, entrypointDir);
await mkdirp(tmpPackage);
let goModAbsPathDir = '';
if (await pathExists(join(workPath, 'go.mod'))) {
goModAbsPathDir = workPath;
}
const analyzedRaw = await getAnalyzedEntrypoint(
entrypointWithExt,
goModAbsPathDir
);
if (!analyzedRaw) {
throw new Error(
`Could not find an exported function in "${entrypointWithExt}"
Learn more: https://vercel.com/docs/runtimes#official-runtimes/go`
);
}
const analyzed: Analyzed = JSON.parse(analyzedRaw);
await Promise.all([
copyEntrypoint(entrypointWithExt, tmpPackage),
copyDevServer(analyzed.functionName, tmpPackage),
]);
const env: typeof process.env = {
...process.env,
...meta.env,
};
const tmpRelative = `.${sep}${entrypointDir}`;
const child = spawn('go', ['run', tmpRelative], {
cwd: tmp,
env,
stdio: ['ignore', 'inherit', 'inherit', 'pipe'],
});
child.once('exit', async () => {
await remove(tmp); // Cleanup
});
const portPipe = child.stdio[3];
if (!isReadable(portPipe)) {
throw new Error('File descriptor 3 is not readable');
}
// `dev-server.go` writes the ephemeral port number to FD 3 to be consumed here
const onPort = new Promise<PortInfo>(resolve => {
portPipe.setEncoding('utf8');
portPipe.once('data', d => {
resolve({ port: Number(d) });
});
});
const onExit = once.spread<[number, string | null]>(child, 'exit');
const result = await Promise.race([onPort, onExit]);
onExit.cancel();
if (isPortInfo(result)) {
return {
port: result.port,
pid: child.pid,
};
} else {
// Got "exit" event from child process
throw new Error(
`Failed to start dev server for "${entrypointWithExt}" (code=${result[0]}, signal=${result[1]})`
);
}
}
export { shouldServe };

View File

@@ -1,8 +1,8 @@
package main
import (
vc "github.com/vercel/go-bridge/go/bridge"
"net/http"
vc "github.com/vercel/go-bridge/go/bridge"
)
func main() {

View File

@@ -1,12 +1,12 @@
package main
import (
"__NOW_HANDLER_PACKAGE_NAME"
"net/http"
"net/http"
"__NOW_HANDLER_PACKAGE_NAME"
vc "github.com/vercel/go-bridge/go/bridge"
vc "github.com/vercel/go-bridge/go/bridge"
)
func main() {
vc.Start(http.HandlerFunc(__NOW_HANDLER_FUNC_NAME))
vc.Start(http.HandlerFunc(__NOW_HANDLER_FUNC_NAME))
}

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/go",
"version": "1.1.3-canary.1",
"version": "1.1.4",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
@@ -19,11 +19,11 @@
"dist"
],
"devDependencies": {
"@tootallnate/once": "1.1.2",
"@types/execa": "^0.9.0",
"@types/fs-extra": "^5.0.5",
"@types/node-fetch": "^2.3.0",
"@types/tar": "^4.0.0",
"async-retry": "1.3.1",
"execa": "^1.0.0",
"fs-extra": "^7.0.0",
"node-fetch": "^2.2.1",

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/next",
"version": "2.6.8",
"version": "2.6.13",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -26,7 +26,7 @@
"@types/resolve-from": "5.0.1",
"@types/semver": "6.0.0",
"@types/yazl": "2.4.1",
"@zeit/node-file-trace": "0.6.5",
"@zeit/node-file-trace": "0.8.0",
"async-sema": "3.0.1",
"buffer-crc32": "0.2.13",
"escape-string-regexp": "3.0.0",
@@ -36,6 +36,7 @@
"get-port": "5.0.0",
"resolve-from": "5.0.0",
"semver": "6.1.1",
"set-cookie-parser": "2.4.6",
"typescript": "3.9.3",
"yazl": "https://github.com/ijjk/yazl#70949c55b482647669ce37023017b1514c42b33c"
}

View File

@@ -15,25 +15,26 @@ const {
} = buildUtils;
import {
Lambda,
BuildOptions,
Config,
FileBlob,
FileFsRef,
Files,
Lambda,
NowBuildError,
PackageJson,
PrepareCacheOptions,
Prerender,
NowBuildError,
} from '@vercel/build-utils';
import { Route, Handler } from '@vercel/routing-utils';
import { Handler, Route } from '@vercel/routing-utils';
import {
convertHeaders,
convertRedirects,
convertRewrites,
} from '@vercel/routing-utils/dist/superstatic';
import nodeFileTrace, { NodeFileTraceReasons } from '@zeit/node-file-trace';
import { nodeFileTrace, NodeFileTraceReasons } from '@zeit/node-file-trace';
import { ChildProcess, fork } from 'child_process';
import escapeStringRegexp from 'escape-string-regexp';
import {
lstat,
pathExists,
@@ -46,7 +47,6 @@ import path from 'path';
import resolveFrom from 'resolve-from';
import semver from 'semver';
import createServerlessConfig from './create-serverless-config';
import escapeStringRegexp from 'escape-string-regexp';
import nextLegacyVersions from './legacy-versions';
import {
createLambdaFromPseudoLayers,
@@ -91,7 +91,7 @@ export const version = 2;
const htmlContentType = 'text/html; charset=utf-8';
const nowDevChildProcesses = new Set<ChildProcess>();
['SIGINT', 'SIGTERM'].forEach((signal) => {
['SIGINT', 'SIGTERM'].forEach(signal => {
process.once(signal as NodeJS.Signals, () => {
for (const child of nowDevChildProcesses) {
debug(
@@ -108,7 +108,13 @@ const MAX_AGE_ONE_YEAR = 31536000;
/**
* Read package.json from files
*/
async function readPackageJson(entryPath: string) {
async function readPackageJson(
entryPath: string
): Promise<{
scripts?: { [key: string]: string };
dependencies?: { [key: string]: string };
devDependencies?: { [key: string]: string };
}> {
const packagePath = path.join(entryPath, 'package.json');
try {
@@ -139,15 +145,38 @@ async function writeNpmRc(workPath: string, token: string) {
);
}
function getNextVersion(packageJson: {
dependencies?: { [key: string]: string };
devDependencies?: { [key: string]: string };
}) {
let nextVersion;
if (packageJson.dependencies && packageJson.dependencies.next) {
nextVersion = packageJson.dependencies.next;
} else if (packageJson.devDependencies && packageJson.devDependencies.next) {
nextVersion = packageJson.devDependencies.next;
/**
* Get the installed Next version.
*/
function getRealNextVersion(entryPath: string): string | false {
try {
// First try to resolve the `next` dependency and get the real version from its
// package.json. This allows the builder to be used with frameworks like Blitz that
// bundle Next but where Next isn't in the project root's package.json
const nextVersion: string = require(resolveFrom(
entryPath,
'next/package.json'
)).version;
debug(`Detected Next.js version: ${nextVersion}`);
return nextVersion;
} catch (_ignored) {
debug(
`Could not identify real Next.js version, ensure it is defined as a project dependency.`
);
return false;
}
}
/**
* Get the package.json Next version.
*/
async function getNextVersionRange(entryPath: string): Promise<string | false> {
let nextVersion: string | false = false;
const pkg = await readPackageJson(entryPath);
if (pkg.dependencies && pkg.dependencies.next) {
nextVersion = pkg.dependencies.next;
} else if (pkg.devDependencies && pkg.devDependencies.next) {
nextVersion = pkg.devDependencies.next;
}
return nextVersion;
}
@@ -218,19 +247,10 @@ export const build = async ({
await download(files, workPath, meta);
const pkg = await readPackageJson(entryPath);
const nextVersion = getNextVersion(pkg);
const nextVersionRange = await getNextVersionRange(entryPath);
const nodeVersion = await getNodeVersion(entryPath, undefined, config, meta);
const spawnOpts = getSpawnOptions(meta, nodeVersion);
if (!nextVersion) {
throw new NowBuildError({
code: 'NEXT_NO_VERSION',
message:
'No Next.js version could be detected in "package.json". Make sure `"next"` is installed in "dependencies" or "devDependencies"',
});
}
const nowJsonPath = await findUp(['now.json', 'vercel.json'], {
cwd: path.join(workPath, path.dirname(entrypoint)),
});
@@ -308,7 +328,7 @@ export const build = async ({
console.warn('WARNING: You should not upload the `.next` directory.');
}
const isLegacy = isLegacyNext(nextVersion);
const isLegacy = nextVersionRange && isLegacyNext(nextVersionRange);
let shouldRunScript = 'now-build';
debug(`MODE: ${isLegacy ? 'legacy' : 'serverless'}`);
@@ -362,18 +382,20 @@ export const build = async ({
console.log('Installing dependencies...');
await runNpmInstall(entryPath, ['--prefer-offline'], spawnOpts, meta);
let realNextVersion: string | undefined;
try {
realNextVersion = require(resolveFrom(entryPath, 'next/package.json'))
.version;
debug(`Detected Next.js version: ${realNextVersion}`);
} catch (_ignored) {
debug(`Could not identify real Next.js version, that's OK!`);
// Refetch Next version now that dependencies are installed.
// This will now resolve the actual installed Next version,
// even if Next isn't in the project package.json
const nextVersion = getRealNextVersion(entryPath);
if (!nextVersion) {
throw new NowBuildError({
code: 'NEXT_NO_VERSION',
message:
'No Next.js version could be detected in your project. Make sure `"next"` is installed in "dependencies" or "devDependencies"',
});
}
if (!isLegacy) {
await createServerlessConfig(workPath, entryPath, realNextVersion);
await createServerlessConfig(workPath, entryPath, nextVersion);
}
debug('Running user script...');
@@ -410,7 +432,7 @@ export const build = async ({
const routesManifest = await getRoutesManifest(
entryPath,
outputDirectory,
realNextVersion
nextVersion
);
const prerenderManifest = await getPrerenderManifest(entryPath);
const headers: Route[] = [];
@@ -463,7 +485,7 @@ export const build = async ({
`${(ssgDataRoute && ssgDataRoute.dataRoute) || dataRoute.page}${
dataRoute.routeKeys
? `?${Object.keys(dataRoute.routeKeys)
.map((key) => `${dataRoute.routeKeys![key]}=$${key}`)
.map(key => `${dataRoute.routeKeys![key]}=$${key}`)
.join('&')}`
: ''
}`
@@ -557,8 +579,6 @@ export const build = async ({
return {
output,
routes: [
// TODO: low priority: handle trailingSlash
// User headers
...headers,
@@ -694,7 +714,7 @@ export const build = async ({
);
const nodeModules = excludeFiles(
await glob('node_modules/**', entryPath),
(file) => file.startsWith('node_modules/.cache')
file => file.startsWith('node_modules/.cache')
);
const launcherFiles = {
'now__bridge.js': new FileFsRef({
@@ -723,7 +743,7 @@ export const build = async ({
const launcherData = await readFile(launcherPath, 'utf8');
await Promise.all(
Object.keys(pages).map(async (page) => {
Object.keys(pages).map(async page => {
// These default pages don't have to be handled as they'd always 404
if (['_app.js', '_error.js', '_document.js'].includes(page)) {
return;
@@ -839,10 +859,7 @@ export const build = async ({
// Assume tracing to be safe, bail if we know we don't need it.
let requiresTracing = hasLambdas;
try {
if (
realNextVersion &&
semver.lt(realNextVersion, ExperimentalTraceVersion)
) {
if (nextVersion && semver.lt(nextVersion, ExperimentalTraceVersion)) {
debug(
'Next.js version is too old for us to trace the required dependencies.\n' +
'Assuming Next.js has handled it!'
@@ -884,7 +901,7 @@ export const build = async ({
const apiPages: string[] = [];
const nonApiPages: string[] = [];
const allPagePaths = Object.keys(pages).map((page) => pages[page].fsPath);
const allPagePaths = Object.keys(pages).map(page => pages[page].fsPath);
for (const page of allPagePaths) {
if (isApiPage(page)) {
@@ -977,7 +994,7 @@ export const build = async ({
debug(
'detected (legacy) assets to be bundled with serverless function:'
);
assetKeys.forEach((assetFile) => debug(`\t${assetFile}`));
assetKeys.forEach(assetFile => debug(`\t${assetFile}`));
debug(
'\nPlease upgrade to Next.js 9.1 to leverage modern asset handling.'
);
@@ -1117,7 +1134,7 @@ export const build = async ({
}
} else {
await Promise.all(
pageKeys.map(async (page) => {
pageKeys.map(async page => {
// These default pages don't have to be handled as they'd always 404
if (['_app.js', '_document.js'].includes(page)) {
return;
@@ -1198,8 +1215,8 @@ export const build = async ({
false,
routesManifest,
new Set(prerenderManifest.omittedRoutes)
).then((arr) =>
arr.map((route) => {
).then(arr =>
arr.map(route => {
route.src = route.src.replace('^', `^${dynamicPrefix}`);
return route;
})
@@ -1209,6 +1226,21 @@ export const build = async ({
const launcherPath = path.join(__dirname, 'templated-launcher-shared.js');
const launcherData = await readFile(launcherPath, 'utf8');
// we need to include the prerenderManifest.omittedRoutes here
// for the page to be able to be matched in the lambda for preview mode
const completeDynamicRoutes = await getDynamicRoutes(
entryPath,
entryDirectory,
dynamicPages,
false,
routesManifest
).then(arr =>
arr.map(route => {
route.src = route.src.replace('^', `^${dynamicPrefix}`);
return route;
})
);
await Promise.all(
[...apiLambdaGroups, ...pageLambdaGroups].map(
async function buildLambdaGroup(group: LambdaGroup) {
@@ -1223,7 +1255,7 @@ export const build = async ({
const pages = {
${groupPageKeys
.map(
(page) =>
page =>
`'${page}': require('./${path.join(
'./',
group.pages[page].pageFileName
@@ -1268,7 +1300,7 @@ export const build = async ({
// for prerendered dynamic routes (/blog/post-1) we need to
// find the match since it won't match the page directly
const dynamicRoutes = ${JSON.stringify(
dynamicRoutes.map((route) => ({
completeDynamicRoutes.map(route => ({
src: route.src,
dest: route.dest,
}))
@@ -1482,13 +1514,13 @@ export const build = async ({
}
};
Object.keys(prerenderManifest.staticRoutes).forEach((route) =>
Object.keys(prerenderManifest.staticRoutes).forEach(route =>
onPrerenderRoute(route, { isBlocking: false, isFallback: false })
);
Object.keys(prerenderManifest.fallbackRoutes).forEach((route) =>
Object.keys(prerenderManifest.fallbackRoutes).forEach(route =>
onPrerenderRoute(route, { isBlocking: false, isFallback: true })
);
Object.keys(prerenderManifest.legacyBlockingRoutes).forEach((route) =>
Object.keys(prerenderManifest.legacyBlockingRoutes).forEach(route =>
onPrerenderRoute(route, { isBlocking: true, isFallback: false })
);
@@ -1542,7 +1574,7 @@ export const build = async ({
...mappedFiles,
[path.join(
entryDirectory,
file.replace(/public[/\\]+/, '')
file.replace(/^public[/\\]+/, '')
)]: publicFolderFiles[file],
}),
{}
@@ -1552,7 +1584,7 @@ export const build = async ({
// We need to delete lambdas from output instead of omitting them from the
// start since we rely on them for powering Preview Mode (read above in
// onPrerenderRoute).
prerenderManifest.omittedRoutes.forEach((routeKey) => {
prerenderManifest.omittedRoutes.forEach(routeKey => {
// Get the route file as it'd be mounted in the builder output
const routeFileNoExt = path.posix.join(
entryDirectory,
@@ -1760,14 +1792,8 @@ export const prepareCache = async ({
const entryPath = path.join(workPath, entryDirectory);
const outputDirectory = config.outputDirectory || '.next';
const pkg = await readPackageJson(entryPath);
const nextVersion = getNextVersion(pkg);
if (!nextVersion)
throw new NowBuildError({
code: 'NEXT_VERSION_PARSE_FAILED',
message: 'Could not parse Next.js version',
});
const isLegacy = isLegacyNext(nextVersion);
const nextVersionRange = await getNextVersionRange(entryPath);
const isLegacy = nextVersionRange && isLegacyNext(nextVersionRange);
if (isLegacy) {
// skip caching legacy mode (swapping deps between all and production can get bug-prone)

View File

@@ -198,7 +198,7 @@ async function getRoutes(
// If default pages dir isn't found check for `src/pages`
if (
!pagesDir &&
fileKeys.some(file =>
fileKeys.some((file) =>
file.startsWith(path.join(entryDirectory, 'src/pages'))
)
) {
@@ -260,7 +260,7 @@ async function getRoutes(
entryDirectory,
dynamicPages,
true
).then(arr =>
).then((arr) =>
arr.map((route: Source) => {
// convert to make entire RegExp match as one group
route.src = route.src
@@ -287,7 +287,7 @@ async function getRoutes(
};
// Only add the route if a page is not already using it
if (!routes.some(r => (r as Source).src === route.src)) {
if (!routes.some((r) => (r as Source).src === route.src)) {
routes.push(route);
}
}
@@ -363,17 +363,18 @@ export async function getRoutesManifest(
// eslint-disable-next-line @typescript-eslint/no-var-requires
const routesManifest: RoutesManifest = require(pathRoutesManifest);
// massage temporary array based routeKeys from v1/v2 of routes
// manifest into new object based
for (const route of [
...(routesManifest.dataRoutes || []),
...(routesManifest.dynamicRoutes || []),
]) {
// remove temporary array based routeKeys from v1/v2 of routes
// manifest since it can result in invalid routes
for (const route of routesManifest.dataRoutes || []) {
if (Array.isArray(route.routeKeys)) {
route.routeKeys = route.routeKeys.reduce((prev, cur) => {
prev[cur] = cur;
return prev;
}, {});
delete route.routeKeys;
delete route.namedDataRouteRegex;
}
}
for (const route of routesManifest.dynamicRoutes || []) {
if (Array.isArray(route.routeKeys)) {
delete route.routeKeys;
delete route.namedRegex;
}
}
@@ -419,7 +420,7 @@ export async function getDynamicRoutes(
dest: `${!isDev ? path.join('/', entryDirectory, page) : page}${
routeKeys
? `?${Object.keys(routeKeys)
.map(key => `${routeKeys[key]}=$${key}`)
.map((key) => `${routeKeys[key]}=$${key}`)
.join('&')}`
: ''
}`,
@@ -478,13 +479,13 @@ export async function getDynamicRoutes(
});
}
const pageMatchers = getSortedRoutes(dynamicPages).map(pageName => ({
const pageMatchers = getSortedRoutes(dynamicPages).map((pageName) => ({
pageName,
matcher: getRouteRegex && getRouteRegex(pageName).re,
}));
const routes: Source[] = [];
pageMatchers.forEach(pageMatcher => {
pageMatchers.forEach((pageMatcher) => {
// in `vercel dev` we don't need to prefix the destination
const dest = !isDev
? path.join('/', entryDirectory, pageMatcher.pageName)
@@ -861,7 +862,7 @@ export async function getPrerenderManifest(
omittedRoutes: [],
};
routes.forEach(route => {
routes.forEach((route) => {
const {
initialRevalidateSeconds,
dataRoute,
@@ -877,7 +878,7 @@ export async function getPrerenderManifest(
};
});
lazyRoutes.forEach(lazyRoute => {
lazyRoutes.forEach((lazyRoute) => {
const {
routeRegex,
fallback,
@@ -915,7 +916,7 @@ export async function getPrerenderManifest(
omittedRoutes: [],
};
routes.forEach(route => {
routes.forEach((route) => {
const {
initialRevalidateSeconds,
dataRoute,
@@ -931,7 +932,7 @@ export async function getPrerenderManifest(
};
});
lazyRoutes.forEach(lazyRoute => {
lazyRoutes.forEach((lazyRoute) => {
const {
routeRegex,
fallback,

View File

@@ -1 +1 @@
export default () => 'hello from /[teamSlug]/[project]/[id]'
export default () => 'hello from /[teamSlug]/[project]/[id]';

View File

@@ -1,18 +1,17 @@
import { useRouter } from 'next/router'
import { useRouter } from 'next/router';
export const getStaticProps = ({ params }) => {
return {
props: {
id: params.id
}
}
}
id: params.id,
},
};
};
export const getStaticPaths = () => ({
paths: ['first', 'second'].map(id => ({ params: { id }})),
fallback: true
})
paths: ['first', 'second'].map(id => ({ params: { id } })),
fallback: true,
});
export default ({ id }) => useRouter().isFallback
? `loading...`
: `hello from /groups/[id] ${id}`
export default ({ id }) =>
useRouter().isFallback ? `loading...` : `hello from /groups/[id] ${id}`;

View File

@@ -1,9 +1,9 @@
export const getServerSideProps = ({ params }) => {
return {
props: {
code: params.inviteCode
}
}
}
code: params.inviteCode,
},
};
};
export default ({ code }) => `hello from /teams/invite/[inviteCode] ${code}`
export default ({ code }) => `hello from /teams/invite/[inviteCode] ${code}`;

View File

@@ -0,0 +1 @@
module.exports = { trailingSlash: true };

View File

@@ -0,0 +1,38 @@
{
"version": 2,
"builds": [{ "src": "package.json", "use": "@vercel/next" }],
"probes": [
{ "path": "/foo/", "status": 200, "mustContain": "foo page" },
{
"fetchOptions": { "redirect": "manual" },
"path": "/foo",
"status": 308,
"responseHeaders": {
"refresh": "/url=/foo/$/"
}
},
{ "path": "/abc/def/", "status": 200, "mustContain": "nested page" },
{
"fetchOptions": { "redirect": "manual" },
"path": "/abc/def",
"status": 308,
"responseHeaders": {
"refresh": "/url=/abc/def/$/"
}
},
{
"fetchOptions": { "redirect": "manual" },
"path": "/test.txt/",
"status": 308,
"responseHeaders": {
"refresh": "/url=/test\\.txt$/"
}
},
{
"fetchOptions": { "redirect": "manual" },
"path": "/test.txt",
"status": 200,
"mustContain": "this is a file"
}
]
}

View File

@@ -0,0 +1,7 @@
{
"dependencies": {
"next": "canary",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}
}

View File

@@ -0,0 +1,3 @@
export default function Page() {
return <p>nested page</p>;
}

View File

@@ -0,0 +1,3 @@
export default function Page() {
return <p>foo page</p>;
}

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