Skip to content

Commit a9c5da3

Browse files
jorgemoyaclaude
andcommitted
LTRAC-873: fix(cli) - Derive Wrangler compatibility_date dynamically (#3045)
The build pinned compatibility_date to 2025-09-15 while the deployment service stamps a current date at deploy time, so workers ran under newer Cloudflare runtime semantics than they were built against. Compute the date as current UTC date minus one month, matching the same offset the deployment service applies, so build and deploy semantics stay aligned. Refs LTRAC-873 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0844861 commit a9c5da3

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst": patch
3+
---
4+
5+
`catalyst build` now derives the Cloudflare Workers `compatibility_date` dynamically (current date minus one month) instead of using a pinned date, keeping the build-time runtime semantics aligned with what the deployment service applies at deploy time.

packages/catalyst/src/cli/lib/wrangler-config.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from 'vitest';
22

3-
import { getWranglerConfig } from './wrangler-config';
3+
import { getCompatibilityDate, getWranglerConfig } from './wrangler-config';
44

55
test('returns a config with name identical to worker self reference service', () => {
66
const config = getWranglerConfig('uuid');
@@ -10,3 +10,17 @@ test('returns a config with name identical to worker self reference service', ()
1010
config.services.find((service) => service.binding === 'WORKER_SELF_REFERENCE')?.service,
1111
).toBe(`project-uuid`);
1212
});
13+
14+
test('compatibility date is one month before the given date', () => {
15+
expect(getCompatibilityDate(new Date('2026-06-11T15:00:00Z'))).toBe('2026-05-11');
16+
});
17+
18+
test('compatibility date handles month-end normalization', () => {
19+
// May 31 minus one month lands in early May (no April 31), still a valid date.
20+
expect(getCompatibilityDate(new Date('2026-05-31T12:00:00Z'))).toBe('2026-05-01');
21+
expect(getCompatibilityDate(new Date('2026-01-15T00:00:00Z'))).toBe('2025-12-15');
22+
});
23+
24+
test('config uses a YYYY-MM-DD compatibility date', () => {
25+
expect(getWranglerConfig('uuid').compatibility_date).toMatch(/^\d{4}-\d{2}-\d{2}$/u);
26+
});

packages/catalyst/src/cli/lib/wrangler-config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
// The compatibility date, compatibility flags, Durable Object classes, and
2+
// migration tag below are mirrored in Ignition, which builds its own Worker
3+
// metadata at deploy time (pkg/cloudflare/upload/metadata.go and
4+
// pkg/cloudflare/upload/migrations/migrations.go). Keep both sides in sync
5+
// when changing any of them.
6+
export function getCompatibilityDate(now = new Date()): string {
7+
const date = new Date(now);
8+
9+
// One month behind the current date: recent enough to track Cloudflare
10+
// runtime behavior (per Cloudflare guidance), buffered enough to avoid
11+
// brand-new compatibility-date-gated changes. Ignition applies the same
12+
// offset at deploy time, so the bundle is never built against newer
13+
// semantics than it runs under.
14+
date.setUTCMonth(date.getUTCMonth() - 1);
15+
16+
return date.toISOString().slice(0, 10);
17+
}
18+
119
export function getWranglerConfig(projectUuid: string) {
220
return {
321
$schema: 'node_modules/wrangler/config-schema.json',
422
main: '../.open-next/worker.js',
523
name: `project-${projectUuid}`,
6-
compatibility_date: '2025-09-15',
24+
compatibility_date: getCompatibilityDate(),
725
compatibility_flags: ['nodejs_compat', 'global_fetch_strictly_public'],
826
observability: {
927
enabled: true,

0 commit comments

Comments
 (0)