This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Support environments in Worker configs #127
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8980062
Added cloudflare-env playground
jamesopstad 47bbfe7
Updated wrangler and miniflare dependencies
jamesopstad 840a4a1
Updated Workflow playgrounds and tests
jamesopstad 844eec3
Added support for CLOUDFLARE_ENV
jamesopstad 037c3fd
Added tests for CLOUDFLARE_ENV
jamesopstad 4817773
Update playgrounds and compatibility dates
jamesopstad 22c3cf0
Made compatibility date required
jamesopstad f25aea0
Made required fields non-nullable in types
jamesopstad cb16c2c
Added missing playground commands
jamesopstad bc7dfad
Added missing file to tsconfig
jamesopstad 4a7b253
Updated plugin config types
jamesopstad 62f0fee
Use loadEnv to load .env files
jamesopstad e75c6fc
Added tests for CLOUDFLARE_ENV in .env.[mode] file
jamesopstad ee954ed
Used inheritance rather than union
jamesopstad 8b35fbf
Fixed lock file
jamesopstad d2eada9
Removed cloudflare-env custom-env test
jamesopstad fbe0fb3
Adding missingFieldErrorMessage function and included Worker environm…
jamesopstad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/vite-plugin-cloudflare/src/__tests__/fixtures/simple-wrangler.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| name = "my-worker" | ||
| main = "./index.ts" | ||
| compatibility_date = "2024-09-09" | ||
| compatibility_date = "2024-12-30" |
2 changes: 1 addition & 1 deletion
2
packages/vite-plugin-cloudflare/src/__tests__/fixtures/wrangler-with-fields-to-ignore.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CLOUDFLARE_ENV=custom-env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { expect, test } from 'vitest'; | ||
| import { getTextResponse } from '../../__test-utils__'; | ||
|
|
||
| test('returns the correct top-level var when CLOUDFLARE_ENV is undefined', async () => { | ||
| expect(await getTextResponse()).toEqual('Top level var'); | ||
| }); |
6 changes: 6 additions & 0 deletions
6
playground/cloudflare-env/__tests__/custom-mode/cloudflare-env.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { expect, test } from 'vitest'; | ||
| import { getTextResponse } from '../../../__test-utils__'; | ||
|
|
||
| test('returns the correct var when CLOUDFLARE_ENV is provided in a .env.[mode] file', async () => { | ||
| expect(await getTextResponse()).toEqual('Custom env var'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "@playground/cloudflare-env", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "vite build --app", | ||
| "build:custom-mode": "vite build --app -c vite.config.custom-mode.ts", | ||
| "check:types": "tsc --build", | ||
| "dev": "vite dev", | ||
| "dev:custom-mode": "vite dev -c vite.config.custom-mode.ts", | ||
| "preview": "vite preview", | ||
| "preview:custom-mode": "vite preview -c vite.config.custom-mode.ts" | ||
| }, | ||
| "devDependencies": { | ||
| "@cloudflare/workers-types": "catalog:default", | ||
| "@flarelabs-net/vite-plugin-cloudflare": "workspace:*", | ||
| "@vite-plugin-cloudflare/typescript-config": "workspace:*", | ||
| "typescript": "catalog:default", | ||
| "vite": "catalog:default", | ||
| "wrangler": "catalog:default" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| interface Env { | ||
| MY_VAR: string; | ||
| } | ||
|
|
||
| export default { | ||
| async fetch(request, env) { | ||
| return new Response(env.MY_VAR); | ||
| }, | ||
| } satisfies ExportedHandler<Env>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "files": [], | ||
| "references": [ | ||
| { "path": "./tsconfig.node.json" }, | ||
| { "path": "./tsconfig.worker.json" } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": ["@vite-plugin-cloudflare/typescript-config/base.json"], | ||
| "include": ["vite.config.ts", "vite.config.custom-mode.ts", "__tests__"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": ["@vite-plugin-cloudflare/typescript-config/worker.json"], | ||
| "include": ["src"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { cloudflare } from '@flarelabs-net/vite-plugin-cloudflare'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| mode: 'custom-mode', | ||
| plugins: [cloudflare({ persistState: false })], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { cloudflare } from '@flarelabs-net/vite-plugin-cloudflare'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [cloudflare({ persistState: false })], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| name = "worker" | ||
| main = "./src/index.ts" | ||
| compatibility_date = "2024-12-30" | ||
|
|
||
| vars = { MY_VAR = "Top level var" } | ||
|
|
||
| [env.custom-env] | ||
| vars = { MY_VAR = "Custom env var" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.