- Removed obsolete scripts: `test-all-environments.js`, `test-fallback-function.js`, `test-fallback-simple.js`, `test-fix.js`, `test-tensorflow-textencoder.js`, `test-unified-encoding.js`, and `test-worker-utils.js`. - Introduced `scripts/comprehensive-test.js` as a unified testing script covering all environments: Browser, Node.js, and CLI. - Added `examples/cli-wrapper-example.js` to demonstrate a proper CLI implementation with TensorFlow.js initialization. This refactor simplifies the testing structure by consolidating redundant scripts into a single comprehensive script while ensuring robust cross-environment coverage.
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
/**
|
|
* Unified entry point for Brainy
|
|
* This file exports everything from index.ts
|
|
* Environment detection is handled here and made available to all components
|
|
*/
|
|
|
|
// CRITICAL: The TensorFlow.js environment patch is now centralized in setup.ts
|
|
// We import setup.ts below which applies the necessary patches
|
|
|
|
// CRITICAL: Import setup.js first to ensure TensorFlow.js environment patching
|
|
// This MUST be the first import to prevent race conditions with TensorFlow.js initialization
|
|
// Moving or removing this import will cause errors like "TextEncoder is not a constructor"
|
|
// when the package is used in Node.js environments
|
|
//
|
|
// The setup.js file applies a patch that ensures TextEncoder/TextDecoder are properly
|
|
// available to TensorFlow.js before it initializes its platform detection
|
|
import './setup.js'
|
|
|
|
// Export environment information
|
|
export const environment = {
|
|
isBrowser: typeof window !== 'undefined',
|
|
isNode:
|
|
typeof process !== 'undefined' && process.versions && process.versions.node,
|
|
isServerless:
|
|
typeof window === 'undefined' &&
|
|
(typeof process === 'undefined' ||
|
|
!process.versions ||
|
|
!process.versions.node)
|
|
}
|
|
|
|
// Make environment information available globally
|
|
if (typeof globalThis !== 'undefined') {
|
|
;(globalThis as any).__ENV__ = environment
|
|
}
|
|
|
|
// Log the detected environment
|
|
console.log(
|
|
`Brainy running in ${
|
|
environment.isBrowser
|
|
? 'browser'
|
|
: environment.isNode
|
|
? 'Node.js'
|
|
: 'serverless/unknown'
|
|
} environment`
|
|
)
|
|
|
|
// Re-export everything from index.ts
|
|
export * from './index.js'
|