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

@ -115,7 +115,7 @@ export class APIServerAugmentation extends BaseAugmentation {
const express = await import('express').catch(() => null)
const cors = await import('cors').catch(() => null)
const ws = await import('ws').catch(() => null)
const { createServer } = await import('http')
const { createServer } = await import('node:http')
if (!express || !cors || !ws) {
this.log('Express, cors, or ws not available. Install with: npm install express cors ws', 'error')

View file

@ -5,7 +5,7 @@
import { BaseAugmentation } from './brainyAugmentation.js'
import { AugmentationManifest } from './manifest.js'
import { createHash } from 'crypto'
import { createHash } from 'node:crypto'
export interface AuditLogConfig {
enabled?: boolean

View file

@ -8,9 +8,9 @@
* - Default values from schema
*/
import { existsSync, readFileSync } from 'fs'
import { join } from 'path'
import { homedir } from 'os'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { homedir } from 'node:os'
import { JSONSchema } from './manifest.js'
/**
@ -446,8 +446,8 @@ export class AugmentationConfigResolver {
throw new Error('Cannot save configuration files in browser environment')
}
const fs = await import('fs')
const path = await import('path')
const fs = await import('node:fs')
const path = await import('node:path')
const configPath = filepath || this.options.configPaths?.[0] || '.brainyrc'
const augId = this.options.augmentationId

View file

@ -5,8 +5,8 @@
* and built-in augmentations that ship with Brainy
*/
import { existsSync, readdirSync, readFileSync } from 'fs'
import { join } from 'path'
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { AugmentationManifest } from '../manifest.js'
export interface LocalAugmentation {