Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

assert-bundle-output.ts

60 lines1.4 KB

1import { readFileSync, readdirSync, statSync } from 'node:fs'
2import { join, resolve } from 'node:path'
3​
4const bundleDir = resolve(process.argv[2] ?? '.esbuild-smoke-dist')
5​
6const forbidden = [
7 '/api/chat',
8 '@anthropic-ai/sdk',
9 '@fal-ai/client',
10 '@google/genai',
11 '@google/generative-ai',
12 '@openrouter/sdk',
13 '@tanstack/ai-react-ui',
14 '@tanstack/react-ai-devtools',
15 '@tanstack/solid-ai-devtools',
16 'elevenlabs',
17 'node:fs',
18 'node:http',
19 'node:https',
20 'node:stream',
21 'ollama',
22 'openai',
23 'react-dom',
24 'solid-js',
25 'svelte',
26 'vue',
27 'zod',
29​
30function filesIn(dir: string): Array<string> {
31 return readdirSync(dir).flatMap((entry) => {
32 const full = join(dir, entry)
33 return statSync(full).isDirectory() ? filesIn(full) : [full]
34 })
36​
37const failures: Array<string> = []
38let scannedJavaScriptFiles = 0
39​
40for (const file of filesIn(bundleDir)) {
41 if (!/\.(js|json|html)$/.test(file)) continue
42 if (/\.js$/.test(file)) scannedJavaScriptFiles += 1
43 const source = readFileSync(file, 'utf8')
44 for (const token of forbidden) {
45 if (source.includes(token)) {
46 failures.push(`${file} contains forbidden bundle token ${token}`)
47 }
48 }
50​
51if (scannedJavaScriptFiles === 0) {
52 failures.push(`${bundleDir} does not contain any JavaScript output files`)
54​
55if (failures.length > 0) {
56 console.error(failures.join('\n'))
57 process.exit(1)
59​
60console.log('React Native bundle smoke passed.')