Skip to content

Commit

Permalink
Service worker in TypeScript with versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Apr 30, 2024
1 parent 7075a41 commit d74a44f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build:

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

watch: dist
Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ $(BUILD)/micropython.js: $(OBJ) jshal.js simulator-js

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

include $(TOP)/py/mkrules.mk

Expand Down
9 changes: 7 additions & 2 deletions src/sw.js → src/sw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const version = "v0.0.3";
/// <reference lib="WebWorker" />
// Empty export required due to --isolatedModules flag in tsconfig.json
export type {};
declare const self: ServiceWorkerGlobalScope;
declare const clients: Clients;

const assets = ["simulator.html", "build/simulator.js", "build/firmware.js"];
const cacheName = `simulator-${version}`;
const cacheName = `simulator-${process.env.version}`;

self.addEventListener("install", (event) => {
console.log("Installing simulator service worker...");
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2019",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": ["dom", "dom.iterable", "esnext", "WebWorker"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand Down

0 comments on commit d74a44f

Please sign in to comment.