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
|
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
import chalk from 'chalk'
|
||||
import { readFileSync, writeFileSync, existsSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { homedir } from 'os'
|
||||
import { readFileSync, writeFileSync, existsSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { homedir } from 'node:os'
|
||||
|
||||
const CATALOG_API = process.env.BRAINY_CATALOG_URL || null
|
||||
const CACHE_PATH = join(homedir(), '.brainy', 'catalog-cache.json')
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import chalk from 'chalk'
|
||||
import ora from 'ora'
|
||||
import { readFileSync, writeFileSync } from 'fs'
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { Brainy } from '../../brainy.js'
|
||||
import { BrainyTypes, NounType, VerbType } from '../../index.js'
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
import inquirer from 'inquirer';
|
||||
import chalk from 'chalk';
|
||||
import ora from 'ora';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { Brainy } from '../../brainyData.js';
|
||||
import { NeuralAPI } from '../../neural/neuralAPI.js';
|
||||
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ export async function promptFileOrUrl(
|
|||
const data = await promptDataInput('import')
|
||||
// Save to temp file and return path
|
||||
const tmpFile = `/tmp/brainy-import-${Date.now()}.json`
|
||||
const { writeFileSync } = await import('fs')
|
||||
const { writeFileSync } = await import('node:fs')
|
||||
writeFileSync(tmpFile, data)
|
||||
return tmpFile
|
||||
default:
|
||||
|
|
@ -392,7 +392,7 @@ async function promptFilePath(action: string): Promise<string> {
|
|||
return 'Please enter a file path'
|
||||
}
|
||||
|
||||
const { existsSync } = await import('fs')
|
||||
const { existsSync } = await import('node:fs')
|
||||
if (action === 'import' && !existsSync(input)) {
|
||||
return `File not found: ${input}`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue