-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support environments in Worker configs (#127)
* Added cloudflare-env playground * Updated wrangler and miniflare dependencies * Updated Workflow playgrounds and tests * Added support for CLOUDFLARE_ENV * Added tests for CLOUDFLARE_ENV * Update playgrounds and compatibility dates * Made compatibility date required * Made required fields non-nullable in types * Use loadEnv to load .env files * Added tests for CLOUDFLARE_ENV in .env.[mode] file * Adding missingFieldErrorMessage function and included Worker environment in error message
- Loading branch information
1 parent
b852a42
commit 917395c
Showing
48 changed files
with
1,519 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.