mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 12:57:46 +00:00
Compare commits
97 Commits
vercel@27.
...
@vercel/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2906d83eae | ||
|
|
675c3e2915 | ||
|
|
13a8a7dbf6 | ||
|
|
b480e632a3 | ||
|
|
bc6c364888 | ||
|
|
6cad10c899 | ||
|
|
0d78ec4666 | ||
|
|
b05d653cf1 | ||
|
|
5a38b94de2 | ||
|
|
6668d6cf21 | ||
|
|
b63f444abd | ||
|
|
9d71d4332f | ||
|
|
151db21a2f | ||
|
|
aba9c95ea2 | ||
|
|
e7e0a55b72 | ||
|
|
c2163e3e4f | ||
|
|
873f549637 | ||
|
|
ead1e411ee | ||
|
|
7c1c089a70 | ||
|
|
a7dbd9649b | ||
|
|
2e439045c9 | ||
|
|
520e0d01f4 | ||
|
|
3856623785 | ||
|
|
1c14e945f9 | ||
|
|
32357fc06f | ||
|
|
f7c57dc539 | ||
|
|
34f7c35c13 | ||
|
|
6700630feb | ||
|
|
34cd8b4144 | ||
|
|
ad0ed6d852 | ||
|
|
0bad09b47a | ||
|
|
5120689bf2 | ||
|
|
5a39fd9242 | ||
|
|
352cd00ef0 | ||
|
|
abfe817f86 | ||
|
|
ebb5e2b208 | ||
|
|
e34858d082 | ||
|
|
f03c947f91 | ||
|
|
0d13fe7e34 | ||
|
|
4afec9d373 | ||
|
|
09c85f63d2 | ||
|
|
9963965e9a | ||
|
|
f3ed279007 | ||
|
|
4fe489edad | ||
|
|
e2911aac0b | ||
|
|
f3cbc5d746 | ||
|
|
40df88b483 | ||
|
|
75c4f45b73 | ||
|
|
05a236f944 | ||
|
|
4b7383f521 | ||
|
|
c263c31e48 | ||
|
|
c80530f9b1 | ||
|
|
16fd4396ef | ||
|
|
4e7138f400 | ||
|
|
5273279cf1 | ||
|
|
37290039d6 | ||
|
|
b52d01f809 | ||
|
|
ffefaf82a1 | ||
|
|
6d8dbfc7d6 | ||
|
|
551cd7f688 | ||
|
|
2dfb6b45cd | ||
|
|
65ae2a289e | ||
|
|
72ea3532b1 | ||
|
|
78fac00823 | ||
|
|
9e255afa37 | ||
|
|
e4be68270f | ||
|
|
9c636dc1ba | ||
|
|
c98c9996bf | ||
|
|
0fcf172a10 | ||
|
|
99e5c4a6db | ||
|
|
b8269b0111 | ||
|
|
decac0fe3f | ||
|
|
591d1686d0 | ||
|
|
5e1d5c921c | ||
|
|
603b1256c6 | ||
|
|
6957c72828 | ||
|
|
9be3650cb7 | ||
|
|
6e1ee7a7d6 | ||
|
|
767ce2cff1 | ||
|
|
bb1d0ce1b7 | ||
|
|
31f79c7de1 | ||
|
|
4c230c8436 | ||
|
|
7941f5a104 | ||
|
|
5b931afbf3 | ||
|
|
15080364b8 | ||
|
|
47e3381c6d | ||
|
|
33aefdc029 | ||
|
|
30fe76a0cf | ||
|
|
97ef88dc28 | ||
|
|
f679098d7a | ||
|
|
2b57e12ad3 | ||
|
|
c4e94ad03f | ||
|
|
32afd67d29 | ||
|
|
7523e39f18 | ||
|
|
99f2f2f1ba | ||
|
|
63830d38ce | ||
|
|
f3428dd212 |
28
.github/CODEOWNERS
vendored
28
.github/CODEOWNERS
vendored
@@ -1,23 +1,17 @@
|
|||||||
# Documentation
|
# Documentation
|
||||||
# https://help.github.com/en/articles/about-code-owners
|
# https://help.github.com/en/articles/about-code-owners
|
||||||
|
|
||||||
* @TooTallNate @EndangeredMassa @styfle
|
* @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood
|
||||||
/.github/workflows @TooTallNate @EndangeredMassa @styfle @ijjk
|
/.github/workflows @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @ijjk
|
||||||
/packages/frameworks @TooTallNate @EndangeredMassa @styfle @AndyBitz
|
/packages/cli/src/commands/domains @mglagola @anatrajkovska
|
||||||
/packages/cli/src/commands/domains @javivelasco @mglagola @anatrajkovska
|
/packages/cli/src/commands/certs @mglagola @anatrajkovska
|
||||||
/packages/cli/src/commands/certs @javivelasco @mglagola @anatrajkovska
|
/packages/cli/src/commands/env @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood
|
||||||
/packages/cli/src/commands/env @styfle @lucleray
|
/packages/fs-detectors @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @agadzik @chloetedder
|
||||||
/packages/client @TooTallNate @EndangeredMassa @styfle
|
/packages/middleware @gdborton @vercel/edge-function
|
||||||
/packages/build-utils @TooTallNate @EndangeredMassa @styfle @AndyBitz
|
/packages/node-bridge @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @ijjk
|
||||||
/packages/middleware @gdborton @javivelasco
|
/packages/next @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @ijjk
|
||||||
/packages/node @TooTallNate @EndangeredMassa @styfle
|
/packages/routing-utils @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @ijjk
|
||||||
/packages/node-bridge @TooTallNate @EndangeredMassa @styfle @ijjk
|
/packages/edge @vercel/edge-function
|
||||||
/packages/next @TooTallNate @ijjk
|
|
||||||
/packages/go @TooTallNate @EndangeredMassa @styfle
|
|
||||||
/packages/python @TooTallNate @EndangeredMassa @styfle
|
|
||||||
/packages/ruby @TooTallNate @EndangeredMassa @styfle
|
|
||||||
/packages/static-build @TooTallNate @EndangeredMassa @styfle @AndyBitz
|
|
||||||
/packages/routing-utils @TooTallNate @EndangeredMassa @styfle @ijjk
|
|
||||||
/examples @leerob
|
/examples @leerob
|
||||||
/examples/create-react-app @Timer
|
/examples/create-react-app @Timer
|
||||||
/examples/nextjs @timneutkens @ijjk @styfle
|
/examples/nextjs @timneutkens @ijjk @styfle
|
||||||
|
|||||||
25
.github/workflows/cron-update-next.yml
vendored
Normal file
25
.github/workflows/cron-update-next.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Cron Update Next
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Run every 4 hours https://crontab.guru/every-4-hours
|
||||||
|
schedule:
|
||||||
|
- cron: '0 */4 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create-pull-request:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
# 0 means fetch all commits so we can commit and push in the script below
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
# See https://github.com/actions/github-script#run-a-separate-file-with-an-async-function
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const script = require('./utils/update-next.js')
|
||||||
|
await script({ github, context })
|
||||||
4
.github/workflows/publish.yml
vendored
4
.github/workflows/publish.yml
vendored
@@ -26,12 +26,12 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
|
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.13.15'
|
go-version: '1.13.15'
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
|
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: 14
|
||||||
- name: Install
|
- name: Install
|
||||||
|
|||||||
22
.github/workflows/required-pr-label.yml
vendored
Normal file
22
.github/workflows/required-pr-label.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: Required PR Label
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, labeled, unlabeled, synchronize]
|
||||||
|
jobs:
|
||||||
|
label:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check PR Labels
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const labels = context.payload.pull_request.labels.map(l => l.name);
|
||||||
|
if (labels.filter(l => l.startsWith('area:')).length === 0) {
|
||||||
|
console.error('\u001b[31mMissing label: Please add at least one "area" label.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
if (labels.filter(l => l.startsWith('semver:')).length !== 1) {
|
||||||
|
console.error('\u001b[31mMissing label: Please add exactly one "semver" label.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
console.log('\u001b[32mSuccess: This pull request has correct labels, thanks!');
|
||||||
8
.github/workflows/test-integration-cli.yml
vendored
8
.github/workflows/test-integration-cli.yml
vendored
@@ -25,20 +25,20 @@ jobs:
|
|||||||
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
||||||
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
||||||
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.13.15'
|
go-version: '1.13.15'
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 100
|
fetch-depth: 100
|
||||||
- run: git --version
|
- run: git --version
|
||||||
- run: git fetch origin main --depth=100
|
- run: git fetch origin main --depth=100
|
||||||
- run: git fetch origin ${{ github.ref }} --depth=100
|
- run: git fetch origin ${{ github.ref }} --depth=100
|
||||||
- run: git diff origin/main...HEAD --name-only
|
- run: git diff origin/main...HEAD --name-only
|
||||||
- run: yarn install --network-timeout 1000000
|
- run: yarn install --network-timeout 1000000 --frozen-lockfile
|
||||||
- run: yarn run build
|
- run: yarn run build
|
||||||
- run: yarn test-integration-cli
|
- run: yarn test-integration-cli
|
||||||
env:
|
env:
|
||||||
|
|||||||
8
.github/workflows/test-unit.yml
vendored
8
.github/workflows/test-unit.yml
vendored
@@ -25,20 +25,20 @@ jobs:
|
|||||||
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
||||||
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
||||||
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.13.15'
|
go-version: '1.13.15'
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 100
|
fetch-depth: 100
|
||||||
- run: git --version
|
- run: git --version
|
||||||
- run: git fetch origin main --depth=100
|
- run: git fetch origin main --depth=100
|
||||||
- run: git fetch origin ${{ github.ref }} --depth=100
|
- run: git fetch origin ${{ github.ref }} --depth=100
|
||||||
- run: git diff origin/main...HEAD --name-only
|
- run: git diff origin/main...HEAD --name-only
|
||||||
- run: yarn install --network-timeout 1000000
|
- run: yarn install --network-timeout 1000000 --frozen-lockfile
|
||||||
- run: yarn run build
|
- run: yarn run build
|
||||||
- run: yarn run lint
|
- run: yarn run lint
|
||||||
if: matrix.os == 'ubuntu-latest' && matrix.node == 14 # only run lint once
|
if: matrix.os == 'ubuntu-latest' && matrix.node == 14 # only run lint once
|
||||||
|
|||||||
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
@@ -19,14 +19,14 @@ jobs:
|
|||||||
tests: ${{ steps['set-tests'].outputs['tests'] }}
|
tests: ${{ steps['set-tests'].outputs['tests'] }}
|
||||||
dplUrl: ${{ steps.waitForTarball.outputs.url }}
|
dplUrl: ${{ steps.waitForTarball.outputs.url }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- run: git --version
|
- run: git --version
|
||||||
- run: git fetch origin main
|
- run: git fetch origin main
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
- run: yarn install --network-timeout 1000000
|
- run: yarn install --network-timeout 1000000 --frozen-lockfile
|
||||||
- id: set-tests
|
- id: set-tests
|
||||||
run: |
|
run: |
|
||||||
TESTS_ARRAY=$(node utils/chunk-tests.js $SCRIPT_NAME)
|
TESTS_ARRAY=$(node utils/chunk-tests.js $SCRIPT_NAME)
|
||||||
@@ -58,13 +58,13 @@ jobs:
|
|||||||
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
||||||
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
||||||
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.13.15'
|
go-version: '1.13.15'
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
[merge]
|
[merge]
|
||||||
automerge_label = ["semver-major","semver-minor","semver-patch"]
|
automerge_label = ["pr: automerge"]
|
||||||
blacklist_title_regex = "^WIP.*"
|
blacklist_title_regex = "^WIP.*"
|
||||||
blacklist_labels = ["work in progress"]
|
blacklist_labels = ["work in progress"]
|
||||||
method = "squash"
|
method = "squash"
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ export async function build(options: BuildOptions) {
|
|||||||
const lambda = createLambda(/* … */);
|
const lambda = createLambda(/* … */);
|
||||||
return {
|
return {
|
||||||
output: lambda,
|
output: lambda,
|
||||||
watch: [
|
|
||||||
// Dependent files to trigger a rebuild in `vercel dev` go here…
|
|
||||||
],
|
|
||||||
routes: [
|
routes: [
|
||||||
// If your Runtime needs to define additional routing, define it here…
|
// If your Runtime needs to define additional routing, define it here…
|
||||||
],
|
],
|
||||||
@@ -115,7 +112,8 @@ export async function shouldServe(options: ShouldServeOptions) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If this function is not defined, Vercel CLI will use the [default implementation](https://github.com/vercel/vercel/blob/52994bfe26c5f4f179bdb49783ee57ce19334631/packages/now-build-utils/src/should-serve.ts).
|
If this function is not defined, Vercel CLI will use the [default
|
||||||
|
implementation](https://github.com/vercel/vercel/blob/52994bfe26c5f4f179bdb49783ee57ce19334631/packages/now-build-utils/src/should-serve.ts).
|
||||||
|
|
||||||
### `startDevServer()`
|
### `startDevServer()`
|
||||||
|
|
||||||
@@ -189,7 +187,8 @@ If you need to share state between those steps, use the filesystem.
|
|||||||
|
|
||||||
### Directory and Cache Lifecycle
|
### Directory and Cache Lifecycle
|
||||||
|
|
||||||
When a new build is created, we pre-populate the `workPath` supplied to `analyze` with the results of the `prepareCache` step of the previous build.
|
When a new build is created, we pre-populate the `workPath` supplied to `analyze` with the results of the `prepareCache` step of the
|
||||||
|
previous build.
|
||||||
|
|
||||||
The `analyze` step can modify that directory, and it will not be re-created when it's supplied to `build` and `prepareCache`.
|
The `analyze` step can modify that directory, and it will not be re-created when it's supplied to `build` and `prepareCache`.
|
||||||
|
|
||||||
@@ -197,6 +196,77 @@ The `analyze` step can modify that directory, and it will not be re-created when
|
|||||||
|
|
||||||
The env and secrets specified by the user as `build.env` are passed to the Runtime process. This means you can access user env via `process.env` in Node.js.
|
The env and secrets specified by the user as `build.env` are passed to the Runtime process. This means you can access user env via `process.env` in Node.js.
|
||||||
|
|
||||||
|
### Supporting Large Environment
|
||||||
|
|
||||||
|
We provide the ability to support more than 4KB of environment (up to 64KB) by way of
|
||||||
|
a Lambda runtime wrapper that is added to every Lambda function we create. These are
|
||||||
|
supported by many of the existing Lambda runtimes, but custom runtimes may require
|
||||||
|
additional work.
|
||||||
|
|
||||||
|
The following Lambda runtime families have built-in support for the runtime wrapper:
|
||||||
|
|
||||||
|
- `nodejs`
|
||||||
|
- `python` (>= 3.8)
|
||||||
|
- `ruby`
|
||||||
|
- `java11`
|
||||||
|
- `java8.al2` (not `java8`)
|
||||||
|
- `dotnetcore`
|
||||||
|
|
||||||
|
If a custom runtime is based on one of these Lambda runtimes, large environment
|
||||||
|
support will be available without further configuration. Custom runtimes based on
|
||||||
|
other Lambda runtimes, including those that provide the runtime via `provided` and
|
||||||
|
`provided.al2`, must implement runtime wrapper support and indicate it via the
|
||||||
|
`supportsWrapper` flag when calling [`createLambda`](#createlambda()).
|
||||||
|
|
||||||
|
To add support for runtime wrappers to a custom runtime, first check the value of the
|
||||||
|
`AWS_LAMBDA_EXEC_WRAPPER` environment variable in the bootstrap script. Its value is
|
||||||
|
the path to the wrapper executable.
|
||||||
|
|
||||||
|
The wrapper must be passed the path to the runtime as well as any parameters that the
|
||||||
|
runtime requires. This is most easily done in a small `bootstrap` script.
|
||||||
|
|
||||||
|
In this simple `bash` example, the runtime is called directly if
|
||||||
|
`AWS_LAMBDA_EXEC_WRAPPER` has no value, otherwise the wrapper is called with the
|
||||||
|
runtime command as parameters.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
exec $AWS_LAMBDA_EXEC_WRAPPER path/to/runtime param1 param2
|
||||||
|
```
|
||||||
|
|
||||||
|
If the `bootstrap` file is not a launcher script, but the entrypoint of the runtime
|
||||||
|
itself, replace the bootstrap process with the wrapper. Pass the path and parameters
|
||||||
|
of the executing file, ensuring the `AWS_LAMBDA_EXEC_WRAPPER` environment variable is
|
||||||
|
set to blank.
|
||||||
|
|
||||||
|
This `bash` example uses `exec` to replace the running bootstrap process with the
|
||||||
|
wrapper, passing its own path and parameters.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ -n $AWS_LAMBDA_EXEC_WRAPPER ]]
|
||||||
|
__WRAPPER=$AWS_LAMBDA_EXEC_WRAPPER
|
||||||
|
AWS_LAMBDA_EXEC_WRAPPER=""
|
||||||
|
exec $__WRAPPER "$0" "${@}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# start the actual runtime functionality
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that unsetting the variable may not have the desired effect due to the way
|
||||||
|
Lambda spawns runtime processes. It is better to explicitly set it to blank.
|
||||||
|
|
||||||
|
The best way to replace the existing bootstrap process is with the
|
||||||
|
[`execve`](https://www.man7.org/linux/man-pages/man2/execve.2.html) syscall.
|
||||||
|
This is achieved by using `exec` in `bash` to replace the running process with the wrapper,
|
||||||
|
maintaining the same PID and environment.
|
||||||
|
|
||||||
|
Once support for runtime wrappers is included, ensure `supportsWrapper` is set to
|
||||||
|
`true` in the call to [`createLambda`](#createlambda()). This will inform the build
|
||||||
|
process to enable large environment support for this runtime.
|
||||||
|
|
||||||
### Utilities as peerDependencies
|
### Utilities as peerDependencies
|
||||||
|
|
||||||
When you publish your Runtime to npm, make sure to not specify `@vercel/build-utils` (as seen below in the API definitions) as a dependency, but rather as part of `peerDependencies`.
|
When you publish your Runtime to npm, make sure to not specify `@vercel/build-utils` (as seen below in the API definitions) as a dependency, but rather as part of `peerDependencies`.
|
||||||
@@ -304,6 +374,7 @@ This is a [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere
|
|||||||
- `handler: String` path to handler file and (optionally) a function name it exports
|
- `handler: String` path to handler file and (optionally) a function name it exports
|
||||||
- `runtime: LambdaRuntime` the name of the lambda runtime
|
- `runtime: LambdaRuntime` the name of the lambda runtime
|
||||||
- `environment: Object` key-value map of handler-related (aside of those passed by user) environment variables
|
- `environment: Object` key-value map of handler-related (aside of those passed by user) environment variables
|
||||||
|
- `supportsWrapper: Boolean` set to true to indicate that Lambda runtime wrappers are supported by this runtime
|
||||||
|
|
||||||
### `LambdaRuntime`
|
### `LambdaRuntime`
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,6 @@ For details on how to use Vercel, check out our [documentation](https://vercel.c
|
|||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
- [Code of Conduct](https://github.com/vercel/vercel/blob/main/.github/CODE_OF_CONDUCT.md)
|
- [Code of Conduct](./.github/CODE_OF_CONDUCT.md)
|
||||||
- [Contributing Guidelines](https://github.com/vercel/vercel/blob/main/.github/CONTRIBUTING.md)
|
- [Contributing Guidelines](./.github/CONTRIBUTING.md)
|
||||||
- [MIT License](https://github.com/vercel/vercel/blob/main/LICENSE)
|
- [MIT License](./LICENSE)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const frameworks = (_frameworks as Framework[])
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (framework.logo) {
|
if (framework.logo) {
|
||||||
framework.logo = `https://res.cloudinary.com/zeit-inc/image/fetch/${framework.logo}`;
|
framework.logo = `https://assets.vercel.com/zeit-inc/image/fetch/${framework.logo}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return framework;
|
return framework;
|
||||||
|
|||||||
1
examples/astro/.gitignore
vendored
1
examples/astro/.gitignore
vendored
@@ -18,3 +18,4 @@ pnpm-debug.log*
|
|||||||
|
|
||||||
# macOS-specific files
|
# macOS-specific files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.vercel
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
README.md
|
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
# Welcome to [Astro](https://astro.build)
|
# Astro
|
||||||
|
|
||||||
[](https://stackblitz.com/github/withastro/astro/tree/latest/examples/starter)
|
This directory is a brief example of an [Astro](https://astro.build/) site that can be deployed to Vercel with zero configuration.
|
||||||
|
|
||||||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun!
|
## Deploy Your Own
|
||||||
|
|
||||||
## 🚀 Project Structure
|
Deploy your own Astro project with Vercel.
|
||||||
|
|
||||||
|
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/vercel/tree/main/examples/astro&template=astro)
|
||||||
|
|
||||||
|
_Live Example: https://astro-template.vercel.app_
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
Inside of your Astro project, you'll see the following folders and files:
|
Inside of your Astro project, you'll see the following folders and files:
|
||||||
|
|
||||||
@@ -26,17 +32,15 @@ There's nothing special about `src/components/`, but that's where we like to put
|
|||||||
|
|
||||||
Any static assets, like images, can be placed in the `public/` directory.
|
Any static assets, like images, can be placed in the `public/` directory.
|
||||||
|
|
||||||
## 🧞 Commands
|
## Commands
|
||||||
|
|
||||||
All commands are run from the root of the project, from a terminal:
|
All commands are run from the root of the project, from a terminal:
|
||||||
|
|
||||||
| Command | Action |
|
| Command | Action |
|
||||||
| :---------------- | :------------------------------------------- |
|
| :--------------------- | :------------------------------------------------- |
|
||||||
| `npm install` | Installs dependencies |
|
| `npm install` | Installs dependencies |
|
||||||
| `npm run dev` | Starts local dev server at `localhost:3000` |
|
| `npm run dev` | Starts local dev server at `localhost:3000` |
|
||||||
| `npm run build` | Build your production site to `./dist/` |
|
| `npm run build` | Build your production site to `./dist/` |
|
||||||
| `npm run preview` | Preview your build locally, before deploying |
|
| `npm run preview` | Preview your build locally, before deploying |
|
||||||
|
| `npm run astro ...` | Run CLI commands like `astro add`, `astro preview` |
|
||||||
## 👀 Want to learn more?
|
| `npm run astro --help` | Get help using the Astro CLI |
|
||||||
|
|
||||||
Feel free to check [our documentation](https://github.com/withastro/astro) or jump into our [Discord server](https://astro.build/chat).
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@example/basics",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "astro dev",
|
"dev": "astro dev",
|
||||||
"start": "astro dev",
|
"start": "astro dev",
|
||||||
"build": "astro build",
|
"build": "astro build",
|
||||||
"preview": "astro preview"
|
"preview": "astro preview",
|
||||||
|
"astro": "astro"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"astro": "^1.0.0-beta.20"
|
"astro": "^1.0.0-rc.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
76
examples/astro/src/components/Card.astro
Normal file
76
examples/astro/src/components/Card.astro
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
---
|
||||||
|
export interface Props {
|
||||||
|
title: string;
|
||||||
|
body: string;
|
||||||
|
href: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { href, title, body } = Astro.props as Props;
|
||||||
|
---
|
||||||
|
|
||||||
|
<li class="link-card">
|
||||||
|
<a href={href}>
|
||||||
|
<h2>
|
||||||
|
{title}
|
||||||
|
<span>→</span>
|
||||||
|
</h2>
|
||||||
|
<p>
|
||||||
|
{body}
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--link-gradient: linear-gradient(45deg, #4f39fa, #da62c4 30%, var(--color-border) 60%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card {
|
||||||
|
list-style: none;
|
||||||
|
display: flex;
|
||||||
|
padding: 0.15rem;
|
||||||
|
background-image: var(--link-gradient);
|
||||||
|
background-size: 400%;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background-position: 100%;
|
||||||
|
transition: background-position 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card > a {
|
||||||
|
width: 100%;
|
||||||
|
text-decoration: none;
|
||||||
|
line-height: 1.4;
|
||||||
|
padding: 1em 1.3em;
|
||||||
|
border-radius: 0.35rem;
|
||||||
|
color: var(--text-color);
|
||||||
|
background-color: white;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin: 0;
|
||||||
|
transition: color 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 span {
|
||||||
|
display: inline-block;
|
||||||
|
transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card:is(:hover, :focus-within) {
|
||||||
|
background-position: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card:is(:hover, :focus-within) h2 {
|
||||||
|
color: #4f39fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card:is(:hover, :focus-within) h2 span {
|
||||||
|
will-change: transform;
|
||||||
|
transform: translateX(2px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
---
|
|
||||||
export interface Props {
|
|
||||||
title: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { title } = Astro.props as Props;
|
|
||||||
---
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width">
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
|
||||||
<title>{title}</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<slot />
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--font-size-base: clamp(1rem, 0.34vw + 0.91rem, 1.19rem);
|
|
||||||
--font-size-lg: clamp(1.2rem, 0.7vw + 1.2rem, 1.5rem);
|
|
||||||
--font-size-xl: clamp(2.44rem, 2.38vw + 1.85rem, 3.75rem);
|
|
||||||
|
|
||||||
--color-text: hsl(12, 5%, 4%);
|
|
||||||
--color-bg: hsl(10, 21%, 95%);
|
|
||||||
}
|
|
||||||
|
|
||||||
html {
|
|
||||||
font-family: system-ui, sans-serif;
|
|
||||||
font-size: var(--font-size-base);
|
|
||||||
color: var(--color-text);
|
|
||||||
background-color: var(--color-bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
:global(h1) {
|
|
||||||
font-size: var(--font-size-xl);
|
|
||||||
}
|
|
||||||
|
|
||||||
:global(h2) {
|
|
||||||
font-size: var(--font-size-lg);
|
|
||||||
}
|
|
||||||
|
|
||||||
:global(code) {
|
|
||||||
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
|
|
||||||
Bitstream Vera Sans Mono, Courier New, monospace;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
1
examples/astro/src/env.d.ts
vendored
Normal file
1
examples/astro/src/env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="astro/client" />
|
||||||
56
examples/astro/src/layouts/Layout.astro
Normal file
56
examples/astro/src/layouts/Layout.astro
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
export interface Props {
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { title } = Astro.props as Props;
|
||||||
|
---
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
|
<title>{title}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<slot />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--font-size-base: clamp(1rem, 0.34vw + 0.91rem, 1.19rem);
|
||||||
|
--font-size-lg: clamp(1.2rem, 0.7vw + 1.2rem, 1.5rem);
|
||||||
|
--font-size-xl: clamp(2.44rem, 2.38vw + 1.85rem, 3.75rem);
|
||||||
|
|
||||||
|
--color-text: hsl(12, 5%, 4%);
|
||||||
|
--color-bg: hsl(10, 21%, 95%);
|
||||||
|
--color-border: hsl(17, 24%, 90%);
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-family: system-ui, sans-serif;
|
||||||
|
font-size: var(--font-size-base);
|
||||||
|
color: var(--color-text);
|
||||||
|
background-color: var(--color-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(h1) {
|
||||||
|
font-size: var(--font-size-xl);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(h2) {
|
||||||
|
font-size: var(--font-size-lg);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(code) {
|
||||||
|
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
|
||||||
|
Bitstream Vera Sans Mono, Courier New, monospace;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,81 +1,52 @@
|
|||||||
---
|
---
|
||||||
import Layout from '../components/Layout.astro';
|
import Layout from '../layouts/Layout.astro';
|
||||||
|
import Card from '../components/Card.astro';
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="Welcome to Astro.">
|
<Layout title="Welcome to Astro.">
|
||||||
<main>
|
<main>
|
||||||
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
|
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
|
||||||
<p class="instructions"><strong>Your first mission:</strong> tweak this message to try our hot module reloading. Check the <code>src/pages</code> directory!</p>
|
<p class="instructions">
|
||||||
|
Check out the <code>src/pages</code> directory to get started.<br />
|
||||||
|
<strong>Code Challenge:</strong> Tweak the "Welcome to Astro" message above.
|
||||||
|
</p>
|
||||||
<ul role="list" class="link-card-grid">
|
<ul role="list" class="link-card-grid">
|
||||||
<li class="link-card">
|
<Card
|
||||||
<a href="https://astro.build/integrations/">
|
href="https://docs.astro.build/"
|
||||||
<h2>Integrations <span>→</span></h2>
|
title="Documentation"
|
||||||
<p>Add component frameworks, Tailwind, Partytown, and more!</p>
|
body="Learn how Astro works and explore the official API docs."
|
||||||
</a>
|
/>
|
||||||
</li>
|
<Card
|
||||||
<li class="link-card">
|
href="https://astro.build/integrations/"
|
||||||
<a href="https://astro.build/themes/">
|
title="Integrations"
|
||||||
<h2>Themes <span>→</span></h2>
|
body="Supercharge your project with new frameworks and libraries."
|
||||||
<p>Explore a galaxy of community-built starters.</p>
|
/>
|
||||||
</a>
|
<Card
|
||||||
</li>
|
href="https://astro.build/themes/"
|
||||||
<li class="link-card">
|
title="Themes"
|
||||||
<a href="https://docs.astro.build/">
|
body="Explore a galaxy of community-built starter themes."
|
||||||
<h2>Docs <span>→</span></h2>
|
/>
|
||||||
<p>Learn our complete feature set and explore the API.</p>
|
<Card
|
||||||
</a>
|
href="https://astro.build/chat/"
|
||||||
</li>
|
title="Chat"
|
||||||
<li class="link-card">
|
body="Come say hi to our amazing Discord community. ❤️"
|
||||||
<a href="https://astro.build/chat/">
|
/>
|
||||||
<h2>Chat <span>→</span></h2>
|
|
||||||
<p>
|
|
||||||
Ask, contribute, and have fun on our community Discord
|
|
||||||
<svg
|
|
||||||
class="heart"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
viewBox="0 0 512 512"
|
|
||||||
width="16"
|
|
||||||
height="16"
|
|
||||||
fill="currentColor"
|
|
||||||
>
|
|
||||||
<title>heart</title>
|
|
||||||
<path d="M256 448l-30.164-27.211C118.718 322.442 48 258.61 48 179.095 48 114.221 97.918 64 162.4 64c36.399 0 70.717 16.742 93.6 43.947C278.882 80.742 313.199 64 349.6 64 414.082 64 464 114.221 464 179.095c0 79.516-70.719 143.348-177.836 241.694L256 448z" />
|
|
||||||
</svg>
|
|
||||||
</p>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</main>
|
</main>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
--color-border: hsl(17, 24%, 90%);
|
--astro-gradient: linear-gradient(0deg, #4f39fa, #da62c4);
|
||||||
--astro-gradient: linear-gradient(0deg,#4F39FA, #DA62C4);
|
|
||||||
--link-gradient: linear-gradient(45deg, #4F39FA, #DA62C4 30%, var(--color-border) 60%);
|
|
||||||
--night-sky-gradient: linear-gradient(0deg, #392362 -33%, #431f69 10%, #30216b 50%, #1f1638 100%);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h1 {
|
||||||
margin: 0;
|
margin: 2rem 0;
|
||||||
transition: color 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 span {
|
|
||||||
display: inline-block;
|
|
||||||
transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
font-size: 0.875em;
|
|
||||||
border: 0.1em solid var(--color-border);
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 0.15em 0.25em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
max-width: 60ch;
|
max-width: 60ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +54,7 @@ import Layout from '../components/Layout.astro';
|
|||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
background-image: var(--astro-gradient);
|
background-image: var(--astro-gradient);
|
||||||
-webkit-background-clip: text;
|
-webkit-background-clip: text;
|
||||||
-webkit-text-fill-color: transparent;
|
-webkit-text-fill-color: transparent;
|
||||||
background-size: 100% 200%;
|
background-size: 100% 200%;
|
||||||
background-position-y: 100%;
|
background-position-y: 100%;
|
||||||
border-radius: 0.4rem;
|
border-radius: 0.4rem;
|
||||||
@@ -91,7 +62,8 @@ import Layout from '../components/Layout.astro';
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes pulse {
|
@keyframes pulse {
|
||||||
0%, 100% {
|
0%,
|
||||||
|
100% {
|
||||||
background-position-y: 0%;
|
background-position-y: 0%;
|
||||||
}
|
}
|
||||||
50% {
|
50% {
|
||||||
@@ -100,75 +72,25 @@ import Layout from '../components/Layout.astro';
|
|||||||
}
|
}
|
||||||
|
|
||||||
.instructions {
|
.instructions {
|
||||||
line-height: 1.8;
|
line-height: 1.6;
|
||||||
margin-bottom: 2rem;
|
margin: 1rem 0;
|
||||||
background-image: var(--night-sky-gradient);
|
background: #4f39fa;
|
||||||
padding: 1.5rem;
|
padding: 1rem;
|
||||||
border-radius: 0.4rem;
|
border-radius: 0.4rem;
|
||||||
color: var(--color-bg);
|
color: var(--color-bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.instructions code {
|
||||||
|
font-size: 0.875em;
|
||||||
|
border: 0.1em solid var(--color-border);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0.15em 0.25em;
|
||||||
|
}
|
||||||
|
|
||||||
.link-card-grid {
|
.link-card-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
|
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-card {
|
|
||||||
list-style: none;
|
|
||||||
display: flex;
|
|
||||||
padding: 0.15rem;
|
|
||||||
background-image: var(--link-gradient);
|
|
||||||
background-size: 400%;
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
background-position: 100%;
|
|
||||||
transition: background-position 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.link-card > a {
|
|
||||||
width: 100%;
|
|
||||||
text-decoration: none;
|
|
||||||
line-height: 1.4;
|
|
||||||
padding: 1em 1.3em;
|
|
||||||
border-radius: 0.35rem;
|
|
||||||
color: var(--text-color);
|
|
||||||
background-color: white;
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link-card:is(:hover, :focus-within) {
|
|
||||||
background-position: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link-card:is(:hover, :focus-within) h2 {
|
|
||||||
color: #4F39FA;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link-card:is(:hover, :focus-within) h2 span {
|
|
||||||
transform: translateX(2px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.heart {
|
|
||||||
display: inline-block;
|
|
||||||
color: #DA62C4;
|
|
||||||
animation: heartbeat 3s ease-in-out infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes heartbeat {
|
|
||||||
0%,
|
|
||||||
50%,
|
|
||||||
100% {
|
|
||||||
transform: scale(1);
|
|
||||||
}
|
|
||||||
5% {
|
|
||||||
transform: scale(1.125);
|
|
||||||
}
|
|
||||||
10% {
|
|
||||||
transform: scale(1.05);
|
|
||||||
}
|
|
||||||
15% {
|
|
||||||
transform: scale(1.25);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
// Enable top-level await, and other modern ESM features.
|
|
||||||
"target": "ESNext",
|
|
||||||
"module": "ESNext",
|
|
||||||
// Enable node-style module resolution, for things like npm package imports.
|
|
||||||
"moduleResolution": "node",
|
|
||||||
// Enable JSON imports.
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
// Enable stricter transpilation for better output.
|
|
||||||
"isolatedModules": true,
|
|
||||||
// Add type definitions for our Vite runtime.
|
|
||||||
"types": ["vite/client"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
9
examples/nextjs/.gitignore
vendored
9
examples/nextjs/.gitignore
vendored
@@ -26,10 +26,11 @@ yarn-error.log*
|
|||||||
.pnpm-debug.log*
|
.pnpm-debug.log*
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env.local
|
.env*.local
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
|
swcMinify: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig
|
||||||
|
|||||||
4882
examples/nextjs/package-lock.json
generated
4882
examples/nextjs/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"name": "nextjs",
|
||||||
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
@@ -7,12 +9,12 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"next": "12.1.4",
|
"next": "12.2.5",
|
||||||
"react": "18.0.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.0.0"
|
"react-dom": "18.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "8.12.0",
|
"eslint": "8.22.0",
|
||||||
"eslint-config-next": "12.1.4"
|
"eslint-config-next": "12.2.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,3 +114,16 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
.card,
|
||||||
|
.footer {
|
||||||
|
border-color: #222;
|
||||||
|
}
|
||||||
|
.code {
|
||||||
|
background: #111;
|
||||||
|
}
|
||||||
|
.logo img {
|
||||||
|
filter: invert(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,3 +14,13 @@ a {
|
|||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
html {
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
color: white;
|
||||||
|
background: black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
1703
examples/nextjs/yarn.lock
Normal file
1703
examples/nextjs/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,21 +8,9 @@ Everything you need to build a Svelte project, powered by [`create-svelte`](http
|
|||||||
|
|
||||||
_Live Example: https://sveltekit-template.vercel.app_
|
_Live Example: https://sveltekit-template.vercel.app_
|
||||||
|
|
||||||
## Creating a project
|
|
||||||
|
|
||||||
If you're seeing this, you've probably already done this step. Congrats!
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# create a new project in the current directory
|
|
||||||
npm init svelte
|
|
||||||
|
|
||||||
# create a new project in my-app
|
|
||||||
npm init svelte my-app
|
|
||||||
```
|
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
|
||||||
Once you've created a project and installed dependencies with `pnpm install`, start a development server:
|
Once you've installed dependencies with `pnpm install`, start a development server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm run dev
|
pnpm run dev
|
||||||
|
|||||||
@@ -10,4 +10,8 @@
|
|||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"strict": true
|
"strict": true
|
||||||
}
|
}
|
||||||
|
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias and https://kit.svelte.dev/docs/configuration#files
|
||||||
|
//
|
||||||
|
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||||
|
// from the referenced tsconfig.json - TypeScript does not merge them in
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "svelte-kit dev",
|
"dev": "vite dev",
|
||||||
"build": "svelte-kit build",
|
"build": "vite build",
|
||||||
"package": "svelte-kit package",
|
"package": "svelte-kit package",
|
||||||
"preview": "svelte-kit preview",
|
"preview": "vite preview",
|
||||||
"prepare": "svelte-kit sync",
|
|
||||||
"check": "svelte-check --tsconfig ./jsconfig.json",
|
"check": "svelte-check --tsconfig ./jsconfig.json",
|
||||||
"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch",
|
"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch",
|
||||||
"lint": "prettier --check --plugin-search-dir=. .",
|
"lint": "prettier --check .",
|
||||||
"format": "prettier --write --plugin-search-dir=. ."
|
"format": "prettier --write ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "1.0.0-next.50",
|
"@sveltejs/adapter-auto": "next",
|
||||||
"@sveltejs/kit": "1.0.0-next.347",
|
"@sveltejs/kit": "next",
|
||||||
"@types/cookie": "^0.4.1",
|
"@types/cookie": "^0.5.1",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.6.2",
|
||||||
"prettier-plugin-svelte": "^2.5.0",
|
"prettier-plugin-svelte": "^2.7.0",
|
||||||
"svelte": "^3.46.0",
|
"svelte": "^3.46.0",
|
||||||
"svelte-check": "^2.2.6",
|
"svelte-check": "^2.7.1",
|
||||||
"typescript": "~4.6.2"
|
"typescript": "^4.7.4",
|
||||||
|
"vite": "^3.0.8"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
1458
examples/sveltekit/pnpm-lock.yaml
generated
Normal file
1458
examples/sveltekit/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
7
examples/sveltekit/src/app.d.ts
vendored
7
examples/sveltekit/src/app.d.ts
vendored
@@ -1,7 +1,6 @@
|
|||||||
/// <reference types="@sveltejs/kit" />
|
|
||||||
|
|
||||||
// See https://kit.svelte.dev/docs/types#app
|
// See https://kit.svelte.dev/docs/types#app
|
||||||
// for information about these interfaces
|
// for information about these interfaces
|
||||||
|
// and what to do when importing types
|
||||||
declare namespace App {
|
declare namespace App {
|
||||||
interface Locals {
|
interface Locals {
|
||||||
userid: string;
|
userid: string;
|
||||||
@@ -9,7 +8,7 @@ declare namespace App {
|
|||||||
|
|
||||||
// interface Platform {}
|
// interface Platform {}
|
||||||
|
|
||||||
// interface Session {}
|
// interface PrivateEnv {}
|
||||||
|
|
||||||
// interface Stuff {}
|
// interface PublicEnv {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,107 +1,107 @@
|
|||||||
<script>
|
<script>
|
||||||
import { spring } from 'svelte/motion';
|
import { spring } from 'svelte/motion';
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
const displayed_count = spring();
|
const displayed_count = spring();
|
||||||
$: displayed_count.set(count);
|
$: displayed_count.set(count);
|
||||||
$: offset = modulo($displayed_count, 1);
|
$: offset = modulo($displayed_count, 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} n
|
* @param {number} n
|
||||||
* @param {number} m
|
* @param {number} m
|
||||||
*/
|
*/
|
||||||
function modulo(n, m) {
|
function modulo(n, m) {
|
||||||
// handle negative numbers
|
// handle negative numbers
|
||||||
return ((n % m) + m) % m;
|
return ((n % m) + m) % m;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="counter">
|
<div class="counter">
|
||||||
<button on:click={() => (count -= 1)} aria-label="Decrease the counter by one">
|
<button on:click={() => (count -= 1)} aria-label="Decrease the counter by one">
|
||||||
<svg aria-hidden="true" viewBox="0 0 1 1">
|
<svg aria-hidden="true" viewBox="0 0 1 1">
|
||||||
<path d="M0,0.5 L1,0.5" />
|
<path d="M0,0.5 L1,0.5" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="counter-viewport">
|
<div class="counter-viewport">
|
||||||
<div class="counter-digits" style="transform: translate(0, {100 * offset}%)">
|
<div class="counter-digits" style="transform: translate(0, {100 * offset}%)">
|
||||||
<strong class="hidden" aria-hidden="true">{Math.floor($displayed_count + 1)}</strong>
|
<strong class="hidden" aria-hidden="true">{Math.floor($displayed_count + 1)}</strong>
|
||||||
<strong>{Math.floor($displayed_count)}</strong>
|
<strong>{Math.floor($displayed_count)}</strong>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button on:click={() => (count += 1)} aria-label="Increase the counter by one">
|
<button on:click={() => (count += 1)} aria-label="Increase the counter by one">
|
||||||
<svg aria-hidden="true" viewBox="0 0 1 1">
|
<svg aria-hidden="true" viewBox="0 0 1 1">
|
||||||
<path d="M0,0.5 L1,0.5 M0.5,0 L0.5,1" />
|
<path d="M0,0.5 L1,0.5 M0.5,0 L0.5,1" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.counter {
|
.counter {
|
||||||
display: flex;
|
display: flex;
|
||||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
margin: 1rem 0;
|
margin: 1rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.counter button {
|
.counter button {
|
||||||
width: 2em;
|
width: 2em;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
border: 0;
|
border: 0;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
touch-action: manipulation;
|
touch-action: manipulation;
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.counter button:hover {
|
.counter button:hover {
|
||||||
background-color: var(--secondary-color);
|
background-color: var(--secondary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: 25%;
|
width: 25%;
|
||||||
height: 25%;
|
height: 25%;
|
||||||
}
|
}
|
||||||
|
|
||||||
path {
|
path {
|
||||||
vector-effect: non-scaling-stroke;
|
vector-effect: non-scaling-stroke;
|
||||||
stroke-width: 2px;
|
stroke-width: 2px;
|
||||||
stroke: var(--text-color);
|
stroke: var(--text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.counter-viewport {
|
.counter-viewport {
|
||||||
width: 8em;
|
width: 8em;
|
||||||
height: 4em;
|
height: 4em;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.counter-viewport strong {
|
.counter-viewport strong {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: var(--accent-color);
|
color: var(--accent-color);
|
||||||
font-size: 4rem;
|
font-size: 4rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.counter-digits {
|
.counter-digits {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
top: -100%;
|
top: -100%;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ import { invalidate } from '$app/navigation';
|
|||||||
export function enhance(form, { pending, error, result } = {}) {
|
export function enhance(form, { pending, error, result } = {}) {
|
||||||
let current_token;
|
let current_token;
|
||||||
|
|
||||||
/** @param {SubmitEvent} e */
|
/** @param {SubmitEvent} event */
|
||||||
async function handle_submit(e) {
|
async function handle_submit(event) {
|
||||||
const token = (current_token = {});
|
const token = (current_token = {});
|
||||||
|
|
||||||
e.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const data = new FormData(form);
|
const data = new FormData(form);
|
||||||
|
|
||||||
@@ -63,11 +63,11 @@ export function enhance(form, { pending, error, result } = {}) {
|
|||||||
} else {
|
} else {
|
||||||
console.error(await response.text());
|
console.error(await response.text());
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (err) {
|
||||||
if (error && e instanceof Error) {
|
if (error && err instanceof Error) {
|
||||||
error({ data, form, error: e, response: null });
|
error({ data, form, error: err, response: null });
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,124 +1,124 @@
|
|||||||
<script>
|
<script>
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import logo from './svelte-logo.svg';
|
import logo from './svelte-logo.svg';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<div class="corner">
|
<div class="corner">
|
||||||
<a href="https://kit.svelte.dev">
|
<a href="https://kit.svelte.dev">
|
||||||
<img src={logo} alt="SvelteKit" />
|
<img src={logo} alt="SvelteKit" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
<svg viewBox="0 0 2 3" aria-hidden="true">
|
<svg viewBox="0 0 2 3" aria-hidden="true">
|
||||||
<path d="M0,0 L1,2 C1.5,3 1.5,3 2,3 L2,0 Z" />
|
<path d="M0,0 L1,2 C1.5,3 1.5,3 2,3 L2,0 Z" />
|
||||||
</svg>
|
</svg>
|
||||||
<ul>
|
<ul>
|
||||||
<li class:active={$page.url.pathname === '/'}><a sveltekit:prefetch href="/">Home</a></li>
|
<li class:active={$page.url.pathname === '/'}><a sveltekit:prefetch href="/">Home</a></li>
|
||||||
<li class:active={$page.url.pathname === '/about'}>
|
<li class:active={$page.url.pathname === '/about'}>
|
||||||
<a sveltekit:prefetch href="/about">About</a>
|
<a sveltekit:prefetch href="/about">About</a>
|
||||||
</li>
|
</li>
|
||||||
<li class:active={$page.url.pathname === '/todos'}>
|
<li class:active={$page.url.pathname === '/todos'}>
|
||||||
<a sveltekit:prefetch href="/todos">Todos</a>
|
<a sveltekit:prefetch href="/todos">Todos</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<svg viewBox="0 0 2 3" aria-hidden="true">
|
<svg viewBox="0 0 2 3" aria-hidden="true">
|
||||||
<path d="M0,0 L0,3 C0.5,3 0.5,3 1,2 L2,0 Z" />
|
<path d="M0,0 L0,3 C0.5,3 0.5,3 1,2 L2,0 Z" />
|
||||||
</svg>
|
</svg>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="corner">
|
<div class="corner">
|
||||||
<!-- TODO put something else here? github link? -->
|
<!-- TODO put something else here? github link? -->
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
header {
|
header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
.corner {
|
.corner {
|
||||||
width: 3em;
|
width: 3em;
|
||||||
height: 3em;
|
height: 3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.corner a {
|
.corner a {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.corner img {
|
.corner img {
|
||||||
width: 2em;
|
width: 2em;
|
||||||
height: 2em;
|
height: 2em;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
--background: rgba(255, 255, 255, 0.7);
|
--background: rgba(255, 255, 255, 0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: 2em;
|
width: 2em;
|
||||||
height: 3em;
|
height: 3em;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
path {
|
path {
|
||||||
fill: var(--background);
|
fill: var(--background);
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
height: 3em;
|
height: 3em;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
background: var(--background);
|
background: var(--background);
|
||||||
background-size: contain;
|
background-size: contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
li {
|
li {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
li.active::before {
|
li.active::before {
|
||||||
--size: 6px;
|
--size: 6px;
|
||||||
content: '';
|
content: '';
|
||||||
width: 0;
|
width: 0;
|
||||||
height: 0;
|
height: 0;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: calc(50% - var(--size));
|
left: calc(50% - var(--size));
|
||||||
border: var(--size) solid transparent;
|
border: var(--size) solid transparent;
|
||||||
border-top: var(--size) solid var(--accent-color);
|
border-top: var(--size) solid var(--accent-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
nav a {
|
nav a {
|
||||||
display: flex;
|
display: flex;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 1em;
|
padding: 0 1em;
|
||||||
color: var(--heading-color);
|
color: var(--heading-color);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
letter-spacing: 0.1em;
|
letter-spacing: 0.1em;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
transition: color 0.2s linear;
|
transition: color 0.2s linear;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
color: var(--accent-color);
|
color: var(--accent-color);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
58
examples/sveltekit/src/routes/+layout.svelte
Normal file
58
examples/sveltekit/src/routes/+layout.svelte
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<script>
|
||||||
|
import Header from '$lib/header/Header.svelte';
|
||||||
|
import { webVitals } from '$lib/vitals';
|
||||||
|
import { browser } from '$app/env';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import '../app.css';
|
||||||
|
|
||||||
|
let analyticsId = import.meta.env.VERCEL_ANALYTICS_ID;
|
||||||
|
|
||||||
|
$: if (browser && analyticsId) {
|
||||||
|
webVitals({
|
||||||
|
path: $page.url.pathname,
|
||||||
|
params: $page.params,
|
||||||
|
analyticsId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Header />
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<slot />
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to learn SvelteKit</p>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
main {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 1rem;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 1024px;
|
||||||
|
margin: 0 auto;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer a {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 480px) {
|
||||||
|
footer {
|
||||||
|
padding: 40px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
1
examples/sveltekit/src/routes/+page.js
Normal file
1
examples/sveltekit/src/routes/+page.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const prerender = true;
|
||||||
57
examples/sveltekit/src/routes/+page.svelte
Normal file
57
examples/sveltekit/src/routes/+page.svelte
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<script>
|
||||||
|
import Counter from '$lib/Counter.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Home</title>
|
||||||
|
<meta name="description" content="Svelte demo app" />
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h1>
|
||||||
|
<span class="welcome">
|
||||||
|
<picture>
|
||||||
|
<source srcset="svelte-welcome.webp" type="image/webp" />
|
||||||
|
<img src="svelte-welcome.png" alt="Welcome" />
|
||||||
|
</picture>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
to your new<br />SvelteKit app
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
try editing <strong>src/routes/index.svelte</strong>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<Counter />
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 0;
|
||||||
|
padding: 0 0 calc(100% * 495 / 2048) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome img {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
top: 0;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<script>
|
|
||||||
import Header from '$lib/header/Header.svelte';
|
|
||||||
import { webVitals } from '$lib/vitals';
|
|
||||||
import { browser } from '$app/env';
|
|
||||||
import { page } from '$app/stores';
|
|
||||||
import '../app.css';
|
|
||||||
|
|
||||||
let analyticsId = import.meta.env.VERCEL_ANALYTICS_ID;
|
|
||||||
|
|
||||||
$: if (browser && analyticsId) {
|
|
||||||
webVitals({
|
|
||||||
path: $page.url.pathname,
|
|
||||||
params: $page.params,
|
|
||||||
analyticsId
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<Header />
|
|
||||||
|
|
||||||
<main>
|
|
||||||
<slot />
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer>
|
|
||||||
<p>visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to learn SvelteKit</p>
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
main {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 1rem;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 1024px;
|
|
||||||
margin: 0 auto;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
padding: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer a {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 480px) {
|
|
||||||
footer {
|
|
||||||
padding: 40px 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
<script context="module">
|
|
||||||
import { browser, dev } from '$app/env';
|
|
||||||
|
|
||||||
// we don't need any JS on this page, though we'll load
|
|
||||||
// it in dev so that we get hot module replacement...
|
|
||||||
export const hydrate = dev;
|
|
||||||
|
|
||||||
// ...but if the client-side router is already loaded
|
|
||||||
// (i.e. we came here from elsewhere in the app), use it
|
|
||||||
export const router = browser;
|
|
||||||
|
|
||||||
// since there's no dynamic data here, we can prerender
|
|
||||||
// it so that it gets served as a static asset in prod
|
|
||||||
export const prerender = true;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>About</title>
|
|
||||||
<meta name="description" content="About this app" />
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<div class="content">
|
|
||||||
<h1>About this app</h1>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
This is a <a href="https://kit.svelte.dev">SvelteKit</a> app. You can make your own by typing the
|
|
||||||
following into your command line and following the prompts:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre>npm init svelte</pre>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
The page you're looking at is purely static HTML, with no client-side interactivity needed.
|
|
||||||
Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening
|
|
||||||
the devtools network panel and reloading.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
The <a href="/todos">TODOs</a> page illustrates SvelteKit's data loading and form handling. Try using
|
|
||||||
it with JavaScript disabled!
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.content {
|
|
||||||
width: 100%;
|
|
||||||
max-width: var(--column-width);
|
|
||||||
margin: var(--column-margin-top) auto 0 auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
13
examples/sveltekit/src/routes/about/+page.js
Normal file
13
examples/sveltekit/src/routes/about/+page.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { browser, dev } from '$app/env';
|
||||||
|
|
||||||
|
// we don't need any JS on this page, though we'll load
|
||||||
|
// it in dev so that we get hot module replacement...
|
||||||
|
export const hydrate = dev;
|
||||||
|
|
||||||
|
// ...but if the client-side router is already loaded
|
||||||
|
// (i.e. we came here from elsewhere in the app), use it
|
||||||
|
export const router = browser;
|
||||||
|
|
||||||
|
// since there's no dynamic data here, we can prerender
|
||||||
|
// it so that it gets served as a static asset in prod
|
||||||
|
export const prerender = true;
|
||||||
34
examples/sveltekit/src/routes/about/+page.svelte
Normal file
34
examples/sveltekit/src/routes/about/+page.svelte
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<svelte:head>
|
||||||
|
<title>About</title>
|
||||||
|
<meta name="description" content="About this app" />
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<h1>About this app</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This is a <a href="https://kit.svelte.dev">SvelteKit</a> app. You can make your own by typing the
|
||||||
|
following into your command line and following the prompts:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>npm create svelte@latest</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The page you're looking at is purely static HTML, with no client-side interactivity needed.
|
||||||
|
Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening
|
||||||
|
the devtools network panel and reloading.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The <a href="/todos">TODOs</a> page illustrates SvelteKit's data loading and form handling. Try using
|
||||||
|
it with JavaScript disabled!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.content {
|
||||||
|
width: 100%;
|
||||||
|
max-width: var(--column-width);
|
||||||
|
margin: var(--column-margin-top) auto 0 auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<script context="module">
|
|
||||||
export const prerender = true;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import Counter from '$lib/Counter.svelte';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>Home</title>
|
|
||||||
<meta name="description" content="Svelte demo app" />
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<h1>
|
|
||||||
<div class="welcome">
|
|
||||||
<picture>
|
|
||||||
<source srcset="svelte-welcome.webp" type="image/webp" />
|
|
||||||
<img src="svelte-welcome.png" alt="Welcome" />
|
|
||||||
</picture>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
to your new<br />SvelteKit app
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<h2>
|
|
||||||
try editing <strong>src/routes/index.svelte</strong>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<Counter />
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
section {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.welcome {
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
height: 0;
|
|
||||||
padding: 0 0 calc(100% * 495 / 2048) 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.welcome img {
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
top: 0;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
62
examples/sveltekit/src/routes/todos/+page.server.js
Normal file
62
examples/sveltekit/src/routes/todos/+page.server.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
import { api } from './api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{
|
||||||
|
* uid: string;
|
||||||
|
* created_at: Date;
|
||||||
|
* text: string;
|
||||||
|
* done: boolean;
|
||||||
|
* pending_delete: boolean;
|
||||||
|
* }} Todo
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @type {import('./$types').PageServerLoad} */
|
||||||
|
export const load = async ({ locals }) => {
|
||||||
|
// locals.userid comes from src/hooks.js
|
||||||
|
const response = await api('GET', `todos/${locals.userid}`);
|
||||||
|
|
||||||
|
if (response.status === 404) {
|
||||||
|
// user hasn't created a todo list.
|
||||||
|
// start with an empty array
|
||||||
|
return {
|
||||||
|
/** @type {Todo[]} */
|
||||||
|
todos: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
return {
|
||||||
|
/** @type {Todo[]} */
|
||||||
|
todos: await response.json()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error(response.status);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {import('./$types').Action} */
|
||||||
|
export const POST = async ({ request, locals }) => {
|
||||||
|
const form = await request.formData();
|
||||||
|
|
||||||
|
await api('POST', `todos/${locals.userid}`, {
|
||||||
|
text: form.get('text')
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {import('./$types').Action} */
|
||||||
|
export const PATCH = async ({ request, locals }) => {
|
||||||
|
const form = await request.formData();
|
||||||
|
|
||||||
|
await api('PATCH', `todos/${locals.userid}/${form.get('uid')}`, {
|
||||||
|
text: form.has('text') ? form.get('text') : undefined,
|
||||||
|
done: form.has('done') ? !!form.get('done') : undefined
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {import('./$types').Action} */
|
||||||
|
export const DELETE = async ({ request, locals }) => {
|
||||||
|
const form = await request.formData();
|
||||||
|
|
||||||
|
await api('DELETE', `todos/${locals.userid}/${form.get('uid')}`);
|
||||||
|
};
|
||||||
180
examples/sveltekit/src/routes/todos/+page.svelte
Normal file
180
examples/sveltekit/src/routes/todos/+page.svelte
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
<script>
|
||||||
|
import { enhance } from '$lib/form';
|
||||||
|
import { scale } from 'svelte/transition';
|
||||||
|
import { flip } from 'svelte/animate';
|
||||||
|
|
||||||
|
/** @type {import('./$types').PageData} */
|
||||||
|
export let data;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Todos</title>
|
||||||
|
<meta name="description" content="A todo list app" />
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<div class="todos">
|
||||||
|
<h1>Todos</h1>
|
||||||
|
|
||||||
|
<form
|
||||||
|
class="new"
|
||||||
|
action="/todos"
|
||||||
|
method="post"
|
||||||
|
use:enhance={{
|
||||||
|
result: async ({ form }) => {
|
||||||
|
form.reset();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input name="text" aria-label="Add todo" placeholder="+ tap to add a todo" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{#each data.todos as todo (todo.uid)}
|
||||||
|
<div
|
||||||
|
class="todo"
|
||||||
|
class:done={todo.done}
|
||||||
|
transition:scale|local={{ start: 0.7 }}
|
||||||
|
animate:flip={{ duration: 200 }}
|
||||||
|
>
|
||||||
|
<form
|
||||||
|
action="/todos?_method=PATCH"
|
||||||
|
method="post"
|
||||||
|
use:enhance={{
|
||||||
|
pending: ({ data }) => {
|
||||||
|
todo.done = !!data.get('done');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input type="hidden" name="uid" value={todo.uid} />
|
||||||
|
<input type="hidden" name="done" value={todo.done ? '' : 'true'} />
|
||||||
|
<button class="toggle" aria-label="Mark todo as {todo.done ? 'not done' : 'done'}" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form class="text" action="/todos?_method=PATCH" method="post" use:enhance>
|
||||||
|
<input type="hidden" name="uid" value={todo.uid} />
|
||||||
|
<input aria-label="Edit todo" type="text" name="text" value={todo.text} />
|
||||||
|
<button class="save" aria-label="Save todo" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form
|
||||||
|
action="/todos?_method=DELETE"
|
||||||
|
method="post"
|
||||||
|
use:enhance={{
|
||||||
|
pending: () => (todo.pending_delete = true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input type="hidden" name="uid" value={todo.uid} />
|
||||||
|
<button class="delete" aria-label="Delete todo" disabled={todo.pending_delete} />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.todos {
|
||||||
|
width: 100%;
|
||||||
|
max-width: var(--column-width);
|
||||||
|
margin: var(--column-margin-top) auto 0 auto;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
border: 1px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus-visible {
|
||||||
|
box-shadow: inset 1px 1px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
border: 1px solid #ff3e00 !important;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new input {
|
||||||
|
font-size: 28px;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5em 1em 0.3em 1em;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
border-radius: 8px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 2rem 1fr 2rem;
|
||||||
|
grid-gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background-color: white;
|
||||||
|
border-radius: 8px;
|
||||||
|
filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.1));
|
||||||
|
transform: translate(-1px, -1px);
|
||||||
|
transition: filter 0.2s, transform 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.done {
|
||||||
|
transform: none;
|
||||||
|
opacity: 0.4;
|
||||||
|
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.1));
|
||||||
|
}
|
||||||
|
|
||||||
|
form.text {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 0.5em 2em 0.5em 0.8em;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo button {
|
||||||
|
width: 2em;
|
||||||
|
height: 2em;
|
||||||
|
border: none;
|
||||||
|
background-color: transparent;
|
||||||
|
background-position: 50% 50%;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.toggle {
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||||
|
border-radius: 50%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background-size: 1em auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.done .toggle {
|
||||||
|
background-image: url("data:image/svg+xml,%3Csvg width='22' height='16' viewBox='0 0 22 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20.5 1.5L7.4375 14.5L1.5 8.5909' stroke='%23676778' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete {
|
||||||
|
background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4.5 5V22H19.5V5H4.5Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M10 10V16.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M14 10V16.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M2 5H22' stroke='%23676778' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M8 5L9.6445 2H14.3885L16 5H8Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E%0A");
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete:hover,
|
||||||
|
.delete:focus {
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
opacity: 0;
|
||||||
|
background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20.5 2H3.5C2.67158 2 2 2.67157 2 3.5V20.5C2 21.3284 2.67158 22 3.5 22H20.5C21.3284 22 22 21.3284 22 20.5V3.5C22 2.67157 21.3284 2 20.5 2Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M17 2V11H7.5V2H17Z' fill='white' stroke='white' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M13.5 5.5V7.5' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3Cpath d='M5.99844 2H18.4992' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E%0A");
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo input:focus + .save,
|
||||||
|
.save:focus {
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This module is used by the /todos endpoint to
|
This module is used by the /todos endpoint to
|
||||||
make calls to api.svelte.dev, which stores todos
|
make calls to api.svelte.dev, which stores todos
|
||||||
for each user. The leading underscore indicates that this is
|
for each user.
|
||||||
a private module, _not_ an endpoint — visiting /todos/_api
|
|
||||||
will net you a 404 response.
|
|
||||||
|
|
||||||
(The data on the todo app will expire periodically; no
|
(The data on the todo app will expire periodically; no
|
||||||
guarantees are made. Don't use it to organise your life.)
|
guarantees are made. Don't use it to organise your life.)
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import { api } from './_api';
|
|
||||||
|
|
||||||
/** @type {import('./__types').RequestHandler} */
|
|
||||||
export const get = async ({ locals }) => {
|
|
||||||
// locals.userid comes from src/hooks.js
|
|
||||||
const response = await api('get', `todos/${locals.userid}`);
|
|
||||||
|
|
||||||
if (response.status === 404) {
|
|
||||||
// user hasn't created a todo list.
|
|
||||||
// start with an empty array
|
|
||||||
return {
|
|
||||||
body: {
|
|
||||||
todos: []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.status === 200) {
|
|
||||||
return {
|
|
||||||
body: {
|
|
||||||
todos: await response.json()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: response.status
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @type {import('./index').RequestHandler} */
|
|
||||||
export const post = async ({ request, locals }) => {
|
|
||||||
const form = await request.formData();
|
|
||||||
|
|
||||||
await api('post', `todos/${locals.userid}`, {
|
|
||||||
text: form.get('text')
|
|
||||||
});
|
|
||||||
|
|
||||||
return {};
|
|
||||||
};
|
|
||||||
|
|
||||||
// If the user has JavaScript disabled, the URL will change to
|
|
||||||
// include the method override unless we redirect back to /todos
|
|
||||||
const redirect = {
|
|
||||||
status: 303,
|
|
||||||
headers: {
|
|
||||||
location: '/todos'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @type {import('./index').RequestHandler} */
|
|
||||||
export const patch = async ({ request, locals }) => {
|
|
||||||
const form = await request.formData();
|
|
||||||
|
|
||||||
await api('patch', `todos/${locals.userid}/${form.get('uid')}`, {
|
|
||||||
text: form.has('text') ? form.get('text') : undefined,
|
|
||||||
done: form.has('done') ? !!form.get('done') : undefined
|
|
||||||
});
|
|
||||||
|
|
||||||
return redirect;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @type {import('./index').RequestHandler} */
|
|
||||||
export const del = async ({ request, locals }) => {
|
|
||||||
const form = await request.formData();
|
|
||||||
|
|
||||||
await api('delete', `todos/${locals.userid}/${form.get('uid')}`);
|
|
||||||
|
|
||||||
return redirect;
|
|
||||||
};
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
<script>
|
|
||||||
import { enhance } from '$lib/form';
|
|
||||||
import { scale } from 'svelte/transition';
|
|
||||||
import { flip } from 'svelte/animate';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {{
|
|
||||||
* uid: string;
|
|
||||||
* created_at: Date;
|
|
||||||
* text: string;
|
|
||||||
* done: boolean;
|
|
||||||
* pending_delete: boolean;
|
|
||||||
* }} Todo
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @type {Todo[]} */
|
|
||||||
export let todos;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>Todos</title>
|
|
||||||
<meta name="description" content="A todo list app" />
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<div class="todos">
|
|
||||||
<h1>Todos</h1>
|
|
||||||
|
|
||||||
<form
|
|
||||||
class="new"
|
|
||||||
action="/todos"
|
|
||||||
method="post"
|
|
||||||
use:enhance={{
|
|
||||||
result: async ({ form }) => {
|
|
||||||
form.reset();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input name="text" aria-label="Add todo" placeholder="+ tap to add a todo" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{#each todos as todo (todo.uid)}
|
|
||||||
<div
|
|
||||||
class="todo"
|
|
||||||
class:done={todo.done}
|
|
||||||
transition:scale|local={{ start: 0.7 }}
|
|
||||||
animate:flip={{ duration: 200 }}
|
|
||||||
>
|
|
||||||
<form
|
|
||||||
action="/todos?_method=PATCH"
|
|
||||||
method="post"
|
|
||||||
use:enhance={{
|
|
||||||
pending: ({ data }) => {
|
|
||||||
todo.done = !!data.get('done');
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input type="hidden" name="uid" value={todo.uid} />
|
|
||||||
<input type="hidden" name="done" value={todo.done ? '' : 'true'} />
|
|
||||||
<button class="toggle" aria-label="Mark todo as {todo.done ? 'not done' : 'done'}" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form class="text" action="/todos?_method=PATCH" method="post" use:enhance>
|
|
||||||
<input type="hidden" name="uid" value={todo.uid} />
|
|
||||||
<input aria-label="Edit todo" type="text" name="text" value={todo.text} />
|
|
||||||
<button class="save" aria-label="Save todo" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form
|
|
||||||
action="/todos?_method=DELETE"
|
|
||||||
method="post"
|
|
||||||
use:enhance={{
|
|
||||||
pending: () => (todo.pending_delete = true)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input type="hidden" name="uid" value={todo.uid} />
|
|
||||||
<button class="delete" aria-label="Delete todo" disabled={todo.pending_delete} />
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.todos {
|
|
||||||
width: 100%;
|
|
||||||
max-width: var(--column-width);
|
|
||||||
margin: var(--column-margin-top) auto 0 auto;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.new {
|
|
||||||
margin: 0 0 0.5rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
border: 1px solid transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
input:focus-visible {
|
|
||||||
box-shadow: inset 1px 1px 6px rgba(0, 0, 0, 0.1);
|
|
||||||
border: 1px solid #ff3e00 !important;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.new input {
|
|
||||||
font-size: 28px;
|
|
||||||
width: 100%;
|
|
||||||
padding: 0.5em 1em 0.3em 1em;
|
|
||||||
box-sizing: border-box;
|
|
||||||
background: rgba(255, 255, 255, 0.05);
|
|
||||||
border-radius: 8px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.todo {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 2rem 1fr 2rem;
|
|
||||||
grid-gap: 0.5rem;
|
|
||||||
align-items: center;
|
|
||||||
margin: 0 0 0.5rem 0;
|
|
||||||
padding: 0.5rem;
|
|
||||||
background-color: white;
|
|
||||||
border-radius: 8px;
|
|
||||||
filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.1));
|
|
||||||
transform: translate(-1px, -1px);
|
|
||||||
transition: filter 0.2s, transform 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.done {
|
|
||||||
transform: none;
|
|
||||||
opacity: 0.4;
|
|
||||||
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.1));
|
|
||||||
}
|
|
||||||
|
|
||||||
form.text {
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.todo input {
|
|
||||||
flex: 1;
|
|
||||||
padding: 0.5em 2em 0.5em 0.8em;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.todo button {
|
|
||||||
width: 2em;
|
|
||||||
height: 2em;
|
|
||||||
border: none;
|
|
||||||
background-color: transparent;
|
|
||||||
background-position: 50% 50%;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
button.toggle {
|
|
||||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
|
||||||
border-radius: 50%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
background-size: 1em auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.done .toggle {
|
|
||||||
background-image: url("data:image/svg+xml,%3Csvg width='22' height='16' viewBox='0 0 22 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20.5 1.5L7.4375 14.5L1.5 8.5909' stroke='%23676778' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
|
||||||
}
|
|
||||||
|
|
||||||
.delete {
|
|
||||||
background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4.5 5V22H19.5V5H4.5Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M10 10V16.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M14 10V16.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M2 5H22' stroke='%23676778' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M8 5L9.6445 2H14.3885L16 5H8Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E%0A");
|
|
||||||
opacity: 0.2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.delete:hover,
|
|
||||||
.delete:focus {
|
|
||||||
transition: opacity 0.2s;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.save {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
opacity: 0;
|
|
||||||
background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20.5 2H3.5C2.67158 2 2 2.67157 2 3.5V20.5C2 21.3284 2.67158 22 3.5 22H20.5C21.3284 22 22 21.3284 22 20.5V3.5C22 2.67157 21.3284 2 20.5 2Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M17 2V11H7.5V2H17Z' fill='white' stroke='white' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M13.5 5.5V7.5' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3Cpath d='M5.99844 2H18.4992' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E%0A");
|
|
||||||
}
|
|
||||||
|
|
||||||
.todo input:focus + .save,
|
|
||||||
.save:focus {
|
|
||||||
transition: opacity 0.2s;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -8,11 +8,6 @@ const config = {
|
|||||||
// Override http methods in the Todo forms
|
// Override http methods in the Todo forms
|
||||||
methodOverride: {
|
methodOverride: {
|
||||||
allowed: ['PATCH', 'DELETE']
|
allowed: ['PATCH', 'DELETE']
|
||||||
},
|
|
||||||
vite: {
|
|
||||||
define: {
|
|
||||||
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
11
examples/sveltekit/vite.config.js
Normal file
11
examples/sveltekit/vite.config.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
|
||||||
|
/** @type {import('vite').UserConfig} */
|
||||||
|
const config = {
|
||||||
|
plugins: [sveltekit()],
|
||||||
|
define: {
|
||||||
|
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,10 @@
|
|||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"nohoist": [
|
"nohoist": [
|
||||||
"**/@types/**"
|
"**/@types/**",
|
||||||
|
"**/typedoc",
|
||||||
|
"**/typedoc-plugin-markdown",
|
||||||
|
"**/typedoc-plugin-mdn-links"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -99,6 +102,7 @@
|
|||||||
"selector": "MemberExpression > Identifier[name='substr']"
|
"selector": "MemberExpression > Identifier[name='substr']"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"no-dupe-keys": 2,
|
||||||
"require-atomic-updates": 0,
|
"require-atomic-updates": 0,
|
||||||
"@typescript-eslint/ban-ts-comment": 0,
|
"@typescript-eslint/ban-ts-comment": 0,
|
||||||
"@typescript-eslint/camelcase": 0,
|
"@typescript-eslint/camelcase": 0,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vercel/build-utils",
|
"name": "@vercel/build-utils",
|
||||||
"version": "5.1.1",
|
"version": "5.4.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.js",
|
"types": "./dist/index.d.js",
|
||||||
|
|||||||
@@ -3,5 +3,7 @@ import { getPlatformEnv } from './get-platform-env';
|
|||||||
export default function debug(message: string, ...additional: any[]) {
|
export default function debug(message: string, ...additional: any[]) {
|
||||||
if (getPlatformEnv('BUILDER_DEBUG')) {
|
if (getPlatformEnv('BUILDER_DEBUG')) {
|
||||||
console.log(message, ...additional);
|
console.log(message, ...additional);
|
||||||
|
} else if (process.env.VERCEL_DEBUG_PREFIX) {
|
||||||
|
console.log(`${process.env.VERCEL_DEBUG_PREFIX}${message}`, ...additional);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,13 @@ import FileFsRef from '../file-fs-ref';
|
|||||||
|
|
||||||
export type GlobOptions = vanillaGlob_.IOptions;
|
export type GlobOptions = vanillaGlob_.IOptions;
|
||||||
|
|
||||||
interface FsFiles {
|
|
||||||
[filePath: string]: FileFsRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
const vanillaGlob = promisify(vanillaGlob_);
|
const vanillaGlob = promisify(vanillaGlob_);
|
||||||
|
|
||||||
export default async function glob(
|
export default async function glob(
|
||||||
pattern: string,
|
pattern: string,
|
||||||
opts: GlobOptions | string,
|
opts: GlobOptions | string,
|
||||||
mountpoint?: string
|
mountpoint?: string
|
||||||
): Promise<FsFiles> {
|
): Promise<Record<string, FileFsRef>> {
|
||||||
let options: GlobOptions;
|
let options: GlobOptions;
|
||||||
if (typeof opts === 'string') {
|
if (typeof opts === 'string') {
|
||||||
options = { cwd: opts };
|
options = { cwd: opts };
|
||||||
@@ -36,10 +32,11 @@ export default async function glob(
|
|||||||
throw new Error(`basePath/cwd must be an absolute path (${options.cwd})`);
|
throw new Error(`basePath/cwd must be an absolute path (${options.cwd})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const results: FsFiles = {};
|
const results: Record<string, FileFsRef> = {};
|
||||||
|
const statCache: Record<string, Stats> = {};
|
||||||
|
|
||||||
options.symlinks = {};
|
options.symlinks = {};
|
||||||
options.statCache = {};
|
options.statCache = statCache;
|
||||||
options.stat = true;
|
options.stat = true;
|
||||||
options.dot = true;
|
options.dot = true;
|
||||||
|
|
||||||
@@ -47,7 +44,7 @@ export default async function glob(
|
|||||||
|
|
||||||
for (const relativePath of files) {
|
for (const relativePath of files) {
|
||||||
const fsPath = normalizePath(path.join(options.cwd, relativePath));
|
const fsPath = normalizePath(path.join(options.cwd, relativePath));
|
||||||
let stat: Stats = options.statCache[fsPath] as Stats;
|
let stat = statCache[fsPath];
|
||||||
assert(
|
assert(
|
||||||
stat,
|
stat,
|
||||||
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
|
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const allOptions = [
|
|||||||
major: 12,
|
major: 12,
|
||||||
range: '12.x',
|
range: '12.x',
|
||||||
runtime: 'nodejs12.x',
|
runtime: 'nodejs12.x',
|
||||||
discontinueDate: new Date('2022-08-09'),
|
discontinueDate: new Date('2022-10-01'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
major: 10,
|
major: 10,
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ export interface ScanParentDirsResult {
|
|||||||
*/
|
*/
|
||||||
cliType: CliType;
|
cliType: CliType;
|
||||||
/**
|
/**
|
||||||
* The file path of found `package.json` file, or `undefined` if none was
|
* The file path of found `package.json` file, or `undefined` if not found.
|
||||||
* found.
|
|
||||||
*/
|
*/
|
||||||
packageJsonPath?: string;
|
packageJsonPath?: string;
|
||||||
/**
|
/**
|
||||||
@@ -33,8 +32,13 @@ export interface ScanParentDirsResult {
|
|||||||
*/
|
*/
|
||||||
packageJson?: PackageJson;
|
packageJson?: PackageJson;
|
||||||
/**
|
/**
|
||||||
* The `lockfileVersion` number from the `package-lock.json` file,
|
* The file path of the lockfile (`yarn.lock`, `package-lock.json`, or `pnpm-lock.yaml`)
|
||||||
* when present.
|
* or `undefined` if not found.
|
||||||
|
*/
|
||||||
|
lockfilePath?: string;
|
||||||
|
/**
|
||||||
|
* The `lockfileVersion` number from lockfile (`package-lock.json` or `pnpm-lock.yaml`),
|
||||||
|
* or `undefined` if not found.
|
||||||
*/
|
*/
|
||||||
lockfileVersion?: number;
|
lockfileVersion?: number;
|
||||||
}
|
}
|
||||||
@@ -178,25 +182,9 @@ export async function getNodeBinPath({
|
|||||||
}: {
|
}: {
|
||||||
cwd: string;
|
cwd: string;
|
||||||
}): Promise<string> {
|
}): Promise<string> {
|
||||||
const { code, stdout, stderr } = await execAsync('npm', ['bin'], {
|
const { lockfilePath } = await scanParentDirs(cwd);
|
||||||
cwd,
|
const dir = path.dirname(lockfilePath || cwd);
|
||||||
prettyCommand: 'npm bin',
|
return path.join(dir, 'node_modules', '.bin');
|
||||||
|
|
||||||
// in some rare cases, we saw `npm bin` exit with a non-0 code, but still
|
|
||||||
// output the right bin path, so we ignore the exit code
|
|
||||||
ignoreNon0Exit: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const nodeBinPath = stdout.trim();
|
|
||||||
|
|
||||||
if (path.isAbsolute(nodeBinPath)) {
|
|
||||||
return nodeBinPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NowBuildError({
|
|
||||||
code: `BUILD_UTILS_GET_NODE_BIN_PATH`,
|
|
||||||
message: `Running \`npm bin\` failed to return a valid bin path (code=${code}, stdout=${stdout}, stderr=${stderr})`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function chmodPlusX(fsPath: string) {
|
async function chmodPlusX(fsPath: string) {
|
||||||
@@ -319,6 +307,7 @@ export async function scanParentDirs(
|
|||||||
start: destPath,
|
start: destPath,
|
||||||
filenames: ['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'],
|
filenames: ['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'],
|
||||||
});
|
});
|
||||||
|
let lockfilePath: string | undefined;
|
||||||
let lockfileVersion: number | undefined;
|
let lockfileVersion: number | undefined;
|
||||||
let cliType: CliType = 'yarn';
|
let cliType: CliType = 'yarn';
|
||||||
|
|
||||||
@@ -335,17 +324,25 @@ export async function scanParentDirs(
|
|||||||
// Priority order is Yarn > pnpm > npm
|
// Priority order is Yarn > pnpm > npm
|
||||||
if (hasYarnLock) {
|
if (hasYarnLock) {
|
||||||
cliType = 'yarn';
|
cliType = 'yarn';
|
||||||
|
lockfilePath = yarnLockPath;
|
||||||
} else if (pnpmLockYaml) {
|
} else if (pnpmLockYaml) {
|
||||||
cliType = 'pnpm';
|
cliType = 'pnpm';
|
||||||
// just ensure that it is read as a number and not a string
|
lockfilePath = pnpmLockPath;
|
||||||
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
||||||
} else if (packageLockJson) {
|
} else if (packageLockJson) {
|
||||||
cliType = 'npm';
|
cliType = 'npm';
|
||||||
|
lockfilePath = npmLockPath;
|
||||||
lockfileVersion = packageLockJson.lockfileVersion;
|
lockfileVersion = packageLockJson.lockfileVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageJsonPath = pkgJsonPath || undefined;
|
const packageJsonPath = pkgJsonPath || undefined;
|
||||||
return { cliType, packageJson, lockfileVersion, packageJsonPath };
|
return {
|
||||||
|
cliType,
|
||||||
|
packageJson,
|
||||||
|
lockfilePath,
|
||||||
|
lockfileVersion,
|
||||||
|
packageJsonPath,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function walkParentDirs({
|
export async function walkParentDirs({
|
||||||
|
|||||||
32
packages/build-utils/src/get-prefixed-env-vars.ts
Normal file
32
packages/build-utils/src/get-prefixed-env-vars.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
type Envs = { [key: string]: string | undefined };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the framework-specific prefixed System Environment Variables.
|
||||||
|
* See https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables
|
||||||
|
* @param envPrefix - Prefix, typically from `@vercel/frameworks`
|
||||||
|
* @param envs - Environment Variables, typically from `process.env`
|
||||||
|
*/
|
||||||
|
export function getPrefixedEnvVars({
|
||||||
|
envPrefix,
|
||||||
|
envs,
|
||||||
|
}: {
|
||||||
|
envPrefix: string | undefined;
|
||||||
|
envs: Envs;
|
||||||
|
}): Envs {
|
||||||
|
const vercelSystemEnvPrefix = 'VERCEL_';
|
||||||
|
const newEnvs: Envs = {};
|
||||||
|
if (envPrefix && envs.VERCEL_URL) {
|
||||||
|
Object.keys(envs)
|
||||||
|
.filter(key => key.startsWith(vercelSystemEnvPrefix))
|
||||||
|
.forEach(key => {
|
||||||
|
const newKey = `${envPrefix}${key}`;
|
||||||
|
if (!(newKey in envs)) {
|
||||||
|
newEnvs[newKey] = envs[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Tell turbo to exclude all Vercel System Env Vars
|
||||||
|
// See https://github.com/vercel/turborepo/pull/1622
|
||||||
|
newEnvs.TURBO_CI_VENDOR_ENV_KEY = `${envPrefix}${vercelSystemEnvPrefix}`;
|
||||||
|
}
|
||||||
|
return newEnvs;
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ import streamToBuffer from './fs/stream-to-buffer';
|
|||||||
import debug from './debug';
|
import debug from './debug';
|
||||||
import getIgnoreFilter from './get-ignore-filter';
|
import getIgnoreFilter from './get-ignore-filter';
|
||||||
import { getPlatformEnv } from './get-platform-env';
|
import { getPlatformEnv } from './get-platform-env';
|
||||||
|
import { getPrefixedEnvVars } from './get-prefixed-env-vars';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
FileBlob,
|
FileBlob,
|
||||||
@@ -76,6 +77,7 @@ export {
|
|||||||
getDiscontinuedNodeVersions,
|
getDiscontinuedNodeVersions,
|
||||||
getSpawnOptions,
|
getSpawnOptions,
|
||||||
getPlatformEnv,
|
getPlatformEnv,
|
||||||
|
getPrefixedEnvVars,
|
||||||
streamToBuffer,
|
streamToBuffer,
|
||||||
debug,
|
debug,
|
||||||
isSymbolicLink,
|
isSymbolicLink,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export interface LambdaOptionsBase {
|
|||||||
allowQuery?: string[];
|
allowQuery?: string[];
|
||||||
regions?: string[];
|
regions?: string[];
|
||||||
supportsMultiPayloads?: boolean;
|
supportsMultiPayloads?: boolean;
|
||||||
|
supportsWrapper?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LambdaOptionsWithFiles extends LambdaOptionsBase {
|
export interface LambdaOptionsWithFiles extends LambdaOptionsBase {
|
||||||
@@ -58,6 +59,7 @@ export class Lambda {
|
|||||||
*/
|
*/
|
||||||
zipBuffer?: Buffer;
|
zipBuffer?: Buffer;
|
||||||
supportsMultiPayloads?: boolean;
|
supportsMultiPayloads?: boolean;
|
||||||
|
supportsWrapper?: boolean;
|
||||||
|
|
||||||
constructor(opts: LambdaOptions) {
|
constructor(opts: LambdaOptions) {
|
||||||
const {
|
const {
|
||||||
@@ -69,6 +71,7 @@ export class Lambda {
|
|||||||
allowQuery,
|
allowQuery,
|
||||||
regions,
|
regions,
|
||||||
supportsMultiPayloads,
|
supportsMultiPayloads,
|
||||||
|
supportsWrapper,
|
||||||
} = opts;
|
} = opts;
|
||||||
if ('files' in opts) {
|
if ('files' in opts) {
|
||||||
assert(typeof opts.files === 'object', '"files" must be an object');
|
assert(typeof opts.files === 'object', '"files" must be an object');
|
||||||
@@ -103,6 +106,13 @@ export class Lambda {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (supportsWrapper !== undefined) {
|
||||||
|
assert(
|
||||||
|
typeof supportsWrapper === 'boolean',
|
||||||
|
'"supportsWrapper" is not a boolean'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (regions !== undefined) {
|
if (regions !== undefined) {
|
||||||
assert(Array.isArray(regions), '"regions" is not an Array');
|
assert(Array.isArray(regions), '"regions" is not an Array');
|
||||||
assert(
|
assert(
|
||||||
@@ -121,6 +131,7 @@ export class Lambda {
|
|||||||
this.regions = regions;
|
this.regions = regions;
|
||||||
this.zipBuffer = 'zipBuffer' in opts ? opts.zipBuffer : undefined;
|
this.zipBuffer = 'zipBuffer' in opts ? opts.zipBuffer : undefined;
|
||||||
this.supportsMultiPayloads = supportsMultiPayloads;
|
this.supportsMultiPayloads = supportsMultiPayloads;
|
||||||
|
this.supportsWrapper = supportsWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createZip(): Promise<Buffer> {
|
async createZip(): Promise<Buffer> {
|
||||||
|
|||||||
46
packages/build-utils/test/unit.get-npm-bin-path.test.ts
vendored
Normal file
46
packages/build-utils/test/unit.get-npm-bin-path.test.ts
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { join, parse } from 'path';
|
||||||
|
import { getNodeBinPath } from '../src';
|
||||||
|
|
||||||
|
describe('Test `getNodeBinPath()`', () => {
|
||||||
|
it('should work with npm7', async () => {
|
||||||
|
const cwd = join(__dirname, 'fixtures', '20-npm-7');
|
||||||
|
const result = await getNodeBinPath({ cwd });
|
||||||
|
expect(result).toBe(join(cwd, 'node_modules', '.bin'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with yarn', async () => {
|
||||||
|
const cwd = join(__dirname, 'fixtures', '19-yarn-v2');
|
||||||
|
const result = await getNodeBinPath({ cwd });
|
||||||
|
expect(result).toBe(join(cwd, 'node_modules', '.bin'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with npm 6', async () => {
|
||||||
|
const cwd = join(__dirname, 'fixtures', '08-yarn-npm/with-npm');
|
||||||
|
const result = await getNodeBinPath({ cwd });
|
||||||
|
expect(result).toBe(join(cwd, 'node_modules', '.bin'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with npm workspaces', async () => {
|
||||||
|
const cwd = join(__dirname, 'fixtures', '21-npm-workspaces/a');
|
||||||
|
const result = await getNodeBinPath({ cwd });
|
||||||
|
expect(result).toBe(join(cwd, '..', 'node_modules', '.bin'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with pnpm', async () => {
|
||||||
|
const cwd = join(__dirname, 'fixtures', '22-pnpm');
|
||||||
|
const result = await getNodeBinPath({ cwd });
|
||||||
|
expect(result).toBe(join(cwd, 'node_modules', '.bin'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with pnpm workspaces', async () => {
|
||||||
|
const cwd = join(__dirname, 'fixtures', '23-pnpm-workspaces/c');
|
||||||
|
const result = await getNodeBinPath({ cwd });
|
||||||
|
expect(result).toBe(join(cwd, '..', 'node_modules', '.bin'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback to cwd if no lockfile found', async () => {
|
||||||
|
const cwd = parse(process.cwd()).root;
|
||||||
|
const result = await getNodeBinPath({ cwd });
|
||||||
|
expect(result).toBe(join(cwd, 'node_modules', '.bin'));
|
||||||
|
});
|
||||||
|
});
|
||||||
87
packages/build-utils/test/unit.get-prefixed-env-vars.test.ts
vendored
Normal file
87
packages/build-utils/test/unit.get-prefixed-env-vars.test.ts
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import { getPrefixedEnvVars } from '../src';
|
||||||
|
|
||||||
|
describe('Test `getPrefixedEnvVars()`', () => {
|
||||||
|
const cases: Array<{
|
||||||
|
name: string;
|
||||||
|
args: Parameters<typeof getPrefixedEnvVars>[0];
|
||||||
|
want: ReturnType<typeof getPrefixedEnvVars>;
|
||||||
|
}> = [
|
||||||
|
{
|
||||||
|
name: 'should work with NEXT_PUBLIC_',
|
||||||
|
args: {
|
||||||
|
envPrefix: 'NEXT_PUBLIC_',
|
||||||
|
envs: {
|
||||||
|
VERCEL: '1',
|
||||||
|
VERCEL_URL: 'example.vercel.sh',
|
||||||
|
USER_ENV_VAR_NOT_VERCEL: 'example.com',
|
||||||
|
FOO: 'bar',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: {
|
||||||
|
NEXT_PUBLIC_VERCEL_URL: 'example.vercel.sh',
|
||||||
|
TURBO_CI_VENDOR_ENV_KEY: 'NEXT_PUBLIC_VERCEL_',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'should work with GATSBY_',
|
||||||
|
args: {
|
||||||
|
envPrefix: 'GATSBY_',
|
||||||
|
envs: {
|
||||||
|
USER_ENV_VAR_NOT_VERCEL: 'example.com',
|
||||||
|
FOO: 'bar',
|
||||||
|
VERCEL_URL: 'example.vercel.sh',
|
||||||
|
VERCEL_ENV: 'production',
|
||||||
|
VERCEL_REGION: 'iad1',
|
||||||
|
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: 'rauchg',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: {
|
||||||
|
GATSBY_VERCEL_URL: 'example.vercel.sh',
|
||||||
|
GATSBY_VERCEL_ENV: 'production',
|
||||||
|
GATSBY_VERCEL_REGION: 'iad1',
|
||||||
|
GATSBY_VERCEL_GIT_COMMIT_AUTHOR_LOGIN: 'rauchg',
|
||||||
|
TURBO_CI_VENDOR_ENV_KEY: 'GATSBY_VERCEL_',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'should not return anything if no system env vars detected',
|
||||||
|
args: {
|
||||||
|
envPrefix: 'GATSBY_',
|
||||||
|
envs: {
|
||||||
|
USER_ENV_VAR_NOT_VERCEL: 'example.com',
|
||||||
|
FOO: 'bar',
|
||||||
|
BLARG_VERCEL_THING: 'fake',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'should not return anything if envPrefix is empty string',
|
||||||
|
args: {
|
||||||
|
envPrefix: '',
|
||||||
|
envs: {
|
||||||
|
VERCEL: '1',
|
||||||
|
VERCEL_URL: 'example.vercel.sh',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'should not return anything if envPrefix is undefined',
|
||||||
|
args: {
|
||||||
|
envPrefix: undefined,
|
||||||
|
envs: {
|
||||||
|
VERCEL: '1',
|
||||||
|
VERCEL_URL: 'example.vercel.sh',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: {},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const { name, args, want } of cases) {
|
||||||
|
it(name, () => {
|
||||||
|
expect(getPrefixedEnvVars(args)).toEqual(want);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
18
packages/build-utils/test/unit.test.ts
vendored
18
packages/build-utils/test/unit.test.ts
vendored
@@ -394,7 +394,7 @@ it('should get latest node version', async () => {
|
|||||||
it('should throw for discontinued versions', async () => {
|
it('should throw for discontinued versions', async () => {
|
||||||
// Mock a future date so that Node 8 and 10 become discontinued
|
// Mock a future date so that Node 8 and 10 become discontinued
|
||||||
const realDateNow = Date.now.bind(global.Date);
|
const realDateNow = Date.now.bind(global.Date);
|
||||||
global.Date.now = () => new Date('2022-09-01').getTime();
|
global.Date.now = () => new Date('2022-10-15').getTime();
|
||||||
|
|
||||||
expect(getSupportedNodeVersion('8.10.x', false)).rejects.toThrow();
|
expect(getSupportedNodeVersion('8.10.x', false)).rejects.toThrow();
|
||||||
expect(getSupportedNodeVersion('8.10.x', true)).rejects.toThrow();
|
expect(getSupportedNodeVersion('8.10.x', true)).rejects.toThrow();
|
||||||
@@ -436,8 +436,8 @@ it('should warn for deprecated versions, soon to be discontinued', async () => {
|
|||||||
expect(warningMessages).toStrictEqual([
|
expect(warningMessages).toStrictEqual([
|
||||||
'Error: Node.js version 10.x has reached End-of-Life. Deployments created on or after 2021-04-20 will fail to build. Please set "engines": { "node": "16.x" } in your `package.json` file to use Node.js 16.',
|
'Error: Node.js version 10.x has reached End-of-Life. Deployments created on or after 2021-04-20 will fail to build. Please set "engines": { "node": "16.x" } in your `package.json` file to use Node.js 16.',
|
||||||
'Error: Node.js version 10.x has reached End-of-Life. Deployments created on or after 2021-04-20 will fail to build. Please set Node.js Version to 16.x in your Project Settings to use Node.js 16.',
|
'Error: Node.js version 10.x has reached End-of-Life. Deployments created on or after 2021-04-20 will fail to build. Please set Node.js Version to 16.x in your Project Settings to use Node.js 16.',
|
||||||
'Error: Node.js version 12.x has reached End-of-Life. Deployments created on or after 2022-08-09 will fail to build. Please set "engines": { "node": "16.x" } in your `package.json` file to use Node.js 16.',
|
'Error: Node.js version 12.x has reached End-of-Life. Deployments created on or after 2022-10-01 will fail to build. Please set "engines": { "node": "16.x" } in your `package.json` file to use Node.js 16.',
|
||||||
'Error: Node.js version 12.x has reached End-of-Life. Deployments created on or after 2022-08-09 will fail to build. Please set Node.js Version to 16.x in your Project Settings to use Node.js 16.',
|
'Error: Node.js version 12.x has reached End-of-Life. Deployments created on or after 2022-10-01 will fail to build. Please set Node.js Version to 16.x in your Project Settings to use Node.js 16.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
global.Date.now = realDateNow;
|
global.Date.now = realDateNow;
|
||||||
@@ -501,6 +501,7 @@ it('should return lockfileVersion 2 with npm7', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('npm');
|
expect(result.cliType).toEqual('npm');
|
||||||
expect(result.lockfileVersion).toEqual(2);
|
expect(result.lockfileVersion).toEqual(2);
|
||||||
|
expect(result.lockfilePath).toEqual(path.join(fixture, 'package-lock.json'));
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -509,6 +510,7 @@ it('should not return lockfileVersion with yarn', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('yarn');
|
expect(result.cliType).toEqual('yarn');
|
||||||
expect(result.lockfileVersion).toEqual(undefined);
|
expect(result.lockfileVersion).toEqual(undefined);
|
||||||
|
expect(result.lockfilePath).toEqual(path.join(fixture, 'yarn.lock'));
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -517,6 +519,7 @@ it('should return lockfileVersion 1 with older versions of npm', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('npm');
|
expect(result.cliType).toEqual('npm');
|
||||||
expect(result.lockfileVersion).toEqual(1);
|
expect(result.lockfileVersion).toEqual(1);
|
||||||
|
expect(result.lockfilePath).toEqual(path.join(fixture, 'package-lock.json'));
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -525,6 +528,9 @@ it('should detect npm Workspaces', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('npm');
|
expect(result.cliType).toEqual('npm');
|
||||||
expect(result.lockfileVersion).toEqual(2);
|
expect(result.lockfileVersion).toEqual(2);
|
||||||
|
expect(result.lockfilePath).toEqual(
|
||||||
|
path.join(fixture, '..', 'package-lock.json')
|
||||||
|
);
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -533,6 +539,7 @@ it('should detect pnpm without workspace', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('pnpm');
|
expect(result.cliType).toEqual('pnpm');
|
||||||
expect(result.lockfileVersion).toEqual(5.3);
|
expect(result.lockfileVersion).toEqual(5.3);
|
||||||
|
expect(result.lockfilePath).toEqual(path.join(fixture, 'pnpm-lock.yaml'));
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -541,6 +548,9 @@ it('should detect pnpm with workspaces', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('pnpm');
|
expect(result.cliType).toEqual('pnpm');
|
||||||
expect(result.lockfileVersion).toEqual(5.3);
|
expect(result.lockfileVersion).toEqual(5.3);
|
||||||
|
expect(result.lockfilePath).toEqual(
|
||||||
|
path.join(fixture, '..', 'pnpm-lock.yaml')
|
||||||
|
);
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -552,6 +562,7 @@ it('should detect package.json in nested backend', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('yarn');
|
expect(result.cliType).toEqual('yarn');
|
||||||
expect(result.lockfileVersion).toEqual(undefined);
|
expect(result.lockfileVersion).toEqual(undefined);
|
||||||
|
// There is no lockfile but this test will pick up vercel/vercel/yarn.lock
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -563,6 +574,7 @@ it('should detect package.json in nested frontend', async () => {
|
|||||||
const result = await scanParentDirs(fixture);
|
const result = await scanParentDirs(fixture);
|
||||||
expect(result.cliType).toEqual('yarn');
|
expect(result.cliType).toEqual('yarn');
|
||||||
expect(result.lockfileVersion).toEqual(undefined);
|
expect(result.lockfileVersion).toEqual(undefined);
|
||||||
|
// There is no lockfile but this test will pick up vercel/vercel/yarn.lock
|
||||||
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
expect(result.packageJsonPath).toEqual(path.join(fixture, 'package.json'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vercel",
|
"name": "vercel",
|
||||||
"version": "27.3.6",
|
"version": "28.2.1",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"description": "The command-line interface for Vercel",
|
"description": "The command-line interface for Vercel",
|
||||||
@@ -41,16 +41,16 @@
|
|||||||
"node": ">= 14"
|
"node": ">= 14"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vercel/build-utils": "5.1.1",
|
"@vercel/build-utils": "5.4.1",
|
||||||
"@vercel/go": "2.0.14",
|
"@vercel/go": "2.2.4",
|
||||||
"@vercel/hydrogen": "0.0.11",
|
"@vercel/hydrogen": "0.0.17",
|
||||||
"@vercel/next": "3.1.14",
|
"@vercel/next": "3.1.23",
|
||||||
"@vercel/node": "2.5.5",
|
"@vercel/node": "2.5.12",
|
||||||
"@vercel/python": "3.1.6",
|
"@vercel/python": "3.1.13",
|
||||||
"@vercel/redwood": "1.0.15",
|
"@vercel/redwood": "1.0.21",
|
||||||
"@vercel/remix": "1.0.16",
|
"@vercel/remix": "1.0.22",
|
||||||
"@vercel/ruby": "1.3.22",
|
"@vercel/ruby": "1.3.30",
|
||||||
"@vercel/static-build": "1.0.15",
|
"@vercel/static-build": "1.0.21",
|
||||||
"update-notifier": "5.1.0"
|
"update-notifier": "5.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -85,7 +85,6 @@
|
|||||||
"@types/node-fetch": "2.5.10",
|
"@types/node-fetch": "2.5.10",
|
||||||
"@types/npm-package-arg": "6.1.0",
|
"@types/npm-package-arg": "6.1.0",
|
||||||
"@types/pluralize": "0.0.29",
|
"@types/pluralize": "0.0.29",
|
||||||
"@types/progress": "2.0.3",
|
|
||||||
"@types/psl": "1.1.0",
|
"@types/psl": "1.1.0",
|
||||||
"@types/semver": "6.0.1",
|
"@types/semver": "6.0.1",
|
||||||
"@types/tar-fs": "1.16.1",
|
"@types/tar-fs": "1.16.1",
|
||||||
@@ -96,9 +95,9 @@
|
|||||||
"@types/which": "1.3.2",
|
"@types/which": "1.3.2",
|
||||||
"@types/write-json-file": "2.2.1",
|
"@types/write-json-file": "2.2.1",
|
||||||
"@types/yauzl-promise": "2.1.0",
|
"@types/yauzl-promise": "2.1.0",
|
||||||
"@vercel/client": "12.1.9",
|
"@vercel/client": "12.2.3",
|
||||||
"@vercel/frameworks": "1.1.2",
|
"@vercel/frameworks": "1.1.3",
|
||||||
"@vercel/fs-detectors": "2.0.4",
|
"@vercel/fs-detectors": "2.1.0",
|
||||||
"@vercel/fun": "1.0.4",
|
"@vercel/fun": "1.0.4",
|
||||||
"@vercel/ncc": "0.24.0",
|
"@vercel/ncc": "0.24.0",
|
||||||
"@zeit/source-map-support": "0.6.2",
|
"@zeit/source-map-support": "0.6.2",
|
||||||
@@ -118,7 +117,6 @@
|
|||||||
"chokidar": "3.3.1",
|
"chokidar": "3.3.1",
|
||||||
"codecov": "3.8.2",
|
"codecov": "3.8.2",
|
||||||
"cpy": "7.2.0",
|
"cpy": "7.2.0",
|
||||||
"credit-card": "3.0.1",
|
|
||||||
"date-fns": "1.29.0",
|
"date-fns": "1.29.0",
|
||||||
"debug": "3.1.0",
|
"debug": "3.1.0",
|
||||||
"dot": "1.1.3",
|
"dot": "1.1.3",
|
||||||
@@ -154,7 +152,6 @@
|
|||||||
"ora": "3.4.0",
|
"ora": "3.4.0",
|
||||||
"pcre-to-regexp": "1.0.0",
|
"pcre-to-regexp": "1.0.0",
|
||||||
"pluralize": "7.0.0",
|
"pluralize": "7.0.0",
|
||||||
"progress": "2.0.3",
|
|
||||||
"promisepipe": "3.0.0",
|
"promisepipe": "3.0.0",
|
||||||
"psl": "1.1.31",
|
"psl": "1.1.31",
|
||||||
"qr-image": "3.2.0",
|
"qr-image": "3.2.0",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const { statSync } = require('fs');
|
|||||||
const pkg = require('../package');
|
const pkg = require('../package');
|
||||||
|
|
||||||
function error(command) {
|
function error(command) {
|
||||||
console.error('> Error!', command);
|
console.error('> Error:', command);
|
||||||
}
|
}
|
||||||
|
|
||||||
function debug(str) {
|
function debug(str) {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const help = () => {
|
|||||||
)} Login token
|
)} Login token
|
||||||
-S, --scope Set a custom scope
|
-S, --scope Set a custom scope
|
||||||
-N, --next Show next page of results
|
-N, --next Show next page of results
|
||||||
|
-y, --yes Skip the confirmation prompt when removing an alias
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export default async function rm(
|
|||||||
|
|
||||||
const removeStamp = stamp();
|
const removeStamp = stamp();
|
||||||
if (!opts['--yes'] && !(await confirmAliasRemove(client, alias))) {
|
if (!opts['--yes'] && !(await confirmAliasRemove(client, alias))) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ function handleSetupDomainError<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error instanceof ERRORS.UserAborted) {
|
if (error instanceof ERRORS.UserAborted) {
|
||||||
output.error(`User aborted`);
|
output.error(`User canceled.`);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,170 +0,0 @@
|
|||||||
import ansiEscapes from 'ansi-escapes';
|
|
||||||
import chalk from 'chalk';
|
|
||||||
import ccValidator from 'credit-card';
|
|
||||||
import textInput from '../../util/input/text';
|
|
||||||
import cardBrands from '../../util/billing/card-brands';
|
|
||||||
import success from '../../util/output/success';
|
|
||||||
import wait from '../../util/output/wait';
|
|
||||||
import chars from '../../util/output/chars';
|
|
||||||
import error from '../../util/output/error';
|
|
||||||
|
|
||||||
const expDateMiddleware = data => data;
|
|
||||||
|
|
||||||
export default async function ({ creditCards, clear = false, contextName }) {
|
|
||||||
const state = {
|
|
||||||
error: undefined,
|
|
||||||
cardGroupLabel: `> ${chalk.bold(
|
|
||||||
`Enter your card details for ${chalk.bold(contextName)}`
|
|
||||||
)}`,
|
|
||||||
|
|
||||||
name: {
|
|
||||||
label: 'Full Name'.padEnd(12),
|
|
||||||
placeholder: 'John Appleseed',
|
|
||||||
validateValue: data => data.trim().length > 0,
|
|
||||||
},
|
|
||||||
|
|
||||||
cardNumber: {
|
|
||||||
label: 'Number'.padEnd(12),
|
|
||||||
mask: 'cc',
|
|
||||||
placeholder: '#### #### #### ####',
|
|
||||||
validateKeypress: (data, value) => /\d/.test(data) && value.length < 19,
|
|
||||||
validateValue: data => {
|
|
||||||
data = data.replace(/ /g, '');
|
|
||||||
const type = ccValidator.determineCardType(data);
|
|
||||||
if (!type) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ccValidator.isValidCardNumber(data, type);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
ccv: {
|
|
||||||
label: 'CCV'.padEnd(12),
|
|
||||||
mask: 'ccv',
|
|
||||||
placeholder: '###',
|
|
||||||
validateValue: data => {
|
|
||||||
const brand = state.cardNumber.brand.toLowerCase();
|
|
||||||
return ccValidator.doesCvvMatchType(data, brand);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
expDate: {
|
|
||||||
label: 'Exp. Date'.padEnd(12),
|
|
||||||
mask: 'expDate',
|
|
||||||
placeholder: 'mm / yyyy',
|
|
||||||
middleware: expDateMiddleware,
|
|
||||||
validateValue: data => !ccValidator.isExpired(...data.split(' / ')),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
async function render() {
|
|
||||||
for (const key in state) {
|
|
||||||
if (!Object.hasOwnProperty.call(state, key)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const piece = state[key];
|
|
||||||
|
|
||||||
if (typeof piece === 'string') {
|
|
||||||
console.log(piece);
|
|
||||||
} else if (typeof piece === 'object') {
|
|
||||||
let result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
result = await textInput({
|
|
||||||
label: `- ${piece.label}`,
|
|
||||||
initialValue: piece.initialValue || piece.value,
|
|
||||||
placeholder: piece.placeholder,
|
|
||||||
mask: piece.mask,
|
|
||||||
validateKeypress: piece.validateKeypress,
|
|
||||||
validateValue: piece.validateValue,
|
|
||||||
autoComplete: piece.autoComplete,
|
|
||||||
});
|
|
||||||
|
|
||||||
piece.value = result;
|
|
||||||
|
|
||||||
if (key === 'cardNumber') {
|
|
||||||
let brand = cardBrands[ccValidator.determineCardType(result)];
|
|
||||||
piece.brand = brand;
|
|
||||||
|
|
||||||
if (brand === 'American Express') {
|
|
||||||
state.ccv.placeholder = '#'.repeat(4);
|
|
||||||
} else {
|
|
||||||
state.ccv.placeholder = '#'.repeat(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
brand = chalk.cyan(`[${brand}]`);
|
|
||||||
const masked = chalk.gray('#### '.repeat(3)) + result.split(' ')[3];
|
|
||||||
process.stdout.write(
|
|
||||||
`${chalk.cyan(chars.tick)} ${piece.label}${masked} ${brand}\n`
|
|
||||||
);
|
|
||||||
} else if (key === 'ccv') {
|
|
||||||
process.stdout.write(
|
|
||||||
`${chalk.cyan(chars.tick)} ${piece.label}${'*'.repeat(
|
|
||||||
result.length
|
|
||||||
)}\n`
|
|
||||||
);
|
|
||||||
} else if (key === 'expDate') {
|
|
||||||
let text = result.split(' / ');
|
|
||||||
text = text[0] + chalk.gray(' / ') + text[1];
|
|
||||||
process.stdout.write(
|
|
||||||
`${chalk.cyan(chars.tick)} ${piece.label}${text}\n`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
process.stdout.write(
|
|
||||||
`${chalk.cyan(chars.tick)} ${piece.label}${result}\n`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
if (err.message === 'USER_ABORT') {
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
console.error(error(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(''); // New line
|
|
||||||
const stopSpinner = wait(process.stderr, 'Saving card');
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await creditCards.add({
|
|
||||||
name: state.name.value,
|
|
||||||
cardNumber: state.cardNumber.value,
|
|
||||||
ccv: state.ccv.value,
|
|
||||||
expDate: state.expDate.value,
|
|
||||||
});
|
|
||||||
|
|
||||||
stopSpinner();
|
|
||||||
|
|
||||||
if (clear) {
|
|
||||||
const linesToClear = state.error ? 15 : 14;
|
|
||||||
process.stdout.write(ansiEscapes.eraseLines(linesToClear));
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
success(
|
|
||||||
`${state.cardNumber.brand || state.cardNumber.card.brand} ending in ${
|
|
||||||
res.last4 || res.card.last4
|
|
||||||
} was added to ${chalk.bold(contextName)}`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
stopSpinner();
|
|
||||||
const linesToClear = state.error ? 15 : 14;
|
|
||||||
process.stdout.write(ansiEscapes.eraseLines(linesToClear));
|
|
||||||
state.error = `${chalk.red('> Error!')} ${
|
|
||||||
err.message
|
|
||||||
} Please make sure the info is correct`;
|
|
||||||
await render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await render();
|
|
||||||
} catch (err) {
|
|
||||||
console.erorr(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,353 +0,0 @@
|
|||||||
import chalk from 'chalk';
|
|
||||||
import ms from 'ms';
|
|
||||||
import plural from 'pluralize';
|
|
||||||
import { error } from '../../util/error';
|
|
||||||
import NowCreditCards from '../../util/credit-cards';
|
|
||||||
import indent from '../../util/output/indent';
|
|
||||||
import listInput from '../../util/input/list';
|
|
||||||
import success from '../../util/output/success';
|
|
||||||
import promptBool from '../../util/input/prompt-bool';
|
|
||||||
import info from '../../util/output/info';
|
|
||||||
import logo from '../../util/output/logo';
|
|
||||||
import addBilling from './add';
|
|
||||||
import exit from '../../util/exit';
|
|
||||||
import getScope from '../../util/get-scope.ts';
|
|
||||||
import { getPkgName } from '../../util/pkg-name.ts';
|
|
||||||
import getArgs from '../../util/get-args.ts';
|
|
||||||
import handleError from '../../util/handle-error.ts';
|
|
||||||
|
|
||||||
const help = () => {
|
|
||||||
console.log(`
|
|
||||||
${chalk.bold(`${logo} ${getPkgName()} billing`)} [options] <command>
|
|
||||||
|
|
||||||
${chalk.dim('Options:')}
|
|
||||||
|
|
||||||
ls Show all of your credit cards
|
|
||||||
add Add a new credit card
|
|
||||||
rm [id] Remove a credit card
|
|
||||||
set-default [id] Make a credit card your default one
|
|
||||||
|
|
||||||
${chalk.dim('Options:')}
|
|
||||||
|
|
||||||
-h, --help Output usage information
|
|
||||||
-A ${chalk.bold.underline('FILE')}, --local-config=${chalk.bold.underline(
|
|
||||||
'FILE'
|
|
||||||
)} Path to the local ${'`vercel.json`'} file
|
|
||||||
-Q ${chalk.bold.underline('DIR')}, --global-config=${chalk.bold.underline(
|
|
||||||
'DIR'
|
|
||||||
)} Path to the global ${'`.vercel`'} directory
|
|
||||||
-d, --debug Debug mode [off]
|
|
||||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
|
||||||
'TOKEN'
|
|
||||||
)} Login token
|
|
||||||
-S, --scope Set a custom scope
|
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
|
||||||
|
|
||||||
${chalk.gray('–')} Add a new credit card (interactively)
|
|
||||||
|
|
||||||
${chalk.cyan(`$ ${getPkgName()} billing add`)}
|
|
||||||
`);
|
|
||||||
};
|
|
||||||
|
|
||||||
let argv;
|
|
||||||
let subcommand;
|
|
||||||
|
|
||||||
export default async client => {
|
|
||||||
try {
|
|
||||||
argv = getArgs(client.argv.slice(2), {});
|
|
||||||
} catch (error) {
|
|
||||||
handleError(error);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
argv._ = argv._.slice(1);
|
|
||||||
|
|
||||||
subcommand = argv._[0];
|
|
||||||
|
|
||||||
if (argv['--help'] || !subcommand) {
|
|
||||||
help();
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
output,
|
|
||||||
config: { currentTeam },
|
|
||||||
} = client;
|
|
||||||
|
|
||||||
const start = new Date();
|
|
||||||
const creditCards = new NowCreditCards({
|
|
||||||
client,
|
|
||||||
currentTeam,
|
|
||||||
});
|
|
||||||
|
|
||||||
let contextName = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
({ contextName } = await getScope(client));
|
|
||||||
} catch (err) {
|
|
||||||
if (err.code === 'NOT_AUTHORIZED' || err.code === 'TEAM_DELETED') {
|
|
||||||
output.error(err.message);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
const args = argv._.slice(1);
|
|
||||||
|
|
||||||
switch (subcommand) {
|
|
||||||
case 'ls':
|
|
||||||
case 'list': {
|
|
||||||
let cards;
|
|
||||||
|
|
||||||
try {
|
|
||||||
cards = await creditCards.ls();
|
|
||||||
} catch (err) {
|
|
||||||
console.error(error(err.message));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const text = cards.sources
|
|
||||||
.map(source => {
|
|
||||||
const _default =
|
|
||||||
source.id === cards.defaultSource
|
|
||||||
? ` ${chalk.bold('(default)')}`
|
|
||||||
: '';
|
|
||||||
const id = `${chalk.gray('-')} ${chalk.cyan(
|
|
||||||
`ID: ${source.id}`
|
|
||||||
)}${_default}`;
|
|
||||||
const number = `${chalk.gray('#### ').repeat(3)}${
|
|
||||||
source.last4 || source.card.last4
|
|
||||||
}`;
|
|
||||||
|
|
||||||
return [
|
|
||||||
id,
|
|
||||||
indent(source.name || source.owner.name, 2),
|
|
||||||
indent(`${source.brand || source.card.brand} ${number}`, 2),
|
|
||||||
].join('\n');
|
|
||||||
})
|
|
||||||
.join('\n\n');
|
|
||||||
|
|
||||||
const elapsed = ms(new Date() - start);
|
|
||||||
console.log(
|
|
||||||
`> ${plural(
|
|
||||||
'card',
|
|
||||||
cards.sources.length,
|
|
||||||
true
|
|
||||||
)} found under ${chalk.bold(contextName)} ${chalk.gray(`[${elapsed}]`)}`
|
|
||||||
);
|
|
||||||
if (text) {
|
|
||||||
console.log(`\n${text}\n`);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'set-default': {
|
|
||||||
if (args.length > 1) {
|
|
||||||
console.error(error('Invalid number of arguments'));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = new Date();
|
|
||||||
|
|
||||||
let cards;
|
|
||||||
try {
|
|
||||||
cards = await creditCards.ls();
|
|
||||||
} catch (err) {
|
|
||||||
console.error(error(err.message));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cards.sources.length === 0) {
|
|
||||||
console.error(error('You have no credit cards to choose from'));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cardId = args[0];
|
|
||||||
|
|
||||||
if (cardId === undefined) {
|
|
||||||
const elapsed = ms(new Date() - start);
|
|
||||||
const message = `Selecting a new default payment card for ${chalk.bold(
|
|
||||||
contextName
|
|
||||||
)} ${chalk.gray(`[${elapsed}]`)}`;
|
|
||||||
const choices = buildInquirerChoices(cards);
|
|
||||||
|
|
||||||
cardId = await listInput(client, {
|
|
||||||
message,
|
|
||||||
choices,
|
|
||||||
separator: true,
|
|
||||||
abort: 'end',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the provided cardId (in case the user
|
|
||||||
// typed `vercel billing set-default <some-id>`) is valid
|
|
||||||
if (cardId) {
|
|
||||||
const label = `Are you sure that you to set this card as the default?`;
|
|
||||||
const confirmation = await promptBool(label, {
|
|
||||||
...client,
|
|
||||||
trailing: '\n',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!confirmation) {
|
|
||||||
console.log(info('Aborted'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = new Date();
|
|
||||||
await creditCards.setDefault(cardId);
|
|
||||||
|
|
||||||
const card = cards.sources.find(card => card.id === cardId);
|
|
||||||
const elapsed = ms(new Date() - start);
|
|
||||||
console.log(
|
|
||||||
success(
|
|
||||||
`${card.brand || card.card.brand} ending in ${
|
|
||||||
card.last4 || card.card.last4
|
|
||||||
} is now the default ${chalk.gray(`[${elapsed}]`)}`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.log('No changes made');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'rm':
|
|
||||||
case 'remove': {
|
|
||||||
if (args.length > 1) {
|
|
||||||
console.error(error('Invalid number of arguments'));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = new Date();
|
|
||||||
let cards;
|
|
||||||
try {
|
|
||||||
cards = await creditCards.ls();
|
|
||||||
} catch (err) {
|
|
||||||
console.error(error(err.message));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cards.sources.length === 0) {
|
|
||||||
console.error(
|
|
||||||
error(
|
|
||||||
`You have no credit cards to choose from to delete under ${chalk.bold(
|
|
||||||
contextName
|
|
||||||
)}`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cardId = args[0];
|
|
||||||
|
|
||||||
if (cardId === undefined) {
|
|
||||||
const elapsed = ms(new Date() - start);
|
|
||||||
const message = `Selecting a card to ${chalk.underline(
|
|
||||||
'remove'
|
|
||||||
)} under ${chalk.bold(contextName)} ${chalk.gray(`[${elapsed}]`)}`;
|
|
||||||
const choices = buildInquirerChoices(cards);
|
|
||||||
|
|
||||||
cardId = await listInput(client, {
|
|
||||||
message,
|
|
||||||
choices,
|
|
||||||
separator: true,
|
|
||||||
abort: 'start',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shoud check if the provided cardId (in case the user
|
|
||||||
// typed `vercel billing rm <some-id>`) is valid
|
|
||||||
if (cardId) {
|
|
||||||
const label = `Are you sure that you want to remove this card?`;
|
|
||||||
const confirmation = await promptBool(label, client);
|
|
||||||
if (!confirmation) {
|
|
||||||
console.log('Aborted');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const start = new Date();
|
|
||||||
await creditCards.rm(cardId);
|
|
||||||
|
|
||||||
const deletedCard = cards.sources.find(card => card.id === cardId);
|
|
||||||
const remainingCards = cards.sources.filter(card => card.id !== cardId);
|
|
||||||
|
|
||||||
let text = `${deletedCard.brand || deletedCard.card.brand} ending in ${
|
|
||||||
deletedCard.last4 || deletedCard.card.last4
|
|
||||||
} was deleted`;
|
|
||||||
// ${chalk.gray(`[${elapsed}]`)}
|
|
||||||
|
|
||||||
if (cardId === cards.defaultSource) {
|
|
||||||
if (remainingCards.length === 0) {
|
|
||||||
// The user deleted the last card in their account
|
|
||||||
text += `\n${chalk.yellow('Warning!')} You have no default card`;
|
|
||||||
} else {
|
|
||||||
// We can't guess the current default card – let's ask the API
|
|
||||||
const cards = await creditCards.ls();
|
|
||||||
const newDefaultCard = cards.sources.find(
|
|
||||||
card => card.id === cards.defaultCardId
|
|
||||||
);
|
|
||||||
|
|
||||||
text += `\n${
|
|
||||||
newDefaultCard.brand || newDefaultCard.card.brand
|
|
||||||
} ending in ${
|
|
||||||
newDefaultCard.last4 || newDefaultCard.card.last4
|
|
||||||
} in now default for ${chalk.bold(contextName)}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const elapsed = ms(new Date() - start);
|
|
||||||
text += ` ${chalk.gray(`[${elapsed}]`)}`;
|
|
||||||
console.log(success(text));
|
|
||||||
} else {
|
|
||||||
console.log('No changes made');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'add': {
|
|
||||||
await addBilling({
|
|
||||||
creditCards,
|
|
||||||
contextName,
|
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
console.error(
|
|
||||||
error('Please specify a valid subcommand: ls | add | rm | set-default')
|
|
||||||
);
|
|
||||||
help();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is required, otherwise we get those weird zlib errors
|
|
||||||
return exit(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Builds a `choices` object that can be passesd to inquirer.prompt()
|
|
||||||
function buildInquirerChoices(cards) {
|
|
||||||
return cards.sources.map(source => {
|
|
||||||
const _default =
|
|
||||||
source.id === cards.defaultSource ? ` ${chalk.bold('(default)')}` : '';
|
|
||||||
const id = `${chalk.cyan(`ID: ${source.id}`)}${_default}`;
|
|
||||||
const number = `${chalk.gray('#### ').repeat(3)}${
|
|
||||||
source.last4 || source.card.last4
|
|
||||||
}`;
|
|
||||||
const str = [
|
|
||||||
id,
|
|
||||||
indent(source.name || source.owner.name, 2),
|
|
||||||
indent(`${source.brand || source.card.brand} ${number}`, 2),
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: str, // Will be displayed by Inquirer
|
|
||||||
value: source.id, // Will be used to identify the answer
|
|
||||||
short: source.id, // Will be displayed after the users answers
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -116,8 +116,6 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const badDeploymentPromise = getDeployment(client, bad).catch(err => err);
|
|
||||||
|
|
||||||
good = normalizeURL(good);
|
good = normalizeURL(good);
|
||||||
parsed = parse(good);
|
parsed = parse(good);
|
||||||
if (!parsed.hostname) {
|
if (!parsed.hostname) {
|
||||||
@@ -138,8 +136,6 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const goodDeploymentPromise = getDeployment(client, good).catch(err => err);
|
|
||||||
|
|
||||||
if (!subpath) {
|
if (!subpath) {
|
||||||
subpath = await prompt(
|
subpath = await prompt(
|
||||||
client,
|
client,
|
||||||
@@ -148,10 +144,9 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output.spinner('Retrieving deployments…');
|
output.spinner('Retrieving deployments…');
|
||||||
const [badDeployment, goodDeployment] = await Promise.all([
|
|
||||||
badDeploymentPromise,
|
// `getDeployment` cannot be parallelized because it might prompt for login
|
||||||
goodDeploymentPromise,
|
const badDeployment = await getDeployment(client, bad).catch(err => err);
|
||||||
]);
|
|
||||||
|
|
||||||
if (badDeployment) {
|
if (badDeployment) {
|
||||||
if (badDeployment instanceof Error) {
|
if (badDeployment instanceof Error) {
|
||||||
@@ -165,7 +160,8 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { projectId } = badDeployment;
|
// `getDeployment` cannot be parallelized because it might prompt for login
|
||||||
|
const goodDeployment = await getDeployment(client, good).catch(err => err);
|
||||||
|
|
||||||
if (goodDeployment) {
|
if (goodDeployment) {
|
||||||
if (goodDeployment instanceof Error) {
|
if (goodDeployment instanceof Error) {
|
||||||
@@ -181,6 +177,8 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { projectId } = badDeployment;
|
||||||
|
|
||||||
if (projectId !== goodDeployment.projectId) {
|
if (projectId !== goodDeployment.projectId) {
|
||||||
output.error(`Good and Bad deployments must be from the same Project`);
|
output.error(`Good and Bad deployments must be from the same Project`);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import cliPkg from '../util/pkg';
|
|||||||
import readJSONFile from '../util/read-json-file';
|
import readJSONFile from '../util/read-json-file';
|
||||||
import { CantParseJSONFile } from '../util/errors-ts';
|
import { CantParseJSONFile } from '../util/errors-ts';
|
||||||
import {
|
import {
|
||||||
|
pickOverrides,
|
||||||
ProjectLinkAndSettings,
|
ProjectLinkAndSettings,
|
||||||
readProjectSettings,
|
readProjectSettings,
|
||||||
} from '../util/projects/project-settings';
|
} from '../util/projects/project-settings';
|
||||||
@@ -91,7 +92,7 @@ const help = () => {
|
|||||||
--output [path] Directory where built assets should be written to
|
--output [path] Directory where built assets should be written to
|
||||||
--prod Build a production deployment
|
--prod Build a production deployment
|
||||||
-d, --debug Debug mode [off]
|
-d, --debug Debug mode [off]
|
||||||
-y, --yes Skip the confirmation prompt
|
-y, --yes Skip the confirmation prompt about pulling environment variables and project settings when not found locally
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
@@ -157,7 +158,7 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
client.output.print(
|
client.output.print(
|
||||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||||
'pull --yes'
|
'pull --yes'
|
||||||
)} to retreive them.`
|
)} to retrieve them.`
|
||||||
);
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -171,7 +172,7 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
client.output.print(`Aborted. No Project Settings retrieved.\n`);
|
client.output.print(`Canceled. No Project Settings retrieved.\n`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const { argv: originalArgv } = client;
|
const { argv: originalArgv } = client;
|
||||||
@@ -278,6 +279,11 @@ async function doBuild(
|
|||||||
if (pkg instanceof CantParseJSONFile) throw pkg;
|
if (pkg instanceof CantParseJSONFile) throw pkg;
|
||||||
if (vercelConfig instanceof CantParseJSONFile) throw vercelConfig;
|
if (vercelConfig instanceof CantParseJSONFile) throw vercelConfig;
|
||||||
|
|
||||||
|
const projectSettings = {
|
||||||
|
...project.settings,
|
||||||
|
...pickOverrides(vercelConfig || {}),
|
||||||
|
};
|
||||||
|
|
||||||
// Get a list of source files
|
// Get a list of source files
|
||||||
const files = (await getFiles(workPath, client)).map(f =>
|
const files = (await getFiles(workPath, client)).map(f =>
|
||||||
normalizePath(relative(workPath, f))
|
normalizePath(relative(workPath, f))
|
||||||
@@ -313,7 +319,7 @@ async function doBuild(
|
|||||||
// Detect the Vercel Builders that will need to be invoked
|
// Detect the Vercel Builders that will need to be invoked
|
||||||
const detectedBuilders = await detectBuilders(files, pkg, {
|
const detectedBuilders = await detectBuilders(files, pkg, {
|
||||||
...vercelConfig,
|
...vercelConfig,
|
||||||
projectSettings: project.settings,
|
projectSettings,
|
||||||
ignoreBuildScript: true,
|
ignoreBuildScript: true,
|
||||||
featHandleMiss: true,
|
featHandleMiss: true,
|
||||||
});
|
});
|
||||||
@@ -425,14 +431,14 @@ async function doBuild(
|
|||||||
|
|
||||||
const buildConfig: Config = isZeroConfig
|
const buildConfig: Config = isZeroConfig
|
||||||
? {
|
? {
|
||||||
outputDirectory: project.settings.outputDirectory ?? undefined,
|
outputDirectory: projectSettings.outputDirectory ?? undefined,
|
||||||
...build.config,
|
...build.config,
|
||||||
projectSettings: project.settings,
|
projectSettings,
|
||||||
installCommand: project.settings.installCommand ?? undefined,
|
installCommand: projectSettings.installCommand ?? undefined,
|
||||||
devCommand: project.settings.devCommand ?? undefined,
|
devCommand: projectSettings.devCommand ?? undefined,
|
||||||
buildCommand: project.settings.buildCommand ?? undefined,
|
buildCommand: projectSettings.buildCommand ?? undefined,
|
||||||
framework: project.settings.framework,
|
framework: projectSettings.framework,
|
||||||
nodeVersion: project.settings.nodeVersion,
|
nodeVersion: projectSettings.nodeVersion,
|
||||||
}
|
}
|
||||||
: build.config || {};
|
: build.config || {};
|
||||||
const buildOptions: BuildOptions = {
|
const buildOptions: BuildOptions = {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ export const help = () => `
|
|||||||
|
|
||||||
${chalk.dim('Basic')}
|
${chalk.dim('Basic')}
|
||||||
|
|
||||||
billing Manages the account payment methods
|
|
||||||
deploy [path] Performs a deployment ${chalk.bold(
|
deploy [path] Performs a deployment ${chalk.bold(
|
||||||
'(default)'
|
'(default)'
|
||||||
)}
|
)}
|
||||||
@@ -73,7 +72,7 @@ export const help = () => `
|
|||||||
-S, --scope Set a custom scope
|
-S, --scope Set a custom scope
|
||||||
--regions Set default regions to enable the deployment on
|
--regions Set default regions to enable the deployment on
|
||||||
--prod Create a production deployment
|
--prod Create a production deployment
|
||||||
-c, --confirm Confirm default options and skip questions
|
-y, --yes Skip questions when setting up new project using default scope and settings
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import fs from 'fs-extra';
|
|||||||
import bytes from 'bytes';
|
import bytes from 'bytes';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { join, resolve, basename } from 'path';
|
import { join, resolve, basename } from 'path';
|
||||||
import { fileNameSymbol, VercelConfig } from '@vercel/client';
|
import {
|
||||||
|
fileNameSymbol,
|
||||||
|
VALID_ARCHIVE_FORMATS,
|
||||||
|
VercelConfig,
|
||||||
|
} from '@vercel/client';
|
||||||
import code from '../../util/output/code';
|
import code from '../../util/output/code';
|
||||||
import highlight from '../../util/output/highlight';
|
import highlight from '../../util/output/highlight';
|
||||||
import { readLocalConfig } from '../../util/config/files';
|
import { readLocalConfig } from '../../util/config/files';
|
||||||
@@ -43,9 +47,7 @@ import {
|
|||||||
import { SchemaValidationFailed } from '../../util/errors';
|
import { SchemaValidationFailed } from '../../util/errors';
|
||||||
import purchaseDomainIfAvailable from '../../util/domains/purchase-domain-if-available';
|
import purchaseDomainIfAvailable from '../../util/domains/purchase-domain-if-available';
|
||||||
import confirm from '../../util/input/confirm';
|
import confirm from '../../util/input/confirm';
|
||||||
import editProjectSettings, {
|
import editProjectSettings from '../../util/input/edit-project-settings';
|
||||||
PartialProjectSettings,
|
|
||||||
} from '../../util/input/edit-project-settings';
|
|
||||||
import {
|
import {
|
||||||
getLinkedProject,
|
getLinkedProject,
|
||||||
linkFolderToProject,
|
linkFolderToProject,
|
||||||
@@ -66,10 +68,12 @@ import { getDeploymentChecks } from '../../util/deploy/get-deployment-checks';
|
|||||||
import parseTarget from '../../util/deploy/parse-target';
|
import parseTarget from '../../util/deploy/parse-target';
|
||||||
import getPrebuiltJson from '../../util/deploy/get-prebuilt-json';
|
import getPrebuiltJson from '../../util/deploy/get-prebuilt-json';
|
||||||
import { createGitMeta } from '../../util/create-git-meta';
|
import { createGitMeta } from '../../util/create-git-meta';
|
||||||
|
import { isValidArchive } from '../../util/deploy/validate-archive-format';
|
||||||
import { parseEnv } from '../../util/parse-env';
|
import { parseEnv } from '../../util/parse-env';
|
||||||
import { errorToString, isErrnoException, isError } from '../../util/is-error';
|
import { errorToString, isErrnoException, isError } from '../../util/is-error';
|
||||||
|
import { pickOverrides } from '../../util/projects/project-settings';
|
||||||
|
|
||||||
export default async (client: Client) => {
|
export default async (client: Client): Promise<number> => {
|
||||||
const { output } = client;
|
const { output } = client;
|
||||||
|
|
||||||
let argv = null;
|
let argv = null;
|
||||||
@@ -87,20 +91,28 @@ export default async (client: Client) => {
|
|||||||
'--regions': String,
|
'--regions': String,
|
||||||
'--prebuilt': Boolean,
|
'--prebuilt': Boolean,
|
||||||
'--prod': Boolean,
|
'--prod': Boolean,
|
||||||
'--confirm': Boolean,
|
'--archive': String,
|
||||||
|
'--yes': Boolean,
|
||||||
'-f': '--force',
|
'-f': '--force',
|
||||||
'-p': '--public',
|
'-p': '--public',
|
||||||
'-e': '--env',
|
'-e': '--env',
|
||||||
'-b': '--build-env',
|
'-b': '--build-env',
|
||||||
'-m': '--meta',
|
'-m': '--meta',
|
||||||
'-c': '--confirm',
|
'-y': '--yes',
|
||||||
|
|
||||||
// deprecated
|
// deprecated
|
||||||
'--name': String,
|
'--name': String,
|
||||||
'-n': '--name',
|
'-n': '--name',
|
||||||
'--no-clipboard': Boolean,
|
'--no-clipboard': Boolean,
|
||||||
'--target': String,
|
'--target': String,
|
||||||
|
'--confirm': Boolean,
|
||||||
|
'-c': '--confirm',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if ('--confirm' in argv) {
|
||||||
|
output.warn('`--confirm` is deprecated, please use `--yes` instead');
|
||||||
|
argv['--yes'] = argv['--confirm'];
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error);
|
handleError(error);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -173,7 +185,7 @@ export default async (client: Client) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { path } = pathValidation;
|
const { path } = pathValidation;
|
||||||
const autoConfirm = argv['--confirm'];
|
const autoConfirm = argv['--yes'];
|
||||||
|
|
||||||
// deprecate --name
|
// deprecate --name
|
||||||
if (argv['--name']) {
|
if (argv['--name']) {
|
||||||
@@ -254,6 +266,12 @@ export default async (client: Client) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const archive = argv['--archive'];
|
||||||
|
if (typeof archive === 'string' && !isValidArchive(archive)) {
|
||||||
|
output.error(`Format must be one of: ${VALID_ARCHIVE_FORMATS.join(', ')}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// retrieve `project` and `org` from .vercel
|
// retrieve `project` and `org` from .vercel
|
||||||
const link = await getLinkedProject(client, path);
|
const link = await getLinkedProject(client, path);
|
||||||
|
|
||||||
@@ -277,7 +295,7 @@ export default async (client: Client) => {
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (!shouldStartSetup) {
|
if (!shouldStartSetup) {
|
||||||
output.print(`Aborted. Project not set up.\n`);
|
output.print(`Canceled. Project not set up.\n`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,14 +508,7 @@ export default async (client: Client) => {
|
|||||||
let deployStamp = stamp();
|
let deployStamp = stamp();
|
||||||
let deployment = null;
|
let deployment = null;
|
||||||
|
|
||||||
const localConfigurationOverrides: PartialProjectSettings = {
|
const localConfigurationOverrides = pickOverrides(localConfig);
|
||||||
buildCommand: localConfig?.buildCommand,
|
|
||||||
devCommand: localConfig?.devCommand,
|
|
||||||
framework: localConfig?.framework,
|
|
||||||
commandForIgnoringBuildStep: localConfig?.ignoreCommand,
|
|
||||||
installCommand: localConfig?.installCommand,
|
|
||||||
outputDirectory: localConfig?.outputDirectory,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const createArgs: any = {
|
const createArgs: any = {
|
||||||
@@ -538,7 +549,8 @@ export default async (client: Client) => {
|
|||||||
createArgs,
|
createArgs,
|
||||||
org,
|
org,
|
||||||
!project,
|
!project,
|
||||||
path
|
path,
|
||||||
|
archive
|
||||||
);
|
);
|
||||||
|
|
||||||
if (deployment.code === 'missing_project_settings') {
|
if (deployment.code === 'missing_project_settings') {
|
||||||
@@ -911,4 +923,6 @@ const printDeploymentStatus = async (
|
|||||||
) + newline;
|
) + newline;
|
||||||
output.print(message + link);
|
output.print(message + link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import parseListen from '../../util/dev/parse-listen';
|
|||||||
import { ProjectEnvVariable } from '../../types';
|
import { ProjectEnvVariable } from '../../types';
|
||||||
import Client from '../../util/client';
|
import Client from '../../util/client';
|
||||||
import { getLinkedProject } from '../../util/projects/link';
|
import { getLinkedProject } from '../../util/projects/link';
|
||||||
import { getFrameworks } from '../../util/get-frameworks';
|
|
||||||
import { ProjectSettings } from '../../types';
|
import { ProjectSettings } from '../../types';
|
||||||
import getDecryptedEnvRecords from '../../util/get-decrypted-env-records';
|
import getDecryptedEnvRecords from '../../util/get-decrypted-env-records';
|
||||||
import setupAndLink from '../../util/link/setup-and-link';
|
import setupAndLink from '../../util/link/setup-and-link';
|
||||||
@@ -17,7 +16,7 @@ import { OUTPUT_DIR } from '../../util/build/write-build-result';
|
|||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
'--listen': string;
|
'--listen': string;
|
||||||
'--confirm': boolean;
|
'--yes': boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function dev(
|
export default async function dev(
|
||||||
@@ -31,14 +30,11 @@ export default async function dev(
|
|||||||
const listen = parseListen(opts['--listen'] || '3000');
|
const listen = parseListen(opts['--listen'] || '3000');
|
||||||
|
|
||||||
// retrieve dev command
|
// retrieve dev command
|
||||||
let [link, frameworks] = await Promise.all([
|
let link = await getLinkedProject(client, cwd);
|
||||||
getLinkedProject(client, cwd),
|
|
||||||
getFrameworks(client),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (link.status === 'not_linked' && !process.env.__VERCEL_SKIP_DEV_CMD) {
|
if (link.status === 'not_linked' && !process.env.__VERCEL_SKIP_DEV_CMD) {
|
||||||
link = await setupAndLink(client, cwd, {
|
link = await setupAndLink(client, cwd, {
|
||||||
autoConfirm: opts['--confirm'],
|
autoConfirm: opts['--yes'],
|
||||||
successEmoji: 'link',
|
successEmoji: 'link',
|
||||||
setupMsg: 'Set up and develop',
|
setupMsg: 'Set up and develop',
|
||||||
});
|
});
|
||||||
@@ -54,14 +50,12 @@ export default async function dev(
|
|||||||
client.output.error(
|
client.output.error(
|
||||||
`Command ${getCommandName(
|
`Command ${getCommandName(
|
||||||
'dev'
|
'dev'
|
||||||
)} requires confirmation. Use option ${param('--confirm')} to confirm.`
|
)} requires confirmation. Use option ${param('--yes')} to confirm.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return link.exitCode;
|
return link.exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
let devCommand: string | undefined;
|
|
||||||
let frameworkSlug: string | undefined;
|
|
||||||
let projectSettings: ProjectSettings | undefined;
|
let projectSettings: ProjectSettings | undefined;
|
||||||
let projectEnvs: ProjectEnvVariable[] = [];
|
let projectEnvs: ProjectEnvVariable[] = [];
|
||||||
let systemEnvValues: string[] = [];
|
let systemEnvValues: string[] = [];
|
||||||
@@ -71,23 +65,6 @@ export default async function dev(
|
|||||||
|
|
||||||
projectSettings = project;
|
projectSettings = project;
|
||||||
|
|
||||||
if (project.devCommand) {
|
|
||||||
devCommand = project.devCommand;
|
|
||||||
} else if (project.framework) {
|
|
||||||
const framework = frameworks.find(f => f.slug === project.framework);
|
|
||||||
|
|
||||||
if (framework) {
|
|
||||||
if (framework.slug) {
|
|
||||||
frameworkSlug = framework.slug;
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaults = framework.settings.devCommand.value;
|
|
||||||
if (defaults) {
|
|
||||||
devCommand = defaults;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project.rootDirectory) {
|
if (project.rootDirectory) {
|
||||||
cwd = join(cwd, project.rootDirectory);
|
cwd = join(cwd, project.rootDirectory);
|
||||||
}
|
}
|
||||||
@@ -100,16 +77,17 @@ export default async function dev(
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is just for tests - can be removed once project settings
|
const devServer = new DevServer(cwd, {
|
||||||
// are respected locally in `.vercel/project.json`
|
output,
|
||||||
if (process.env.VERCEL_DEV_COMMAND) {
|
projectSettings,
|
||||||
devCommand = process.env.VERCEL_DEV_COMMAND;
|
projectEnvs,
|
||||||
}
|
systemEnvValues,
|
||||||
|
});
|
||||||
|
|
||||||
// If there is no Development Command, we must delete the
|
// If there is no Development Command, we must delete the
|
||||||
// v3 Build Output because it will incorrectly be detected by
|
// v3 Build Output because it will incorrectly be detected by
|
||||||
// @vercel/static-build in BuildOutputV3.getBuildOutputDirectory()
|
// @vercel/static-build in BuildOutputV3.getBuildOutputDirectory()
|
||||||
if (!devCommand) {
|
if (!devServer.devCommand) {
|
||||||
const outputDir = join(cwd, OUTPUT_DIR);
|
const outputDir = join(cwd, OUTPUT_DIR);
|
||||||
if (await fs.pathExists(outputDir)) {
|
if (await fs.pathExists(outputDir)) {
|
||||||
output.log(`Removing ${OUTPUT_DIR}`);
|
output.log(`Removing ${OUTPUT_DIR}`);
|
||||||
@@ -117,14 +95,5 @@ export default async function dev(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const devServer = new DevServer(cwd, {
|
|
||||||
output,
|
|
||||||
devCommand,
|
|
||||||
frameworkSlug,
|
|
||||||
projectSettings,
|
|
||||||
projectEnvs,
|
|
||||||
systemEnvValues,
|
|
||||||
});
|
|
||||||
|
|
||||||
await devServer.start(...listen);
|
await devServer.start(...listen);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const help = () => {
|
|||||||
-d, --debug Debug mode [off]
|
-d, --debug Debug mode [off]
|
||||||
-l, --listen [uri] Specify a URI endpoint on which to listen [0.0.0.0:3000]
|
-l, --listen [uri] Specify a URI endpoint on which to listen [0.0.0.0:3000]
|
||||||
-t, --token [token] Specify an Authorization Token
|
-t, --token [token] Specify an Authorization Token
|
||||||
--confirm Skip questions and use defaults when setting up a new project
|
-y, --yes Skip questions when setting up new project using default scope and settings
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
@@ -74,14 +74,22 @@ export default async function main(client: Client) {
|
|||||||
argv = getArgs(client.argv.slice(2), {
|
argv = getArgs(client.argv.slice(2), {
|
||||||
'--listen': String,
|
'--listen': String,
|
||||||
'-l': '--listen',
|
'-l': '--listen',
|
||||||
'--confirm': Boolean,
|
'--yes': Boolean,
|
||||||
|
'-y': '--yes',
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
'--port': Number,
|
'--port': Number,
|
||||||
'-p': '--port',
|
'-p': '--port',
|
||||||
|
'--confirm': Boolean,
|
||||||
|
'-c': '--confirm',
|
||||||
});
|
});
|
||||||
args = getSubcommand(argv._.slice(1), COMMAND_CONFIG).args;
|
args = getSubcommand(argv._.slice(1), COMMAND_CONFIG).args;
|
||||||
|
|
||||||
|
if ('--confirm' in argv) {
|
||||||
|
output.warn('`--confirm` is deprecated, please use `--yes` instead');
|
||||||
|
argv['--yes'] = argv['--confirm'];
|
||||||
|
}
|
||||||
|
|
||||||
if ('--port' in argv) {
|
if ('--port' in argv) {
|
||||||
output.warn('`--port` is deprecated, please use `--listen` instead');
|
output.warn('`--port` is deprecated, please use `--listen` instead');
|
||||||
argv['--listen'] = String(argv['--port']);
|
argv['--listen'] = String(argv['--port']);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default async function add(
|
|||||||
const { domain, data: argData } = parsedParams;
|
const { domain, data: argData } = parsedParams;
|
||||||
const data = await getDNSData(client, argData);
|
const data = await getDNSData(client, argData);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
output.log(`Aborted`);
|
output.log(`Canceled`);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default async function rm(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!yes) {
|
if (!yes) {
|
||||||
output.error(`User aborted.`);
|
output.error(`User canceled.`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,9 +116,7 @@ export default async function buy(
|
|||||||
|
|
||||||
if (buyResult instanceof ERRORS.SourceNotFound) {
|
if (buyResult instanceof ERRORS.SourceNotFound) {
|
||||||
output.error(
|
output.error(
|
||||||
`Could not purchase domain. Please add a payment method using ${getCommandName(
|
`Could not purchase domain. Please add a payment method using the dashboard.`
|
||||||
`billing add`
|
|
||||||
)}.`
|
|
||||||
);
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ const help = () => {
|
|||||||
)} Login token
|
)} Login token
|
||||||
-S, --scope Set a custom scope
|
-S, --scope Set a custom scope
|
||||||
-N, --next Show next page of results
|
-N, --next Show next page of results
|
||||||
|
-y, --yes Skip the confirmation prompt when removing a domain
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ export default async function main(client: Client) {
|
|||||||
'--force': Boolean,
|
'--force': Boolean,
|
||||||
'--next': Number,
|
'--next': Number,
|
||||||
'-N': '--next',
|
'-N': '--next',
|
||||||
|
'-y': '--yes',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error);
|
handleError(error);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default async function move(
|
|||||||
client
|
client
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ export default async function move(
|
|||||||
client
|
client
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export default async function rm(
|
|||||||
client
|
client
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ async function removeDomain(
|
|||||||
!skipConfirmation &&
|
!skipConfirmation &&
|
||||||
!(await promptBool(`Remove conflicts associated with domain?`, client))
|
!(await promptBool(`Remove conflicts associated with domain?`, client))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,9 +111,7 @@ export default async function transferIn(
|
|||||||
|
|
||||||
if (transferInResult instanceof ERRORS.SourceNotFound) {
|
if (transferInResult instanceof ERRORS.SourceNotFound) {
|
||||||
output.error(
|
output.error(
|
||||||
`Could not purchase domain. Please add a payment method using ${getCommandName(
|
`Could not purchase domain. Please add a payment method using the dashboard.`
|
||||||
`billing add`
|
|
||||||
)}.`
|
|
||||||
);
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/cli/src/commands/env/index.ts
vendored
1
packages/cli/src/commands/env/index.ts
vendored
@@ -42,6 +42,7 @@ const help = () => {
|
|||||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||||
'TOKEN'
|
'TOKEN'
|
||||||
)} Login token
|
)} Login token
|
||||||
|
-y, --yes Skip the confirmation prompt when overwriting env file on pull or removing an env variable
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
|
|||||||
9
packages/cli/src/commands/env/pull.ts
vendored
9
packages/cli/src/commands/env/pull.ts
vendored
@@ -84,7 +84,7 @@ export default async function pull(
|
|||||||
false
|
false
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,12 @@ export default async function pull(
|
|||||||
if (exists) {
|
if (exists) {
|
||||||
oldEnv = await createEnvObject(fullPath, output);
|
oldEnv = await createEnvObject(fullPath, output);
|
||||||
if (oldEnv) {
|
if (oldEnv) {
|
||||||
deltaString = buildDeltaString(oldEnv, records);
|
// Removes any double quotes from `records`, if they exist
|
||||||
|
// We need this because double quotes are stripped from the local .env file,
|
||||||
|
// but `records` is already in the form of a JSON object that doesn't filter
|
||||||
|
// double quotes.
|
||||||
|
const newEnv = JSON.parse(JSON.stringify(records).replace(/\\"/g, ''));
|
||||||
|
deltaString = buildDeltaString(oldEnv, newEnv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
packages/cli/src/commands/env/rm.ts
vendored
7
packages/cli/src/commands/env/rm.ts
vendored
@@ -1,5 +1,4 @@
|
|||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import inquirer from 'inquirer';
|
|
||||||
import { Project } from '../../types';
|
import { Project } from '../../types';
|
||||||
import { Output } from '../../util/output';
|
import { Output } from '../../util/output';
|
||||||
import confirm from '../../util/input/confirm';
|
import confirm from '../../util/input/confirm';
|
||||||
@@ -45,7 +44,7 @@ export default async function rm(
|
|||||||
let [envName, envTarget, envGitBranch] = args;
|
let [envName, envTarget, envGitBranch] = args;
|
||||||
|
|
||||||
while (!envName) {
|
while (!envName) {
|
||||||
const { inputName } = await inquirer.prompt({
|
const { inputName } = await client.prompt({
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'inputName',
|
name: 'inputName',
|
||||||
message: `What’s the name of the variable?`,
|
message: `What’s the name of the variable?`,
|
||||||
@@ -87,7 +86,7 @@ export default async function rm(
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (envs.length > 1) {
|
while (envs.length > 1) {
|
||||||
const { id } = await inquirer.prompt({
|
const { id } = await client.prompt({
|
||||||
name: 'id',
|
name: 'id',
|
||||||
type: 'list',
|
type: 'list',
|
||||||
message: `Remove ${envName} from which Environments?`,
|
message: `Remove ${envName} from which Environments?`,
|
||||||
@@ -112,7 +111,7 @@ export default async function rm(
|
|||||||
false
|
false
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,54 @@
|
|||||||
|
import { Dictionary } from '@vercel/client';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Org, Project } from '../../types';
|
import { Org, Project, ProjectLinkData } from '../../types';
|
||||||
import Client from '../../util/client';
|
import Client from '../../util/client';
|
||||||
import { parseGitConfig, pluckRemoteUrls } from '../../util/create-git-meta';
|
import { parseGitConfig, pluckRemoteUrls } from '../../util/create-git-meta';
|
||||||
import confirm from '../../util/input/confirm';
|
import confirm from '../../util/input/confirm';
|
||||||
import list, { ListChoice } from '../../util/input/list';
|
import list, { ListChoice } from '../../util/input/list';
|
||||||
import { Output } from '../../util/output';
|
|
||||||
import link from '../../util/output/link';
|
import link from '../../util/output/link';
|
||||||
import { getCommandName } from '../../util/pkg-name';
|
import { getCommandName } from '../../util/pkg-name';
|
||||||
import {
|
import {
|
||||||
connectGitProvider,
|
connectGitProvider,
|
||||||
disconnectGitProvider,
|
disconnectGitProvider,
|
||||||
formatProvider,
|
formatProvider,
|
||||||
|
RepoInfo,
|
||||||
parseRepoUrl,
|
parseRepoUrl,
|
||||||
} from '../../util/projects/connect-git-provider';
|
printRemoteUrls,
|
||||||
|
} from '../../util/git/connect-git-provider';
|
||||||
import validatePaths from '../../util/validate-paths';
|
import validatePaths from '../../util/validate-paths';
|
||||||
|
|
||||||
|
interface GitRepoCheckParams {
|
||||||
|
client: Client;
|
||||||
|
confirm: boolean;
|
||||||
|
gitProviderLink?: ProjectLinkData;
|
||||||
|
org: Org;
|
||||||
|
gitOrg: string;
|
||||||
|
project: Project;
|
||||||
|
provider: string;
|
||||||
|
repo: string;
|
||||||
|
repoPath: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectArgParams {
|
||||||
|
client: Client;
|
||||||
|
org: Org;
|
||||||
|
project: Project;
|
||||||
|
confirm: boolean;
|
||||||
|
repoInfo: RepoInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectGitArgParams extends ConnectArgParams {
|
||||||
|
gitConfig: Dictionary<any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PromptConnectArgParams {
|
||||||
|
client: Client;
|
||||||
|
yes: boolean;
|
||||||
|
repoInfo: RepoInfo;
|
||||||
|
remoteUrls: Dictionary<string>;
|
||||||
|
}
|
||||||
|
|
||||||
export default async function connect(
|
export default async function connect(
|
||||||
client: Client,
|
client: Client,
|
||||||
argv: any,
|
argv: any,
|
||||||
@@ -24,9 +57,10 @@ export default async function connect(
|
|||||||
org: Org | undefined
|
org: Org | undefined
|
||||||
) {
|
) {
|
||||||
const { output } = client;
|
const { output } = client;
|
||||||
const confirm = Boolean(argv['--confirm']);
|
const confirm = Boolean(argv['--yes']);
|
||||||
|
const repoArg = argv._[1];
|
||||||
|
|
||||||
if (args.length !== 0) {
|
if (args.length > 1) {
|
||||||
output.error(
|
output.error(
|
||||||
`Invalid number of arguments. Usage: ${chalk.cyan(
|
`Invalid number of arguments. Usage: ${chalk.cyan(
|
||||||
`${getCommandName('project connect')}`
|
`${getCommandName('project connect')}`
|
||||||
@@ -36,7 +70,7 @@ export default async function connect(
|
|||||||
}
|
}
|
||||||
if (!project || !org) {
|
if (!project || !org) {
|
||||||
output.error(
|
output.error(
|
||||||
`Can't find \`org\` or \`project\`. Make sure your current directory is linked to a Vercel projet by running ${getCommandName(
|
`Can't find \`org\` or \`project\`. Make sure your current directory is linked to a Vercel project by running ${getCommandName(
|
||||||
'link'
|
'link'
|
||||||
)}.`
|
)}.`
|
||||||
);
|
);
|
||||||
@@ -57,9 +91,38 @@ export default async function connect(
|
|||||||
// get project from .git
|
// get project from .git
|
||||||
const gitConfigPath = join(path, '.git/config');
|
const gitConfigPath = join(path, '.git/config');
|
||||||
const gitConfig = await parseGitConfig(gitConfigPath, output);
|
const gitConfig = await parseGitConfig(gitConfigPath, output);
|
||||||
|
|
||||||
|
if (repoArg) {
|
||||||
|
// parse repo arg
|
||||||
|
const parsedUrlArg = parseRepoUrl(repoArg);
|
||||||
|
if (!parsedUrlArg) {
|
||||||
|
output.error(
|
||||||
|
`Failed to parse URL "${repoArg}". Please ensure the URL is valid.`
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (gitConfig) {
|
||||||
|
return await connectArgWithLocalGit({
|
||||||
|
client,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
confirm,
|
||||||
|
gitConfig,
|
||||||
|
repoInfo: parsedUrlArg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return await connectArg({
|
||||||
|
client,
|
||||||
|
confirm,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
repoInfo: repoArg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!gitConfig) {
|
if (!gitConfig) {
|
||||||
output.error(
|
output.error(
|
||||||
`No local git repo found. Run ${chalk.cyan(
|
`No local Git repository found. Run ${chalk.cyan(
|
||||||
'`git clone <url>`'
|
'`git clone <url>`'
|
||||||
)} to clone a remote Git repository first.`
|
)} to clone a remote Git repository first.`
|
||||||
);
|
);
|
||||||
@@ -78,7 +141,7 @@ export default async function connect(
|
|||||||
let remoteUrl: string;
|
let remoteUrl: string;
|
||||||
|
|
||||||
if (Object.keys(remoteUrls).length > 1) {
|
if (Object.keys(remoteUrls).length > 1) {
|
||||||
output.log(`Found multiple remote URLs.`);
|
output.log('Found multiple remote URLs.');
|
||||||
remoteUrl = await selectRemoteUrl(client, remoteUrls);
|
remoteUrl = await selectRemoteUrl(client, remoteUrls);
|
||||||
} else {
|
} else {
|
||||||
// If only one is found, get it — usually "origin"
|
// If only one is found, get it — usually "origin"
|
||||||
@@ -86,14 +149,14 @@ export default async function connect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (remoteUrl === '') {
|
if (remoteUrl === '') {
|
||||||
output.log('Aborted.');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.log(`Connecting Git remote: ${link(remoteUrl)}`);
|
output.log(`Connecting Git remote: ${link(remoteUrl)}`);
|
||||||
|
|
||||||
const parsedUrl = parseRepoUrl(remoteUrl);
|
const repoInfo = parseRepoUrl(remoteUrl);
|
||||||
if (!parsedUrl) {
|
if (!repoInfo) {
|
||||||
output.error(
|
output.error(
|
||||||
`Failed to parse Git repo data from the following remote URL: ${link(
|
`Failed to parse Git repo data from the following remote URL: ${link(
|
||||||
remoteUrl
|
remoteUrl
|
||||||
@@ -101,10 +164,176 @@ export default async function connect(
|
|||||||
);
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
const { provider, org: gitOrg, repo } = parsedUrl;
|
const { provider, org: gitOrg, repo } = repoInfo;
|
||||||
const repoPath = `${gitOrg}/${repo}`;
|
const repoPath = `${gitOrg}/${repo}`;
|
||||||
let connectedRepoPath;
|
|
||||||
|
|
||||||
|
const checkAndConnect = await checkExistsAndConnect({
|
||||||
|
client,
|
||||||
|
confirm,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
gitProviderLink,
|
||||||
|
provider,
|
||||||
|
repoPath,
|
||||||
|
gitOrg,
|
||||||
|
repo,
|
||||||
|
});
|
||||||
|
if (typeof checkAndConnect === 'number') {
|
||||||
|
return checkAndConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
output.log(
|
||||||
|
`Connected ${formatProvider(provider)} repository ${chalk.cyan(repoPath)}!`
|
||||||
|
);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function connectArg({
|
||||||
|
client,
|
||||||
|
confirm,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
repoInfo,
|
||||||
|
}: ConnectArgParams) {
|
||||||
|
const { url: repoUrl } = repoInfo;
|
||||||
|
client.output.log(`Connecting Git remote: ${link(repoUrl)}`);
|
||||||
|
const parsedRepoArg = parseRepoUrl(repoUrl);
|
||||||
|
if (!parsedRepoArg) {
|
||||||
|
client.output.error(
|
||||||
|
`Failed to parse URL "${repoUrl}". Please ensure the URL is valid.`
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const { provider, org: gitOrg, repo } = parsedRepoArg;
|
||||||
|
const repoPath = `${gitOrg}/${repo}`;
|
||||||
|
const connect = await checkExistsAndConnect({
|
||||||
|
client,
|
||||||
|
confirm,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
gitProviderLink: project.link,
|
||||||
|
provider,
|
||||||
|
repoPath,
|
||||||
|
gitOrg,
|
||||||
|
repo,
|
||||||
|
});
|
||||||
|
if (typeof connect === 'number') {
|
||||||
|
return connect;
|
||||||
|
}
|
||||||
|
client.output.log(
|
||||||
|
`Connected ${formatProvider(provider)} repository ${chalk.cyan(repoPath)}!`
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function connectArgWithLocalGit({
|
||||||
|
client,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
confirm,
|
||||||
|
gitConfig,
|
||||||
|
repoInfo,
|
||||||
|
}: ConnectGitArgParams) {
|
||||||
|
const remoteUrls = pluckRemoteUrls(gitConfig);
|
||||||
|
if (remoteUrls) {
|
||||||
|
const shouldConnect = await promptConnectArg({
|
||||||
|
client,
|
||||||
|
yes: confirm,
|
||||||
|
repoInfo,
|
||||||
|
remoteUrls,
|
||||||
|
});
|
||||||
|
if (!shouldConnect) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (shouldConnect) {
|
||||||
|
const { provider, org: gitOrg, repo, url: repoUrl } = repoInfo;
|
||||||
|
const repoPath = `${gitOrg}/${repo}`;
|
||||||
|
client.output.log(`Connecting Git remote: ${link(repoUrl)}`);
|
||||||
|
const connect = await checkExistsAndConnect({
|
||||||
|
client,
|
||||||
|
confirm,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
gitProviderLink: project.link,
|
||||||
|
provider,
|
||||||
|
repoPath,
|
||||||
|
gitOrg,
|
||||||
|
repo,
|
||||||
|
});
|
||||||
|
if (typeof connect === 'number') {
|
||||||
|
return connect;
|
||||||
|
}
|
||||||
|
client.output.log(
|
||||||
|
`Connected ${formatProvider(provider)} repository ${chalk.cyan(
|
||||||
|
repoPath
|
||||||
|
)}!`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return await connectArg({ client, confirm, org, project, repoInfo });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function promptConnectArg({
|
||||||
|
client,
|
||||||
|
yes,
|
||||||
|
repoInfo: repoInfoFromArg,
|
||||||
|
remoteUrls,
|
||||||
|
}: PromptConnectArgParams) {
|
||||||
|
if (Object.keys(remoteUrls).length > 1) {
|
||||||
|
client.output.log(
|
||||||
|
'Found multiple Git repositories in your local Git config:'
|
||||||
|
);
|
||||||
|
printRemoteUrls(client.output, remoteUrls);
|
||||||
|
} else {
|
||||||
|
const url = Object.values(remoteUrls)[0];
|
||||||
|
const repoInfoFromGitConfig = parseRepoUrl(url);
|
||||||
|
if (!repoInfoFromGitConfig) {
|
||||||
|
client.output.error(
|
||||||
|
`Failed to parse URL "${url}". Please ensure the URL is valid.`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
JSON.stringify(repoInfoFromGitConfig) === JSON.stringify(repoInfoFromArg)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
client.output.log(
|
||||||
|
`Found a repository in your local Git Config: ${chalk.cyan(
|
||||||
|
Object.values(remoteUrls)[0]
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let shouldConnect = yes;
|
||||||
|
if (!shouldConnect) {
|
||||||
|
const { url: repoUrlFromArg } = repoInfoFromArg;
|
||||||
|
shouldConnect = await confirm(
|
||||||
|
client,
|
||||||
|
`Do you still want to connect ${link(repoUrlFromArg)}?`,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
if (!shouldConnect) {
|
||||||
|
client.output.log('Canceled. Repo not connected.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shouldConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkExistsAndConnect({
|
||||||
|
client,
|
||||||
|
confirm,
|
||||||
|
org,
|
||||||
|
project,
|
||||||
|
gitProviderLink,
|
||||||
|
provider,
|
||||||
|
repoPath,
|
||||||
|
gitOrg,
|
||||||
|
repo,
|
||||||
|
}: GitRepoCheckParams) {
|
||||||
if (!gitProviderLink) {
|
if (!gitProviderLink) {
|
||||||
const connect = await connectGitProvider(
|
const connect = await connectGitProvider(
|
||||||
client,
|
client,
|
||||||
@@ -120,14 +349,14 @@ export default async function connect(
|
|||||||
const connectedProvider = gitProviderLink.type;
|
const connectedProvider = gitProviderLink.type;
|
||||||
const connectedOrg = gitProviderLink.org;
|
const connectedOrg = gitProviderLink.org;
|
||||||
const connectedRepo = gitProviderLink.repo;
|
const connectedRepo = gitProviderLink.repo;
|
||||||
connectedRepoPath = `${connectedOrg}/${connectedRepo}`;
|
const connectedRepoPath = `${connectedOrg}/${connectedRepo}`;
|
||||||
|
|
||||||
const isSameRepo =
|
const isSameRepo =
|
||||||
connectedProvider === provider &&
|
connectedProvider === provider &&
|
||||||
connectedOrg === gitOrg &&
|
connectedOrg === gitOrg &&
|
||||||
connectedRepo === repo;
|
connectedRepo === repo;
|
||||||
if (isSameRepo) {
|
if (isSameRepo) {
|
||||||
output.log(
|
client.output.log(
|
||||||
`${chalk.cyan(connectedRepoPath)} is already connected to your project.`
|
`${chalk.cyan(connectedRepoPath)} is already connected to your project.`
|
||||||
);
|
);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -135,8 +364,8 @@ export default async function connect(
|
|||||||
|
|
||||||
const shouldReplaceRepo = await confirmRepoConnect(
|
const shouldReplaceRepo = await confirmRepoConnect(
|
||||||
client,
|
client,
|
||||||
output,
|
|
||||||
confirm,
|
confirm,
|
||||||
|
connectedProvider,
|
||||||
connectedRepoPath
|
connectedRepoPath
|
||||||
);
|
);
|
||||||
if (!shouldReplaceRepo) {
|
if (!shouldReplaceRepo) {
|
||||||
@@ -155,31 +384,27 @@ export default async function connect(
|
|||||||
return connect;
|
return connect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output.log(
|
|
||||||
`Connected ${formatProvider(provider)} repository ${chalk.cyan(repoPath)}!`
|
|
||||||
);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirmRepoConnect(
|
async function confirmRepoConnect(
|
||||||
client: Client,
|
client: Client,
|
||||||
output: Output,
|
|
||||||
yes: boolean,
|
yes: boolean,
|
||||||
|
connectedProvider: string,
|
||||||
connectedRepoPath: string
|
connectedRepoPath: string
|
||||||
) {
|
) {
|
||||||
let shouldReplaceProject = yes;
|
let shouldReplaceProject = yes;
|
||||||
if (!shouldReplaceProject) {
|
if (!shouldReplaceProject) {
|
||||||
shouldReplaceProject = await confirm(
|
shouldReplaceProject = await confirm(
|
||||||
client,
|
client,
|
||||||
`Looks like you already have a repository connected: ${chalk.cyan(
|
`Looks like you already have a ${formatProvider(
|
||||||
|
connectedProvider
|
||||||
|
)} repository connected: ${chalk.cyan(
|
||||||
connectedRepoPath
|
connectedRepoPath
|
||||||
)}. Do you want to replace it?`,
|
)}. Do you want to replace it?`,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
if (!shouldReplaceProject) {
|
if (!shouldReplaceProject) {
|
||||||
output.log(`Aborted. Repo not connected.`);
|
client.output.log('Canceled. Repo not connected.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shouldReplaceProject;
|
return shouldReplaceProject;
|
||||||
@@ -187,7 +412,7 @@ async function confirmRepoConnect(
|
|||||||
|
|
||||||
async function selectRemoteUrl(
|
async function selectRemoteUrl(
|
||||||
client: Client,
|
client: Client,
|
||||||
remoteUrls: { [key: string]: string }
|
remoteUrls: Dictionary<string>
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
let choices: ListChoice[] = [];
|
let choices: ListChoice[] = [];
|
||||||
for (const [urlKey, urlValue] of Object.entries(remoteUrls)) {
|
for (const [urlKey, urlValue] of Object.entries(remoteUrls)) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Org, Project } from '../../types';
|
|||||||
import Client from '../../util/client';
|
import Client from '../../util/client';
|
||||||
import confirm from '../../util/input/confirm';
|
import confirm from '../../util/input/confirm';
|
||||||
import { getCommandName } from '../../util/pkg-name';
|
import { getCommandName } from '../../util/pkg-name';
|
||||||
import { disconnectGitProvider } from '../../util/projects/connect-git-provider';
|
import { disconnectGitProvider } from '../../util/git/connect-git-provider';
|
||||||
|
|
||||||
export default async function disconnect(
|
export default async function disconnect(
|
||||||
client: Client,
|
client: Client,
|
||||||
@@ -43,7 +43,7 @@ export default async function disconnect(
|
|||||||
await disconnectGitProvider(client, org, project.id);
|
await disconnectGitProvider(client, org, project.id);
|
||||||
output.log(`Disconnected ${chalk.cyan(`${linkOrg}/${repo}`)}.`);
|
output.log(`Disconnected ${chalk.cyan(`${linkOrg}/${repo}`)}.`);
|
||||||
} else {
|
} else {
|
||||||
output.log('Aborted.');
|
output.log('Canceled');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
output.error(
|
output.error(
|
||||||
|
|||||||
@@ -16,21 +16,32 @@ const help = () => {
|
|||||||
|
|
||||||
${chalk.dim('Commands:')}
|
${chalk.dim('Commands:')}
|
||||||
|
|
||||||
connect Connect your Git config "origin" remote as a Git provider to your project
|
connect [url] Connect your Vercel Project to your Git repository or provide the remote URL to your Git repository
|
||||||
disconnect Disconnect the Git provider repository from your project
|
disconnect Disconnect the Git provider repository from your project
|
||||||
|
|
||||||
${chalk.dim('Options:')}
|
${chalk.dim('Options:')}
|
||||||
|
|
||||||
-h, --help Output usage information
|
-h, --help Output usage information
|
||||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||||
'TOKEN'
|
'TOKEN'
|
||||||
)} Login token
|
)} Login token
|
||||||
|
-y, --yes Skip confirmation when connecting a Git provider
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
${chalk.gray('–')} Connect a Git provider repository
|
${chalk.gray(
|
||||||
|
'–'
|
||||||
|
)} Connect your Vercel Project to your Git repository defined in your local .git config
|
||||||
|
|
||||||
${chalk.cyan(`$ ${getPkgName()} git connect`)}
|
${chalk.cyan(`$ ${getPkgName()} git connect`)}
|
||||||
|
|
||||||
|
${chalk.gray(
|
||||||
|
'–'
|
||||||
|
)} Connect your Vercel Project to a Git repository using the remote URL
|
||||||
|
|
||||||
|
${chalk.cyan(
|
||||||
|
`$ ${getPkgName()} git connect https://github.com/user/repo.git`
|
||||||
|
)}
|
||||||
|
|
||||||
${chalk.gray('–')} Disconnect the Git provider repository
|
${chalk.gray('–')} Disconnect the Git provider repository
|
||||||
|
|
||||||
@@ -49,7 +60,12 @@ export default async function main(client: Client) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
argv = getArgs(client.argv.slice(2), {
|
argv = getArgs(client.argv.slice(2), {
|
||||||
'--confirm': Boolean,
|
'--yes': Boolean,
|
||||||
|
'-y': '--yes',
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
'-c': '--yes',
|
||||||
|
'--confirm': '--yes',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error);
|
handleError(error);
|
||||||
@@ -64,7 +80,7 @@ export default async function main(client: Client) {
|
|||||||
argv._ = argv._.slice(1);
|
argv._ = argv._.slice(1);
|
||||||
subcommand = argv._[0];
|
subcommand = argv._[0];
|
||||||
const args = argv._.slice(1);
|
const args = argv._.slice(1);
|
||||||
const confirm = Boolean(argv['--confirm']);
|
const confirm = Boolean(argv['--yes']);
|
||||||
const { output } = client;
|
const { output } = client;
|
||||||
|
|
||||||
let paths = [process.cwd()];
|
let paths = [process.cwd()];
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
export default new Map([
|
export default new Map([
|
||||||
['alias', 'alias'],
|
['alias', 'alias'],
|
||||||
['aliases', 'alias'],
|
['aliases', 'alias'],
|
||||||
['billing', 'billing'],
|
|
||||||
['bisect', 'bisect'],
|
['bisect', 'bisect'],
|
||||||
['build', 'build'],
|
['build', 'build'],
|
||||||
['cc', 'billing'],
|
|
||||||
['cert', 'certs'],
|
['cert', 'certs'],
|
||||||
['certs', 'certs'],
|
['certs', 'certs'],
|
||||||
['deploy', 'deploy'],
|
['deploy', 'deploy'],
|
||||||
@@ -36,6 +34,5 @@ export default new Map([
|
|||||||
['switch', 'teams'],
|
['switch', 'teams'],
|
||||||
['team', 'teams'],
|
['team', 'teams'],
|
||||||
['teams', 'teams'],
|
['teams', 'teams'],
|
||||||
['update', 'update'],
|
|
||||||
['whoami', 'whoami'],
|
['whoami', 'whoami'],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export default async function init(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!chosen) {
|
if (!chosen) {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const help = () => {
|
|||||||
-p ${chalk.bold.underline('NAME')}, --project=${chalk.bold.underline(
|
-p ${chalk.bold.underline('NAME')}, --project=${chalk.bold.underline(
|
||||||
'NAME'
|
'NAME'
|
||||||
)} Project name
|
)} Project name
|
||||||
--confirm Confirm default options and skip questions
|
-y, --yes Skip questions when setting up new project using default scope and settings
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ const help = () => {
|
|||||||
'–'
|
'–'
|
||||||
)} Link current directory with default options and skip questions
|
)} Link current directory with default options and skip questions
|
||||||
|
|
||||||
${chalk.cyan(`$ ${getPkgName()} link --confirm`)}
|
${chalk.cyan(`$ ${getPkgName()} link --yes`)}
|
||||||
|
|
||||||
${chalk.gray('–')} Link a specific directory to a Vercel Project
|
${chalk.gray('–')} Link a specific directory to a Vercel Project
|
||||||
|
|
||||||
@@ -49,9 +49,14 @@ const help = () => {
|
|||||||
|
|
||||||
export default async function main(client: Client) {
|
export default async function main(client: Client) {
|
||||||
const argv = getArgs(client.argv.slice(2), {
|
const argv = getArgs(client.argv.slice(2), {
|
||||||
'--confirm': Boolean,
|
'--yes': Boolean,
|
||||||
|
'-y': '--yes',
|
||||||
'--project': String,
|
'--project': String,
|
||||||
'-p': '--project',
|
'-p': '--project',
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
'--confirm': Boolean,
|
||||||
|
'-c': '--confirm',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (argv['--help']) {
|
if (argv['--help']) {
|
||||||
@@ -59,10 +64,15 @@ export default async function main(client: Client) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('--confirm' in argv) {
|
||||||
|
client.output.warn('`--confirm` is deprecated, please use `--yes` instead');
|
||||||
|
argv['--yes'] = argv['--confirm'];
|
||||||
|
}
|
||||||
|
|
||||||
const cwd = argv._[1] || process.cwd();
|
const cwd = argv._[1] || process.cwd();
|
||||||
const link = await setupAndLink(client, cwd, {
|
const link = await setupAndLink(client, cwd, {
|
||||||
forceDelete: true,
|
forceDelete: true,
|
||||||
autoConfirm: argv['--confirm'],
|
autoConfirm: argv['--yes'],
|
||||||
projectName: argv['--project'],
|
projectName: argv['--project'],
|
||||||
successEmoji: 'success',
|
successEmoji: 'success',
|
||||||
setupMsg: 'Set up',
|
setupMsg: 'Set up',
|
||||||
@@ -73,7 +83,7 @@ export default async function main(client: Client) {
|
|||||||
client.output.error(
|
client.output.error(
|
||||||
`Command ${getCommandName(
|
`Command ${getCommandName(
|
||||||
'link'
|
'link'
|
||||||
)} requires confirmation. Use option ${param('--confirm')} to confirm.`
|
)} requires confirmation. Use option ${param('--yes')} to confirm.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return link.exitCode;
|
return link.exitCode;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import ms from 'ms';
|
import ms from 'ms';
|
||||||
import table from 'text-table';
|
import table from 'text-table';
|
||||||
|
import title from 'title';
|
||||||
import Now from '../util';
|
import Now from '../util';
|
||||||
import getArgs from '../util/get-args';
|
import getArgs from '../util/get-args';
|
||||||
import { handleError } from '../util/error';
|
import { handleError } from '../util/error';
|
||||||
import cmd from '../util/output/cmd';
|
|
||||||
import logo from '../util/output/logo';
|
import logo from '../util/output/logo';
|
||||||
import elapsed from '../util/output/elapsed';
|
import elapsed from '../util/output/elapsed';
|
||||||
import strlen from '../util/strlen';
|
import strlen from '../util/strlen';
|
||||||
@@ -14,12 +14,13 @@ import { isValidName } from '../util/is-valid-name';
|
|||||||
import getCommandFlags from '../util/get-command-flags';
|
import getCommandFlags from '../util/get-command-flags';
|
||||||
import { getPkgName, getCommandName } from '../util/pkg-name';
|
import { getPkgName, getCommandName } from '../util/pkg-name';
|
||||||
import Client from '../util/client';
|
import Client from '../util/client';
|
||||||
import { Deployment } from '../types';
|
import { Deployment } from '@vercel/client';
|
||||||
import validatePaths from '../util/validate-paths';
|
import validatePaths from '../util/validate-paths';
|
||||||
import { getLinkedProject } from '../util/projects/link';
|
import { getLinkedProject } from '../util/projects/link';
|
||||||
import { ensureLink } from '../util/ensure-link';
|
import { ensureLink } from '../util/ensure-link';
|
||||||
import getScope from '../util/get-scope';
|
import getScope from '../util/get-scope';
|
||||||
import { isAPIError } from '../util/errors-ts';
|
import { isAPIError } from '../util/errors-ts';
|
||||||
|
import { isErrnoException } from '../util/is-error';
|
||||||
|
|
||||||
const help = () => {
|
const help = () => {
|
||||||
console.log(`
|
console.log(`
|
||||||
@@ -35,7 +36,7 @@ const help = () => {
|
|||||||
'DIR'
|
'DIR'
|
||||||
)} Path to the global ${'`.vercel`'} directory
|
)} Path to the global ${'`.vercel`'} directory
|
||||||
-d, --debug Debug mode [off]
|
-d, --debug Debug mode [off]
|
||||||
--confirm Skip the confirmation prompt
|
-y, --yes Skip questions when setting up new project using default scope and settings
|
||||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||||
'TOKEN'
|
'TOKEN'
|
||||||
)} Login token
|
)} Login token
|
||||||
@@ -43,6 +44,7 @@ const help = () => {
|
|||||||
-m, --meta Filter deployments by metadata (e.g.: ${chalk.dim(
|
-m, --meta Filter deployments by metadata (e.g.: ${chalk.dim(
|
||||||
'`-m KEY=value`'
|
'`-m KEY=value`'
|
||||||
)}). Can appear many times.
|
)}). Can appear many times.
|
||||||
|
--prod Filter for production URLs
|
||||||
-N, --next Show next page of results
|
-N, --next Show next page of results
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
@@ -78,7 +80,13 @@ export default async function main(client: Client) {
|
|||||||
'-m': '--meta',
|
'-m': '--meta',
|
||||||
'--next': Number,
|
'--next': Number,
|
||||||
'-N': '--next',
|
'-N': '--next',
|
||||||
|
'--prod': Boolean,
|
||||||
|
'--yes': Boolean,
|
||||||
|
'-y': '--yes',
|
||||||
|
|
||||||
|
// deprecated
|
||||||
'--confirm': Boolean,
|
'--confirm': Boolean,
|
||||||
|
'-c': '--confirm',
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
handleError(err);
|
handleError(err);
|
||||||
@@ -87,6 +95,11 @@ export default async function main(client: Client) {
|
|||||||
|
|
||||||
const { output, config } = client;
|
const { output, config } = client;
|
||||||
|
|
||||||
|
if ('--confirm' in argv) {
|
||||||
|
output.warn('`--confirm` is deprecated, please use `--yes` instead');
|
||||||
|
argv['--yes'] = argv['--confirm'];
|
||||||
|
}
|
||||||
|
|
||||||
const { print, log, error, note, debug, spinner } = output;
|
const { print, log, error, note, debug, spinner } = output;
|
||||||
|
|
||||||
if (argv._.length > 2) {
|
if (argv._.length > 2) {
|
||||||
@@ -99,10 +112,10 @@ export default async function main(client: Client) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const yes = argv['--confirm'] || false;
|
const yes = !!argv['--yes'];
|
||||||
|
const prod = argv['--prod'] || false;
|
||||||
|
|
||||||
const meta = parseMeta(argv['--meta']);
|
const meta = parseMeta(argv['--meta']);
|
||||||
const { includeScheme } = config;
|
|
||||||
|
|
||||||
let paths = [process.cwd()];
|
let paths = [process.cwd()];
|
||||||
const pathValidation = await validatePaths(client, paths);
|
const pathValidation = await validatePaths(client, paths);
|
||||||
@@ -136,11 +149,25 @@ export default async function main(client: Client) {
|
|||||||
if (typeof linkedProject === 'number') {
|
if (typeof linkedProject === 'number') {
|
||||||
return linkedProject;
|
return linkedProject;
|
||||||
}
|
}
|
||||||
link.org = linkedProject.org;
|
org = linkedProject.org;
|
||||||
link.project = linkedProject.project;
|
project = linkedProject.project;
|
||||||
|
app = project.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { contextName, team } = await getScope(client);
|
let contextName;
|
||||||
|
let team;
|
||||||
|
|
||||||
|
try {
|
||||||
|
({ contextName, team } = await getScope(client));
|
||||||
|
} catch (err: unknown) {
|
||||||
|
if (
|
||||||
|
isErrnoException(err) &&
|
||||||
|
(err.code === 'NOT_AUTHORIZED' || err.code === 'TEAM_DELETED')
|
||||||
|
) {
|
||||||
|
error(err.message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If user passed in a custom scope, update the current team & context name
|
// If user passed in a custom scope, update the current team & context name
|
||||||
if (argv['--scope']) {
|
if (argv['--scope']) {
|
||||||
@@ -198,11 +225,15 @@ export default async function main(client: Client) {
|
|||||||
|
|
||||||
debug('Fetching deployments');
|
debug('Fetching deployments');
|
||||||
|
|
||||||
const response = await now.list(app, {
|
const response = await now.list(
|
||||||
version: 6,
|
app,
|
||||||
meta,
|
{
|
||||||
nextTimestamp,
|
version: 6,
|
||||||
});
|
meta,
|
||||||
|
nextTimestamp,
|
||||||
|
},
|
||||||
|
prod
|
||||||
|
);
|
||||||
|
|
||||||
let {
|
let {
|
||||||
deployments,
|
deployments,
|
||||||
@@ -212,6 +243,14 @@ export default async function main(client: Client) {
|
|||||||
pagination: { count: number; next: number };
|
pagination: { count: number; next: number };
|
||||||
} = response;
|
} = response;
|
||||||
|
|
||||||
|
let showUsername = false;
|
||||||
|
for (const deployment of deployments) {
|
||||||
|
const username = deployment.creator?.username;
|
||||||
|
if (username !== contextName) {
|
||||||
|
showUsername = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (app && !deployments.length) {
|
if (app && !deployments.length) {
|
||||||
debug(
|
debug(
|
||||||
'No deployments: attempting to find deployment that matches supplied app name'
|
'No deployments: attempting to find deployment that matches supplied app name'
|
||||||
@@ -247,37 +286,34 @@ export default async function main(client: Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log(
|
log(
|
||||||
`Deployments under ${chalk.bold(contextName)} ${elapsed(
|
`${prod ? `Production deployments` : `Deployments`} for ${chalk.bold(
|
||||||
Date.now() - start
|
app
|
||||||
)}`
|
)} under ${chalk.bold(contextName)} ${elapsed(Date.now() - start)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// information to help the user find other deployments or instances
|
// information to help the user find other deployments or instances
|
||||||
if (app == null) {
|
log(
|
||||||
log(
|
`To list deployments for a project, run ${getCommandName('ls [project]')}.`
|
||||||
`To list more deployments for a project run ${cmd(
|
);
|
||||||
`${getCommandName('ls [project]')}`
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
print('\n');
|
print('\n');
|
||||||
|
|
||||||
|
const headers = ['Age', 'Deployment', 'Status', 'Duration'];
|
||||||
|
if (showUsername) headers.push('Username');
|
||||||
|
|
||||||
client.output.print(
|
client.output.print(
|
||||||
`${table(
|
`${table(
|
||||||
[
|
[
|
||||||
['project', 'latest deployment', 'state', 'age', 'username'].map(
|
headers.map(header => chalk.bold(chalk.cyan(header))),
|
||||||
header => chalk.dim(header)
|
|
||||||
),
|
|
||||||
...deployments
|
...deployments
|
||||||
.sort(sortRecent())
|
.sort(sortRecent())
|
||||||
.map(dep => [
|
.map(dep => [
|
||||||
[
|
[
|
||||||
getProjectName(dep),
|
|
||||||
chalk.bold((includeScheme ? 'https://' : '') + dep.url),
|
|
||||||
stateString(dep.state),
|
|
||||||
chalk.gray(ms(Date.now() - dep.createdAt)),
|
chalk.gray(ms(Date.now() - dep.createdAt)),
|
||||||
dep.creator.username,
|
`https://${dep.url}`,
|
||||||
|
stateString(dep.state || ''),
|
||||||
|
chalk.gray(getDeploymentDuration(dep)),
|
||||||
|
showUsername ? chalk.gray(dep.creator?.username) : '',
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
// flatten since the previous step returns a nested
|
// flatten since the previous step returns a nested
|
||||||
@@ -290,8 +326,8 @@ export default async function main(client: Client) {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
align: ['l', 'l', 'r', 'l', 'l'],
|
align: ['l', 'l', 'l', 'l', 'l'],
|
||||||
hsep: ' '.repeat(4),
|
hsep: ' '.repeat(5),
|
||||||
stringLength: strlen,
|
stringLength: strlen,
|
||||||
}
|
}
|
||||||
).replace(/^/gm, ' ')}\n\n`
|
).replace(/^/gm, ' ')}\n\n`
|
||||||
@@ -300,34 +336,43 @@ export default async function main(client: Client) {
|
|||||||
if (pagination && pagination.count === 20) {
|
if (pagination && pagination.count === 20) {
|
||||||
const flags = getCommandFlags(argv, ['_', '--next']);
|
const flags = getCommandFlags(argv, ['_', '--next']);
|
||||||
log(
|
log(
|
||||||
`To display the next page run ${getCommandName(
|
`To display the next page, run ${getCommandName(
|
||||||
`ls${app ? ' ' + app : ''}${flags} --next ${pagination.next}`
|
`ls${app ? ' ' + app : ''}${flags} --next ${pagination.next}`
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProjectName(d: Deployment) {
|
export function getDeploymentDuration(dep: Deployment): string {
|
||||||
// We group both file and files into a single project
|
if (!dep || !dep.ready || !dep.buildingAt) {
|
||||||
if (d.name === 'file') {
|
return '?';
|
||||||
return 'files';
|
|
||||||
}
|
}
|
||||||
|
const duration = ms(dep.ready - dep.buildingAt);
|
||||||
return d.name;
|
if (duration === '0ms') {
|
||||||
|
return '--';
|
||||||
|
}
|
||||||
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// renders the state string
|
// renders the state string
|
||||||
export function stateString(s: string) {
|
export function stateString(s: string) {
|
||||||
|
const CIRCLE = '● ';
|
||||||
|
// make `s` title case
|
||||||
|
const sTitle = title(s);
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case 'INITIALIZING':
|
case 'INITIALIZING':
|
||||||
return chalk.yellow(s);
|
case 'BUILDING':
|
||||||
|
case 'DEPLOYING':
|
||||||
|
case 'ANALYZING':
|
||||||
|
return chalk.yellow(CIRCLE) + sTitle;
|
||||||
case 'ERROR':
|
case 'ERROR':
|
||||||
return chalk.red(s);
|
return chalk.red(CIRCLE) + sTitle;
|
||||||
|
|
||||||
case 'READY':
|
case 'READY':
|
||||||
return s;
|
return chalk.green(CIRCLE) + sTitle;
|
||||||
|
case 'QUEUED':
|
||||||
|
return chalk.white(CIRCLE) + sTitle;
|
||||||
|
case 'CANCELED':
|
||||||
|
return chalk.gray(sTitle);
|
||||||
default:
|
default:
|
||||||
return chalk.gray('UNKNOWN');
|
return chalk.gray('UNKNOWN');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import ms from 'ms';
|
import ms from 'ms';
|
||||||
import table from 'text-table';
|
import table from 'text-table';
|
||||||
|
import { Project } from '../../types';
|
||||||
import Client from '../../util/client';
|
import Client from '../../util/client';
|
||||||
import getCommandFlags from '../../util/get-command-flags';
|
import getCommandFlags from '../../util/get-command-flags';
|
||||||
import { getCommandName } from '../../util/pkg-name';
|
import { getCommandName } from '../../util/pkg-name';
|
||||||
@@ -34,10 +35,10 @@ export default async function list(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
projects: list,
|
projects: projectList,
|
||||||
pagination,
|
pagination,
|
||||||
}: {
|
}: {
|
||||||
projects: [{ name: string; updatedAt: number }];
|
projects: Project[];
|
||||||
pagination: { count: number; next: number };
|
pagination: { count: number; next: number };
|
||||||
} = await client.fetch(projectsUrl, {
|
} = await client.fetch(projectsUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -48,39 +49,48 @@ export default async function list(
|
|||||||
const elapsed = ms(Date.now() - start);
|
const elapsed = ms(Date.now() - start);
|
||||||
|
|
||||||
output.log(
|
output.log(
|
||||||
`${list.length > 0 ? 'Projects' : 'No projects'} found under ${chalk.bold(
|
`${
|
||||||
contextName
|
projectList.length > 0 ? 'Projects' : 'No projects'
|
||||||
)} ${chalk.gray(`[${elapsed}]`)}`
|
} found under ${chalk.bold(contextName)} ${chalk.gray(`[${elapsed}]`)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (list.length > 0) {
|
if (projectList.length > 0) {
|
||||||
const cur = Date.now();
|
const tablePrint = table(
|
||||||
const header = [['', 'name', 'updated'].map(title => chalk.dim(title))];
|
[
|
||||||
|
['Project Name', 'Latest Production URL', 'Updated'].map(header =>
|
||||||
const out = table(
|
chalk.bold(chalk.cyan(header))
|
||||||
header.concat(
|
),
|
||||||
list.map(secret => [
|
...projectList
|
||||||
'',
|
.map(project => [
|
||||||
chalk.bold(secret.name),
|
[
|
||||||
chalk.gray(`${ms(cur - secret.updatedAt)} ago`),
|
chalk.bold(project.name),
|
||||||
])
|
getLatestProdUrl(project),
|
||||||
),
|
chalk.gray(ms(Date.now() - project.updatedAt)),
|
||||||
|
],
|
||||||
|
])
|
||||||
|
.flat(),
|
||||||
|
],
|
||||||
{
|
{
|
||||||
align: ['l', 'l', 'l'],
|
align: ['l', 'l', 'l'],
|
||||||
hsep: ' '.repeat(2),
|
hsep: ' '.repeat(3),
|
||||||
stringLength: strlen,
|
stringLength: strlen,
|
||||||
}
|
}
|
||||||
);
|
).replace(/^/gm, ' ');
|
||||||
|
output.print(`\n${tablePrint}\n\n`);
|
||||||
if (out) {
|
|
||||||
output.print(`\n${out}\n\n`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pagination && pagination.count === 20) {
|
if (pagination && pagination.count === 20) {
|
||||||
const flags = getCommandFlags(argv, ['_', '--next', '-N', '-d', '-y']);
|
const flags = getCommandFlags(argv, ['_', '--next', '-N', '-d', '-y']);
|
||||||
const nextCmd = `project ls${flags} --next ${pagination.next}`;
|
const nextCmd = `project ls${flags} --next ${pagination.next}`;
|
||||||
output.log(`To display the next page run ${getCommandName(nextCmd)}`);
|
output.log(`To display the next page, run ${getCommandName(nextCmd)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLatestProdUrl(project: Project): string {
|
||||||
|
const alias =
|
||||||
|
project.alias?.filter(al => al.deployment)?.[0]?.domain ||
|
||||||
|
project.alias?.[0]?.domain;
|
||||||
|
if (alias) return 'https://' + alias;
|
||||||
|
return '--';
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const help = () => {
|
|||||||
)} Path to the global ${'`.vercel`'} directory
|
)} Path to the global ${'`.vercel`'} directory
|
||||||
-d, --debug Debug mode [off]
|
-d, --debug Debug mode [off]
|
||||||
--environment [environment] Deployment environment [development]
|
--environment [environment] Deployment environment [development]
|
||||||
-y, --yes Skip the confirmation prompt
|
-y, --yes Skip questions when setting up new project using default scope and settings
|
||||||
|
|
||||||
${chalk.dim('Examples:')}
|
${chalk.dim('Examples:')}
|
||||||
|
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ export default async function main(client: Client) {
|
|||||||
).toLowerCase();
|
).toLowerCase();
|
||||||
|
|
||||||
if (confirmation !== 'y' && confirmation !== 'yes') {
|
if (confirmation !== 'y' && confirmation !== 'yes') {
|
||||||
output.log('Aborted');
|
output.log('Canceled');
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,9 +226,10 @@ async function run({ output, contextName, currentTeam, client }) {
|
|||||||
|
|
||||||
if (theSecret) {
|
if (theSecret) {
|
||||||
const yes =
|
const yes =
|
||||||
argv.yes || (await readConfirmation(output, theSecret, contextName));
|
argv.yes ||
|
||||||
|
(await readConfirmation(client, output, theSecret, contextName));
|
||||||
if (!yes) {
|
if (!yes) {
|
||||||
output.print(`Aborted. Secret not deleted.\n`);
|
output.print(`Canceled. Secret not deleted.\n`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -353,7 +354,7 @@ async function run({ output, contextName, currentTeam, client }) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readConfirmation(output, secret, contextName) {
|
async function readConfirmation(client, output, secret, contextName) {
|
||||||
const time = chalk.gray(`${ms(new Date() - new Date(secret.created))} ago`);
|
const time = chalk.gray(`${ms(new Date() - new Date(secret.created))} ago`);
|
||||||
const tbl = table([[chalk.bold(secret.name), time]], {
|
const tbl = table([[chalk.bold(secret.name), time]], {
|
||||||
align: ['r', 'l'],
|
align: ['r', 'l'],
|
||||||
@@ -367,5 +368,5 @@ async function readConfirmation(output, secret, contextName) {
|
|||||||
);
|
);
|
||||||
output.print(` ${tbl}\n`);
|
output.print(` ${tbl}\n`);
|
||||||
|
|
||||||
return confirm(`${chalk.bold.red('Are you sure?')}`, false);
|
return confirm(client, `${chalk.bold.red('Are you sure?')}`, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user