**chore(deps): update dependencies and Node.js version requirements**

- Updated Node.js version requirement to `>=24.3.0` in `README.md` and `package-lock.json`.
- Upgraded `TypeScript` to version `5.4.5` and synced references.
- Updated multiple dependencies, including:
  - `@aws-sdk/client-s3` to `^3.540.0`.
  - `uuid` to `^9.0.1`.
  - Development tools such as `eslint` to `^8.57.0`, `typescript-eslint` plugins to `^7.4.0`, and more.
- Refreshed transitive dependencies with up-to-date versions for consistency and performance.

This update ensures compatibility with the latest Node.js features, aligns TypeScript references, and keeps the project dependencies up-to-date for improved stability and functionality.
This commit is contained in:
David Snelling 2025-07-04 12:19:48 -07:00
parent 457feeccda
commit 20c114dd3e
8 changed files with 593 additions and 788 deletions

View file

@ -60,8 +60,8 @@ export async function areWorkerThreadsAvailable(): Promise<boolean> {
export function areWorkerThreadsAvailableSync(): boolean {
if (!isNode()) return false
// In Node.js 12+, worker_threads is available without requiring a flag
return parseInt(process.versions.node.split('.')[0]) >= 12
// In Node.js 24.3.0+, worker_threads is always available
return parseInt(process.versions.node.split('.')[0]) >= 24
}
/**

View file

@ -10,93 +10,6 @@ import type {
PlatformNodeObject
} from '../types/tensorflowTypes.js'
// Flag to track if we're in a Node.js environment
const isNodeEnvironment =
typeof process !== 'undefined' &&
process.versions &&
process.versions.node
// Promise to load Node.js TextEncoder and TextDecoder
let nodeUtilPromise: Promise<any> | null = null
// Function to get TextEncoder based on environment
async function getTextEncoder(): Promise<typeof TextEncoder | null> {
// First check if TextEncoder is globally available
if (typeof TextEncoder !== 'undefined') {
return TextEncoder
}
// Then try to get it from Node.js util module
if (isNodeEnvironment) {
try {
// Check if we can access the util module directly (in case it's already loaded)
// @ts-ignore - Ignore TypeScript error for global.require
if (typeof global !== 'undefined' && global.require && global.require.cache && global.require.cache['util']) {
// @ts-ignore - Ignore TypeScript error for global.require
const cachedUtil = global.require('util')
if (cachedUtil && cachedUtil.TextEncoder) {
return cachedUtil.TextEncoder
}
}
// Otherwise, use dynamic import
if (!nodeUtilPromise) {
nodeUtilPromise = import('util').catch(error => {
console.warn('Failed to import from util:', error)
return null
})
}
const util = await nodeUtilPromise
return util?.TextEncoder || null
} catch (error) {
console.warn('Error accessing TextEncoder:', error)
return null
}
}
return null
}
// Function to get TextDecoder based on environment
async function getTextDecoder(): Promise<typeof TextDecoder | null> {
// First check if TextDecoder is globally available
if (typeof TextDecoder !== 'undefined') {
return TextDecoder
}
// Then try to get it from Node.js util module
if (isNodeEnvironment) {
try {
// Check if we can access the util module directly (in case it's already loaded)
// @ts-ignore - Ignore TypeScript error for global.require
if (typeof global !== 'undefined' && global.require && global.require.cache && global.require.cache['util']) {
// @ts-ignore - Ignore TypeScript error for global.require
const cachedUtil = global.require('util')
if (cachedUtil && cachedUtil.TextDecoder) {
return cachedUtil.TextDecoder
}
}
// Otherwise, use dynamic import
if (!nodeUtilPromise) {
nodeUtilPromise = import('util').catch(error => {
console.warn('Failed to import from util:', error)
return null
})
}
const util = await nodeUtilPromise
return util?.TextDecoder || null
} catch (error) {
console.warn('Error accessing TextDecoder:', error)
return null
}
}
return null
}
// Define a global PlatformNode class for TensorFlow.js compatibility
// This is needed because TensorFlow.js creates its own PlatformNode instance
// and we need to ensure it uses the correct TextEncoder/TextDecoder
@ -104,10 +17,10 @@ if (
typeof global !== 'undefined' &&
typeof process !== 'undefined' &&
process.versions &&
process.versions.node &&
process.versions.node.split('.')[0] >= '23'
process.versions.node
) {
try {
// In Node.js v24.3.0+, TextEncoder and TextDecoder are globally available
// Define the PlatformNode class that TensorFlow.js will use
class PlatformNode {
util: any
@ -119,96 +32,13 @@ if (
this.util = {
isFloat32Array,
isTypedArray,
// Provide synchronous constructors that return objects with the expected interface
// TensorFlow.js expects these to be synchronous
TextEncoder: function() {
// For Node.js environments, create a direct implementation
if (isNodeEnvironment) {
return {
encode: (str: string) => {
try {
// Direct implementation for Node.js
// Convert string to UTF-8 encoded Uint8Array
const buffer = Buffer.from(str, 'utf-8')
const uint8Array = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
return uint8Array
} catch (error) {
console.warn('Error in Node.js TextEncoder implementation:', error)
return new Uint8Array([])
}
}
}
}
// For browser environments, use the global TextEncoder
else if (typeof TextEncoder !== 'undefined') {
return new TextEncoder()
}
// Fallback for other environments
else {
console.warn('TextEncoder not available in this environment')
return {
encode: (str: string) => new Uint8Array([])
}
}
},
TextDecoder: function() {
// For Node.js environments, create a direct implementation
if (isNodeEnvironment) {
return {
decode: (bytes: Uint8Array) => {
try {
// Direct implementation for Node.js
// Convert Uint8Array to string using Buffer
const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)
return buffer.toString('utf-8')
} catch (error) {
console.warn('Error in Node.js TextDecoder implementation:', error)
return ''
}
}
}
}
// For browser environments, use the global TextDecoder
else if (typeof TextDecoder !== 'undefined') {
return new TextDecoder()
}
// Fallback for other environments
else {
console.warn('TextDecoder not available in this environment')
return {
decode: (bytes: Uint8Array) => ''
}
}
}
TextEncoder,
TextDecoder
}
// Initialize TextEncoder/TextDecoder
this.initializeEncoders()
}
// Initialize TextEncoder and TextDecoder asynchronously
async initializeEncoders() {
try {
const TextEncoderClass = await getTextEncoder()
if (TextEncoderClass) {
this.textEncoder = new TextEncoderClass()
} else {
console.warn('TextEncoder is not available in this environment')
this.textEncoder = { encode: (str: string) => new Uint8Array([]) }
}
const TextDecoderClass = await getTextDecoder()
if (TextDecoderClass) {
this.textDecoder = new TextDecoderClass()
} else {
console.warn('TextDecoder is not available in this environment')
this.textDecoder = { decode: (bytes: Uint8Array) => '' }
}
} catch (error) {
console.error('Failed to initialize encoders:', error)
this.textEncoder = { encode: (str: string) => new Uint8Array([]) }
this.textDecoder = { decode: (bytes: Uint8Array) => '' }
}
// Initialize TextEncoder/TextDecoder instances
this.textEncoder = new TextEncoder()
this.textDecoder = new TextDecoder()
}
}