Skip to content

Commit 30f1b91

Browse files
authored
Merge pull request #20 from fastly/kats/built-in-typescript
Update starter kit to use built-in TypeScript.
2 parents 7f0ba1c + acbe361 commit 30f1b91

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22

33
[![Deploy to Fastly](https://deploy.edgecompute.app/button)](https://deploy.edgecompute.app/deploy)
44

5-
Get to know the Fastly Compute environment with a basic starter that demonstrates routing, simple synthetic responses and code comments that cover common patterns.
5+
Get to know the Fastly Compute environment with a basic starter in TypeScript that demonstrates routing, simple synthetic responses and code comments that cover common patterns.
66

77
**For more details about other starter kits for Compute, see the [Fastly Documentation Hub](https://www.fastly.com/documentation/solutions/starters)**
88

99
## Features
10+
* TypeScript source files
11+
* `tsconfig.json` file to use as a starting point
1012
* Allow only requests with particular HTTP methods
1113
* Match request URL path and methods for routing
1214
* Build synthetic responses at the edge
1315

1416
## Understanding the code
1517

16-
This starter is intentionally lightweight, and requires no dependencies aside from the [`@fastly/js-compute`](https://www.npmjs.com/package/@fastly/js-compute) npm package. It will help you understand the basics of processing requests at the edge using Fastly. This starter includes implementations of common patterns explained in our [using Compute](https://www.fastly.com/documentation/guides/compute/javascript/) and [VCL migration](https://www.fastly.com/documentation/guides/compute/migrate/) guides.
18+
This starter kit is written in TypeScript and illustrates the same features as the [Compute JavaScript default starter kit](https://github.com/fastly/compute-starter-kit-typescript-default). It is intentionally lightweight, and requires no dependencies aside from the [`@fastly/js-compute`](https://www.npmjs.com/package/@fastly/js-compute) npm package. It will help you understand the basics of processing requests at the edge using Fastly. This starter includes implementations of common patterns explained in our [using Compute](https://www.fastly.com/documentation/guides/compute/javascript/) and [VCL migration](https://www.fastly.com/documentation/guides/compute/migrate/) guides. The starter doesn't require the use of any backends. Once deployed, you will have a Fastly service running on Compute that can generate synthetic responses at the edge.
1719

18-
The starter doesn't require the use of any backends. Once deployed, you will have a Fastly service running on Compute that can generate synthetic responses at the edge.
20+
The Compute JavaScript SDK [has built-in support](https://www.fastly.com/documentation/guides/compute/developer-guides/javascript/#built-in-typescript) for executing TypeScript source files that contain only erasable TypeScript syntax. In this mode, type checking is not performed.
1921

20-
The template uses TypeScript to compile source files in `./src` into JS files in `./build`, which are then wrapped into `./bin/index.wasm` using the `js-compute-runtime` CLI tool bundled with the `@fastly/js-compute` npm package, and bundled into a `.tar.gz` file ready for deployment to Compute.
22+
The SDK does not directly refer to the `tsconfig.json` file, but one is included to aid your IDE in coding support as well as to illustrate the recommended practice of running `tsc --noEmit` in a `prebuild` script to check for TypeScript errors, since the SDK does not perform type checking.
2123

2224
## Running the application
2325

fastly.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://developer.fastly.com/reference/fastly-toml/
33

44
authors = ["<[email protected]>"]
5-
description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules."
5+
description = "A basic TypeScript starter kit that demonstrates routing, simple synthetic responses and overriding caching rules."
66
language = "javascript"
77
manifest_version = 3
88
name = "Default starter for TypeScript"

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"@fastly/js-compute": "^3.33.2"
66
},
77
"devDependencies": {
8-
"@fastly/cli": "^11.0.0",
8+
"@fastly/cli": "^12.0.0",
99
"typescript": "^5.2.2"
1010
},
1111
"scripts": {
12-
"prebuild": "tsc",
13-
"build": "js-compute-runtime build/index.js bin/main.wasm",
12+
"prebuild": "tsc --noEmit",
13+
"build": "js-compute-runtime src/index.ts bin/main.wasm",
1414
"start": "fastly compute serve",
1515
"deploy": "fastly compute publish"
1616
}

tsconfig.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
{
22
"compilerOptions": {
33
"strict": true,
4-
"module": "ES2022",
4+
"erasableSyntaxOnly": true,
5+
"skipLibCheck": true,
56
"target": "ES2022",
7+
"lib": [ "ES2022" ],
8+
"module": "ESNext",
69
"moduleResolution": "bundler",
710
"customConditions": [ "fastly" ],
11+
"types": [ "@fastly/js-compute" ],
812
"esModuleInterop": true,
9-
"lib": [ "ES2022" ],
10-
"rootDir": "src",
11-
"outDir": "build"
12-
},
13-
"include": [
14-
"./src/**/*.js",
15-
"./src/**/*.ts",
16-
],
17-
"exclude": [
18-
"node_modules"
19-
]
13+
"isolatedModules": true,
14+
"verbatimModuleSyntax": true,
15+
"allowImportingTsExtensions": true
16+
}
2017
}

0 commit comments

Comments
 (0)