Skip to content
This repository was archived by the owner on Apr 19, 2021. It is now read-only.

Commit 6374c42

Browse files
committed
🌊 upstream: update to the way TypeScript is employed in the official Svelte template
support type checking during development and before a production build update all the colors and styles to match the Tailwind UI color palette remove all `@ts-ignore`s because they're no longer needed! (include a typing declaration for `@sapper`) support TypeScript 4 (beta) easily
1 parent 30097cc commit 6374c42

19 files changed

+776
-239
lines changed

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"svelte.svelte-vscode"
4+
]
5+
}

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
},
1111
"eslint.format.enable": true,
1212
"eslint.lintTask.enable": true,
13+
"typescript.tsdk": "node_modules/typescript/lib",
1314
}

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Set up Cloud Functions for Firebase
2+
13
const { https: { onRequest } } = require("firebase-functions");
24

35
const { createSapperAndApolloServer } = require("./__sapper__/build/server/server"); // eslint-disable-line import/no-unresolved

package-lock.json

Lines changed: 641 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,66 @@
2121
"url": "https://github.com/babichjacob/sapper-firebase-typescript-graphql-tailwindcss-actions-template.git"
2222
},
2323
"license": "MIT",
24-
"version": "2020.07.22",
24+
"version": "2020.08.05",
2525
"scripts": {
2626
"eslint": "eslint",
2727
"eslint:fix": "eslint --fix ./*.js ./src/*.ts ./src/components/**/*.svelte ./src/graphql/**/*.ts ./src/routes/**/*.svelte ./src/routes/**/*.ts",
28+
"validate": "svelte-check --ignore src/node_modules/@sapper",
29+
"validate:dev": "svelte-check --ignore src/node_modules/@sapper --watch",
2830
"firebase": "firebase",
2931
"firebase:deploy": "firebase deploy",
3032
"firebase:deploy:hosting": "firebase deploy --only hosting",
3133
"firebase:deploy:functions": "firebase deploy --only functions",
34+
"sapper:dev": "sapper dev",
3235
"sapper:build": "cross-env NODE_ENV=production sapper build --legacy",
3336
"sapper:export": "cross-env NODE_ENV=production sapper export --legacy",
3437
"static:rmdir": "rimraf - __sapper__/export",
3538
"static:mkdir": "mkdirp __sapper__/export",
3639
"static:cp": "ncp static __sapper__/export",
3740
"static:404:cp": "ncp __sapper__/export/404/index.html __sapper__/export/404.html",
3841
"static:404:rmdir": "rimraf - __sapper__/export/404",
39-
"dev": "cross-env ROLLUP_WATCH=true sapper dev",
40-
"prod": "run-s sapper:build static:rmdir static:mkdir static:cp",
42+
"dev": "run-p validate:dev sapper:dev",
43+
"prod": "run-s validate sapper:build static:rmdir static:mkdir static:cp",
4144
"start": "node __sapper__/build",
4245
"deploy": "run-s prod firebase:deploy",
43-
"export": "run-s sapper:export static:404:cp static:404:rmdir",
46+
"export": "run-s validate sapper:export static:404:cp static:404:rmdir",
4447
"deploy:export": "run-s export firebase:deploy:hosting"
4548
},
4649
"dependencies": {
4750
"compression": "^1.7.4",
4851
"express": "^4.17.1",
4952
"firebase-admin": "^9.0.0",
50-
"firebase-functions": "^3.8.0",
53+
"firebase-functions": "^3.9.0",
5154
"firebase-tools": "^8.6.0",
5255
"node-fetch": "^2.6.0",
53-
"sirv": "^1.0.1"
56+
"sirv": "^1.0.5"
5457
},
5558
"devDependencies": {
56-
"@babel/core": "^7.10.5",
59+
"@babel/core": "^7.11.1",
5760
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
58-
"@babel/plugin-transform-runtime": "^7.10.5",
59-
"@babel/preset-env": "^7.10.4",
60-
"@babel/runtime": "^7.10.5",
61+
"@babel/plugin-transform-runtime": "^7.11.0",
62+
"@babel/preset-env": "^7.11.0",
63+
"@babel/runtime": "^7.11.1",
6164
"@fullhuman/postcss-purgecss": "^2.3.0",
6265
"@rollup/plugin-babel": "^5.1.0",
6366
"@rollup/plugin-commonjs": "^14.0.0",
6467
"@rollup/plugin-json": "^4.1.0",
6568
"@rollup/plugin-node-resolve": "^8.4.0",
6669
"@rollup/plugin-replace": "^2.3.3",
67-
"@rollup/plugin-typescript": ">=5.0.2",
70+
"@rollup/plugin-typescript": "^5.0.2",
6871
"@tailwindcss/custom-forms": "^0.2.1",
69-
"@tailwindcss/ui": "^0.4.0",
72+
"@tailwindcss/ui": "^0.5.0",
7073
"@types/compression": "^1.7.0",
7174
"@types/express": "^4.17.7",
7275
"@types/node-fetch": "^2.5.7",
73-
"@typescript-eslint/eslint-plugin": "^3.7.0",
74-
"@typescript-eslint/parser": "^3.7.0",
75-
"apollo-server-express": "^2.16.0",
76+
"@typescript-eslint/eslint-plugin": "^3.8.0",
77+
"@typescript-eslint/parser": "^3.8.0",
78+
"apollo-server-express": "^2.16.1",
7679
"bufferutil": "^4.0.1",
7780
"class-validator": "^0.12.2",
7881
"cross-env": "^7.0.2",
7982
"cssnano": "^4.1.10",
80-
"eslint": "^7.5.0",
83+
"eslint": "^7.6.0",
8184
"eslint-config-airbnb-base": "^14.2.0",
8285
"eslint-plugin-import": "^2.22.0",
8386
"eslint-plugin-svelte3": "^2.7.3",
@@ -91,13 +94,14 @@
9194
"postcss-preset-env": "^6.7.0",
9295
"reflect-metadata": "^0.1.13",
9396
"rimraf": "^3.0.2",
94-
"rollup": "^2.22.2",
97+
"rollup": "^2.23.0",
9598
"rollup-plugin-svelte": "^5.2.3",
9699
"rollup-plugin-terser": "^6.1.0",
97100
"sapper": "^0.27.16",
98101
"svelte": "^3.24.0",
99-
"svelte-preprocess": "^4.0.8",
100-
"tailwindcss": "^1.5.2",
102+
"svelte-check": "^1.0.6",
103+
"svelte-preprocess": "^4.0.10",
104+
"tailwindcss": "^1.6.2",
101105
"tslib": "^2.0.0",
102106
"type-graphql": "^1.0.0-rc.3",
103107
"typescript": "^3.9.7",

rollup.config.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import svelte from "rollup-plugin-svelte";
77
import babel from "@rollup/plugin-babel";
88
import { terser } from "rollup-plugin-terser";
99
import config from "sapper/config/rollup";
10+
import sveltePreprocess from "svelte-preprocess";
1011
import pkg from "./package.json";
11-
import { preprocess as sveltePreprocessConfig } from "./svelte.config";
12+
import postcss from "./postcss.config";
1213

1314
const preprocess = [
14-
sveltePreprocessConfig,
15+
sveltePreprocess({ postcss }),
1516
// You could have more preprocessors, like MDsveX
1617
];
1718

@@ -30,7 +31,7 @@ const onwarn = (warning, _onwarn) => (warning.code === "CIRCULAR_DEPENDENCY" &&
3031
export default {
3132
client: {
3233
input: config.client.input().replace(/\.js$/, ".ts"),
33-
output: { ...config.client.output(), sourcemap },
34+
output: config.client.output(),
3435
plugins: [
3536
replace({
3637
"process.browser": true,
@@ -47,7 +48,7 @@ export default {
4748
dedupe: ["svelte"],
4849
}),
4950
commonjs(),
50-
typescript(),
51+
typescript({ sourceMap: !!sourcemap }),
5152
json(),
5253

5354
legacy && babel({
@@ -94,7 +95,7 @@ export default {
9495
dedupe: ["svelte"],
9596
}),
9697
commonjs(),
97-
typescript(),
98+
typescript({ sourceMap: !!sourcemap }),
9899
json(),
99100
],
100101
external: Object.keys(pkg.dependencies).concat(
@@ -115,7 +116,7 @@ export default {
115116
"process.env.NODE_ENV": JSON.stringify(mode),
116117
}),
117118
commonjs(),
118-
typescript(),
119+
typescript({ sourceMap: !!sourcemap }),
119120
!dev && terser(),
120121
],
121122

src/client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-ignore -- generated package
21
import * as sapper from "@sapper/app"; // eslint-disable-line import/no-unresolved
32

43
sapper.start({

src/components/ExampleComponent.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script lang="typescript">
1+
<script lang="ts">
22
export let title: string;
33
export let paragraph: string;
44
</script>

src/routes/404.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
<!-- https://firebase.google.com/docs/hosting/full-config#404 -->
2-
3-
<script lang="typescript">
1+
<script lang="ts">
42
import ErrorPage from "./_error.svelte";
53
</script>
64

7-
<ErrorPage status={404} error={{ message: "Not found" }} />
5+
<!-- https://firebase.google.com/docs/hosting/full-config#404 -->
6+
<ErrorPage status={404} error={{ name: "Error", message: 'Not found' }} />

src/routes/_error.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<script lang="typescript">
2-
export let status: number;
3-
export let error: Error;
1+
<script lang="ts">
2+
export let status: number;
3+
export let error: Error;
44
5-
const mode = process.env.NODE_ENV;
6-
const dev = mode === "development";
5+
const mode = process.env.NODE_ENV;
6+
const dev = mode === "development";
77
</script>
88

99
<section class="flex flex-1 flex-col items-center justify-center">
10-
<h1 class="text-red-700 text-2xl">{error.message}</h1>
11-
<h2 class="mt-1 text-red-700 text-lg">{status}</h2>
10+
<h1 class="text-red-700 text-2xl">{error.message}</h1>
11+
<h2 class="mt-1 text-red-700 text-lg">{status}</h2>
1212
</section>
1313

1414
{#if dev && error.stack}
15-
<pre>{error.stack}</pre>
15+
<pre>{error.stack}</pre>
1616
{/if}

src/routes/_layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script lang="typescript">
1+
<script lang="ts">
22
import { stores } from "@sapper/app";
33
44
// You may not want to use `segment`, but it is passed for the time being and will

src/routes/example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Request as ExpressRequest, Response as ExpressResponse } from "express";
1+
import type { Request as ExpressRequest, Response as ExpressResponse } from "express";
22

33
export const get = async (req: ExpressRequest, res: ExpressResponse): Promise<void> => {
44
res.end("you made a get request");

src/routes/index.svelte

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
<script lang="typescript">
2-
import ExampleComponent from "../components/ExampleComponent.svelte";
1+
<script lang="ts">
2+
import ExampleComponent from "../components/ExampleComponent.svelte";
33
</script>
44

55
<style lang="postcss">
6-
.centerer {
7-
@apply flex-1 flex flex-col items-center justify-center;
8-
}
6+
.centerer {
7+
@apply flex-1 flex flex-col items-center justify-center;
8+
}
99
</style>
1010

11-
<div class:centerer={true}> <!-- Here's how you could extract conditional class groups with @apply -->
12-
<ExampleComponent
13-
title="🌐 Opinionated Sapper project base"
14-
paragraph="This is an example route and component to make sure everything's working." />
11+
<div class:centerer={true}>
12+
<!-- Here's how you could extract conditional class groups with @apply -->
13+
<ExampleComponent
14+
title="🌐 Opinionated Sapper project base"
15+
paragraph="This is an example route and component to make sure everything's
16+
working." />
1517

16-
<a
17-
class="mt-10 p-3 rounded-lg shadow-md text-pink-800 bg-pink-200
18-
transition duration-200 ease-in-out hover:bg-pink-300 focus:bg-pink-300
19-
focus:outline-none focus:shadow-outline"
20-
href="/graphql">
21-
Check out the GraphQL playground!
22-
</a>
18+
<a
19+
class="mt-10 p-3 rounded-lg shadow-md text-pink-800 bg-pink-200 transition
20+
duration-200 ease-in-out hover:bg-pink-300 focus:bg-pink-300
21+
focus:outline-none focus:shadow-outline"
22+
href="/graphql">
23+
Check out the GraphQL playground!
24+
</a>
2325
</div>

src/server.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
// @ts-ignore -- generated package
21
import * as sapper from "@sapper/server"; // eslint-disable-line import/no-unresolved
32
import compression from "compression";
43
import express, { Express } from "express";
54
import sirv from "sirv";
65
import { createApolloServer } from "./graphql";
76

87
const PORT = process.env.PORT; // eslint-disable-line prefer-destructuring
9-
// @ts-ignore -- creates a warning after `rollup-plugin-replace` (set up in `rollup.config.js`)
10-
// replaces `process.env.NODE_ENV` with `"production"` during `prod`
11-
const dev = process.env.NODE_ENV === "development";
8+
const mode = process.env.NODE_ENV;
9+
const dev = mode === "development";
1210

1311
const main = require.main === module || require.main?.filename.match(/__sapper__\/build\/index.js$/);
1412

src/service-worker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-restricted-globals,@typescript-eslint/no-explicit-any */
2-
// @ts-ignore -- generated package
32
import { timestamp, files, shell } from "@sapper/service-worker";
43

54
const ASSETS = `cache${timestamp}`;

static/screenshot-1.png

-93 Bytes
Loading

svelte.config.js

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

tsconfig.json

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@
22
"compilerOptions": {
33
"lib": [
44
"DOM",
5-
"ES2016",
5+
"ES2017",
66
"WebWorker"
77
],
8-
"target": "ES2016",
8+
"target": "es2017",
99
"allowSyntheticDefaultImports": true,
10-
"experimentalDecorators": true,
1110
"emitDecoratorMetadata": true,
11+
"experimentalDecorators": true,
12+
"importsNotUsedAsValues": "error",
13+
"isolatedModules": true,
1214
"moduleResolution": "node",
13-
"skipLibCheck": true,
14-
"strict": true
15+
"sourceMap": true,
16+
"strict": true,
17+
"types": [
18+
"svelte",
19+
"@sapper"
20+
],
21+
"typeRoots": [
22+
"types"
23+
],
1524
},
1625
"include": [
1726
"src/**/*",
1827
"src/node_modules/**/*"
1928
],
2029
"exclude": [
21-
"node_modules"
22-
]
30+
"node_modules/*",
31+
"__sapper__/*",
32+
"static/*"
33+
],
2334
}

types/@sapper/index.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Source: https://github.com/sveltejs/sapper/issues/760#issuecomment-504230103
2+
declare module "@sapper/app"
3+
declare module "@sapper/server"
4+
declare module "@sapper/service-worker"
5+
6+
declare module "@sapper/app" {
7+
interface Redirect {
8+
statusCode: number
9+
location: string
10+
}
11+
12+
function goto(href: string, opts: { replaceState: boolean }): Promise<unknown>
13+
function prefetch(href: string): Promise<{ redirect?: Redirect; data?: unknown }>
14+
function prefetchRoutes(pathnames: string[]): Promise<unknown>
15+
function start(opts: { target: Node }): Promise<unknown>
16+
const stores: () => unknown;
17+
18+
export {
19+
goto, prefetch, prefetchRoutes, start, stores,
20+
};
21+
}
22+
23+
declare module "@sapper/server" {
24+
import { RequestHandler } from "express";
25+
26+
interface MiddlewareOptions {
27+
session?: (req: Express.Request, res: Express.Response) => unknown
28+
ignore?: unknown
29+
}
30+
31+
function middleware(opts: MiddlewareOptions): RequestHandler
32+
33+
export { middleware };
34+
}
35+
36+
declare module "@sapper/service-worker" {
37+
const timestamp: number;
38+
const files: string[];
39+
const shell: string[];
40+
const routes: { pattern: RegExp }[];
41+
42+
export {
43+
timestamp, files, files as assets, shell, routes,
44+
};
45+
}

0 commit comments

Comments
 (0)