Skip to content

Commit 0c4098b

Browse files
314systemsCopilot
andcommitted
refactor: improve date extraction logic in getLatestCompatDate function
Co-authored-by: Copilot <[email protected]>
1 parent 48ba2c0 commit 0c4098b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

packages/cloudflare/src/cli/utils/create-wrangler-config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ async function getLatestCompatDate(): Promise<string | undefined> {
128128
// The format of the workerd version is `major.yyyymmdd.patch`.
129129
const match = latestWorkerdVersion.match(/\d+\.(\d{4})(\d{2})(\d{2})\.\d+/);
130130

131-
if (match) {
132-
const [, year, month, day] = match;
133-
const compatDate = `${year}-${month}-${day}`;
131+
if (!match) {
132+
return undefined;
133+
}
134+
const [, year, month, day] = match;
135+
if (!year || !month || !day) {
136+
return undefined;
137+
}
138+
const compatDate = `${year}-${month}-${day}`;
134139

135-
const currentDate = new Date().toISOString().slice(0, 10);
140+
const currentDate = new Date().toISOString().slice(0, 10);
136141

137-
return compatDate < currentDate ? compatDate : currentDate;
138-
}
142+
return compatDate < currentDate ? compatDate : currentDate;
139143
} catch {
140144
/* empty */
141145
}

0 commit comments

Comments
 (0)