feat: add node: protocol to all Node.js built-in imports for bundler compatibility

- Updated all fs, path, crypto, os, url, util, events, http, https, net, child_process, stream, and zlib imports
- Changed both static imports and dynamic imports to use node: protocol
- This makes Brainy more bundler-friendly by explicitly marking Node.js built-ins
- Prevents bundlers from attempting to polyfill or bundle these modules
- Reduces bundle size for web applications using Brainy
- Improves tree-shaking and dead code elimination

Benefits for external bundlers:
- Clear distinction between Node.js built-ins and external dependencies
- No ambiguity about what needs polyfilling
- Smaller bundles for browser builds
- Better compatibility with modern bundlers (Webpack 5, Vite, Rollup, esbuild)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-09-17 14:20:21 -07:00
parent 1b32870e43
commit fcb7197fb0
40 changed files with 165 additions and 77 deletions

View file

@ -29,8 +29,8 @@ let moduleLoadingPromise: Promise<void> | null = null
// Try to load Node.js modules
try {
// Using dynamic imports to avoid issues in browser environments
const fsPromise = import('fs')
const pathPromise = import('path')
const fsPromise = import('node:fs')
const pathPromise = import('node:path')
moduleLoadingPromise = Promise.all([fsPromise, pathPromise])
.then(([fsModule, pathModule]) => {

View file

@ -463,7 +463,7 @@ export class CacheManager<T extends HNSWNode | Edge | HNSWVerb> {
if (this.environment === Environment.NODE) {
try {
// Use dynamic import for OS module
const os = await import('os')
const os = await import('node:os')
// Get actual system memory information
const totalMemory = os.totalmem()

View file

@ -237,7 +237,7 @@ export class EnhancedFileSystemClear {
const backupDir = `${this.rootDir}-backup-${timestamp}`
// Use cp -r for efficient directory copying
const { spawn } = await import('child_process')
const { spawn } = await import('node:child_process')
return new Promise((resolve, reject) => {
const cp = spawn('cp', ['-r', this.rootDir, backupDir])