From 03b74c0d4350e3c0d7923f1c34b5a200c8d31544 Mon Sep 17 00:00:00 2001 From: Kentaro Suzuki Date: Tue, 23 Apr 2024 16:35:02 +0900 Subject: [PATCH] feat/tsconfig workers (#74) * feat: add cloudflare workers preset * refactor: extend `cloudflare-workers` preset in hono * chore: changeset --- .changeset/metal-berries-boil.md | 5 ++++ packages/tsconfig/README.md | 31 ++++++++++++++++++----- packages/tsconfig/cloudflare-workers.json | 12 +++++++++ packages/tsconfig/hono.json | 9 ++----- packages/tsconfig/package.json | 8 ++++++ 5 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 .changeset/metal-berries-boil.md create mode 100644 packages/tsconfig/cloudflare-workers.json diff --git a/.changeset/metal-berries-boil.md b/.changeset/metal-berries-boil.md new file mode 100644 index 0000000..e748697 --- /dev/null +++ b/.changeset/metal-berries-boil.md @@ -0,0 +1,5 @@ +--- +"@virtual-live-lab/tsconfig": patch +--- + +Add Cloudflare Workers preset diff --git a/packages/tsconfig/README.md b/packages/tsconfig/README.md index c573270..dc2e1c4 100644 --- a/packages/tsconfig/README.md +++ b/packages/tsconfig/README.md @@ -9,7 +9,8 @@ TypeScript configuration for Virtual Live Lab. - `astro`: Configuration for Astro. - `base`: Basic configuration. -- `hono`: Configuration for Hono. +- `cloudflare-workers`: Configuration for Cloudflare Workers. +- `hono`: Configuration for Hono. Automatically extends `cloudflare-workers`. - `library`: Configuration for library. - `nextjs`: Configuration for Next.js. - `react`: Configuration for React. @@ -22,10 +23,10 @@ TypeScript configuration for Virtual Live Lab. ## Installation ```bash -npm install @virtual-live-lab/tsconfig --save-dev +npm install typescript @virtual-live-lab/tsconfig --save-dev ``` -### Use presets except Astro +### Use Normal presets ```json // tsconfig.json @@ -38,11 +39,11 @@ npm install @virtual-live-lab/tsconfig --save-dev ### Use Astro preset +> [!TIP] +> TypeScript Plugin is required to worker properly outside of VSCode. + ```bash -npm install prettier \ - @virtual-live-lab/tsconfig \ - typescript \ - @astrojs/ts-plugin \ +npm install @astrojs/ts-plugin \ --save-dev ``` @@ -55,6 +56,22 @@ npm install prettier \ } ``` +### Use Cloudflare Workers preset + +```bash +npm install @cloudflare/workers-types \ + --save-dev +``` + +```json +// tsconfig.json +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@virtual-live-lab/tsconfig/cloudflare-workers", + // your configuration +} +``` + ## License [MIT](https://choosealicense.com/licenses/mit/) diff --git a/packages/tsconfig/cloudflare-workers.json b/packages/tsconfig/cloudflare-workers.json new file mode 100644 index 0000000..3646c28 --- /dev/null +++ b/packages/tsconfig/cloudflare-workers.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "display": "Cloudflare Workers", + "extends": "./base.json", + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Bundler", + "lib": ["ESNext"], + "types": ["@cloudflare/workers-types"] + } +} diff --git a/packages/tsconfig/hono.json b/packages/tsconfig/hono.json index 130a8d5..1c5b779 100644 --- a/packages/tsconfig/hono.json +++ b/packages/tsconfig/hono.json @@ -1,14 +1,9 @@ { "$schema": "https://json.schemastore.org/tsconfig", "display": "Hono", - "extends": "./base.json", + "extends": "./cloudflare-workers.json", "compilerOptions": { - "target": "ESNext", - "module": "ESNext", - "moduleResolution": "Bundler", "jsx": "react-jsx", - "jsxImportSource": "hono/jsx", - "lib": ["ESNext"], - "types": ["@cloudflare/workers-types"] + "jsxImportSource": "hono/jsx" } } diff --git a/packages/tsconfig/package.json b/packages/tsconfig/package.json index f24e076..cc55e4c 100644 --- a/packages/tsconfig/package.json +++ b/packages/tsconfig/package.json @@ -5,6 +5,14 @@ "files": [ "*.json" ], + "peerDependencies": { + "@cloudflare/workers-types": "^4.20240419.0" + }, + "peerDependenciesMeta": { + "@cloudflare/workers-types": { + "optional": true + } + }, "devDependencies": { "@cloudflare/workers-types": "^4.20240419.0" },