Skip to content
This repository was archived by the owner on Jan 2, 2022. It is now read-only.

Commit e390188

Browse files
committed
feat: add Netlify functions
Signed-off-by: Jonah Snider <[email protected]>
1 parent fb2a5b5 commit e390188

File tree

6 files changed

+154
-89
lines changed

6 files changed

+154
-89
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,3 @@ jobs:
9898
run: yarn install
9999
- name: Check style with Prettier
100100
run: yarn run style
101-
test:
102-
name: Run unit tests
103-
104-
runs-on: ubuntu-latest
105-
106-
steps:
107-
- name: Checkout git repository
108-
uses: actions/checkout@v1
109-
with:
110-
fetch-depth: 0
111-
- name: Setup Node.js for use with Actions
112-
uses: actions/setup-node@v1
113-
with:
114-
node-version: '12.14.1'
115-
- name: Install Yarn
116-
run: curl -o- -L https://yarnpkg.com/install.sh | bash
117-
- name: Get yarn cache
118-
id: yarn-cache
119-
run: echo "::set-output name=dir::$(yarn cache dir)"
120-
- name: Cache dependencies
121-
uses: actions/cache@v1
122-
with:
123-
path: ${{ steps.yarn-cache.outputs.dir }}
124-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
125-
restore-keys: |
126-
${{ runner.os }}-yarn-
127-
- name: Install dependencies with Yarn
128-
run: yarn install
129-
- name: Run tests
130-
run: yarn run test
131-
- name: Submit test coverage
132-
uses: codecov/codecov-action@v1
133-
with:
134-
token: ${{ secrets.CODECOV_TOKEN }}

package.json

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,17 @@
44
"name": "Jonah Snider",
55
"url": "https://jonah.pw"
66
},
7-
"ava": {
8-
"extensions": [
9-
"ts"
10-
],
11-
"files": [
12-
"!tsc_output"
13-
],
14-
"require": [
15-
"ts-node/register",
16-
"source-map-support/register"
17-
]
18-
},
197
"bugs": {
20-
"url": "https://github.com/pizzafox/typescript-starter/issues"
8+
"url": "https://github.com/pizzafox/netlify-cache-nextjs/issues"
9+
},
10+
"dependencies": {
11+
"@netlify/cache-utils": "^0.1.2"
2112
},
2213
"devDependencies": {
23-
"@istanbuljs/nyc-config-typescript": "^1.0.1",
2414
"@typescript-eslint/eslint-plugin": "^2.17.0",
2515
"@typescript-eslint/parser": "^2.17.0",
26-
"ava": "^3.0.0",
2716
"eslint-config-xo-typescript": "^0.24.1",
28-
"nyc": "^15.0.0",
2917
"prettier": "^1.19.1",
30-
"source-map-support": "^0.5.16",
31-
"ts-node": "^8.6.2",
3218
"typescript": "^3.7.5",
3319
"xo": "^0.25.3"
3420
},
@@ -37,30 +23,17 @@
3723
},
3824
"license": "Apache-2.0",
3925
"main": "./tsc_output/src/index.js",
40-
"name": "typescript-starter",
41-
"nyc": {
42-
"all": true,
43-
"extends": "@istanbuljs/nyc-config-typescript",
44-
"include": [
45-
"src/**/*.ts"
46-
],
47-
"reporter": [
48-
"lcov",
49-
"cobertura"
50-
]
51-
},
26+
"name": "netlify-cache-nextjs",
5227
"private": true,
5328
"repository": {
5429
"type": "git",
55-
"url": "git+https://github.com/pizzafox/typescript-starter.git"
30+
"url": "git+https://github.com/pizzafox/netlify-cache-nextjs.git"
5631
},
5732
"scripts": {
5833
"build": "tsc",
5934
"lint": "xo",
6035
"prebuild": "rm -rf tsc_output",
61-
"pretest": "rm -rf coverage .nyc_output",
62-
"style": "prettier --ignore-path .gitignore --check \"./**/*.{{j,t}{s,sx},flow,{sc,c,le}ss,json,m{d,dx},{y,ya}ml}\"",
63-
"test": "nyc ava"
36+
"style": "prettier --ignore-path .gitignore --check \"./**/*.{{j,t}{s,sx},flow,{sc,c,le}ss,json,m{d,dx},{y,ya}ml}\""
6437
},
6538
"version": "1.0.0",
6639
"xo": {

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# [TypeScript](https://www.typescriptlang.org) Starter
22

3-
[![Build Status](https://github.com/pizzafox/typescript-starter/workflows/CI/badge.svg)](https://github.com/pizzafox/typescript-starter/actions)
3+
[![Build Status](https://github.com/pizzafox/netlify-cache-nextjs/workflows/CI/badge.svg)](https://github.com/pizzafox/netlify-cache-nextjs/actions)
44
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)
5-
[![codecov](https://codecov.io/gh/pizzafox/typescript-starter/branch/master/graph/badge.svg)](https://codecov.io/gh/pizzafox/typescript-starter)
5+
[![codecov](https://codecov.io/gh/pizzafox/netlify-cache-nextjs/branch/master/graph/badge.svg)](https://codecov.io/gh/pizzafox/netlify-cache-nextjs)
66

7-
My personal TypeScript starter template.
7+
Cache the `.next` folder in Netlify builds.
88

99
## Prequisites
1010

@@ -64,4 +64,4 @@ yarn run test
6464
### Coverage
6565

6666
This will generate a `coverage` folder which has a breakdown of coverage of the project.
67-
The CI will upload the coverage information to [CodeCov](https://codecov.io) which can be [viewed here](https://codecov.io/gh/pizzafox/typescript-starter).
67+
The CI will upload the coverage information to [CodeCov](https://codecov.io) which can be [viewed here](https://codecov.io/gh/pizzafox/netlify-cache-nextjs).

src/index.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
/**
2-
* Says hello world.
3-
* @param subject What the subject of the message is.
4-
* @returns Hello world message
5-
*/
6-
export function helloWorld(subject?: string): string {
7-
return `Hello, ${subject ?? 'world'}.`;
1+
interface NetlifyUtils {
2+
cache: {
3+
restore(path: string, options: {digest: string[]}): Promise<any>;
4+
save(path: string, options: {digest: string[]}): Promise<any>;
5+
};
86
}
7+
8+
export default {
9+
name: 'cache-nextjs',
10+
// Restore file/directory cached in previous builds.
11+
// Does not do anything if:
12+
// - the file/directory already exists locally
13+
// - the file/directory has not been cached yet
14+
async onGetCache({utils}: {utils: NetlifyUtils}) {
15+
await utils.cache.restore('./.next', {digest: ['./.next/build-manifest.json']});
16+
},
17+
// Cache file/directory for future builds.
18+
// Does not do anything if:
19+
// - the file/directory does not exist locally
20+
// - the file/directory is already cached and its contents has not changed
21+
// If this is a directory, this includes children's contents
22+
async onSaveCache({utils}: {utils: NetlifyUtils}) {
23+
await utils.cache.save('./.next', {digest: ['./.next/build-manifest.json']});
24+
}
25+
};

test/index.test.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

yarn.lock

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@
170170
call-me-maybe "^1.0.1"
171171
glob-to-regexp "^0.3.0"
172172

173+
"@netlify/cache-utils@^0.1.2":
174+
version "0.1.2"
175+
resolved "https://registry.yarnpkg.com/@netlify/cache-utils/-/cache-utils-0.1.2.tgz#a87356bb0a1de5ad4cd9dd3f28621896c66e83d7"
176+
integrity sha512-jtErzXR5WkBYhfr5kNL7j2WpYuivnDfpdAuBqszTiTxOfQ1v5MQ1Rw25roylVz/40ZOFiKaa6IhPka8NQgcE5A==
177+
dependencies:
178+
cpy "^8.0.0"
179+
del "^5.1.0"
180+
get-stream "^5.1.0"
181+
global-cache-dir "^1.0.1"
182+
junk "^3.1.0"
183+
move-file "^1.2.0"
184+
p-map "^3.0.0"
185+
path-exists "^4.0.0"
186+
readdirp "^3.3.0"
187+
173188
"@nodelib/[email protected]":
174189
version "2.1.3"
175190
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"
@@ -677,6 +692,11 @@ cacheable-request@^6.0.0:
677692
normalize-url "^4.1.0"
678693
responselike "^1.0.2"
679694

695+
cachedir@^2.2.0:
696+
version "2.3.0"
697+
resolved "https://registry.yarnpkg.com/cachedir/-/cachedir-2.3.0.tgz#0c75892a052198f0b21c7c1804d8331edfcae0e8"
698+
integrity sha512-A+Fezp4zxnit6FanDmv9EqXNAi3vt9DWp51/71UEhXukb7QUuvtv9344h91dyAxuTLoSYJFU299qzR3tzwPAhw==
699+
680700
caching-transform@^4.0.0:
681701
version "4.0.0"
682702
resolved "https://registry.yarnpkg.com/caching-transform/-/caching-transform-4.0.0.tgz#00d297a4206d71e2163c39eaffa8157ac0651f0f"
@@ -976,6 +996,40 @@ core-assert@^0.2.0:
976996
buf-compare "^1.0.0"
977997
is-error "^2.2.0"
978998

999+
cp-file@^6.1.0:
1000+
version "6.2.0"
1001+
resolved "https://registry.yarnpkg.com/cp-file/-/cp-file-6.2.0.tgz#40d5ea4a1def2a9acdd07ba5c0b0246ef73dc10d"
1002+
integrity sha512-fmvV4caBnofhPe8kOcitBwSn2f39QLjnAnGq3gO9dfd75mUytzKNZB1hde6QHunW2Rt+OwuBOMc3i1tNElbszA==
1003+
dependencies:
1004+
graceful-fs "^4.1.2"
1005+
make-dir "^2.0.0"
1006+
nested-error-stacks "^2.0.0"
1007+
pify "^4.0.1"
1008+
safe-buffer "^5.0.1"
1009+
1010+
cp-file@^7.0.0:
1011+
version "7.0.0"
1012+
resolved "https://registry.yarnpkg.com/cp-file/-/cp-file-7.0.0.tgz#b9454cfd07fe3b974ab9ea0e5f29655791a9b8cd"
1013+
integrity sha512-0Cbj7gyvFVApzpK/uhCtQ/9kE9UnYpxMzaq5nQQC/Dh4iaj5fxp7iEFIullrYwzj8nf0qnsI1Qsx34hAeAebvw==
1014+
dependencies:
1015+
graceful-fs "^4.1.2"
1016+
make-dir "^3.0.0"
1017+
nested-error-stacks "^2.0.0"
1018+
p-event "^4.1.0"
1019+
1020+
cpy@^8.0.0:
1021+
version "8.0.0"
1022+
resolved "https://registry.yarnpkg.com/cpy/-/cpy-8.0.0.tgz#8195db0db19a9ea6aa4f229784cbf3e3f53c3158"
1023+
integrity sha512-iTjLUqtVr45e17GFAyxA0lqFinbGMblMCTtAqrPzT/IETNtDuyyhDDk8weEZ08MiCc6EcuyNq2KtGH5J2BIAoQ==
1024+
dependencies:
1025+
arrify "^2.0.1"
1026+
cp-file "^7.0.0"
1027+
globby "^9.2.0"
1028+
is-glob "^4.0.1"
1029+
junk "^3.1.0"
1030+
nested-error-stacks "^2.1.0"
1031+
p-all "^2.1.0"
1032+
9791033
cross-spawn@^5.0.1:
9801034
version "5.1.0"
9811035
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
@@ -1891,6 +1945,15 @@ glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
18911945
once "^1.3.0"
18921946
path-is-absolute "^1.0.0"
18931947

1948+
global-cache-dir@^1.0.1:
1949+
version "1.0.1"
1950+
resolved "https://registry.yarnpkg.com/global-cache-dir/-/global-cache-dir-1.0.1.tgz#2c0820b43bae8a6ef8adf96fd23ec6bbf52dd13c"
1951+
integrity sha512-wYGh6O3Xkx1LsMXQpObr/uu3PsFpbWhpbslgn9Xq52rbDZ6YOwJcQtU5R4lSEQgCDtXLItV9EH5X1F/VnBTAlw==
1952+
dependencies:
1953+
cachedir "^2.2.0"
1954+
make-dir "^3.0.0"
1955+
path-exists "^4.0.0"
1956+
18941957
global-dirs@^0.1.0:
18951958
version "0.1.1"
18961959
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
@@ -1943,7 +2006,7 @@ globby@^11.0.0:
19432006
merge2 "^1.3.0"
19442007
slash "^3.0.0"
19452008

1946-
globby@^9.0.0:
2009+
globby@^9.0.0, globby@^9.2.0:
19472010
version "9.2.0"
19482011
resolved "https://registry.yarnpkg.com/globby/-/globby-9.2.0.tgz#fd029a706c703d29bdd170f4b6db3a3f7a7cb63d"
19492012
integrity sha512-ollPHROa5mcxDEkwg6bPt3QbEf4pDQSNtd6JPL1YvOvAo/7/0VAm9TccUeoTmarjPw4pfUthSCqcyfNB1I3ZSg==
@@ -2621,6 +2684,11 @@ json5@^2.1.0:
26212684
dependencies:
26222685
minimist "^1.2.0"
26232686

2687+
junk@^3.1.0:
2688+
version "3.1.0"
2689+
resolved "https://registry.yarnpkg.com/junk/-/junk-3.1.0.tgz#31499098d902b7e98c5d9b9c80f43457a88abfa1"
2690+
integrity sha512-pBxcB3LFc8QVgdggvZWyeys+hnrNWg4OcZIU/1X59k5jQdLBlCsYGRQaz234SqoRLTCgMH00fY0xRJH+F9METQ==
2691+
26242692
keyv@^3.0.0:
26252693
version "3.1.0"
26262694
resolved "https://registry.yarnpkg.com/keyv/-/keyv-3.1.0.tgz#ecc228486f69991e49e9476485a5be1e8fc5c4d9"
@@ -2855,6 +2923,14 @@ make-dir@^1.0.0:
28552923
dependencies:
28562924
pify "^3.0.0"
28572925

2926+
make-dir@^2.0.0:
2927+
version "2.1.0"
2928+
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
2929+
integrity sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==
2930+
dependencies:
2931+
pify "^4.0.1"
2932+
semver "^5.6.0"
2933+
28582934
make-dir@^3.0.0:
28592935
version "3.0.0"
28602936
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.0.0.tgz#1b5f39f6b9270ed33f9f054c5c0f84304989f801"
@@ -3012,6 +3088,15 @@ mkdirp@^0.5.1:
30123088
dependencies:
30133089
minimist "0.0.8"
30143090

3091+
move-file@^1.2.0:
3092+
version "1.2.0"
3093+
resolved "https://registry.yarnpkg.com/move-file/-/move-file-1.2.0.tgz#789f92d276c62511d214b1b285aa16e015c2f2fc"
3094+
integrity sha512-USHrRmxzGowUWAGBbJPdFjHzEqtxDU03pLHY0Rfqgtnq+q8FOIs8wvkkf+Udmg77SJKs47y9sI0jJvQeYsmiCA==
3095+
dependencies:
3096+
cp-file "^6.1.0"
3097+
make-dir "^3.0.0"
3098+
path-exists "^3.0.0"
3099+
30153100
30163101
version "2.0.0"
30173102
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
@@ -3065,6 +3150,11 @@ natural-compare@^1.4.0:
30653150
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
30663151
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
30673152

3153+
nested-error-stacks@^2.0.0, nested-error-stacks@^2.1.0:
3154+
version "2.1.0"
3155+
resolved "https://registry.yarnpkg.com/nested-error-stacks/-/nested-error-stacks-2.1.0.tgz#0fbdcf3e13fe4994781280524f8b96b0cdff9c61"
3156+
integrity sha512-AO81vsIO1k1sM4Zrd6Hu7regmJN1NSiAja10gc4bX3F0wd+9rQmcuHQaHVQCYIEC8iFXnE+mavh23GOt7wBgug==
3157+
30683158
nice-try@^1.0.4:
30693159
version "1.0.5"
30703160
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
@@ -3247,11 +3337,25 @@ os-tmpdir@~1.0.2:
32473337
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
32483338
integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=
32493339

3340+
p-all@^2.1.0:
3341+
version "2.1.0"
3342+
resolved "https://registry.yarnpkg.com/p-all/-/p-all-2.1.0.tgz#91419be56b7dee8fe4c5db875d55e0da084244a0"
3343+
integrity sha512-HbZxz5FONzz/z2gJfk6bFca0BCiSRF8jU3yCsWOen/vR6lZjfPOu/e7L3uFzTW1i0H8TlC3vqQstEJPQL4/uLA==
3344+
dependencies:
3345+
p-map "^2.0.0"
3346+
32503347
p-cancelable@^1.0.0:
32513348
version "1.1.0"
32523349
resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-1.1.0.tgz#d078d15a3af409220c886f1d9a0ca2e441ab26cc"
32533350
integrity sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==
32543351

3352+
p-event@^4.1.0:
3353+
version "4.1.0"
3354+
resolved "https://registry.yarnpkg.com/p-event/-/p-event-4.1.0.tgz#e92bb866d7e8e5b732293b1c8269d38e9982bf8e"
3355+
integrity sha512-4vAd06GCsgflX4wHN1JqrMzBh/8QZ4j+rzp0cd2scXRwuBEv+QR3wrVA5aLhWDLw4y2WgDKvzWF3CCLmVM1UgA==
3356+
dependencies:
3357+
p-timeout "^2.0.1"
3358+
32553359
p-finally@^1.0.0:
32563360
version "1.0.0"
32573361
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
@@ -3292,13 +3396,25 @@ p-locate@^4.1.0:
32923396
dependencies:
32933397
p-limit "^2.2.0"
32943398

3399+
p-map@^2.0.0:
3400+
version "2.1.0"
3401+
resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.1.0.tgz#310928feef9c9ecc65b68b17693018a665cea175"
3402+
integrity sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==
3403+
32953404
p-map@^3.0.0:
32963405
version "3.0.0"
32973406
resolved "https://registry.yarnpkg.com/p-map/-/p-map-3.0.0.tgz#d704d9af8a2ba684e2600d9a215983d4141a979d"
32983407
integrity sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==
32993408
dependencies:
33003409
aggregate-error "^3.0.0"
33013410

3411+
p-timeout@^2.0.1:
3412+
version "2.0.1"
3413+
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-2.0.1.tgz#d8dd1979595d2dc0139e1fe46b8b646cb3cdf038"
3414+
integrity sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA==
3415+
dependencies:
3416+
p-finally "^1.0.0"
3417+
33023418
p-try@^1.0.0:
33033419
version "1.0.0"
33043420
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
@@ -3616,7 +3732,7 @@ read-pkg@^5.2.0:
36163732
parse-json "^5.0.0"
36173733
type-fest "^0.6.0"
36183734

3619-
readdirp@~3.3.0:
3735+
readdirp@^3.3.0, readdirp@~3.3.0:
36203736
version "3.3.0"
36213737
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.3.0.tgz#984458d13a1e42e2e9f5841b129e162f369aff17"
36223738
integrity sha512-zz0pAkSPOXXm1viEwygWIPSPkcBYjW1xU5j/JBh5t9bGCJwa6f9+BJa6VaB2g+b55yVrmXzqkyLf4xaWYM0IkQ==
@@ -3831,7 +3947,7 @@ semver-diff@^3.1.1:
38313947
dependencies:
38323948
semver "^6.3.0"
38333949

3834-
"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1:
3950+
"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0:
38353951
version "5.7.1"
38363952
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
38373953
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

0 commit comments

Comments
 (0)