()
| 186 | } |
| 187 | |
| 188 | async function main(): Promise<void> { |
| 189 | // CI gate: `<binary> --smoke-tree-sitter` proves the embedded wasm boots |
| 190 | // through Parser.init end-to-end. Has to live BEFORE commander.parse() — |
| 191 | // an earlier attempt put this in a pre-init module with top-level await, |
| 192 | // and on Windows that didn't actually pause module evaluation (commander |
| 193 | // still ran first and rejected the unknown flag). |
| 194 | if (process.argv.includes('--smoke-tree-sitter')) { |
| 195 | const wasmBinary = ( |
| 196 | globalThis as { __CODEBUFF_TREE_SITTER_WASM_BINARY__?: Uint8Array } |
| 197 | ).__CODEBUFF_TREE_SITTER_WASM_BINARY__ |
| 198 | const wasmPath = ( |
| 199 | globalThis as { __CODEBUFF_TREE_SITTER_WASM_PATH__?: string } |
| 200 | ).__CODEBUFF_TREE_SITTER_WASM_PATH__ |
| 201 | |
| 202 | // Diagnostic dump so CI logs (and bug reports) show exactly what |
| 203 | // the runtime saw when smoke fails. process.execPath, the |
| 204 | // siblingPath we expect, and what's actually in that directory. |
| 205 | const fs = await import('fs') |
| 206 | const path = await import('path') |
| 207 | const execDir = path.dirname(process.execPath) |
| 208 | const siblingPath = path.join(execDir, 'tree-sitter.wasm') |
| 209 | let dirListing: string[] = [] |
| 210 | try { |
| 211 | dirListing = fs.readdirSync(execDir) |
| 212 | } catch (err) { |
| 213 | dirListing = [`<readdir failed: ${err instanceof Error ? err.message : err}>`] |
| 214 | } |
| 215 | console.error( |
| 216 | `[smoke diag] execPath=${process.execPath}\n` + |
| 217 | `[smoke diag] execDir=${execDir}\n` + |
| 218 | `[smoke diag] siblingPath=${siblingPath}\n` + |
| 219 | `[smoke diag] siblingExists=${fs.existsSync(siblingPath)}\n` + |
| 220 | `[smoke diag] dir contents (${dirListing.length}): ${dirListing.slice(0, 30).join(', ')}\n` + |
| 221 | `[smoke diag] globalThis wasmPath=${wasmPath ?? '<unset>'}\n` + |
| 222 | `[smoke diag] globalThis wasmBinary bytes=${wasmBinary?.byteLength ?? 0}\n`, |
| 223 | ) |
| 224 | |
| 225 | try { |
| 226 | const { Parser } = await import('web-tree-sitter') |
| 227 | // Pick the best wasm source available, falling back to the |
| 228 | // sibling-of-execPath lookup if pre-init couldn't reach it. By |
| 229 | // main() time process.execPath has stabilized to the disk path |
| 230 | // even on Windows, where it was the bunfs path during pre-init. |
| 231 | let effectiveBinary = wasmBinary |
| 232 | let effectivePath = wasmPath |
| 233 | if (!effectiveBinary && !effectivePath && fs.existsSync(siblingPath)) { |
| 234 | effectivePath = siblingPath |
| 235 | effectiveBinary = new Uint8Array(fs.readFileSync(siblingPath)) |
| 236 | } |
| 237 | |
| 238 | if (effectiveBinary) { |
| 239 | await Parser.init({ wasmBinary: effectiveBinary }) |
| 240 | // Marker grepped by cli/scripts/smoke-binary.ts — keep this exact text. |
| 241 | console.log( |
| 242 | `tree-sitter smoke ok (wasmBinary, ${effectiveBinary.byteLength} bytes)`, |
| 243 | ) |
| 244 | } else if (effectivePath) { |
| 245 | await Parser.init({ |
no test coverage detected