babylon-mcp/scripts/index-api.ts
Michael Mainguy dfccbf110a Fix WASM backend configuration for Alpine Linux
Set ONNXRUNTIME_BACKEND environment variable before module imports
to prevent onnxruntime-node from loading. The environment variable
must be set before @xenova/transformers is imported.

Updated all index scripts (index-docs, index-api, index-source) to
configure the backend at the script entry point.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 10:36:25 -06:00

59 lines
1.6 KiB
TypeScript

// MUST set environment variable before any imports that use @xenova/transformers
// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc)
if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') {
process.env.ONNXRUNTIME_BACKEND = 'wasm';
}
import { ApiIndexer } from '../src/search/api-indexer.js';
import path from 'path';
async function main() {
// Define entry points for all Babylon.js packages
const repositoryPath = path.resolve('./data/repositories/Babylon.js');
// All packages with public APIs
const packages = [
'core',
'gui',
'materials',
'loaders',
'serializers',
'inspector',
'postProcesses',
'proceduralTextures',
'addons',
'smartFilters',
'smartFilterBlocks',
];
const entryPoints = packages.map(
pkg => `${repositoryPath}/packages/dev/${pkg}/src/index.ts`
);
console.log('Starting API documentation indexing for all Babylon.js packages...');
console.log(`Indexing ${packages.length} packages:`, packages.join(', '));
console.log();
const indexer = new ApiIndexer(
'./data/lancedb',
'babylon_api',
entryPoints,
`${repositoryPath}/tsconfig.json`
);
try {
await indexer.initialize();
await indexer.indexApi();
await indexer.close();
console.log('\n✓ API indexing completed successfully!');
} catch (error) {
console.error('Error during API indexing:', error);
if (error instanceof Error) {
console.error('Stack trace:', error.stack);
}
process.exit(1);
}
}
main().catch(console.error);