8000 feat(cloudflare): pin default worker compatibility date to build time… · sam-goodwin/alchemy@100355b · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 100355b

Browse files
authored
feat(cloudflare): pin default worker compatibility date to build time (#460)
1 parent dea9ed1 commit 100355b

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ wrangler.jsonc
1818
!.husky/pre-commit
1919

2020
.smoke
21-
.svelte-kit
21+
.svelte-kit
22+

‎alchemy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
},
1212
"scripts": {
1313
"build:cli": "./scripts/bundle-cli.sh",
14+
"build": "bun ./scripts/generate-build-date.ts && rm -rf ./*.tsbuildinfo && rm -rf ./lib && tsc -b && bun run build:cli",
1415
"dev:cli": "./scripts/bundle-cli.sh --watch",
15-
"build": "rm -rf ./*.tsbuildinfo && rm -rf ./lib && tsc -b && bun run build:cli",
1616
"docs:gen": "rm -rf ./docs && typedoc",
1717
"postbuild": "cpx 'src/**/*/types.d.ts' lib",
1818
"publish:npm": "cp ../README.md . && bun run build && bun run build:cli && npm publish && rm README.md"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bun
2+
3+
/**
4+
* This script generates a TypeScript file containing the build date
5+
* for use as the default worker compatibility date.
6+
*/
7+
8+
import { writeFileSync } from 'node:fs';
9+
import { resolve } from 'node:path';
10+
11+
// Generate today's date in YYYY-MM-DD format
12+
const buildDate = new Date().toISOString().split('T')[0];
13+
14+
// TypeScript content to generate
15+
const content = `// This file is auto-generated during build
16+
// Do not edit manually
17+
18+
/**
19+
* The build date used as the default worker compatibility date.
20+
* This is set to the date when the package was built.
21+
*/
22+
export const BUILD_DATE = "${buildDate}";
23+
`;
24+
25+
// Write to src directory so it gets included in the package
26+
const outputPath = resolve(import.meta.dirname, '..', 'src', 'build-date.ts');
27+
28+
writeFileSync(outputPath, content, 'utf8');
29+
30+
console.log(`Generated build date: ${buildDate}`);
31+
console.log(`Written to: ${outputPath}`);

‎alchemy/src/build-date.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is auto-generated during build
2+
// Do not edit manually
3+
4+
/**
5+
* The build date used as the default worker compatibility date.
6+
* This is set to the date when the package was built.
7+
*/
8+
export const BUILD_DATE = "2025-06-23";

‎alchemy/src/cloudflare/worker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getContentType } from "../util/content-type.ts";
1313
import { logger } from "../util/logger.ts";
1414
import { withExponentialBackoff } from "../util/retry.ts";
1515
import { slugify } from "../util/slugify.ts";
16+
import { BUILD_DATE } from "../build-date.ts";
1617
import { CloudflareApiError, handleApiError } from "./api-error.ts";
1718
import {
1819
type CloudflareApi,
@@ -178,7 +179,7 @@ export interface BaseWorkerProps<
178179

179180
/**
180181
* The compatibility date for the worker
181-
* @default "2025-04-26"
182+
* @default BUILD_DATE - automatically pinned to the package build date
182183
*/
183184
compatibilityDate?: string;
184185

@@ -861,7 +862,7 @@ export function Worker<const B extends Bindings>(
861862
});
862863
}
863864

864-
export const DEFAULT_COMPATIBILITY_DATE = "2025-04-20";
865+
export const DEFAULT_COMPATIBILITY_DATE = BUILD_DATE;
865866

866867
export const _Worker = Resource(
867868
"cloudflare::Worker",

0 commit comments

Comments
 (0)
0