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:
parent
1b32870e43
commit
fcb7197fb0
40 changed files with 165 additions and 77 deletions
|
|
@ -11,7 +11,8 @@ let nodeCrypto: any = null
|
|||
// Dynamic import for Node.js crypto (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodeCrypto = await import('crypto')
|
||||
// Use node: protocol to prevent bundler polyfilling (requires Node 22+)
|
||||
nodeCrypto = await import('node:crypto')
|
||||
} catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ let nodeEvents: any = null
|
|||
// Dynamic import for Node.js events (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodeEvents = await import('events')
|
||||
nodeEvents = await import('node:events')
|
||||
} catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ let nodeFs: any = null
|
|||
// Dynamic import for Node.js fs (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodeFs = await import('fs/promises')
|
||||
// Use node: protocol to prevent bundler polyfilling (requires Node 22+)
|
||||
nodeFs = await import('node:fs/promises')
|
||||
} catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ let nodePath: any = null
|
|||
// Dynamic import for Node.js path (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodePath = await import('path')
|
||||
// Use node: protocol to prevent bundler polyfilling (requires Node 22+)
|
||||
nodePath = await import('node:path')
|
||||
} catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue