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

@ -350,8 +350,8 @@ export class BackupRestore {
private async compressData(data: string): Promise<string> {
// Use zlib gzip compression
const { gzip } = await import('zlib')
const { promisify } = await import('util')
const { gzip } = await import('node:zlib')
const { promisify } = await import('node:util')
const gzipAsync = promisify(gzip)
const compressed = await gzipAsync(Buffer.from(data, 'utf-8'))
@ -360,8 +360,8 @@ export class BackupRestore {
private async decompressData(data: string): Promise<string> {
// Use zlib gunzip decompression
const { gunzip } = await import('zlib')
const { promisify } = await import('util')
const { gunzip } = await import('node:zlib')
const { promisify } = await import('node:util')
const gunzipAsync = promisify(gunzip)
const compressed = Buffer.from(data, 'base64')
@ -371,7 +371,7 @@ export class BackupRestore {
private async encryptData(data: string, password: string): Promise<string> {
// Use crypto module for AES-256 encryption
const crypto = await import('crypto')
const crypto = await import('node:crypto')
// Generate key from password
const key = crypto.createHash('sha256').update(password).digest()
@ -387,7 +387,7 @@ export class BackupRestore {
private async decryptData(data: string, password: string): Promise<string> {
// Use crypto module for AES-256 decryption
const crypto = await import('crypto')
const crypto = await import('node:crypto')
// Split IV and encrypted data
const [ivString, encrypted] = data.split(':')
@ -487,7 +487,7 @@ export class BackupRestore {
private async calculateChecksum(data: string): Promise<string> {
// Use crypto module for SHA-256 checksum
const crypto = await import('crypto')
const crypto = await import('node:crypto')
return crypto.createHash('sha256').update(data).digest('hex')
}