4// esbuild emits `await init_X()` inside non-async __esm factories when a TLA-containing circular 5// dep enters the graph — bundle then crashes at boot with "SyntaxError: Unexpected reserved word". 6// Fast-fail at build time instead of shipping a broken bundle. 7export const guardBundleValidAwait = ({bundleAbsPath}: {bundleAbsPath: string}) => { 8 const lines = fs.readFileSync(bundleAbsPath, 'utf8').split('\n') 9 const bad: string[] = [] 10 let curFactory: string | null = null, curSync = false 11 for (const line of lines) { 12 const m = line.match(/^ (async )?"([^"]+)"\(\) \{/) 17 if (curSync && /^ await init_/.test(line)) { 18 bad.push(`${curFactory}: ${line.trim()}`) 22 throPtErr('esbuild emitted await-in-sync-fn (TLA cycle pulled into bundle)', {bad: bad.slice(0, 10), bundleAbsPath})