From 4d3083764a832d6f2175299b91a990ba48a46d82 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:23:32 -0800 Subject: [PATCH] change cron discovery to use regex --- apps/cron/20260201-000000/lib/discovery.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/cron/20260201-000000/lib/discovery.ts b/apps/cron/20260201-000000/lib/discovery.ts index 6eb69a4..3cb268f 100644 --- a/apps/cron/20260201-000000/lib/discovery.ts +++ b/apps/cron/20260201-000000/lib/discovery.ts @@ -1,10 +1,12 @@ -import { readdir } from 'fs/promises' +import { readdir, readFile } from 'fs/promises' import { existsSync } from 'fs' import { join } from 'path' import { isValidSchedule, toCronExpr, type CronJob, type Schedule } from './schedules' const APPS_DIR = process.env.APPS_DIR! +const SCHEDULE_RE = /export\s+const\s+schedule\s*=\s*['"]([^'"]+)['"]/ + export async function getApps(): Promise { const entries = await readdir(APPS_DIR, { withFileTypes: true }) const apps: string[] = [] @@ -38,8 +40,15 @@ export async function discoverCronJobs(): Promise { const name = file.replace(/\.ts$/, '') try { - const mod = await import(filePath) - const schedule = mod.schedule as Schedule + const source = await readFile(filePath, 'utf-8') + const match = source.match(SCHEDULE_RE) + + if (!match) { + console.error(`No schedule export found in ${filePath}`) + continue + } + + const schedule = match[1] as Schedule if (!isValidSchedule(schedule)) { console.error(`Invalid schedule in ${filePath}: ${schedule}`)