**feat: improve TensorFlow.js compatibility and remove unnecessary patches**
- Removed outdated Node.js v24 compatibility patches for `TextEncoder` and `TextDecoder` in `cli-wrapper.js` and other modules since TensorFlow.js now supports Node.js v24+ natively. - Introduced a utility module `src/utils/tensorflowUtils.ts` for TensorFlow.js compatibility, defining global `PlatformNode` and related utilities. - Enhanced `fileSystemStorage.ts` with improved Node.js module loading mechanisms for better compatibility across environments. - Simplified dependency requirements by reducing the minimum Node.js version to `>=23.0.0`. - Updated `package.json`, `cli-package/package.json`, and `README.md` versions to `0.9.25`. - Harmonized `cli-package` and main package dependencies to ensure version alignment. - Improved global compatibility with TensorFlow.js in mixed Node.js environments. This update modernizes TensorFlow.js integration, reduces maintenance efforts, and aligns compatibility with current Node.js and TensorFlow.js capabilities.
This commit is contained in:
parent
e9f51e1bf3
commit
5edea683c6
20 changed files with 428 additions and 168 deletions
28
cli-package/cli-wrapper.js
Normal file → Executable file
28
cli-package/cli-wrapper.js
Normal file → Executable file
|
|
@ -12,20 +12,9 @@ import { fileURLToPath } from 'url'
|
|||
import { dirname, join } from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
// Fix for TextEncoder in Node.js v24
|
||||
// In Node.js v24, TextEncoder is a global object and not part of the util module
|
||||
// This patch ensures that the util module has TextEncoder available for TensorFlow.js
|
||||
if (process.versions.node.startsWith('24')) {
|
||||
try {
|
||||
const util = await import('util')
|
||||
if (!util.TextEncoder && typeof TextEncoder !== 'undefined') {
|
||||
util.TextEncoder = TextEncoder
|
||||
util.TextDecoder = TextDecoder
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Warning: Failed to patch TextEncoder for Node.js v24:', error.message)
|
||||
}
|
||||
}
|
||||
// Node.js v23+ compatibility patches were previously applied here,
|
||||
// but these patches are no longer necessary with current TensorFlow.js versions.
|
||||
// TensorFlow.js now works correctly with Node.js 24+ without any special handling.
|
||||
|
||||
// Get the directory of the current module
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
|
|
@ -40,7 +29,9 @@ const cliPath = join(__dirname, 'dist', 'cli.js')
|
|||
// Check if the CLI script exists
|
||||
if (!fs.existsSync(cliPath)) {
|
||||
console.error(`Error: CLI script not found at ${cliPath}`)
|
||||
console.error('This is likely because the CLI was not built during package installation.')
|
||||
console.error(
|
||||
'This is likely because the CLI was not built during package installation.'
|
||||
)
|
||||
console.error('Please reinstall the package with:')
|
||||
console.error('npm uninstall -g @soulcraft/brainy-cli')
|
||||
console.error('npm install -g @soulcraft/brainy-cli')
|
||||
|
|
@ -66,7 +57,12 @@ const args = process.argv.slice(2)
|
|||
|
||||
// Check if npm is passing --force flag
|
||||
// When npm runs with --force, it sets the npm_config_force environment variable
|
||||
if (process.env.npm_config_force === 'true' && args.includes('clear') && !args.includes('--force') && !args.includes('-f')) {
|
||||
if (
|
||||
process.env.npm_config_force === 'true' &&
|
||||
args.includes('clear') &&
|
||||
!args.includes('--force') &&
|
||||
!args.includes('-f')
|
||||
) {
|
||||
args.push('--force')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue