* Don't build libpg-query package. * Use the WASM build of libpg-query in ai-commands. * Fix missing mdast type. * fix: wasm loading in ai-commands tests * fix: better polyfill * Make the sql-to-rest page to be client-side only. --------- Co-authored-by: Greg Richardson <greg.nmr@gmail.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { config } from 'dotenv'
|
|
import { statSync } from 'fs'
|
|
import './test/extensions'
|
|
|
|
if (!process.env.CI) {
|
|
// Use keys from studio .env.local for local tests
|
|
const envPath = '../../apps/studio/.env.local'
|
|
|
|
statSync(envPath)
|
|
config({ path: envPath })
|
|
}
|
|
|
|
// Modify fetch to support wasm file URLs
|
|
globalThis.fetch = async (input: string | URL | Request, init?: RequestInit) => {
|
|
if (input instanceof Request) {
|
|
return fetch(input, init)
|
|
}
|
|
|
|
const url = new URL(input)
|
|
if (url.protocol === 'file:' && url.pathname.endsWith('.wasm')) {
|
|
return fetchFileNode(input, 'application/wasm')
|
|
}
|
|
|
|
return fetch(input, init)
|
|
}
|
|
|
|
async function fetchFileNode(input: string | URL, type: string) {
|
|
const fs = await import('node:fs')
|
|
const { Readable } = await import('node:stream')
|
|
const { fileURLToPath } = await import('node:url')
|
|
const path = fileURLToPath(input)
|
|
const nodeStream = fs.createReadStream(path)
|
|
const stream = Readable.toWeb(nodeStream) as ReadableStream<Uint8Array>
|
|
return new Response(stream, { headers: { 'Content-Type': type } })
|
|
}
|