Skip to content

Commit

Permalink
chore: switch to wrangler v3 (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Aug 31, 2024
1 parent ead1488 commit e66e28e
Show file tree
Hide file tree
Showing 7 changed files with 613 additions and 948 deletions.
1 change: 1 addition & 0 deletions .github/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "commonjs"}
6 changes: 2 additions & 4 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ jobs:
- name: Check TypeScript code
run: yarn check

- name: Compile TypeScript code
run: yarn build

- name: Run linter
run: yarn run lint

Expand Down Expand Up @@ -90,10 +87,11 @@ jobs:
run: yarn build:index

- name: Publish to Cloudflare
uses: cloudflare/wrangler-action@2.0.0
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
packageManager: yarn

- name: Upload config files to Cloudflare
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ node_modules/
.env
.dev.vars
keys.txt
.mf
.mf/
.wrangler/
test_requests

# Auto-generated firmware index
Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
"author": "Dominic Griesel <[email protected]>",
"license": "MIT",
"type": "module",
"module": "build/worker.js",
"scripts": {
"check": "tsc -p tsconfig.build.json --noEmit && tsc -p src/maintenance/tsconfig.json --noEmit",
"build": "esbuild --bundle --format=esm --platform=browser --sourcemap --outdir=build src/worker.ts",
"clean": "rm -rf build",
"lint": "eslint .",
"test:ci": "NODE_OPTIONS='--loader=tsx' ava",
"test": "yarn test:ci --watch",
"dev": "miniflare",
"test": "yarn test:ci",
"dev": "wrangler dev",
"build:index": "yarn tsx src/maintenance/generateIndex.ts",
"upload": "yarn tsx src/maintenance/upload.ts"
},
Expand All @@ -31,7 +28,7 @@
"devDependencies": {
"@actions/core": "^1.9.1",
"@actions/github": "^5.0.3",
"@cloudflare/workers-types": "^3.18.0",
"@cloudflare/workers-types": "^4.20240821.1",
"@tsconfig/node16": "^1.0.3",
"@types/eslint": "^8.4.6",
"@types/itty-router-extras": "^0.4.0",
Expand All @@ -51,12 +48,11 @@
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"miniflare": "~2.11.0",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.1.1",
"tsx": "^3.13.0",
"typescript": "~4.7.4",
"wrangler": "^2.1.4",
"wrangler": "^3.73.0",
"zod-to-json-schema": "^3.17.1"
},
"packageManager": "[email protected]"
Expand Down
29 changes: 13 additions & 16 deletions src/app.route1.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import test from "ava";
import { Miniflare } from "miniflare";
import { UnstableDevWorker, unstable_dev } from "wrangler";

test.beforeEach((t) => {
// Create a new Miniflare environment for each test
const mf = new Miniflare({
// Autoload configuration from `.env`, `package.json` and `wrangler.toml`
envPath: true,
packagePath: true,
wranglerConfigPath: true,
// We don't want to rebuild our worker for each test, we're already doing
// it once before we run all tests in package.json, so disable it here.
// This will override the option in wrangler.toml.
buildCommand: undefined,
test.before(async (t) => {
const worker = await unstable_dev("src/worker.ts", {
experimental: { disableExperimentalWarning: true },
});
t.context = { mf };
t.context = { worker };
});

test.after.always(async (t) => {
const { worker } = t.context as any;
await worker.stop();
});

test("GET `/` route", async (t) => {
process.env.API_REQUIRE_KEY = "false";

// Get the Miniflare instance
const mf = (t.context as any).mf as Miniflare;
// Get the worker instance
const worker = (t.context as any).worker as UnstableDevWorker;
// Dispatch a fetch event to our worker
const res = await mf.dispatchFetch("http://localhost:8787/");
const res = await worker.fetch("/");

t.is(res.status, 200);
t.is(res.headers.get("content-type"), "text/html");
Expand Down
28 changes: 1 addition & 27 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
name = "zwave-js-firmware-updates"
usage_model = "bundled"
# workers_dev = true
main = "./src/worker.ts"
compatibility_date = "2022-08-28"

# node_compat = true

main = "build/worker.js"

kv_namespaces = [
# { binding = "R2_CACHE", id = "a14d0c5671564efda1e3db0e2f98da60" },
{ binding = "API_KEYS", id = "7edd033eda014a5ebdd02aed07f31063" }
]

[build]
command = "yarn build"
watch_dir = "src"

[[migrations]]
tag = "v1" # Should be unique for each entry
new_classes = ["RateLimiterDurableObject"]
Expand All @@ -28,20 +19,3 @@ bindings = [
[[r2_buckets]]
binding = "CONFIG_FILES"
bucket_name = "zwave-js-firmware-updates--config-files"

# ------------------------------------------------------------------------------

# Required for Miniflare:
[build.upload]
format = "modules"

[miniflare]
port = 8787
watch = true

cache_persist = true
env_path = ".env"

# kv_persist = true
durable_objects_persist = true
r2_persist = true
Loading

0 comments on commit e66e28e

Please sign in to comment.