Skip to content

Commit d74a44f

Browse files
Service worker in TypeScript with versioning
1 parent 7075a41 commit d74a44f

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build:
88

99
dist: build
1010
mkdir -p $(BUILD)/build
11-
cp -r $(SRC)/*.html $(SRC)/term.js src/examples $(SRC)/sw.js $(BUILD)
11+
cp -r $(SRC)/*.html $(SRC)/term.js src/examples $(SRC)/build/sw.js $(BUILD)
1212
cp $(SRC)/build/firmware.js $(SRC)/build/simulator.js $(SRC)/build/firmware.wasm $(BUILD)/build/
1313

1414
watch: dist

src/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ $(BUILD)/micropython.js: $(OBJ) jshal.js simulator-js
147147

148148
simulator-js:
149149
npx esbuild ./simulator.ts --bundle --outfile=$(BUILD)/simulator.js --loader:.svg=text
150+
npx esbuild --define:process.env.version=$$(cat ../package.json | jq .version) ./sw.ts --bundle --outfile=$(BUILD)/sw.js
150151

151152
include $(TOP)/py/mkrules.mk
152153

src/sw.js renamed to src/sw.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
const version = "v0.0.3";
1+
/// <reference lib="WebWorker" />
2+
// Empty export required due to --isolatedModules flag in tsconfig.json
3+
export type {};
4+
declare const self: ServiceWorkerGlobalScope;
5+
declare const clients: Clients;
6+
27
const assets = ["simulator.html", "build/simulator.js", "build/firmware.js"];
3-
const cacheName = `simulator-${version}`;
8+
const cacheName = `simulator-${process.env.version}`;
49

510
self.addEventListener("install", (event) => {
611
console.log("Installing simulator service worker...");

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es2019",
4-
"lib": ["dom", "dom.iterable", "esnext"],
4+
"lib": ["dom", "dom.iterable", "esnext", "WebWorker"],
55
"allowJs": true,
66
"skipLibCheck": true,
77
"esModuleInterop": true,

0 commit comments

Comments
 (0)