Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-shrimps-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Add `wrangler types` support for importable env and `process.env`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably this is a minor, but I think it's a fine line. As such, I've made this a patch to test out backporting to v3.

13 changes: 8 additions & 5 deletions packages/wrangler/e2e/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ describe("types", () => {
"utf8"
);
expect(file).toMatchInlineSnapshot(`
"// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: 7fbca0b39560512499078acfe5f450c0)
interface Env {
MY_VAR: "my-var-value";
"// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: 7915eccca244b8d5c107e358ee5929e8)
declare namespace Cloudflare {
interface Env {
MY_VAR: "my-var-value";
}
}
interface Env extends Cloudflare.Env {}
"
`);
});
Expand All @@ -92,7 +95,7 @@ describe("types", () => {
).split("\n");

expect(lines[0]).toMatchInlineSnapshot(
`"// Generated by Wrangler by running \`wrangler types ./types.d.ts\` (hash: 7fbca0b39560512499078acfe5f450c0)"`
`"// Generated by Wrangler by running \`wrangler types ./types.d.ts\` (hash: 7915eccca244b8d5c107e358ee5929e8)"`
);
expect(lines[1]).match(
/\/\/ Runtime types generated with workerd@1\.\d{8}\.\d \d{4}-\d{2}-\d{2} ([a-z_]+,?)*/
Expand All @@ -119,7 +122,7 @@ describe("types", () => {
).split("\n");

expect(lines[0]).toMatchInlineSnapshot(
`"// Generated by Wrangler by running \`wrangler types -c wranglerA.toml --env-interface MyCloudflareEnv ./cflare-env.d.ts\` (hash: 8fcf1ed67a52a2d34d6d34c3068e89b8)"`
`"// Generated by Wrangler by running \`wrangler types -c wranglerA.toml --env-interface MyCloudflareEnv ./cflare-env.d.ts\` (hash: 2f74a5a99f09ae4d994228b5bb959d24)"`
);
expect(lines[1]).match(
/\/\/ Runtime types generated with workerd@1\.\d{8}\.\d \d{4}-\d{2}-\d{2} ([a-z_]+,?)*/
Expand Down
82 changes: 82 additions & 0 deletions packages/wrangler/src/__tests__/process-env-populated.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import assert from "node:assert";
import { isProcessEnvPopulated } from "../process-env";

describe("isProcessEnvPopulated", () => {
test("default", () => {
expect(isProcessEnvPopulated(undefined, ["nodejs_compat"])).toBe(false);
});

test("future date", () => {
expect(isProcessEnvPopulated("2026-01-01", ["nodejs_compat"])).toBe(true);
});

test("old date", () => {
expect(isProcessEnvPopulated("2000-01-01", ["nodejs_compat"])).toBe(false);
});

test("switch date", () => {
expect(isProcessEnvPopulated("2025-04-01", ["nodejs_compat"])).toBe(true);
});

test("old date, but with flag", () => {
expect(
isProcessEnvPopulated("2000-01-01", [
"nodejs_compat",
"nodejs_compat_populate_process_env",
])
).toBe(true);
});

test("old date, with disable flag", () => {
expect(
isProcessEnvPopulated("2000-01-01", [
"nodejs_compat",
"nodejs_compat_do_not_populate_process_env",
])
).toBe(false);
});

test("future date, but with disable flag", () => {
expect(
isProcessEnvPopulated("2026-01-01", [
"nodejs_compat",
"nodejs_compat_do_not_populate_process_env",
])
).toBe(false);
});

test("future date, with enable flag", () => {
expect(
isProcessEnvPopulated("2026-01-01", [
"nodejs_compat",
"nodejs_compat_populate_process_env",
])
).toBe(true);
});

test("future date without nodejs_compat", () => {
expect(isProcessEnvPopulated("2026-01-01")).toBe(false);
});

test("future date, with enable flag but without nodejs_compat", () => {
expect(
isProcessEnvPopulated("2026-01-01", [
"nodejs_compat_populate_process_env",
])
).toBe(false);
});

test("errors with disable and enable flags specified", () => {
try {
isProcessEnvPopulated("2024-01-01", [
"nodejs_compat_populate_process_env",
"nodejs_compat_do_not_populate_process_env",
]);
assert(false, "Unreachable");
} catch (e) {
expect(e).toMatchInlineSnapshot(
`[Error: Can't both enable and disable a flag]`
);
}
});
});
Loading
Loading