mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 21:07:47 +00:00
Compare commits
240 Commits
@vercel/py
...
@vercel/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de0d2fba0b | ||
|
|
e0900128d6 | ||
|
|
8d15f30579 | ||
|
|
960c66584c | ||
|
|
1c8f91031a | ||
|
|
68cb23c3cc | ||
|
|
94f6ae2595 | ||
|
|
b92aeac84d | ||
|
|
00420b7a01 | ||
|
|
a5128790d0 | ||
|
|
ae9aa91f4f | ||
|
|
d4cef69cc9 | ||
|
|
323f67c31a | ||
|
|
63c499a826 | ||
|
|
ad436313e1 | ||
|
|
c414288b2f | ||
|
|
b07ff7431f | ||
|
|
79fde4475c | ||
|
|
855197c699 | ||
|
|
fbd9080859 | ||
|
|
b5c5b7b82c | ||
|
|
0a072ee850 | ||
|
|
0b56caba45 | ||
|
|
ab3db60824 | ||
|
|
f2f2ff2c67 | ||
|
|
ba7dafff71 | ||
|
|
987fb4d4f7 | ||
|
|
be74f79fa0 | ||
|
|
86886e6b60 | ||
|
|
e8a9000137 | ||
|
|
75ea68d445 | ||
|
|
a5a990995c | ||
|
|
cd7dcc6731 | ||
|
|
c4bd462b85 | ||
|
|
5fc266bd8a | ||
|
|
08b04d0bda | ||
|
|
92ae51c6a6 | ||
|
|
909c493d1e | ||
|
|
98b54ff61f | ||
|
|
3defd0b2fd | ||
|
|
5a7851a7f7 | ||
|
|
7f0caa7dec | ||
|
|
89b5aad367 | ||
|
|
c13775ba07 | ||
|
|
cc3c1d1eeb | ||
|
|
3aa2fbbb53 | ||
|
|
3a8b8aa03a | ||
|
|
d008617c0b | ||
|
|
8aecb99447 | ||
|
|
1793fa643f | ||
|
|
913683a8e6 | ||
|
|
0d1dc23d0d | ||
|
|
e829ce47c3 | ||
|
|
474770e9b0 | ||
|
|
e762d8d4e8 | ||
|
|
6e8935883b | ||
|
|
1c3497dc74 | ||
|
|
9836fdb5ca | ||
|
|
d6f88f019f | ||
|
|
0f720472c4 | ||
|
|
8d0c5114e4 | ||
|
|
e3c4435606 | ||
|
|
234c4dfa84 | ||
|
|
acd756436c | ||
|
|
f26858b735 | ||
|
|
623e43f865 | ||
|
|
3e696513a2 | ||
|
|
285f62c9d0 | ||
|
|
c43db1788c | ||
|
|
fc2eb1a30d | ||
|
|
ecf194b7c1 | ||
|
|
c14e5689f1 | ||
|
|
54dfe747e2 | ||
|
|
2afc8db8e7 | ||
|
|
cc628dd9fb | ||
|
|
dfb6ef949b | ||
|
|
cd4799b5d5 | ||
|
|
5e66d4b2cc | ||
|
|
44d7473e7c | ||
|
|
fddec1286c | ||
|
|
6e5e700e8d | ||
|
|
b6e8609b83 | ||
|
|
78b7bd5ec8 | ||
|
|
4104a45c2d | ||
|
|
4c20218e05 | ||
|
|
02a0004719 | ||
|
|
123bffb776 | ||
|
|
074535f27c | ||
|
|
05243fb6e9 | ||
|
|
097725580c | ||
|
|
4b09c89e7d | ||
|
|
3a1eede63b | ||
|
|
9cee0dd5d7 | ||
|
|
b801c6e593 | ||
|
|
505050b923 | ||
|
|
15c7ad241a | ||
|
|
ec57654b5b | ||
|
|
3b9a9878bc | ||
|
|
70b7db1a15 | ||
|
|
41d6666139 | ||
|
|
2857219f89 | ||
|
|
246c2a0f5d | ||
|
|
d91bca7d6b | ||
|
|
be54fce67b | ||
|
|
7753bb8d89 | ||
|
|
ce17ac5c35 | ||
|
|
8006fc32b8 | ||
|
|
8038a90db1 | ||
|
|
f88c862e9d | ||
|
|
9170820371 | ||
|
|
c881546e0e | ||
|
|
fa21db98e4 | ||
|
|
8eabbfc666 | ||
|
|
6783f7afc9 | ||
|
|
a400b9b29d | ||
|
|
b549c37149 | ||
|
|
30d5e64291 | ||
|
|
47c2c361d2 | ||
|
|
438576fc7c | ||
|
|
b30343ef7b | ||
|
|
2dc0dfa572 | ||
|
|
9ee54b3dd6 | ||
|
|
9d67e0bc06 | ||
|
|
466135cf84 | ||
|
|
eab2e229dc | ||
|
|
698b89a2ba | ||
|
|
bae2a2e4df | ||
|
|
57916bb712 | ||
|
|
12bbd4e8eb | ||
|
|
4e4c7023dc | ||
|
|
41805790e7 | ||
|
|
6ad77ae8e1 | ||
|
|
e8daf36cd7 | ||
|
|
c319a2c499 | ||
|
|
a410baa797 | ||
|
|
625568e659 | ||
|
|
41868c1fe0 | ||
|
|
1b644f1218 | ||
|
|
29ea0fb06b | ||
|
|
b61f049f11 | ||
|
|
16e28f326b | ||
|
|
276397c940 | ||
|
|
85d7311199 | ||
|
|
b8114b8b39 | ||
|
|
d63e8d3187 | ||
|
|
11d3dd04aa | ||
|
|
46bf95ee36 | ||
|
|
92252468c2 | ||
|
|
71b83d5587 | ||
|
|
d9e5fdc5e4 | ||
|
|
58f479c603 | ||
|
|
d62461d952 | ||
|
|
e7f524defb | ||
|
|
bdefd0d05d | ||
|
|
ca522fc9f1 | ||
|
|
4a8504fc45 | ||
|
|
576217b344 | ||
|
|
f03129ac7a | ||
|
|
3eaad1fd52 | ||
|
|
4e471491d8 | ||
|
|
99395fd9fe | ||
|
|
4980fe6513 | ||
|
|
24676ae020 | ||
|
|
72ada9abd8 | ||
|
|
da893e7c57 | ||
|
|
e40eecafc9 | ||
|
|
d9e5342eba | ||
|
|
b0ab13778d | ||
|
|
c76dfbe8c9 | ||
|
|
ed6f3cc27e | ||
|
|
7b0186bffe | ||
|
|
45e22b6b60 | ||
|
|
b2bfae6e2e | ||
|
|
b6ed718f52 | ||
|
|
a84c4a37e6 | ||
|
|
d2ba06c6cb | ||
|
|
06e7753df0 | ||
|
|
235a9c3300 | ||
|
|
1b70402325 | ||
|
|
c76781fac9 | ||
|
|
451e0b0cfb | ||
|
|
cf477d45b2 | ||
|
|
cdd2d69e07 | ||
|
|
43f1f8b257 | ||
|
|
34055e3599 | ||
|
|
26abb0a85a | ||
|
|
a1e337e0dd | ||
|
|
b72ead480f | ||
|
|
77cf68105f | ||
|
|
d800f55dfa | ||
|
|
9dde99f19e | ||
|
|
fae7a083fc | ||
|
|
cbd651d6ee | ||
|
|
6077a706d1 | ||
|
|
cedc82dd9e | ||
|
|
b420006401 | ||
|
|
8ba604e8fc | ||
|
|
fadeee4568 | ||
|
|
2b15ba7f46 | ||
|
|
4cdfd0e58c | ||
|
|
b3ccb5f3ef | ||
|
|
584acc43b7 | ||
|
|
f64be93b94 | ||
|
|
9abd31769e | ||
|
|
09e3b35e74 | ||
|
|
8aa9a0ea05 | ||
|
|
b2d0ed74c6 | ||
|
|
aef936af0f | ||
|
|
501be936c0 | ||
|
|
7eba282af5 | ||
|
|
cf3e4bd726 | ||
|
|
ee5361b00e | ||
|
|
bd929dd5c5 | ||
|
|
4ee064bb61 | ||
|
|
312a2090a6 | ||
|
|
a82f117217 | ||
|
|
e908378486 | ||
|
|
8cda5263eb | ||
|
|
a24fd64bce | ||
|
|
0c515a46d5 | ||
|
|
f19690dc32 | ||
|
|
6b2a1c3866 | ||
|
|
1e54d606d7 | ||
|
|
c4ab0ebe9c | ||
|
|
321f1232a1 | ||
|
|
8a8203e149 | ||
|
|
33527165e7 | ||
|
|
db10383bc8 | ||
|
|
56960e506e | ||
|
|
a17f3a96ec | ||
|
|
9ff86a896c | ||
|
|
6ccb4354f9 | ||
|
|
82ba932447 | ||
|
|
b995618afb | ||
|
|
c897b24417 | ||
|
|
e64b2e1993 | ||
|
|
9358a5469e | ||
|
|
2a24210b7d | ||
|
|
2644a59984 | ||
|
|
4eeb8c298c |
@@ -1,7 +1,12 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
examples
|
examples
|
||||||
|
|
||||||
|
packages/node/src/bridge.ts
|
||||||
|
|
||||||
packages/*/test/fixtures
|
packages/*/test/fixtures
|
||||||
|
|
||||||
|
# cli
|
||||||
packages/cli/@types
|
packages/cli/@types
|
||||||
packages/cli/download
|
packages/cli/download
|
||||||
packages/cli/dist
|
packages/cli/dist
|
||||||
@@ -9,11 +14,28 @@ packages/cli/test/dev/fixtures
|
|||||||
packages/cli/bin
|
packages/cli/bin
|
||||||
packages/cli/link
|
packages/cli/link
|
||||||
packages/cli/src/util/dev/templates/*.ts
|
packages/cli/src/util/dev/templates/*.ts
|
||||||
|
|
||||||
|
# client
|
||||||
packages/client/tests/fixtures
|
packages/client/tests/fixtures
|
||||||
packages/client/lib
|
packages/client/lib
|
||||||
packages/node/src/bridge.ts
|
|
||||||
|
# next
|
||||||
|
packages/next/test/integration/middleware
|
||||||
|
packages/next/test/integration/middleware-eval
|
||||||
|
|
||||||
|
# node-bridge
|
||||||
packages/node-bridge/bridge.js
|
packages/node-bridge/bridge.js
|
||||||
packages/node-bridge/launcher.js
|
packages/node-bridge/launcher.js
|
||||||
packages/node-bridge/helpers.js
|
packages/node-bridge/helpers.js
|
||||||
packages/node-bridge/source-map-support.js
|
packages/node-bridge/source-map-support.js
|
||||||
|
|
||||||
|
# middleware
|
||||||
packages/middleware/src/entries.js
|
packages/middleware/src/entries.js
|
||||||
|
|
||||||
|
# static-build
|
||||||
|
packages/static-build/test/fixtures
|
||||||
|
packages/static-build/test/build-fixtures
|
||||||
|
packages/static-build/test/cache-fixtures
|
||||||
|
|
||||||
|
# redwood
|
||||||
|
packages/redwood/test/fixtures
|
||||||
|
|||||||
39
.github/CODEOWNERS
vendored
39
.github/CODEOWNERS
vendored
@@ -1,29 +1,26 @@
|
|||||||
# Documentation
|
# Documentation
|
||||||
# https://help.github.com/en/articles/about-code-owners
|
# https://help.github.com/en/articles/about-code-owners
|
||||||
|
|
||||||
* @TooTallNate
|
* @TooTallNate @EndangeredMassa @styfle
|
||||||
/.github/workflows @AndyBitz @styfle
|
/.github/workflows @TooTallNate @EndangeredMassa @styfle @ijjk
|
||||||
/packages/frameworks @AndyBitz
|
/packages/frameworks @TooTallNate @EndangeredMassa @styfle @AndyBitz
|
||||||
/packages/cli/src/commands/build @TooTallNate @styfle @AndyBitz @gdborton @jaredpalmer
|
|
||||||
/packages/cli/src/commands/dev @TooTallNate @styfle @AndyBitz
|
|
||||||
/packages/cli/src/util/dev @TooTallNate @styfle @AndyBitz
|
|
||||||
/packages/cli/src/commands/domains @javivelasco @mglagola @anatrajkovska
|
/packages/cli/src/commands/domains @javivelasco @mglagola @anatrajkovska
|
||||||
/packages/cli/src/commands/certs @javivelasco @mglagola @anatrajkovska
|
/packages/cli/src/commands/certs @javivelasco @mglagola @anatrajkovska
|
||||||
/packages/cli/src/commands/env @styfle @lucleray
|
/packages/cli/src/commands/env @styfle @lucleray
|
||||||
/packages/client @styfle @TooTallNate
|
/packages/client @TooTallNate @EndangeredMassa @styfle
|
||||||
/packages/build-utils @styfle @AndyBitz @TooTallNate
|
/packages/build-utils @TooTallNate @EndangeredMassa @styfle @AndyBitz
|
||||||
/packages/middleware @gdborton @javivelasco
|
/packages/middleware @gdborton @javivelasco
|
||||||
/packages/node @styfle @TooTallNate @lucleray
|
/packages/node @TooTallNate @EndangeredMassa @styfle
|
||||||
/packages/node-bridge @styfle @TooTallNate @lucleray
|
/packages/node-bridge @TooTallNate @EndangeredMassa @styfle @ijjk
|
||||||
/packages/next @Timer @ijjk
|
/packages/next @TooTallNate @ijjk
|
||||||
/packages/go @styfle @TooTallNate
|
/packages/go @TooTallNate @EndangeredMassa @styfle
|
||||||
/packages/python @styfle @TooTallNate
|
/packages/python @TooTallNate @EndangeredMassa @styfle
|
||||||
/packages/ruby @styfle @TooTallNate
|
/packages/ruby @TooTallNate @EndangeredMassa @styfle
|
||||||
/packages/static-build @styfle @AndyBitz
|
/packages/static-build @TooTallNate @EndangeredMassa @styfle @AndyBitz
|
||||||
/packages/routing-utils @styfle @dav-is @ijjk
|
/packages/routing-utils @TooTallNate @EndangeredMassa @styfle @ijjk
|
||||||
/examples @mcsdevv
|
/examples @leerob
|
||||||
/examples/create-react-app @Timer
|
/examples/create-react-app @Timer
|
||||||
/examples/nextjs @timneutkens @Timer
|
/examples/nextjs @timneutkens @ijjk @styfle
|
||||||
/examples/hugo @mcsdevv @styfle
|
/examples/hugo @styfle
|
||||||
/examples/jekyll @mcsdevv @styfle
|
/examples/jekyll @styfle
|
||||||
/examples/zola @mcsdevv @styfle
|
/examples/zola @styfle
|
||||||
|
|||||||
12
.github/CONTRIBUTING.md
vendored
12
.github/CONTRIBUTING.md
vendored
@@ -16,17 +16,17 @@ yarn install
|
|||||||
yarn bootstrap
|
yarn bootstrap
|
||||||
yarn build
|
yarn build
|
||||||
yarn lint
|
yarn lint
|
||||||
yarn test
|
yarn test-unit
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure all the tests pass before making changes.
|
Make sure all the tests pass before making changes.
|
||||||
|
|
||||||
## Verifying your change
|
## Verifying your change
|
||||||
|
|
||||||
Once you are done with your changes (we even suggest doing it along the way), make sure all the test still run by running:
|
Once you are done with your changes (we even suggest doing it along the way), make sure all the tests still pass by running:
|
||||||
|
|
||||||
```
|
```
|
||||||
yarn build && yarn test
|
yarn test-unit
|
||||||
```
|
```
|
||||||
|
|
||||||
from the root of the project.
|
from the root of the project.
|
||||||
@@ -64,7 +64,7 @@ Integration tests create deployments to your Vercel account using the `test` pro
|
|||||||
x-now-trace=iad1]
|
x-now-trace=iad1]
|
||||||
```
|
```
|
||||||
|
|
||||||
In such cases you can visit the URL of the failed deployment and append `/_logs` so see the build error. In the case above, that would be https://test-8ashcdlew.vercel.app/_logs
|
In such cases, you can visit the URL of the failed deployment and append `/_logs` to see the build error. In the case above, that would be https://test-8ashcdlew.vercel.app/_logs
|
||||||
|
|
||||||
The logs of this deployment will contain the actual error which may help you to understand what went wrong.
|
The logs of this deployment will contain the actual error which may help you to understand what went wrong.
|
||||||
|
|
||||||
@@ -82,11 +82,11 @@ nodeFileTrace(['path/to/entrypoint.js'], {
|
|||||||
.then(e => console.error(e));
|
.then(e => console.error(e));
|
||||||
```
|
```
|
||||||
|
|
||||||
When you run this script, you'll see all imported files. If anything file is missing, the bug is in [@vercel/nft](https://github.com/vercel/nft) and not the Builder.
|
When you run this script, you'll see all the imported files. If anything file is missing, the bug is in [@vercel/nft](https://github.com/vercel/nft) and not the Builder.
|
||||||
|
|
||||||
## Deploy a Builder with existing project
|
## Deploy a Builder with existing project
|
||||||
|
|
||||||
Sometimes you want to test changes to a Builder against an existing project, maybe with `vercel dev` or an actual deployment. You can avoid publishing every Builder change to npm by uploading the Builder as a tarball.
|
Sometimes you want to test changes to a Builder against an existing project, maybe with `vercel dev` or actual deployment. You can avoid publishing every Builder change to npm by uploading the Builder as a tarball.
|
||||||
|
|
||||||
1. Change directory to the desired Builder `cd ./packages/node`
|
1. Change directory to the desired Builder `cd ./packages/node`
|
||||||
2. Run `yarn build` to compile typescript and other build steps
|
2. Run `yarn build` to compile typescript and other build steps
|
||||||
|
|||||||
3
.github/workflows/cancel.yml
vendored
3
.github/workflows/cancel.yml
vendored
@@ -13,6 +13,5 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: styfle/cancel-workflow-action@0.9.1
|
- uses: styfle/cancel-workflow-action@0.9.1
|
||||||
with:
|
with:
|
||||||
workflow_id: 849295, 849296, 849297, 849298
|
workflow_id: test.yml, test-integration-cli.yml, test-unit.yml
|
||||||
access_token: ${{ github.token }}
|
access_token: ${{ github.token }}
|
||||||
|
|
||||||
|
|||||||
10
.github/workflows/test-integration-cli.yml
vendored
10
.github/workflows/test-integration-cli.yml
vendored
@@ -11,14 +11,20 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: CLI
|
name: CLI
|
||||||
timeout-minutes: 30
|
timeout-minutes: 40
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
node: [12]
|
node: [14]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
- name: Conditionally set remote env
|
||||||
|
if: github.event.pull_request.head.repo.full_name == github.repository
|
||||||
|
run: |
|
||||||
|
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
||||||
|
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
||||||
|
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '1.13.15'
|
go-version: '1.13.15'
|
||||||
|
|||||||
43
.github/workflows/test-integration-dev.yml
vendored
43
.github/workflows/test-integration-dev.yml
vendored
@@ -1,43 +0,0 @@
|
|||||||
name: Dev
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
tags:
|
|
||||||
- '!*'
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Dev
|
|
||||||
timeout-minutes: 75
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, macos-latest]
|
|
||||||
node: [12]
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: '1.13.15'
|
|
||||||
- uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node }}
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 100
|
|
||||||
- run: git --version
|
|
||||||
- run: git fetch origin main --depth=100
|
|
||||||
- run: git fetch origin ${{ github.ref }} --depth=100
|
|
||||||
- run: git diff origin/main...HEAD --name-only
|
|
||||||
- name: Install Hugo
|
|
||||||
if: matrix.os == 'macos-latest'
|
|
||||||
run: curl -L -O https://github.com/gohugoio/hugo/releases/download/v0.56.0/hugo_0.56.0_macOS-64bit.tar.gz && tar -xzf hugo_0.56.0_macOS-64bit.tar.gz && mv ./hugo packages/cli/test/dev/fixtures/08-hugo/
|
|
||||||
- run: yarn install --network-timeout 1000000
|
|
||||||
- run: yarn run build
|
|
||||||
- run: yarn test-integration-dev
|
|
||||||
env:
|
|
||||||
VERCEL_TEAM_TOKEN: ${{ secrets.VERCEL_TEAM_TOKEN }}
|
|
||||||
VERCEL_REGISTRATION_URL: ${{ secrets.VERCEL_REGISTRATION_URL }}
|
|
||||||
35
.github/workflows/test-integration-once.yml
vendored
35
.github/workflows/test-integration-once.yml
vendored
@@ -1,35 +0,0 @@
|
|||||||
name: E2E
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
tags:
|
|
||||||
- '!*'
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: E2E
|
|
||||||
timeout-minutes: 120
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: '1.13.15'
|
|
||||||
- uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: 12
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 100
|
|
||||||
- run: git --version
|
|
||||||
- run: git fetch origin main --depth=100
|
|
||||||
- run: git fetch origin ${{ github.ref }} --depth=100
|
|
||||||
- run: git diff origin/main...HEAD --name-only
|
|
||||||
- run: yarn install --network-timeout 1000000
|
|
||||||
- run: yarn run build
|
|
||||||
- run: yarn test-integration-once
|
|
||||||
env:
|
|
||||||
VERCEL_TEAM_TOKEN: ${{ secrets.VERCEL_TEAM_TOKEN }}
|
|
||||||
VERCEL_REGISTRATION_URL: ${{ secrets.VERCEL_REGISTRATION_URL }}
|
|
||||||
12
.github/workflows/test-unit.yml
vendored
12
.github/workflows/test-unit.yml
vendored
@@ -16,9 +16,15 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
node: [12]
|
node: [14]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
- name: Conditionally set remote env
|
||||||
|
if: github.event.pull_request.head.repo.full_name == github.repository
|
||||||
|
run: |
|
||||||
|
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
||||||
|
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
||||||
|
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '1.13.15'
|
go-version: '1.13.15'
|
||||||
@@ -35,9 +41,9 @@ jobs:
|
|||||||
- run: yarn install --network-timeout 1000000
|
- run: yarn install --network-timeout 1000000
|
||||||
- run: yarn run build
|
- run: yarn run build
|
||||||
- run: yarn run lint
|
- run: yarn run lint
|
||||||
if: matrix.os == 'ubuntu-latest' && matrix.node == 12 # only run lint once
|
if: matrix.os == 'ubuntu-latest' && matrix.node == 14 # only run lint once
|
||||||
- run: yarn run test-unit
|
- run: yarn run test-unit
|
||||||
- run: yarn workspace vercel run coverage
|
- run: yarn workspace vercel run coverage
|
||||||
if: matrix.os == 'ubuntu-latest' && matrix.node == 12 # only run coverage once
|
if: matrix.os == 'ubuntu-latest' && matrix.node == 14 # only run coverage once
|
||||||
env:
|
env:
|
||||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|||||||
90
.github/workflows/test.yml
vendored
Normal file
90
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- '!*'
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
NODE_VERSION: '14'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
setup:
|
||||||
|
name: Find Changes
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
tests: ${{ steps['set-tests'].outputs['tests'] }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: git --version
|
||||||
|
- run: git fetch origin main
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'yarn'
|
||||||
|
- run: yarn install --network-timeout 1000000
|
||||||
|
- id: set-tests
|
||||||
|
run: |
|
||||||
|
TESTS_ARRAY=$(node utils/chunk-tests.js $SCRIPT_NAME)
|
||||||
|
echo "Files to test:"
|
||||||
|
echo "$TESTS_ARRAY"
|
||||||
|
echo "::set-output name=tests::$TESTS_ARRAY"
|
||||||
|
|
||||||
|
test:
|
||||||
|
timeout-minutes: 120
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
name: ${{matrix.scriptName}} (${{matrix.packageName}}, ${{matrix.chunkNumber}}, ${{ matrix.runner }})
|
||||||
|
if: ${{ needs.setup.outputs['tests'] != '[]' }}
|
||||||
|
needs:
|
||||||
|
- setup
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include: ${{ fromJson(needs.setup.outputs['tests']) }}
|
||||||
|
steps:
|
||||||
|
- name: Conditionally set remote env
|
||||||
|
if: github.event.pull_request.head.repo.full_name == github.repository
|
||||||
|
run: |
|
||||||
|
echo "TURBO_REMOTE_ONLY=true" >> $GITHUB_ENV
|
||||||
|
echo "TURBO_TEAM=vercel" >> $GITHUB_ENV
|
||||||
|
echo "TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}" >> $GITHUB_ENV
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: '1.13.15'
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'yarn'
|
||||||
|
|
||||||
|
- name: Install Hugo
|
||||||
|
if: matrix.runner == 'macos-latest'
|
||||||
|
run: curl -L -O https://github.com/gohugoio/hugo/releases/download/v0.56.0/hugo_0.56.0_macOS-64bit.tar.gz && tar -xzf hugo_0.56.0_macOS-64bit.tar.gz && mv ./hugo packages/cli/test/dev/fixtures/08-hugo/
|
||||||
|
|
||||||
|
- run: yarn install --network-timeout 1000000
|
||||||
|
|
||||||
|
- name: Build ${{matrix.packageName}} and all its dependencies
|
||||||
|
run: yarn turbo run build --cache-dir=".turbo" --scope=${{matrix.packageName}} --include-dependencies --no-deps
|
||||||
|
env:
|
||||||
|
FORCE_COLOR: '1'
|
||||||
|
- name: Test ${{matrix.packageName}}
|
||||||
|
run: node_modules/.bin/turbo run test --cache-dir=".turbo" --scope=${{matrix.packageName}} --no-deps -- ${{ join(matrix.testPaths, ' ') }}
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
VERCEL_TEAM_TOKEN: ${{ secrets.VERCEL_TEAM_TOKEN }}
|
||||||
|
VERCEL_REGISTRATION_URL: ${{ secrets.VERCEL_REGISTRATION_URL }}
|
||||||
|
FORCE_COLOR: '1'
|
||||||
|
|
||||||
|
conclusion:
|
||||||
|
needs:
|
||||||
|
- test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: E2E
|
||||||
|
steps:
|
||||||
|
- name: Done
|
||||||
|
run: echo "Done."
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
!.yarnrc
|
!.yarnrc
|
||||||
!yarn.lock
|
!yarn.lock
|
||||||
!package.json
|
!package.json
|
||||||
|
!turbo.json
|
||||||
|
|
||||||
# api
|
# api
|
||||||
!api/
|
!api/
|
||||||
@@ -14,4 +15,4 @@
|
|||||||
# packages
|
# packages
|
||||||
!packages/
|
!packages/
|
||||||
!packages/frameworks
|
!packages/frameworks
|
||||||
!packages/frameworks/**
|
!packages/frameworks/**
|
||||||
@@ -9,7 +9,6 @@ A Runtime is an npm module that implements the following interface:
|
|||||||
interface Runtime {
|
interface Runtime {
|
||||||
version: number;
|
version: number;
|
||||||
build: (options: BuildOptions) => Promise<BuildResult>;
|
build: (options: BuildOptions) => Promise<BuildResult>;
|
||||||
analyze?: (options: AnalyzeOptions) => Promise<string>;
|
|
||||||
prepareCache?: (options: PrepareCacheOptions) => Promise<CacheOutputs>;
|
prepareCache?: (options: PrepareCacheOptions) => Promise<CacheOutputs>;
|
||||||
shouldServe?: (options: ShouldServeOptions) => Promise<boolean>;
|
shouldServe?: (options: ShouldServeOptions) => Promise<boolean>;
|
||||||
startDevServer?: (
|
startDevServer?: (
|
||||||
@@ -72,26 +71,6 @@ export async function build(options: BuildOptions) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `analyze()`
|
|
||||||
|
|
||||||
An **optional** exported function that returns a unique fingerprint used for the
|
|
||||||
purpose of [build
|
|
||||||
de-duplication](https://vercel.com/docs/v2/platform/deployments#deduplication).
|
|
||||||
If the `analyze()` function is not supplied, then a random fingerprint is
|
|
||||||
assigned to each build.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { AnalyzeOptions } from '@vercel/build-utils';
|
|
||||||
|
|
||||||
export async function analyze(options: AnalyzeOptions) {
|
|
||||||
// Do calculations to generate a fingerprint based off the source code here…
|
|
||||||
|
|
||||||
return 'fingerprint goes here';
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `prepareCache()`
|
### `prepareCache()`
|
||||||
|
|
||||||
An **optional** exported function that is executed after [`build()`](#build) is
|
An **optional** exported function that is executed after [`build()`](#build) is
|
||||||
@@ -328,15 +307,15 @@ This is a [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere
|
|||||||
|
|
||||||
This is an abstract enumeration type that is implemented by one of the following possible `String` values:
|
This is an abstract enumeration type that is implemented by one of the following possible `String` values:
|
||||||
|
|
||||||
|
- `nodejs14.x`
|
||||||
- `nodejs12.x`
|
- `nodejs12.x`
|
||||||
- `nodejs10.x`
|
|
||||||
- `go1.x`
|
- `go1.x`
|
||||||
- `java11`
|
- `java11`
|
||||||
- `python3.9`
|
- `python3.9`
|
||||||
- `python3.6`
|
- `dotnet6`
|
||||||
- `dotnetcore2.1`
|
- `dotnetcore3.1`
|
||||||
- `ruby2.5`
|
- `ruby2.7`
|
||||||
- `provided`
|
- `provided.al2`
|
||||||
|
|
||||||
## `@vercel/build-utils` Helper Functions
|
## `@vercel/build-utils` Helper Functions
|
||||||
|
|
||||||
|
|||||||
46
api/_lib/script/build.ts
Normal file
46
api/_lib/script/build.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import fs from 'fs/promises';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { getExampleList } from '../examples/example-list';
|
||||||
|
import { mapOldToNew } from '../examples/map-old-to-new';
|
||||||
|
|
||||||
|
const repoRoot = join(__dirname, '..', '..', '..');
|
||||||
|
const pubDir = join(repoRoot, 'public');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log(`Building static frontend ${repoRoot}...`);
|
||||||
|
|
||||||
|
await fs.rm(pubDir, { recursive: true, force: true });
|
||||||
|
await fs.mkdir(pubDir);
|
||||||
|
|
||||||
|
const examples = await getExampleList();
|
||||||
|
const pathListAll = join(pubDir, 'list-all.json');
|
||||||
|
await fs.writeFile(pathListAll, JSON.stringify(examples));
|
||||||
|
|
||||||
|
const exampleDirs = await fs.readdir(join(repoRoot, 'examples'), {
|
||||||
|
withFileTypes: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const existingExamples = exampleDirs
|
||||||
|
.filter(dir => dir.isDirectory())
|
||||||
|
.map(dir => ({
|
||||||
|
name: dir.name,
|
||||||
|
visible: true,
|
||||||
|
suggestions: [],
|
||||||
|
}));
|
||||||
|
|
||||||
|
const oldExamples = Object.keys(mapOldToNew).map(key => ({
|
||||||
|
name: key,
|
||||||
|
visible: false,
|
||||||
|
suggestions: mapOldToNew[key],
|
||||||
|
}));
|
||||||
|
|
||||||
|
const pathList = join(pubDir, 'list.json');
|
||||||
|
await fs.writeFile(
|
||||||
|
pathList,
|
||||||
|
JSON.stringify([...existingExamples, ...oldExamples])
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Completed building static frontend.');
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch(console.error);
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { VercelRequest, VercelResponse } from '@vercel/node';
|
|
||||||
import { getExampleList } from '../_lib/examples/example-list';
|
|
||||||
import { withApiHandler } from '../_lib/util/with-api-handler';
|
|
||||||
|
|
||||||
export default withApiHandler(async function (
|
|
||||||
req: VercelRequest,
|
|
||||||
res: VercelResponse
|
|
||||||
) {
|
|
||||||
res.status(200).json(await getExampleList());
|
|
||||||
});
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import { extract } from '../_lib/examples/extract';
|
|
||||||
import { summary } from '../_lib/examples/summary';
|
|
||||||
import { VercelRequest, VercelResponse } from '@vercel/node';
|
|
||||||
import { mapOldToNew } from '../_lib/examples/map-old-to-new';
|
|
||||||
import { withApiHandler } from '../_lib/util/with-api-handler';
|
|
||||||
|
|
||||||
export default withApiHandler(async function (
|
|
||||||
req: VercelRequest,
|
|
||||||
res: VercelResponse
|
|
||||||
) {
|
|
||||||
await extract('https://github.com/vercel/vercel/archive/main.zip', '/tmp');
|
|
||||||
const exampleList = summary('/tmp/vercel-main/examples');
|
|
||||||
|
|
||||||
const existingExamples = Array.from(exampleList).map(key => ({
|
|
||||||
name: key,
|
|
||||||
visible: true,
|
|
||||||
suggestions: [],
|
|
||||||
}));
|
|
||||||
|
|
||||||
const oldExamples = Object.keys(mapOldToNew).map(key => ({
|
|
||||||
name: key,
|
|
||||||
visible: false,
|
|
||||||
suggestions: mapOldToNew[key],
|
|
||||||
}));
|
|
||||||
|
|
||||||
res.status(200).json([...existingExamples, ...oldExamples]);
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "ES2020",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": false,
|
"strict": false,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ If you would not like to verify your domain, you can remove it from your account
|
|||||||
|
|
||||||
#### Resources
|
#### Resources
|
||||||
|
|
||||||
- [Vercel Custom Domains Documentation](https://vercel.com/docs/v2/custom-domains)
|
- [Vercel Custom Domains Documentation](https://vercel.com/docs/concepts/projects/custom-domains)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#### Why This Error Occurred
|
#### Why This Error Occurred
|
||||||
|
|
||||||
You ran `vercel dev` inside a project that contains a `vercel.json` file with `env` or `build.env` properties that use [Vercel Secrets](https://vercel.com/docs/v2/build-step#environment-variables).
|
You ran `vercel dev` inside a project that contains a `vercel.json` file with `env` or `build.env` properties that use [Vercel Secrets](https://vercel.com/docs/concepts/projects/environment-variables).
|
||||||
|
|
||||||
In order to use environment variables in your project locally that have values defined using the Vercel Secrets format (e.g. `@my-secret-value`), you will need to provide the value as an environment variable using a `.env`.
|
In order to use environment variables in your project locally that have values defined using the Vercel Secrets format (e.g. `@my-secret-value`), you will need to provide the value as an environment variable using a `.env`.
|
||||||
|
|
||||||
@@ -24,4 +24,4 @@ TEST=value
|
|||||||
|
|
||||||
In the above example, `TEST` represents the name of the environment variable and `value` its value.
|
In the above example, `TEST` represents the name of the environment variable and `value` its value.
|
||||||
|
|
||||||
For more information on Environment Variables in development, [see the documentation](https://vercel.com/docs/v2/build-step#environment-variables).
|
For more information on Environment Variables in development, [see the documentation](https://vercel.com/docs/concepts/projects/environment-variables).
|
||||||
|
|||||||
1
examples/amp/.gitignore
vendored
1
examples/amp/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
.env
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# AMP Example
|
|
||||||
|
|
||||||
This directory is a brief example of an [AMP](https://amp.dev/) site that can be deployed to Vercel with zero configuration.
|
|
||||||
|
|
||||||
## Deploy Your Own
|
|
||||||
|
|
||||||
Deploy your own AMP project with Vercel.
|
|
||||||
|
|
||||||
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/vercel/tree/main/examples/amp)
|
|
||||||
|
|
||||||
_Live Example: https://amp-template.vercel.app_
|
|
||||||
|
|
||||||
### How We Created This Example
|
|
||||||
|
|
||||||
To get started deploying AMP with Vercel, you can use the [Vercel CLI](https://vercel.com/download) to initialize the project:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ vercel init amp
|
|
||||||
```
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.0 KiB |
@@ -1,72 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html ⚡>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width,minimum-scale=1" />
|
|
||||||
<link rel="shortcut icon" href="favicon.png">
|
|
||||||
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
|
|
||||||
<link rel="canonical" href="index.html" />
|
|
||||||
<title>AMP Website</title>
|
|
||||||
<script async src="https://cdn.ampproject.org/v0.js"></script>
|
|
||||||
<style amp-custom>
|
|
||||||
body > * {
|
|
||||||
margin: 3rem 1rem;
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
||||||
color: #525252;
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
font-size: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h4 {
|
|
||||||
margin-top: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
font-size: 1.2rem;
|
|
||||||
line-height: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.links {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
margin-bottom: 3rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.links a {
|
|
||||||
margin: 0 10px;
|
|
||||||
font-size: 1rem;
|
|
||||||
color: #005af0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<center>
|
|
||||||
<amp-img width=150 height=150 layout="fixed" class="logo" src="logo.png"></amp-img>
|
|
||||||
<h3>Welcome to your AMP page</h3>
|
|
||||||
<p>AMP is a web component framework to <br> easily create user-first websites, stories, ads and emails.</p>
|
|
||||||
|
|
||||||
<h4>Links</h4>
|
|
||||||
<div class="links">
|
|
||||||
<a href="https://amp.dev/">Homepage</a>
|
|
||||||
<a href="https://amp.dev/documentation/guides-and-tutorials/?format=websites">Tutorials</a>
|
|
||||||
<a href="https://amp.dev/documentation/examples/">Examples</a>
|
|
||||||
<a href="https://blog.amp.dev">Blog</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h4>Ready to get started?</h4>
|
|
||||||
<div class="links">
|
|
||||||
<a href="https://amp.dev/documentation/guides-and-tutorials/start/create/?format=websites">Create your first AMP page</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h4>Get involved</h4>
|
|
||||||
<div class="links">
|
|
||||||
<a href="https://twitter.com/amphtml">Twitter</a>
|
|
||||||
<a href="https://amphtml.slack.com">Slack</a>
|
|
||||||
<a href="https://amp.dev/events/amp-conf-2019">AMP Conf</a>
|
|
||||||
<a href="https://amp.dev/events/amp-roadshow">AMP Roadshow</a>
|
|
||||||
</div>
|
|
||||||
</center>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 43 KiB |
@@ -10,7 +10,7 @@ Deploy your own Angular project with Vercel.
|
|||||||
|
|
||||||
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/vercel/tree/main/examples/angular&template=angular)
|
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/vercel/tree/main/examples/angular&template=angular)
|
||||||
|
|
||||||
_Live Example: https://angular-now-examples.vercel.app_
|
_Live Example: https://angular-template.vercel.app_
|
||||||
|
|
||||||
## Development server
|
## Development server
|
||||||
|
|
||||||
|
|||||||
20
examples/astro/.gitignore
vendored
Normal file
20
examples/astro/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# build output
|
||||||
|
dist/
|
||||||
|
.output/
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# logs
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
|
||||||
|
|
||||||
|
# environment variables
|
||||||
|
.env
|
||||||
|
.env.production
|
||||||
|
|
||||||
|
# macOS-specific files
|
||||||
|
.DS_Store
|
||||||
2
examples/astro/.npmrc
Normal file
2
examples/astro/.npmrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Expose Astro dependencies for `pnpm` users
|
||||||
|
shamefully-hoist=true
|
||||||
1
examples/astro/.vercelignore
Normal file
1
examples/astro/.vercelignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
README.md
|
||||||
42
examples/astro/README.md
Normal file
42
examples/astro/README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Welcome to [Astro](https://astro.build)
|
||||||
|
|
||||||
|
[](https://stackblitz.com/github/withastro/astro/tree/latest/examples/starter)
|
||||||
|
|
||||||
|
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun!
|
||||||
|
|
||||||
|
## 🚀 Project Structure
|
||||||
|
|
||||||
|
Inside of your Astro project, you'll see the following folders and files:
|
||||||
|
|
||||||
|
```
|
||||||
|
/
|
||||||
|
├── public/
|
||||||
|
│ └── favicon.ico
|
||||||
|
├── src/
|
||||||
|
│ ├── components/
|
||||||
|
│ │ └── Layout.astro
|
||||||
|
│ └── pages/
|
||||||
|
│ └── index.astro
|
||||||
|
└── package.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
|
||||||
|
|
||||||
|
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components or layouts.
|
||||||
|
|
||||||
|
Any static assets, like images, can be placed in the `public/` directory.
|
||||||
|
|
||||||
|
## 🧞 Commands
|
||||||
|
|
||||||
|
All commands are run from the root of the project, from a terminal:
|
||||||
|
|
||||||
|
| Command | Action |
|
||||||
|
| :---------------- | :------------------------------------------- |
|
||||||
|
| `npm install` | Installs dependencies |
|
||||||
|
| `npm run dev` | Starts local dev server at `localhost:3000` |
|
||||||
|
| `npm run build` | Build your production site to `./dist/` |
|
||||||
|
| `npm run preview` | Preview your build locally, before deploying |
|
||||||
|
|
||||||
|
## 👀 Want to learn more?
|
||||||
|
|
||||||
|
Feel free to check [our documentation](https://github.com/withastro/astro) or jump into our [Discord server](https://astro.build/chat).
|
||||||
4
examples/astro/astro.config.mjs
Normal file
4
examples/astro/astro.config.mjs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
|
||||||
|
// https://astro.build/config
|
||||||
|
export default defineConfig({});
|
||||||
14
examples/astro/package.json
Normal file
14
examples/astro/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "@example/basics",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "astro dev",
|
||||||
|
"start": "astro dev",
|
||||||
|
"build": "astro build",
|
||||||
|
"preview": "astro preview"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"astro": "^1.0.0-beta.20"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
examples/astro/public/favicon.ico
Normal file
BIN
examples/astro/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
55
examples/astro/src/components/Layout.astro
Normal file
55
examples/astro/src/components/Layout.astro
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
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>
|
||||||
174
examples/astro/src/pages/index.astro
Normal file
174
examples/astro/src/pages/index.astro
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
---
|
||||||
|
import Layout from '../components/Layout.astro';
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="Welcome to Astro.">
|
||||||
|
<main>
|
||||||
|
<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>
|
||||||
|
<ul role="list" class="link-card-grid">
|
||||||
|
<li class="link-card">
|
||||||
|
<a href="https://astro.build/integrations/">
|
||||||
|
<h2>Integrations <span>→</span></h2>
|
||||||
|
<p>Add component frameworks, Tailwind, Partytown, and more!</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="link-card">
|
||||||
|
<a href="https://astro.build/themes/">
|
||||||
|
<h2>Themes <span>→</span></h2>
|
||||||
|
<p>Explore a galaxy of community-built starters.</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="link-card">
|
||||||
|
<a href="https://docs.astro.build/">
|
||||||
|
<h2>Docs <span>→</span></h2>
|
||||||
|
<p>Learn our complete feature set and explore the API.</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="link-card">
|
||||||
|
<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>
|
||||||
|
</main>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--color-border: hsl(17, 24%, 90%);
|
||||||
|
--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 {
|
||||||
|
margin: 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 {
|
||||||
|
margin: auto;
|
||||||
|
padding: 1em;
|
||||||
|
max-width: 60ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-gradient {
|
||||||
|
font-weight: 900;
|
||||||
|
background-image: var(--astro-gradient);
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
background-size: 100% 200%;
|
||||||
|
background-position-y: 100%;
|
||||||
|
border-radius: 0.4rem;
|
||||||
|
animation: pulse 4s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
0%, 100% {
|
||||||
|
background-position-y: 0%;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
background-position-y: 80%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.instructions {
|
||||||
|
line-height: 1.8;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
background-image: var(--night-sky-gradient);
|
||||||
|
padding: 1.5rem;
|
||||||
|
border-radius: 0.4rem;
|
||||||
|
color: var(--color-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-card-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
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>
|
||||||
15
examples/astro/tsconfig.json
Normal file
15
examples/astro/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
3457
examples/astro/yarn.lock
Normal file
3457
examples/astro/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ This directory is a brief example of a [Dojo](https://dojo.io) site that can be
|
|||||||
|
|
||||||
Deploy your own Dojo project with Vercel.
|
Deploy your own Dojo project with Vercel.
|
||||||
|
|
||||||
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/vercel/tree/main/dojo&template=dojo)
|
[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/vercel/tree/main/examples/dojo&template=dojo)
|
||||||
|
|
||||||
### How We Created This Example
|
### How We Created This Example
|
||||||
|
|
||||||
|
|||||||
20
examples/eleventy/LICENSE.md
Normal file
20
examples/eleventy/LICENSE.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
MIT License
|
||||||
|
Copyright (c) 2022 Zach Leatherman @zachleat
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,5 +1,19 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/11ty/eleventy-base-blog.git"
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"name": "Zach Leatherman",
|
||||||
|
"email": "zachleatherman@gmail.com",
|
||||||
|
"url": "https://zachleat.com/"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/11ty/eleventy-base-blog/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "eleventy",
|
"build": "eleventy",
|
||||||
"watch": "eleventy --watch",
|
"watch": "eleventy --watch",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ cache:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
# See https://git.io/vdao3 for details.
|
# See https://github.com/ember-cli/ember-cli/blob/master/docs/build-concurrency.md
|
||||||
- JOBS=1
|
- JOBS=1
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
|||||||
@@ -48,6 +48,6 @@
|
|||||||
"qunit-dom": "^0.8.4"
|
"qunit-dom": "^0.8.4"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "8.* || >= 10.*"
|
"node": "14.x"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ async function main() {
|
|||||||
// if it's an empty string, just ignore it
|
// if it's an empty string, just ignore it
|
||||||
if (!formatted) return false;
|
if (!formatted) return false;
|
||||||
|
|
||||||
let type = url.substr(-3) == 'css' ? 'style' : 'script';
|
let type = url.slice(-3) == 'css' ? 'style' : 'script';
|
||||||
results += `</${formatted}>;rel=preload;as=${type},`;
|
results += `</${formatted}>;rel=preload;as=${type},`;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
4882
examples/nextjs/package-lock.json
generated
Normal file
4882
examples/nextjs/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,12 +7,12 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"next": "12.1.0",
|
"next": "12.1.4",
|
||||||
"react": "17.0.2",
|
"react": "18.0.0",
|
||||||
"react-dom": "17.0.2"
|
"react-dom": "18.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "8.9.0",
|
"eslint": "8.12.0",
|
||||||
"eslint-config-next": "12.1.0"
|
"eslint-config-next": "12.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,3 +2,4 @@ README.md
|
|||||||
.nuxt
|
.nuxt
|
||||||
node_modules
|
node_modules
|
||||||
*.log
|
*.log
|
||||||
|
.output
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default function Index() {
|
|||||||
<p>
|
<p>
|
||||||
Wait a sec...<em>its children</em>? To understand what we mean by
|
Wait a sec...<em>its children</em>? To understand what we mean by
|
||||||
this,{" "}
|
this,{" "}
|
||||||
<a href="https://remix.run/tutorial/4-nested-routes-params">
|
<a href="https://remix.run/docs/en/v1/guides/routing">
|
||||||
read all about nested routes in the docs
|
read all about nested routes in the docs
|
||||||
</a>
|
</a>
|
||||||
.
|
.
|
||||||
|
|||||||
2
examples/remix/package-lock.json
generated
2
examples/remix/package-lock.json
generated
@@ -21,7 +21,7 @@
|
|||||||
"typescript": "^4.1.2"
|
"typescript": "^4.1.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14"
|
"node": "14.x"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
|
|||||||
@@ -22,8 +22,5 @@
|
|||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
"typescript": "^4.1.2"
|
"typescript": "^4.1.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
|
||||||
"node": ">=14"
|
|
||||||
},
|
|
||||||
"sideEffects": false
|
"sideEffects": false
|
||||||
}
|
}
|
||||||
|
|||||||
1
examples/solidstart/.gitignore
vendored
1
examples/solidstart/.gitignore
vendored
@@ -2,6 +2,7 @@ dist
|
|||||||
worker
|
worker
|
||||||
.solid
|
.solid
|
||||||
.vercel
|
.vercel
|
||||||
|
.output
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
/node_modules
|
/node_modules
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# SolidStart
|
# SolidStart
|
||||||
|
|
||||||
This directory is a brief example of a [SolidStart](https://github.com/ryansolid/solid-startp) site that can be deployed to Vercel with zero configuration.
|
This directory is a brief example of a [SolidStart](https://github.com/ryansolid/solid-start) site that can be deployed to Vercel with zero configuration.
|
||||||
|
|
||||||
## Deploy Your Own
|
## Deploy Your Own
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"jsx": "preserve",
|
|
||||||
"jsxImportSource": "solid-js",
|
|
||||||
"paths": {
|
|
||||||
"~/*": ["./src/*"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,14 +7,14 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"solid-app-router": "^0.1.14",
|
"solid-app-router": "^0.3.2",
|
||||||
"solid-js": "^1.2.6",
|
"solid-js": "^1.3.15",
|
||||||
"solid-meta": "^0.27.2",
|
"solid-meta": "^0.27.3",
|
||||||
"solid-start": "next",
|
"solid-start": "next",
|
||||||
"solid-start-vercel": "next",
|
"solid-start-vercel": "next",
|
||||||
"vite": "^2.7.1"
|
"vite": "^2.9.9"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14"
|
"node": "16.x"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
examples/solidstart/src/entry-client.tsx
Normal file
4
examples/solidstart/src/entry-client.tsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { hydrate } from "solid-js/web";
|
||||||
|
import { StartClient } from "solid-start/entry-client";
|
||||||
|
|
||||||
|
hydrate(() => <StartClient />, document);
|
||||||
7
examples/solidstart/src/entry-server.tsx
Normal file
7
examples/solidstart/src/entry-server.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { StartServer, createHandler, renderAsync } from "solid-start/entry-server";
|
||||||
|
import { inlineServerModules } from "solid-start/server";
|
||||||
|
|
||||||
|
export default createHandler(
|
||||||
|
inlineServerModules,
|
||||||
|
renderAsync((context) => <StartServer context={context} />)
|
||||||
|
);
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
// @refresh reload
|
|
||||||
import { Links, Meta, Outlet, Scripts } from "solid-start/components";
|
|
||||||
|
|
||||||
export default function Root({ Start }) {
|
|
||||||
return (
|
|
||||||
<Start>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<Meta />
|
|
||||||
<Links />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<Outlet />
|
|
||||||
<Scripts />
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
</Start>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
25
examples/solidstart/src/root.tsx
Normal file
25
examples/solidstart/src/root.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// @refresh reload
|
||||||
|
import { Links, Meta, Routes, Scripts } from "solid-start/root";
|
||||||
|
import { ErrorBoundary } from "solid-start/error-boundary";
|
||||||
|
import { Suspense } from "solid-js";
|
||||||
|
|
||||||
|
export default function Root() {
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<Meta />
|
||||||
|
<Links />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<ErrorBoundary>
|
||||||
|
<Suspense>
|
||||||
|
<Routes />
|
||||||
|
</Suspense>
|
||||||
|
</ErrorBoundary>
|
||||||
|
<Scripts />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
16
examples/solidstart/tsconfig.json
Normal file
16
examples/solidstart/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsxImportSource": "solid-js",
|
||||||
|
"jsx": "preserve",
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"baseUrl": "./",
|
||||||
|
"paths": {
|
||||||
|
"~/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"build": {
|
"build": {
|
||||||
"env": {
|
"env": {
|
||||||
"ENABLE_FILE_SYSTEM_API": "1"
|
"ENABLE_VC_BUILD": "1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import solid from "solid-start";
|
import solid from "solid-start";
|
||||||
import vercel from "solid-start-vercel"
|
import vercel from "solid-start-vercel";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [solid({ adapter: vercel() })]
|
plugins: [solid({ adapter: vercel() })],
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@ export class AppProfile {
|
|||||||
|
|
||||||
normalize(name: string): string {
|
normalize(name: string): string {
|
||||||
if (name) {
|
if (name) {
|
||||||
return name.substr(0, 1).toUpperCase() + name.substr(1).toLowerCase();
|
return name.slice(0, 1).toUpperCase() + name.slice(1).toLowerCase();
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
1
examples/sveltekit/.gitignore
vendored
1
examples/sveltekit/.gitignore
vendored
@@ -7,3 +7,4 @@ node_modules
|
|||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
.vercel
|
.vercel
|
||||||
|
.output
|
||||||
|
|||||||
13
examples/sveltekit/.prettierignore
Normal file
13
examples/sveltekit/.prettierignore
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
.DS_Store
|
||||||
|
node_modules
|
||||||
|
/build
|
||||||
|
/.svelte-kit
|
||||||
|
/package
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# Ignore files for PNPM, NPM and YARN
|
||||||
|
pnpm-lock.yaml
|
||||||
|
package-lock.json
|
||||||
|
yarn.lock
|
||||||
6
examples/sveltekit/.prettierrc
Normal file
6
examples/sveltekit/.prettierrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"useTabs": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"printWidth": 100
|
||||||
|
}
|
||||||
@@ -14,31 +14,29 @@ If you're seeing this, you've probably already done this step. Congrats!
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# create a new project in the current directory
|
# create a new project in the current directory
|
||||||
npm init svelte@next
|
npm init svelte
|
||||||
|
|
||||||
# create a new project in my-app
|
# create a new project in my-app
|
||||||
npm init svelte@next my-app
|
npm init svelte my-app
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: the `@next` is temporary
|
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
|
||||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
Once you've created a project and installed dependencies with `pnpm install`, start a development server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
pnpm run dev
|
||||||
|
|
||||||
# or start the server and open the app in a new browser tab
|
# or start the server and open the app in a new browser tab
|
||||||
npm run dev -- --open
|
pnpm run dev -- --open
|
||||||
```
|
```
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
This uses the adapter-auto for SvelteKit, which detects Vercel and runs adapter-vercel on your behalf.
|
To create a production version of your app:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run build
|
pnpm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
> You can preview the built app with `npm run preview`, regardless of whether you installed an adapter. This should _not_ be used to serve your app in production.
|
You can preview the production build with `npm run preview`.
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "./.svelte-kit/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"allowJs": true,
|
||||||
"paths": {
|
"checkJs": true,
|
||||||
"$lib": ["src/lib"],
|
"esModuleInterop": true,
|
||||||
"$lib/*": ["src/lib/*"]
|
"forceConsistentCasingInFileNames": true,
|
||||||
}
|
"resolveJsonModule": true,
|
||||||
},
|
"skipLibCheck": true,
|
||||||
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
|
"sourceMap": true,
|
||||||
|
"strict": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1177
examples/sveltekit/package-lock.json
generated
1177
examples/sveltekit/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -4,17 +4,26 @@
|
|||||||
"dev": "svelte-kit dev",
|
"dev": "svelte-kit dev",
|
||||||
"build": "svelte-kit build",
|
"build": "svelte-kit build",
|
||||||
"package": "svelte-kit package",
|
"package": "svelte-kit package",
|
||||||
"preview": "svelte-kit preview"
|
"preview": "svelte-kit preview",
|
||||||
|
"prepare": "svelte-kit sync",
|
||||||
|
"check": "svelte-check --tsconfig ./jsconfig.json",
|
||||||
|
"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch",
|
||||||
|
"lint": "prettier --check --plugin-search-dir=. .",
|
||||||
|
"format": "prettier --write --plugin-search-dir=. ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "next",
|
"@sveltejs/adapter-auto": "next",
|
||||||
"@sveltejs/kit": "next",
|
"@sveltejs/kit": "next",
|
||||||
"svelte": "^3.44.0"
|
"@types/cookie": "^0.4.1",
|
||||||
|
"prettier": "^2.5.1",
|
||||||
|
"prettier-plugin-svelte": "^2.5.0",
|
||||||
|
"svelte": "^3.46.0",
|
||||||
|
"svelte-check": "^2.2.6",
|
||||||
|
"typescript": "~4.6.2"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/fira-mono": "^4.5.0",
|
"@fontsource/fira-mono": "^4.5.0",
|
||||||
"@lukeed/uuid": "^2.0.0",
|
|
||||||
"cookie": "^0.4.1"
|
"cookie": "^0.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1633
examples/sveltekit/pnpm-lock.yaml
generated
Normal file
1633
examples/sveltekit/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,107 +1,107 @@
|
|||||||
@import '@fontsource/fira-mono';
|
@import '@fontsource/fira-mono';
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
font-family: Arial, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
|
font-family: Arial, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
|
||||||
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||||
--font-mono: 'Fira Mono', monospace;
|
--font-mono: 'Fira Mono', monospace;
|
||||||
--pure-white: #ffffff;
|
--pure-white: #ffffff;
|
||||||
--primary-color: #b9c6d2;
|
--primary-color: #b9c6d2;
|
||||||
--secondary-color: #d0dde9;
|
--secondary-color: #d0dde9;
|
||||||
--tertiary-color: #edf0f8;
|
--tertiary-color: #edf0f8;
|
||||||
--accent-color: #ff3e00;
|
--accent-color: #ff3e00;
|
||||||
--heading-color: rgba(0, 0, 0, 0.7);
|
--heading-color: rgba(0, 0, 0, 0.7);
|
||||||
--text-color: #444444;
|
--text-color: #444444;
|
||||||
--background-without-opacity: rgba(255, 255, 255, 0.7);
|
--background-without-opacity: rgba(255, 255, 255, 0.7);
|
||||||
--column-width: 42rem;
|
--column-width: 42rem;
|
||||||
--column-margin-top: 4rem;
|
--column-margin-top: 4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background-color: var(--primary-color);
|
background-color: var(--primary-color);
|
||||||
background: linear-gradient(
|
background: linear-gradient(
|
||||||
180deg,
|
180deg,
|
||||||
var(--primary-color) 0%,
|
var(--primary-color) 0%,
|
||||||
var(--secondary-color) 10.45%,
|
var(--secondary-color) 10.45%,
|
||||||
var(--tertiary-color) 41.35%
|
var(--tertiary-color) 41.35%
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
body::before {
|
body::before {
|
||||||
content: '';
|
content: '';
|
||||||
width: 80vw;
|
width: 80vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 10vw;
|
left: 10vw;
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
background: radial-gradient(
|
background: radial-gradient(
|
||||||
50% 50% at 50% 50%,
|
50% 50% at 50% 50%,
|
||||||
var(--pure-white) 0%,
|
var(--pure-white) 0%,
|
||||||
rgba(255, 255, 255, 0) 100%
|
rgba(255, 255, 255, 0) 100%
|
||||||
);
|
);
|
||||||
opacity: 0.05;
|
opacity: 0.05;
|
||||||
}
|
}
|
||||||
|
|
||||||
#svelte {
|
#svelte {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1,
|
h1,
|
||||||
h2,
|
h2,
|
||||||
p {
|
p {
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: var(--heading-color);
|
color: var(--heading-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: var(--accent-color);
|
color: var(--accent-color);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-family: var(--font-mono);
|
font-family: var(--font-mono);
|
||||||
background-color: rgba(255, 255, 255, 0.45);
|
background-color: rgba(255, 255, 255, 0.45);
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
box-shadow: 2px 2px 6px rgb(255 255 255 / 25%);
|
box-shadow: 2px 2px 6px rgb(255 255 255 / 25%);
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
input,
|
input,
|
||||||
button {
|
button {
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:focus:not(:focus-visible) {
|
button:focus:not(:focus-visible) {
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 720px) {
|
@media (min-width: 720px) {
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 2.4rem;
|
font-size: 2.4rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
examples/sveltekit/src/app.d.ts
vendored
Normal file
15
examples/sveltekit/src/app.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/// <reference types="@sveltejs/kit" />
|
||||||
|
|
||||||
|
// See https://kit.svelte.dev/docs/types#app
|
||||||
|
// for information about these interfaces
|
||||||
|
declare namespace App {
|
||||||
|
interface Locals {
|
||||||
|
userid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// interface Platform {}
|
||||||
|
|
||||||
|
// interface Session {}
|
||||||
|
|
||||||
|
// interface Stuff {}
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="description" content="Svelte demo app" />
|
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||||
<link rel="icon" href="%svelte.assets%/favicon.png" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
%sveltekit.head%
|
||||||
%svelte.head%
|
</head>
|
||||||
</head>
|
<body>
|
||||||
<body>
|
<div>%sveltekit.body%</div>
|
||||||
<div id="svelte">%svelte.body%</div>
|
</body>
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
1
examples/sveltekit/src/global.d.ts
vendored
1
examples/sveltekit/src/global.d.ts
vendored
@@ -1 +0,0 @@
|
|||||||
/// <reference types="@sveltejs/kit" />
|
|
||||||
@@ -1,20 +1,23 @@
|
|||||||
import cookie from 'cookie';
|
import * as cookie from 'cookie';
|
||||||
import { v4 as uuid } from '@lukeed/uuid';
|
|
||||||
|
|
||||||
export const handle = async ({ request, resolve }) => {
|
/** @type {import('@sveltejs/kit').Handle} */
|
||||||
const cookies = cookie.parse(request.headers.cookie || '');
|
export const handle = async ({ event, resolve }) => {
|
||||||
request.locals.userid = cookies.userid || uuid();
|
const cookies = cookie.parse(event.request.headers.get('cookie') || '');
|
||||||
|
event.locals.userid = cookies['userid'] || crypto.randomUUID();
|
||||||
|
|
||||||
const response = await resolve(request);
|
const response = await resolve(event);
|
||||||
|
|
||||||
if (!cookies.userid) {
|
if (!cookies['userid']) {
|
||||||
// if this is the first time the user has visited this app,
|
// if this is the first time the user has visited this app,
|
||||||
// set a cookie so that we recognise them when they return
|
// set a cookie so that we recognise them when they return
|
||||||
response.headers['set-cookie'] = cookie.serialize('userid', request.locals.userid, {
|
response.headers.set(
|
||||||
path: '/',
|
'set-cookie',
|
||||||
httpOnly: true
|
cookie.serialize('userid', event.locals.userid, {
|
||||||
});
|
path: '/',
|
||||||
}
|
httpOnly: true
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,97 +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);
|
||||||
|
|
||||||
function modulo(n, m) {
|
/**
|
||||||
// handle negative numbers
|
* @param {number} n
|
||||||
return ((n % m) + m) % m;
|
* @param {number} m
|
||||||
}
|
*/
|
||||||
|
function modulo(n, m) {
|
||||||
|
// handle negative numbers
|
||||||
|
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 style="top: -100%" 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;
|
||||||
color: var(--text-color);
|
touch-action: manipulation;
|
||||||
font-size: 2rem;
|
color: var(--text-color);
|
||||||
}
|
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 {
|
||||||
|
top: -100%;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,49 +1,82 @@
|
|||||||
|
import { invalidate } from '$app/navigation';
|
||||||
|
|
||||||
// this action (https://svelte.dev/tutorial/actions) allows us to
|
// this action (https://svelte.dev/tutorial/actions) allows us to
|
||||||
// progressively enhance a <form> that already works without JS
|
// progressively enhance a <form> that already works without JS
|
||||||
export function enhance(form, { pending, error, result }) {
|
/**
|
||||||
let current_token;
|
* @param {HTMLFormElement} form
|
||||||
|
* @param {{
|
||||||
|
* pending?: ({ data, form }: { data: FormData; form: HTMLFormElement }) => void;
|
||||||
|
* error?: ({
|
||||||
|
* data,
|
||||||
|
* form,
|
||||||
|
* response,
|
||||||
|
* error
|
||||||
|
* }: {
|
||||||
|
* data: FormData;
|
||||||
|
* form: HTMLFormElement;
|
||||||
|
* response: Response | null;
|
||||||
|
* error: Error | null;
|
||||||
|
* }) => void;
|
||||||
|
* result?: ({
|
||||||
|
* data,
|
||||||
|
* form,
|
||||||
|
* response
|
||||||
|
* }: {
|
||||||
|
* data: FormData;
|
||||||
|
* response: Response;
|
||||||
|
* form: HTMLFormElement;
|
||||||
|
* }) => void;
|
||||||
|
* }} [opts]
|
||||||
|
*/
|
||||||
|
export function enhance(form, { pending, error, result } = {}) {
|
||||||
|
let current_token;
|
||||||
|
|
||||||
async function handle_submit(e) {
|
/** @param {SubmitEvent} e */
|
||||||
const token = (current_token = {});
|
async function handle_submit(e) {
|
||||||
|
const token = (current_token = {});
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const body = new FormData(form);
|
const data = new FormData(form);
|
||||||
|
|
||||||
if (pending) pending(body, form);
|
if (pending) pending({ data, form });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(form.action, {
|
const response = await fetch(form.action, {
|
||||||
method: form.method,
|
method: form.method,
|
||||||
headers: {
|
headers: {
|
||||||
accept: 'application/json'
|
accept: 'application/json'
|
||||||
},
|
},
|
||||||
body
|
body: data
|
||||||
});
|
});
|
||||||
|
|
||||||
if (token !== current_token) return;
|
if (token !== current_token) return;
|
||||||
|
|
||||||
if (res.ok) {
|
if (response.ok) {
|
||||||
result(res, form);
|
if (result) result({ data, form, response });
|
||||||
} else if (error) {
|
|
||||||
error(res, null, form);
|
|
||||||
} else {
|
|
||||||
console.error(await res.text());
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (error) {
|
|
||||||
error(null, e, form);
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
form.addEventListener('submit', handle_submit);
|
const url = new URL(form.action);
|
||||||
|
url.search = url.hash = '';
|
||||||
|
invalidate(url.href);
|
||||||
|
} else if (error) {
|
||||||
|
error({ data, form, error: null, response });
|
||||||
|
} else {
|
||||||
|
console.error(await response.text());
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (error && e instanceof Error) {
|
||||||
|
error({ data, form, error: e, response: null });
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
form.addEventListener('submit', handle_submit);
|
||||||
destroy() {
|
|
||||||
form.removeEventListener('submit', handle_submit);
|
return {
|
||||||
}
|
destroy() {
|
||||||
};
|
form.removeEventListener('submit', handle_submit);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
<script>
|
<script>
|
||||||
import Header from '$lib/header/Header.svelte';
|
import Header from '$lib/header/Header.svelte';
|
||||||
import '../app.css';
|
import '../app.css';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<slot />
|
<slot />
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to learn SvelteKit</p>
|
<p>visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to learn SvelteKit</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
main {
|
main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 1024px;
|
max-width: 1024px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 40px;
|
padding: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer a {
|
footer a {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 480px) {
|
@media (min-width: 480px) {
|
||||||
footer {
|
footer {
|
||||||
padding: 40px 0;
|
padding: 40px 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,50 +1,50 @@
|
|||||||
<script context="module">
|
<script context="module">
|
||||||
import { browser, dev } from '$app/env';
|
import { browser, dev } from '$app/env';
|
||||||
|
|
||||||
// we don't need any JS on this page, though we'll load
|
// we don't need any JS on this page, though we'll load
|
||||||
// it in dev so that we get hot module replacement...
|
// it in dev so that we get hot module replacement...
|
||||||
export const hydrate = dev;
|
export const hydrate = dev;
|
||||||
|
|
||||||
// ...but if the client-side router is already loaded
|
// ...but if the client-side router is already loaded
|
||||||
// (i.e. we came here from elsewhere in the app), use it
|
// (i.e. we came here from elsewhere in the app), use it
|
||||||
export const router = browser;
|
export const router = browser;
|
||||||
|
|
||||||
// since there's no dynamic data here, we can prerender
|
// since there's no dynamic data here, we can prerender
|
||||||
// it so that it gets served as a static asset in prod
|
// it so that it gets served as a static asset in prod
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>About</title>
|
<title>About</title>
|
||||||
|
<meta name="description" content="About this app" />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1>About this app</h1>
|
<h1>About this app</h1>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This is a <a href="https://kit.svelte.dev">SvelteKit</a> app. You can make your own by typing the
|
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:
|
following into your command line and following the prompts:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- TODO lose the @next! -->
|
<pre>npm init svelte</pre>
|
||||||
<pre>npm init svelte@next</pre>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The page you're looking at is purely static HTML, with no client-side interactivity needed.
|
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
|
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.
|
the devtools network panel and reloading.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The <a href="/todos">TODOs</a> page illustrates SvelteKit's data loading and form handling. Try using
|
The <a href="/todos">TODOs</a> page illustrates SvelteKit's data loading and form handling. Try using
|
||||||
it with JavaScript disabled!
|
it with JavaScript disabled!
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.content {
|
.content {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: var(--column-width);
|
max-width: var(--column-width);
|
||||||
margin: var(--column-margin-top) auto 0 auto;
|
margin: var(--column-margin-top) auto 0 auto;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,59 +1,60 @@
|
|||||||
<script context="module">
|
<script context="module">
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Counter from '$lib/Counter.svelte';
|
import Counter from '$lib/Counter.svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Home</title>
|
<title>Home</title>
|
||||||
|
<meta name="description" content="Svelte demo app" />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h1>
|
<h1>
|
||||||
<div class="welcome">
|
<div class="welcome">
|
||||||
<picture>
|
<picture>
|
||||||
<source srcset="svelte-welcome.webp" type="image/webp" />
|
<source srcset="svelte-welcome.webp" type="image/webp" />
|
||||||
<img src="svelte-welcome.png" alt="Welcome" />
|
<img src="svelte-welcome.png" alt="Welcome" />
|
||||||
</picture>
|
</picture>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
to your new<br />SvelteKit app
|
to your new<br />SvelteKit app
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
try editing <strong>src/routes/index.svelte</strong>
|
try editing <strong>src/routes/index.svelte</strong>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<Counter />
|
<Counter />
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
section {
|
section {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome {
|
.welcome {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 0;
|
height: 0;
|
||||||
padding: 0 0 calc(100% * 495 / 2048) 0;
|
padding: 0 0 calc(100% * 495 / 2048) 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome img {
|
.welcome img {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
top: 0;
|
top: 0;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
import { api } from './_api';
|
|
||||||
|
|
||||||
// PATCH /todos/:uid.json
|
|
||||||
export const patch = async (request) => {
|
|
||||||
return api(request, `todos/${request.locals.userid}/${request.params.uid}`, {
|
|
||||||
text: request.body.get('text'),
|
|
||||||
done: request.body.has('done') ? !!request.body.get('done') : undefined
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// DELETE /todos/:uid.json
|
|
||||||
export const del = async (request) => {
|
|
||||||
return api(request, `todos/${request.locals.userid}/${request.params.uid}`);
|
|
||||||
};
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This module is used by the /todos.json and /todos/[uid].json
|
This module is used by the /todos endpoint to
|
||||||
endpoints 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. The leading underscore indicates that this is
|
||||||
a private module, _not_ an endpoint — visiting /todos/_api
|
a private module, _not_ an endpoint — visiting /todos/_api
|
||||||
will net you a 404 response.
|
will net you a 404 response.
|
||||||
@@ -11,35 +11,17 @@
|
|||||||
|
|
||||||
const base = 'https://api.svelte.dev';
|
const base = 'https://api.svelte.dev';
|
||||||
|
|
||||||
export async function api(request, resource, data) {
|
/**
|
||||||
// user must have a cookie set
|
* @param {string} method
|
||||||
if (!request.locals.userid) {
|
* @param {string} resource
|
||||||
return { status: 401 };
|
* @param {Record<string, unknown>} [data]
|
||||||
}
|
*/
|
||||||
|
export function api(method, resource, data) {
|
||||||
const res = await fetch(`${base}/${resource}`, {
|
return fetch(`${base}/${resource}`, {
|
||||||
method: request.method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
},
|
},
|
||||||
body: data && JSON.stringify(data)
|
body: data && JSON.stringify(data)
|
||||||
});
|
});
|
||||||
|
|
||||||
// if the request came from a <form> submission, the browser's default
|
|
||||||
// behaviour is to show the URL corresponding to the form's "action"
|
|
||||||
// attribute. in those cases, we want to redirect them back to the
|
|
||||||
// /todos page, rather than showing the response
|
|
||||||
if (res.ok && request.method !== 'GET' && request.headers.accept !== 'application/json') {
|
|
||||||
return {
|
|
||||||
status: 303,
|
|
||||||
headers: {
|
|
||||||
location: '/todos'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: res.status,
|
|
||||||
body: await res.json()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
70
examples/sveltekit/src/routes/todos/index.js
Normal file
70
examples/sveltekit/src/routes/todos/index.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
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,28 +0,0 @@
|
|||||||
import { api } from './_api';
|
|
||||||
|
|
||||||
// GET /todos.json
|
|
||||||
export const get = async (request) => {
|
|
||||||
// request.locals.userid comes from src/hooks.js
|
|
||||||
const response = await api(request, `todos/${request.locals.userid}`);
|
|
||||||
|
|
||||||
if (response.status === 404) {
|
|
||||||
// user hasn't created a todo list.
|
|
||||||
// start with an empty array
|
|
||||||
return { body: [] };
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
};
|
|
||||||
|
|
||||||
// POST /todos.json
|
|
||||||
export const post = async (request) => {
|
|
||||||
const response = await api(request, `todos/${request.locals.userid}`, {
|
|
||||||
// because index.svelte posts a FormData object,
|
|
||||||
// request.body is _also_ a (readonly) FormData
|
|
||||||
// object, which allows us to get form data
|
|
||||||
// with the `body.get(key)` method
|
|
||||||
text: request.body.get('text')
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
};
|
|
||||||
@@ -1,220 +1,190 @@
|
|||||||
<script context="module">
|
|
||||||
import { enhance } from '$lib/form';
|
|
||||||
|
|
||||||
// see https://kit.svelte.dev/docs#loading
|
|
||||||
export const load = async ({ fetch }) => {
|
|
||||||
const res = await fetch('/todos.json');
|
|
||||||
|
|
||||||
if (res.ok) {
|
|
||||||
const todos = await res.json();
|
|
||||||
|
|
||||||
return {
|
|
||||||
props: { todos }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const { message } = await res.json();
|
|
||||||
|
|
||||||
return {
|
|
||||||
error: new Error(message)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { scale } from 'svelte/transition';
|
import { enhance } from '$lib/form';
|
||||||
import { flip } from 'svelte/animate';
|
import { scale } from 'svelte/transition';
|
||||||
|
import { flip } from 'svelte/animate';
|
||||||
|
|
||||||
export let todos;
|
/**
|
||||||
|
* @typedef {{
|
||||||
|
* uid: string;
|
||||||
|
* created_at: Date;
|
||||||
|
* text: string;
|
||||||
|
* done: boolean;
|
||||||
|
* pending_delete: boolean;
|
||||||
|
* }} Todo
|
||||||
|
*/
|
||||||
|
|
||||||
async function patch(res) {
|
/** @type {Todo[]} */
|
||||||
const todo = await res.json();
|
export let todos;
|
||||||
|
|
||||||
todos = todos.map((t) => {
|
|
||||||
if (t.uid === todo.uid) return todo;
|
|
||||||
return t;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Todos</title>
|
<title>Todos</title>
|
||||||
|
<meta name="description" content="A todo list app" />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="todos">
|
<div class="todos">
|
||||||
<h1>Todos</h1>
|
<h1>Todos</h1>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
class="new"
|
class="new"
|
||||||
action="/todos.json"
|
action="/todos"
|
||||||
method="post"
|
method="post"
|
||||||
use:enhance={{
|
use:enhance={{
|
||||||
result: async (res, form) => {
|
result: async ({ form }) => {
|
||||||
const created = await res.json();
|
form.reset();
|
||||||
todos = [...todos, created];
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input name="text" aria-label="Add todo" placeholder="+ tap to add a todo" />
|
||||||
|
</form>
|
||||||
|
|
||||||
form.reset();
|
{#each todos as todo (todo.uid)}
|
||||||
}
|
<div
|
||||||
}}
|
class="todo"
|
||||||
>
|
class:done={todo.done}
|
||||||
<input name="text" aria-label="Add todo" placeholder="+ tap to add a todo" />
|
transition:scale|local={{ start: 0.7 }}
|
||||||
</form>
|
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>
|
||||||
|
|
||||||
{#each todos as todo (todo.uid)}
|
<form class="text" action="/todos?_method=PATCH" method="post" use:enhance>
|
||||||
<div
|
<input type="hidden" name="uid" value={todo.uid} />
|
||||||
class="todo"
|
<input aria-label="Edit todo" type="text" name="text" value={todo.text} />
|
||||||
class:done={todo.done}
|
<button class="save" aria-label="Save todo" />
|
||||||
transition:scale|local={{ start: 0.7 }}
|
</form>
|
||||||
animate:flip={{ duration: 200 }}
|
|
||||||
>
|
|
||||||
<form
|
|
||||||
action="/todos/{todo.uid}.json?_method=PATCH"
|
|
||||||
method="post"
|
|
||||||
use:enhance={{
|
|
||||||
pending: (data) => {
|
|
||||||
todo.done = !!data.get('done');
|
|
||||||
},
|
|
||||||
result: patch
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input type="hidden" name="done" value={todo.done ? '' : 'true'} />
|
|
||||||
<button class="toggle" aria-label="Mark todo as {todo.done ? 'not done' : 'done'}" />
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form
|
<form
|
||||||
class="text"
|
action="/todos?_method=DELETE"
|
||||||
action="/todos/{todo.uid}.json?_method=PATCH"
|
method="post"
|
||||||
method="post"
|
use:enhance={{
|
||||||
use:enhance={{
|
pending: () => (todo.pending_delete = true)
|
||||||
result: patch
|
}}
|
||||||
}}
|
>
|
||||||
>
|
<input type="hidden" name="uid" value={todo.uid} />
|
||||||
<input aria-label="Edit todo" type="text" name="text" value={todo.text} />
|
<button class="delete" aria-label="Delete todo" disabled={todo.pending_delete} />
|
||||||
<button class="save" aria-label="Save todo" />
|
</form>
|
||||||
</form>
|
</div>
|
||||||
|
{/each}
|
||||||
<form
|
|
||||||
action="/todos/{todo.uid}.json?_method=DELETE"
|
|
||||||
method="post"
|
|
||||||
use:enhance={{
|
|
||||||
pending: () => (todo.pending_delete = true),
|
|
||||||
result: () => {
|
|
||||||
todos = todos.filter((t) => t.uid !== todo.uid);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button class="delete" aria-label="Delete todo" disabled={todo.pending_delete} />
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.todos {
|
.todos {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: var(--column-width);
|
max-width: var(--column-width);
|
||||||
margin: var(--column-margin-top) auto 0 auto;
|
margin: var(--column-margin-top) auto 0 auto;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.new {
|
.new {
|
||||||
margin: 0 0 0.5rem 0;
|
margin: 0 0 0.5rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:focus-visible {
|
input:focus-visible {
|
||||||
box-shadow: inset 1px 1px 6px rgba(0, 0, 0, 0.1);
|
box-shadow: inset 1px 1px 6px rgba(0, 0, 0, 0.1);
|
||||||
border: 1px solid #ff3e00 !important;
|
border: 1px solid #ff3e00 !important;
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.new input {
|
.new input {
|
||||||
font-size: 28px;
|
font-size: 28px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0.5em 1em 0.3em 1em;
|
padding: 0.5em 1em 0.3em 1em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background: rgba(255, 255, 255, 0.05);
|
background: rgba(255, 255, 255, 0.05);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.todo {
|
.todo {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 2rem 1fr 2rem;
|
grid-template-columns: 2rem 1fr 2rem;
|
||||||
grid-gap: 0.5rem;
|
grid-gap: 0.5rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin: 0 0 0.5rem 0;
|
margin: 0 0 0.5rem 0;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.1));
|
filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.1));
|
||||||
transform: translate(-1px, -1px);
|
transform: translate(-1px, -1px);
|
||||||
transition: filter 0.2s, transform 0.2s;
|
transition: filter 0.2s, transform 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.done {
|
.done {
|
||||||
transform: none;
|
transform: none;
|
||||||
opacity: 0.4;
|
opacity: 0.4;
|
||||||
filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 0.1));
|
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.1));
|
||||||
}
|
}
|
||||||
|
|
||||||
form.text {
|
form.text {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.todo input {
|
.todo input {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 0.5em 2em 0.5em 0.8em;
|
padding: 0.5em 2em 0.5em 0.8em;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.todo button {
|
.todo button {
|
||||||
width: 2em;
|
width: 2em;
|
||||||
height: 2em;
|
height: 2em;
|
||||||
border: none;
|
border: none;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
background-position: 50% 50%;
|
background-position: 50% 50%;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.toggle {
|
button.toggle {
|
||||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background-size: 1em auto;
|
background-size: 1em auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.done .toggle {
|
.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");
|
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 {
|
.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");
|
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;
|
opacity: 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.delete:hover,
|
.delete:hover,
|
||||||
.delete:focus {
|
.delete:focus {
|
||||||
transition: opacity 0.2s;
|
transition: opacity 0.2s;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.save {
|
.save {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
opacity: 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");
|
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,
|
.todo input:focus + .save,
|
||||||
.save:focus {
|
.save:focus {
|
||||||
transition: opacity 0.2s;
|
transition: opacity 0.2s;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import adapter from '@sveltejs/adapter-auto';
|
|||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
kit: {
|
kit: {
|
||||||
adapter: adapter(),
|
adapter: adapter(),
|
||||||
|
|
||||||
// hydrate the <div id="svelte"> element in src/app.html
|
// Override http methods in the Todo forms
|
||||||
target: '#svelte'
|
methodOverride: {
|
||||||
}
|
allowed: ['PATCH', 'DELETE']
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|||||||
54
package.json
54
package.json
@@ -14,37 +14,24 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lerna": "3.16.4"
|
"lerna": "3.16.4"
|
||||||
},
|
},
|
||||||
"turbo": {
|
|
||||||
"baseBranch": "origin/main",
|
|
||||||
"pipeline": {
|
|
||||||
"build": {
|
|
||||||
"dependsOn": [
|
|
||||||
"^build"
|
|
||||||
],
|
|
||||||
"outputs": [
|
|
||||||
"dist/**"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "4.28.0",
|
"@typescript-eslint/eslint-plugin": "5.21.0",
|
||||||
"@typescript-eslint/parser": "4.28.0",
|
"@typescript-eslint/parser": "5.21.0",
|
||||||
"async-retry": "1.2.3",
|
"async-retry": "1.2.3",
|
||||||
"buffer-replace": "1.0.0",
|
"buffer-replace": "1.0.0",
|
||||||
"cheerio": "1.0.0-rc.3",
|
"eslint": "8.14.0",
|
||||||
"eslint": "7.29.0",
|
"eslint-config-prettier": "8.5.0",
|
||||||
"eslint-config-prettier": "8.3.0",
|
"eslint-plugin-jest": "26.1.5",
|
||||||
"eslint-plugin-jest": "24.3.6",
|
"husky": "7.0.4",
|
||||||
"husky": "6.0.0",
|
"jest": "28.0.2",
|
||||||
"jest": "27.3.1",
|
|
||||||
"json5": "2.1.1",
|
"json5": "2.1.1",
|
||||||
"lint-staged": "9.2.5",
|
"lint-staged": "9.2.5",
|
||||||
"node-fetch": "2.6.1",
|
"node-fetch": "2.6.1",
|
||||||
"npm-package-arg": "6.1.0",
|
"npm-package-arg": "6.1.0",
|
||||||
"prettier": "2.3.1",
|
"prettier": "2.6.2",
|
||||||
"ts-jest": "27.0.4",
|
"ts-eager": "2.0.2",
|
||||||
"turbo": "1.0.18"
|
"ts-jest": "28.0.0-next.1",
|
||||||
|
"turbo": "1.2.14"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lerna": "lerna",
|
"lerna": "lerna",
|
||||||
@@ -54,12 +41,13 @@
|
|||||||
"publish-from-github": "./utils/publish.sh",
|
"publish-from-github": "./utils/publish.sh",
|
||||||
"changelog": "node utils/changelog.js",
|
"changelog": "node utils/changelog.js",
|
||||||
"build": "turbo run build",
|
"build": "turbo run build",
|
||||||
"vercel-build": "mkdir -p public && echo '<a href=\"https://vercel.com/import\">Import</a>' > public/output.html",
|
"vercel-build": "yarn build && cd api && node -r ts-eager/register ./_lib/script/build.ts",
|
||||||
"pre-commit": "lint-staged",
|
"pre-commit": "lint-staged",
|
||||||
"test-unit": "node utils/run.js test-unit",
|
"test": "jest --rootDir=\"test\" --testPathPattern=\"\\.test.js\"",
|
||||||
"test-integration-cli": "node utils/run.js test-integration-cli",
|
"test-unit": "yarn test && turbo run test-unit",
|
||||||
"test-integration-once": "node utils/run.js test-integration-once",
|
"test-integration-cli": "turbo run test-integration-cli",
|
||||||
"test-integration-dev": "node utils/run.js test-integration-dev",
|
"test-integration-once": "turbo run test-integration-once",
|
||||||
|
"test-integration-dev": "turbo run test-integration-dev",
|
||||||
"lint": "eslint . --ext .ts,.js",
|
"lint": "eslint . --ext .ts,.js",
|
||||||
"prepare": "husky install"
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
@@ -102,6 +90,14 @@
|
|||||||
"es6": true
|
"es6": true
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
|
"no-restricted-syntax": [
|
||||||
|
"warn",
|
||||||
|
"WithStatement",
|
||||||
|
{
|
||||||
|
"message": "substr() is deprecated, use slice() or substring() instead",
|
||||||
|
"selector": "MemberExpression > Identifier[name='substr']"
|
||||||
|
}
|
||||||
|
],
|
||||||
"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,3 +1,6 @@
|
|||||||
/src
|
/src
|
||||||
/test
|
/test
|
||||||
tmp
|
/tsconfig.json
|
||||||
|
/.turbo
|
||||||
|
/jest.config.js
|
||||||
|
tmp
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vercel/build-utils",
|
"name": "@vercel/build-utils",
|
||||||
"version": "2.14.1-canary.1",
|
"version": "4.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.js",
|
"types": "./dist/index.d.js",
|
||||||
@@ -12,8 +12,9 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node build",
|
"build": "node build",
|
||||||
"test-unit": "jest --env node --verbose --runInBand --bail test/unit.*test.*",
|
"test": "jest --env node --verbose --runInBand --bail",
|
||||||
"test-integration-once": "jest --env node --verbose --runInBand --bail test/integration.test.ts",
|
"test-unit": "yarn test test/unit.*test.*",
|
||||||
|
"test-integration-once": "yarn test test/integration.test.ts",
|
||||||
"prepublishOnly": "node build"
|
"prepublishOnly": "node build"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -23,14 +24,14 @@
|
|||||||
"@types/end-of-stream": "^1.4.0",
|
"@types/end-of-stream": "^1.4.0",
|
||||||
"@types/fs-extra": "9.0.13",
|
"@types/fs-extra": "9.0.13",
|
||||||
"@types/glob": "^7.1.1",
|
"@types/glob": "^7.1.1",
|
||||||
"@types/jest": "27.0.1",
|
"@types/jest": "27.4.1",
|
||||||
"@types/js-yaml": "3.12.1",
|
"@types/js-yaml": "3.12.1",
|
||||||
"@types/ms": "0.7.31",
|
"@types/ms": "0.7.31",
|
||||||
"@types/multistream": "2.1.1",
|
"@types/multistream": "2.1.1",
|
||||||
"@types/node-fetch": "^2.1.6",
|
"@types/node-fetch": "^2.1.6",
|
||||||
"@types/semver": "6.0.0",
|
"@types/semver": "6.0.0",
|
||||||
"@types/yazl": "^2.4.1",
|
"@types/yazl": "2.4.2",
|
||||||
"@vercel/frameworks": "0.6.1-canary.1",
|
"@vercel/frameworks": "1.0.1",
|
||||||
"@vercel/ncc": "0.24.0",
|
"@vercel/ncc": "0.24.0",
|
||||||
"aggregate-error": "3.0.1",
|
"aggregate-error": "3.0.1",
|
||||||
"async-retry": "1.2.3",
|
"async-retry": "1.2.3",
|
||||||
@@ -47,6 +48,6 @@
|
|||||||
"node-fetch": "2.6.1",
|
"node-fetch": "2.6.1",
|
||||||
"semver": "6.1.1",
|
"semver": "6.1.1",
|
||||||
"typescript": "4.3.4",
|
"typescript": "4.3.4",
|
||||||
"yazl": "2.4.3"
|
"yazl": "2.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ function getPublicBuilder(
|
|||||||
typeof builder.src === 'string' &&
|
typeof builder.src === 'string' &&
|
||||||
isOfficialRuntime('static', builder.use) &&
|
isOfficialRuntime('static', builder.use) &&
|
||||||
/^.*\/\*\*\/\*$/.test(builder.src) &&
|
/^.*\/\*\*\/\*$/.test(builder.src) &&
|
||||||
builder.config &&
|
builder.config?.zeroConfig === true
|
||||||
builder.config.zeroConfig === true
|
|
||||||
) {
|
) {
|
||||||
return builder as Builder & { src: string };
|
return builder as Builder & { src: string };
|
||||||
}
|
}
|
||||||
@@ -539,7 +538,7 @@ function getMissingBuildScriptError() {
|
|||||||
code: 'missing_build_script',
|
code: 'missing_build_script',
|
||||||
message:
|
message:
|
||||||
'Your `package.json` file is missing a `build` property inside the `scripts` property.' +
|
'Your `package.json` file is missing a `build` property inside the `scripts` property.' +
|
||||||
'\nLearn More: https://vercel.com/docs/v2/platform/frequently-asked-questions#missing-build-script',
|
'\nLearn More: https://vercel.link/missing-build-script',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
import { Framework, FrameworkDetectionItem } from '@vercel/frameworks';
|
import { Framework, FrameworkDetectionItem } from '@vercel/frameworks';
|
||||||
import { DetectorFilesystem } from './detectors/filesystem';
|
import { DetectorFilesystem } from './detectors/filesystem';
|
||||||
|
|
||||||
export interface DetectFrameworkOptions {
|
interface BaseFramework {
|
||||||
fs: DetectorFilesystem;
|
slug: Framework['slug'];
|
||||||
frameworkList: readonly Framework[];
|
detectors?: Framework['detectors'];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function matches(fs: DetectorFilesystem, framework: Framework) {
|
export interface DetectFrameworkOptions {
|
||||||
|
fs: DetectorFilesystem;
|
||||||
|
frameworkList: readonly BaseFramework[];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function matches(fs: DetectorFilesystem, framework: BaseFramework) {
|
||||||
const { detectors } = framework;
|
const { detectors } = framework;
|
||||||
|
|
||||||
if (!detectors) {
|
if (!detectors) {
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
export interface Stat {
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
type: 'file' | 'dir';
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* `DetectorFilesystem` is an abstract class that represents a virtual filesystem
|
* `DetectorFilesystem` is an abstract class that represents a virtual filesystem
|
||||||
* to perform read-only operations on in order to detect which framework is being
|
* to perform read-only operations on in order to detect which framework is being
|
||||||
@@ -27,15 +32,19 @@ export abstract class DetectorFilesystem {
|
|||||||
protected abstract _hasPath(name: string): Promise<boolean>;
|
protected abstract _hasPath(name: string): Promise<boolean>;
|
||||||
protected abstract _readFile(name: string): Promise<Buffer>;
|
protected abstract _readFile(name: string): Promise<Buffer>;
|
||||||
protected abstract _isFile(name: string): Promise<boolean>;
|
protected abstract _isFile(name: string): Promise<boolean>;
|
||||||
|
protected abstract _readdir(name: string): Promise<Stat[]>;
|
||||||
|
protected abstract _chdir(name: string): DetectorFilesystem;
|
||||||
|
|
||||||
private pathCache: Map<string, Promise<boolean>>;
|
private pathCache: Map<string, Promise<boolean>>;
|
||||||
private fileCache: Map<string, Promise<boolean>>;
|
private fileCache: Map<string, Promise<boolean>>;
|
||||||
private readFileCache: Map<string, Promise<Buffer>>;
|
private readFileCache: Map<string, Promise<Buffer>>;
|
||||||
|
private readdirCache: Map<string, Promise<Stat[]>>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pathCache = new Map();
|
this.pathCache = new Map();
|
||||||
this.fileCache = new Map();
|
this.fileCache = new Map();
|
||||||
this.readFileCache = new Map();
|
this.readFileCache = new Map();
|
||||||
|
this.readdirCache = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasPath = async (path: string): Promise<boolean> => {
|
public hasPath = async (path: string): Promise<boolean> => {
|
||||||
@@ -64,4 +73,23 @@ export abstract class DetectorFilesystem {
|
|||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of Stat objects from the current working directory.
|
||||||
|
*/
|
||||||
|
public readdir = async (name: string): Promise<Stat[]> => {
|
||||||
|
let p = this.readdirCache.get(name);
|
||||||
|
if (!p) {
|
||||||
|
p = this._readdir(name);
|
||||||
|
this.readdirCache.set(name, p);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the current directory to the specified path and returns a new instance of DetectorFilesystem.
|
||||||
|
*/
|
||||||
|
public chdir = (name: string): DetectorFilesystem => {
|
||||||
|
return this._chdir(name);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
44
packages/build-utils/src/edge-function.ts
Normal file
44
packages/build-utils/src/edge-function.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import type { Files } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Edge Functions output
|
||||||
|
*/
|
||||||
|
export class EdgeFunction {
|
||||||
|
type: 'EdgeFunction';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A display name for the edge function.
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deployment target.
|
||||||
|
* Only v8-worker is currently supported.
|
||||||
|
*/
|
||||||
|
deploymentTarget: 'v8-worker';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entrypoint for the edge function.
|
||||||
|
*/
|
||||||
|
entrypoint: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of files to be included in the edge function bundle.
|
||||||
|
*/
|
||||||
|
files: Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra environment variables in use for the user code, to be
|
||||||
|
* assigned to the edge function.
|
||||||
|
*/
|
||||||
|
envVarsInUse?: string[];
|
||||||
|
|
||||||
|
constructor(params: Omit<EdgeFunction, 'type'>) {
|
||||||
|
this.type = 'EdgeFunction';
|
||||||
|
this.name = params.name;
|
||||||
|
this.deploymentTarget = params.deploymentTarget;
|
||||||
|
this.entrypoint = params.entrypoint;
|
||||||
|
this.files = params.files;
|
||||||
|
this.envVarsInUse = params.envVarsInUse;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import intoStream from 'into-stream';
|
import intoStream from 'into-stream';
|
||||||
import { File } from './types';
|
import { FileBase } from './types';
|
||||||
|
|
||||||
interface FileBlobOptions {
|
interface FileBlobOptions {
|
||||||
mode?: number;
|
mode?: number;
|
||||||
@@ -14,7 +14,7 @@ interface FromStreamOptions {
|
|||||||
stream: NodeJS.ReadableStream;
|
stream: NodeJS.ReadableStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class FileBlob implements File {
|
export default class FileBlob implements FileBase {
|
||||||
public type: 'FileBlob';
|
public type: 'FileBlob';
|
||||||
public mode: number;
|
public mode: number;
|
||||||
public data: string | Buffer;
|
public data: string | Buffer;
|
||||||
@@ -48,6 +48,10 @@ export default class FileBlob implements File {
|
|||||||
return new FileBlob({ mode, contentType, data });
|
return new FileBlob({ mode, contentType, data });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async toStreamAsync(): Promise<NodeJS.ReadableStream> {
|
||||||
|
return this.toStream();
|
||||||
|
}
|
||||||
|
|
||||||
toStream(): NodeJS.ReadableStream {
|
toStream(): NodeJS.ReadableStream {
|
||||||
return intoStream(this.data);
|
return intoStream(this.data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import fs from 'fs-extra';
|
|||||||
import multiStream from 'multistream';
|
import multiStream from 'multistream';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import Sema from 'async-sema';
|
import Sema from 'async-sema';
|
||||||
import { File } from './types';
|
import { FileBase } from './types';
|
||||||
|
|
||||||
const semaToPreventEMFILE = new Sema(20);
|
const semaToPreventEMFILE = new Sema(20);
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ interface FromStreamOptions {
|
|||||||
fsPath: string;
|
fsPath: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileFsRef implements File {
|
class FileFsRef implements FileBase {
|
||||||
public type: 'FileFsRef';
|
public type: 'FileFsRef';
|
||||||
public mode: number;
|
public mode: number;
|
||||||
public fsPath: string;
|
public fsPath: string;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import fetch from 'node-fetch';
|
|||||||
import multiStream from 'multistream';
|
import multiStream from 'multistream';
|
||||||
import retry from 'async-retry';
|
import retry from 'async-retry';
|
||||||
import Sema from 'async-sema';
|
import Sema from 'async-sema';
|
||||||
import { File } from './types';
|
import { FileBase } from './types';
|
||||||
|
|
||||||
interface FileRefOptions {
|
interface FileRefOptions {
|
||||||
mode?: number;
|
mode?: number;
|
||||||
@@ -23,7 +23,7 @@ class BailableError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class FileRef implements File {
|
export default class FileRef implements FileBase {
|
||||||
public type: 'FileRef';
|
public type: 'FileRef';
|
||||||
public mode: number;
|
public mode: number;
|
||||||
public digest: string;
|
public digest: string;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import debug from '../debug';
|
|||||||
import FileFsRef from '../file-fs-ref';
|
import FileFsRef from '../file-fs-ref';
|
||||||
import { File, Files, Meta } from '../types';
|
import { File, Files, Meta } from '../types';
|
||||||
import { remove, mkdirp, readlink, symlink } from 'fs-extra';
|
import { remove, mkdirp, readlink, symlink } from 'fs-extra';
|
||||||
|
import streamToBuffer from './stream-to-buffer';
|
||||||
|
|
||||||
export interface DownloadedFiles {
|
export interface DownloadedFiles {
|
||||||
[filePath: string]: FileFsRef;
|
[filePath: string]: FileFsRef;
|
||||||
@@ -15,19 +16,44 @@ export function isSymbolicLink(mode: number): boolean {
|
|||||||
return (mode & S_IFMT) === S_IFLNK;
|
return (mode & S_IFMT) === S_IFLNK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function prepareSymlinkTarget(
|
||||||
|
file: File,
|
||||||
|
fsPath: string
|
||||||
|
): Promise<string> {
|
||||||
|
const mkdirPromise = mkdirp(path.dirname(fsPath));
|
||||||
|
if (file.type === 'FileFsRef') {
|
||||||
|
const [target] = await Promise.all([readlink(file.fsPath), mkdirPromise]);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.type === 'FileRef' || file.type === 'FileBlob') {
|
||||||
|
const targetPathBufferPromise = await streamToBuffer(
|
||||||
|
await file.toStreamAsync()
|
||||||
|
);
|
||||||
|
const [targetPathBuffer] = await Promise.all([
|
||||||
|
targetPathBufferPromise,
|
||||||
|
mkdirPromise,
|
||||||
|
]);
|
||||||
|
return targetPathBuffer.toString('utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`file.type "${(file as any).type}" not supported for symlink`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function downloadFile(file: File, fsPath: string): Promise<FileFsRef> {
|
async function downloadFile(file: File, fsPath: string): Promise<FileFsRef> {
|
||||||
const { mode } = file;
|
const { mode } = file;
|
||||||
if (mode && isSymbolicLink(mode) && file.type === 'FileFsRef') {
|
|
||||||
const [target] = await Promise.all([
|
if (isSymbolicLink(mode)) {
|
||||||
readlink((file as FileFsRef).fsPath),
|
const target = await prepareSymlinkTarget(file, fsPath);
|
||||||
mkdirp(path.dirname(fsPath)),
|
|
||||||
]);
|
|
||||||
await symlink(target, fsPath);
|
await symlink(target, fsPath);
|
||||||
return FileFsRef.fromFsPath({ mode, fsPath });
|
return FileFsRef.fromFsPath({ mode, fsPath });
|
||||||
} else {
|
|
||||||
const stream = file.toStream();
|
|
||||||
return FileFsRef.fromStream({ mode, stream, fsPath });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stream = file.toStream();
|
||||||
|
return FileFsRef.fromStream({ mode, stream, fsPath });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeFile(basePath: string, fileMatched: string) {
|
async function removeFile(basePath: string, fileMatched: string) {
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ export default async function glob(
|
|||||||
const files = await vanillaGlob(pattern, options);
|
const files = await vanillaGlob(pattern, options);
|
||||||
|
|
||||||
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: Stats = options.statCache[fsPath] as Stats;
|
||||||
assert(
|
assert(
|
||||||
stat,
|
stat,
|
||||||
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
|
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user