From 78c4f3dc616472c0f796890e2a8198781fa82f47 Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Sat, 26 Nov 2022 16:47:31 +0100 Subject: [PATCH] chore: update wrangler version --- .github/workflows/development.yml | 2 ++ package.json | 12 ++++++------ scripts/build.mjs | 7 ++----- tests/setup.ts | 5 +++-- worker/adapter.ts | 3 --- wrangler.toml | 17 ++--------------- 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index b2445f2..e9b5978 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -60,6 +60,8 @@ jobs: uses: bahmutov/npm-install@v1 with: useLockFile: false + - name: 📦 Build the worker + run: npm run build - name: 🔥 Publish run: npx wrangler publish env: diff --git a/package.json b/package.json index 7b91779..3491e3c 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ { "private": true, "name": "remix-worker-template", - "main": "./dist/worker.mjs", "description": "All-in-one remix starter template for Cloudflare Workers", + "module": "./dist/worker.mjs", "scripts": { "cleanup": "rimraf .cache ./dist ./build ./public/build ./app/styles/tailwind.css", "build:remix": "remix build", "build:style": "cross-env NODE_ENV=production tailwindcss -o ./app/styles/tailwind.css --minify", - "build:worker": "cross-env NODE_ENV=production VERSION=$(git rev-parse --short HEAD) node ./scripts/build.mjs", + "build:worker": "cross-env NODE_ENV=production node ./scripts/build.mjs", "build": "npm run build:style && npm run build:remix && npm run build:worker", - "dev:miniflare": "miniflare --build-command \"node ./scripts/build.mjs\" --build-watch-path ./worker --build-watch-path ./build/index.js --no-cache --watch --open", + "dev:miniflare": "miniflare --modules --build-command \"node ./scripts/build.mjs\" --build-watch-path ./worker --build-watch-path ./build/index.js --no-cache --watch --open", "dev:remix": "remix watch", "dev:style": "tailwindcss -o ./app/styles/tailwind.css --watch", "dev": "concurrently \"npm:dev:*\"", "prebuild": "npm run cleanup", "test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" playwright test", - "start": "miniflare", + "start": "miniflare --modules", "prepare": "husky install" }, "dependencies": { @@ -28,7 +28,6 @@ }, "devDependencies": { "@cloudflare/workers-types": "^3.18.0", - "@cloudflare/wrangler": "^1.20.0", "@playwright/test": "^1.28.1", "@remix-run/dev": "*", "@remix-run/eslint-config": "*", @@ -45,7 +44,8 @@ "prettier": "^2.8.0", "rimraf": "^3.0.2", "tailwindcss": "^3.2.4", - "typescript": "^4.9.3" + "typescript": "^4.9.3", + "wrangler": "^2.4.4" }, "engines": { "node": ">=16.7" diff --git a/scripts/build.mjs b/scripts/build.mjs index ca088a4..b146989 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -3,10 +3,8 @@ import * as esbuild from 'esbuild'; async function build() { // eslint-disable-next-line no-undef const mode = process.env.NODE_ENV?.toLowerCase() ?? 'development'; - // eslint-disable-next-line no-undef - const version = process.env.VERSION ?? new Date().toISOString(); - console.log(`Building Worker in ${mode} mode for version ${version}`); + console.log(`Building Worker in ${mode} mode`); const outfile = './dist/worker.mjs'; const startTime = Date.now(); @@ -20,8 +18,7 @@ async function build() { external: ['__STATIC_CONTENT_MANIFEST'], define: { 'process.env.NODE_ENV': `"${mode}"`, - 'process.env.VERSION': `"${version}"`, - 'process.env.REMIX_DEV_SERVER_WS_PORT': `""`, + 'process.env.REMIX_DEV_SERVER_WS_PORT': `"8002"`, }, outfile, }); diff --git a/tests/setup.ts b/tests/setup.ts index f581c22..842b295 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -1,6 +1,7 @@ import { test as base, expect } from '@playwright/test'; import { Miniflare } from 'miniflare'; import { MockAgent, setGlobalDispatcher } from 'undici'; +import packageJson from '../package.json'; interface TestFixtures { mockAgent: MockAgent; @@ -46,9 +47,9 @@ export const test = base.extend({ mf: [ async ({ port }, use) => { const mf = new Miniflare({ + scriptPath: packageJson.module, + modules: true, wranglerConfigPath: true, - buildCommand: undefined, - bindings: {}, port, }); diff --git a/worker/adapter.ts b/worker/adapter.ts index 788892b..6777a82 100644 --- a/worker/adapter.ts +++ b/worker/adapter.ts @@ -1,8 +1,5 @@ -// Required for custom adapters import type { AppLoadContext } from '@remix-run/cloudflare'; import { createRequestHandler as createRemixRequestHandler } from '@remix-run/cloudflare'; - -// Required only for Worker Site import { getAssetFromKV, MethodNotAllowedError, diff --git a/wrangler.toml b/wrangler.toml index c3a9c8c..7ebe8ae 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,21 +1,8 @@ name = "template" -type = "javascript" -workers_dev = true -# account_id = "Or specified with process.env.CF_ACCOUNT_ID" -# zone_id = "Or specified with process.env.CF_ZONE_ID" +main = "./dist/worker.mjs" # route = "example.com/*" compatibility_date = "2022-11-25" compatibility_flags = ["streams_enable_constructors"] [site] -bucket = "./public" -entry-point = "." - -[build] -command = "npm run build" -watch_dir = "./build/index.js" - -[build.upload] -format = "modules" -dir = "./dist" -main = "./worker.mjs" +bucket = "./public" \ No newline at end of file