**chore(release): bump version to 0.10.0 and refactor project structure**

- Updated version to `0.10.0` in `README.md`, `cli-package/package.json`, and `src/utils/version.ts`.
- Removed `CHANGELOG.md` from the root and `cli-package`, as GitHub auto-generates release notes.
- Refactored `brainy-wrapper.js` to simplify utility methods (`isFloat32Array` and `isTypedArray`) by moving them to instance-level definitions.
- Standardized Node.js version requirement to `>= 24.3.0` across documentation and configuration files.
- Improved `textEncoding.ts` by introducing a unified `Platform` class for cross-environment compatibility (Node.js and browser).
- Restructured scripts:
  - Replaced outdated commands (e.g., `test-cli` -> `test:cli` and `test-all` -> `test:all`) for consistency.
  - Removed changelog updates from `scripts/create-github-release.js` as part of simplification.
- Enhanced `patch-textencoder.js` to also patch `worker.js` for both `TextEncoder` and `TextDecoder`.

This release improves compatibility with Node.js 24, simplifies the deployment/changelog process, and refines text encoding and worker functionalities.
This commit is contained in:
David Snelling 2025-07-07 10:19:04 -07:00
parent 1a88aecdb6
commit 00039f836f
18 changed files with 183 additions and 292 deletions

View file

@ -1,24 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
## [0.9.37] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/compare/v0.9.36...v0.9.37
## [0.9.36] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/commits/v0.9.36
## [0.9.34] - 2024-07-01
This is the initial changelog entry. Future releases will automatically update this file with release notes from GitHub.
### Added
- Auto-generation of release notes for GitHub releases
- Auto-updating of CHANGELOG.md files for both main and CLI packages
- Display of release notes on npmjs.com through the CHANGELOG.md files
### Changed
- Modified deployment scripts to ensure GitHub releases are created with auto-generated notes
- Updated package.json files to include CHANGELOG.md in published packages

View file

@ -4,16 +4,17 @@
<img src="./brainy.png" alt="Brainy Logo" width="200"/> <img src="./brainy.png" alt="Brainy Logo" width="200"/>
</div> </div>
This document contains detailed information for developers working with Brainy, including building, testing, and publishing instructions. This document contains detailed information for developers working with Brainy, including building, testing, and
publishing instructions.
## Table of Contents ## Table of Contents
- [Build System](#build-system) - [Build System](#build-system)
- [Testing](#testing) - [Testing](#testing)
- [Testing All Environments](#testing-all-environments) - [Testing All Environments](#testing-all-environments)
- [Testing the CLI Package Locally](#testing-the-cli-package-locally) - [Testing the CLI Package Locally](#testing-the-cli-package-locally)
- [Publishing](#publishing) - [Publishing](#publishing)
- [Publishing the CLI Package](#publishing-the-cli-package) - [Publishing the CLI Package](#publishing-the-cli-package)
- [Development Usage](#development-usage) - [Development Usage](#development-usage)
- [Node.js 24 Optimizations](#nodejs-24-optimizations) - [Node.js 24 Optimizations](#nodejs-24-optimizations)
- [Development Workflow](#development-workflow) - [Development Workflow](#development-workflow)
@ -63,14 +64,16 @@ Brainy uses a modern build system that optimizes for both Node.js and browser en
### Testing All Environments ### Testing All Environments
Brainy provides a comprehensive test script that verifies the library works correctly in all supported environments (browser, Node.js, and CLI): Brainy provides a comprehensive test script that verifies the library works correctly in all supported environments (
browser, Node.js, and CLI):
```bash ```bash
# Test the library in all environments # Test the library in all environments
npm run test-all npm run test:all
``` ```
This script: This script:
1. Builds all packages (main, browser, CLI) 1. Builds all packages (main, browser, CLI)
2. Runs Node.js tests (worker tests and unified text encoding test) 2. Runs Node.js tests (worker tests and unified text encoding test)
3. Starts a local HTTP server and runs browser tests using Puppeteer (headless browser) 3. Starts a local HTTP server and runs browser tests using Puppeteer (headless browser)
@ -84,10 +87,11 @@ Before publishing the CLI package to npm, you can test it locally to ensure it w
```bash ```bash
# Test the CLI package locally # Test the CLI package locally
npm run test-cli npm run test:cli
``` ```
This script: This script:
1. Builds the main package 1. Builds the main package
2. Creates a local tarball of the main package 2. Creates a local tarball of the main package
3. Builds the CLI package 3. Builds the CLI package
@ -115,7 +119,8 @@ npm uninstall -g @soulcraft/brainy-cli
### Publishing the CLI Package ### Publishing the CLI Package
If you need to publish the CLI package to npm, please refer to the [CLI Publishing Guide](docs/publishing-cli.md) for detailed instructions. If you need to publish the CLI package to npm, please refer to the [CLI Publishing Guide](docs/publishing-cli.md) for
detailed instructions.
## Development Usage ## Development Usage
@ -131,15 +136,21 @@ npm run cli generate-random-graph --noun-count 20 --verb-count 40
Brainy takes advantage of several optimizations available in Node.js 24: Brainy takes advantage of several optimizations available in Node.js 24:
1. **Improved Worker Threads Performance**: The multithreading system has been completely rewritten to leverage Node.js 24's enhanced Worker Threads API, resulting in better performance for compute-intensive operations like embedding generation and vector similarity calculations. 1. **Improved Worker Threads Performance**: The multithreading system has been completely rewritten to leverage Node.js
24's enhanced Worker Threads API, resulting in better performance for compute-intensive operations like embedding
generation and vector similarity calculations.
2. **Worker Pool Management**: A sophisticated worker pool system reuses worker threads to minimize the overhead of creating and destroying threads, leading to more efficient resource utilization. 2. **Worker Pool Management**: A sophisticated worker pool system reuses worker threads to minimize the overhead of
creating and destroying threads, leading to more efficient resource utilization.
3. **Dynamic Module Imports**: Uses the new `node:` protocol prefix for importing core modules, which provides better performance and more reliable module resolution. 3. **Dynamic Module Imports**: Uses the new `node:` protocol prefix for importing core modules, which provides better
performance and more reliable module resolution.
4. **ES Modules Optimizations**: Takes advantage of Node.js 24's improved ESM implementation for faster module loading and execution. 4. **ES Modules Optimizations**: Takes advantage of Node.js 24's improved ESM implementation for faster module loading
and execution.
5. **Enhanced Error Handling**: Implements more robust error handling patterns available in Node.js 24 for better stability and debugging. 5. **Enhanced Error Handling**: Implements more robust error handling patterns available in Node.js 24 for better
stability and debugging.
These optimizations are particularly beneficial for: These optimizations are particularly beneficial for:
@ -157,7 +168,8 @@ These optimizations are particularly beneficial for:
## Reporting Issues ## Reporting Issues
We use GitHub issues to track bugs and feature requests. Please use the provided issue templates when creating a new issue: We use GitHub issues to track bugs and feature requests. Please use the provided issue templates when creating a new
issue:
- [Bug Report Template](.github/ISSUE_TEMPLATE/bug_report.md) - [Bug Report Template](.github/ISSUE_TEMPLATE/bug_report.md)
- [Feature Request Template](.github/ISSUE_TEMPLATE/feature_request.md) - [Feature Request Template](.github/ISSUE_TEMPLATE/feature_request.md)

View file

@ -4,7 +4,7 @@ The Brainy interactive demo showcases the library's features in a web browser. F
## Prerequisites ## Prerequisites
- Make sure you have Node.js installed (version 23.0.0 or higher) - Make sure you have Node.js installed (version 24.3.0 or higher)
- Ensure the project is built (run both `npm run build` and `npm run build:browser`) - Ensure the project is built (run both `npm run build` and `npm run build:browser`)
## Running the Demo ## Running the Demo

View file

@ -6,7 +6,7 @@
[![Node.js](https://img.shields.io/badge/node-%3E%3D24.3.0-brightgreen.svg)](https://nodejs.org/) [![Node.js](https://img.shields.io/badge/node-%3E%3D24.3.0-brightgreen.svg)](https://nodejs.org/)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.4.5-blue.svg)](https://www.typescriptlang.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.4.5-blue.svg)](https://www.typescriptlang.org/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
[![npm](https://img.shields.io/badge/npm-v0.9.37-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy) [![npm](https://img.shields.io/badge/npm-v0.10.0-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy)
[//]: # ([![Cartographer]&#40;https://img.shields.io/badge/Cartographer-Official%20Standard-brightgreen&#41;]&#40;https://github.com/sodal-project/cartographer&#41;) [//]: # ([![Cartographer]&#40;https://img.shields.io/badge/Cartographer-Official%20Standard-brightgreen&#41;]&#40;https://github.com/sodal-project/cartographer&#41;)
@ -1248,7 +1248,7 @@ comprehensive [Scaling Strategy](scalingStrategy.md) document.
## Requirements ## Requirements
- Node.js >= 23.0.0 - Node.js >= 24.3.0
## Contributing ## Contributing

View file

@ -1,24 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
## [0.9.37] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/compare/v0.9.36...v0.9.37
## [0.9.36] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/commits/v0.9.36
## [0.9.34] - 2024-07-01
This is the initial changelog entry. Future releases will automatically update this file with release notes from GitHub.
### Added
- Auto-generation of release notes for GitHub releases
- Auto-updating of CHANGELOG.md files for both main and CLI packages
- Display of release notes on npmjs.com through the CHANGELOG.md files
### Changed
- Modified deployment scripts to ensure GitHub releases are created with auto-generated notes
- Updated package.json files to include CHANGELOG.md in published packages

View file

@ -47,12 +47,7 @@ brainy generate-random-graph --noun-count 20 --verb-count 30 --clear
## Requirements ## Requirements
- Node.js >= 23.0.0 - Node.js >= 24.3.0
## Changelog
### 0.9.25
- Completely removed unnecessary compatibility patches for Node.js v24 as they are no longer needed with current TensorFlow.js versions
## License ## License

View file

@ -18,22 +18,27 @@ if (
// Define a PlatformNode class that uses the global TextEncoder/TextDecoder directly // Define a PlatformNode class that uses the global TextEncoder/TextDecoder directly
class PlatformNode { class PlatformNode {
constructor() { constructor() {
// Create a util object with only the necessary methods // Create a util object (empty but kept for compatibility)
this.util = { this.util = {}
isFloat32Array: (arr) =>
!!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) === '[object Float32Array]')
),
isTypedArray: (arr) =>
!!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
}
// Initialize TextEncoder/TextDecoder instances directly from global // Initialize TextEncoder/TextDecoder instances directly from global
this.textEncoder = new TextEncoder() this.textEncoder = new TextEncoder()
this.textDecoder = new TextDecoder() this.textDecoder = new TextDecoder()
} }
// Define isFloat32Array directly on the instance
isFloat32Array(arr) {
return !!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) === '[object Float32Array]')
)
}
// Define isTypedArray directly on the instance
isTypedArray(arr) {
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
}
} }
// Assign the PlatformNode class to the global object // Assign the PlatformNode class to the global object

View file

@ -1,6 +1,6 @@
{ {
"name": "@soulcraft/brainy-cli", "name": "@soulcraft/brainy-cli",
"version": "0.9.37", "version": "0.10.0",
"description": "Command-line interface for the Brainy vector graph database", "description": "Command-line interface for the Brainy vector graph database",
"type": "module", "type": "module",
"bin": { "bin": {
@ -9,7 +9,6 @@
"files": [ "files": [
"cli-wrapper.js", "cli-wrapper.js",
"README.md", "README.md",
"CHANGELOG.md",
"dist/cli.js", "dist/cli.js",
"dist/cli.js.map" "dist/cli.js.map"
], ],
@ -41,7 +40,7 @@
"url": "git+https://github.com/soulcraft-research/brainy.git" "url": "git+https://github.com/soulcraft-research/brainy.git"
}, },
"dependencies": { "dependencies": {
"@soulcraft/brainy": "0.9.37", "@soulcraft/brainy": "0.10.0",
"commander": "^14.0.0", "commander": "^14.0.0",
"omelette": "^0.4.17" "omelette": "^0.4.17"
}, },

View file

@ -28,15 +28,6 @@ export function applyTensorFlowPatch(): void {
constructor() { constructor() {
// Create a util object with necessary methods and constructors // Create a util object with necessary methods and constructors
this.util = { this.util = {
isFloat32Array: (arr: any) =>
!!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
),
isTypedArray: (arr: any) =>
!!(ArrayBuffer.isView(arr) && !(arr instanceof DataView)),
// Use native TextEncoder and TextDecoder // Use native TextEncoder and TextDecoder
TextEncoder: TextEncoder, TextEncoder: TextEncoder,
TextDecoder: TextDecoder TextDecoder: TextDecoder
@ -46,6 +37,21 @@ export function applyTensorFlowPatch(): void {
this.textEncoder = new this.util.TextEncoder() this.textEncoder = new this.util.TextEncoder()
this.textDecoder = new this.util.TextDecoder() this.textDecoder = new this.util.TextDecoder()
} }
// Define isFloat32Array directly on the instance
isFloat32Array(arr: any) {
return !!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
)
}
// Define isTypedArray directly on the instance
isTypedArray(arr: any) {
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
}
} }
// Assign the PlatformNode class to the global object // Assign the PlatformNode class to the global object

View file

@ -99,9 +99,10 @@
}) })
async function runWorkerTest(resultDiv) { async function runWorkerTest(resultDiv) {
// Define a compute-intensive function // Define a compute-intensive function using a function expression
// This is more compatible with how the worker evaluates the function string
const computeIntensiveFunction = ` const computeIntensiveFunction = `
function(data) { function computeTask(data) {
console.log('Worker/Fallback: Starting computation...'); console.log('Worker/Fallback: Starting computation...');
// Simulate a compute-intensive task // Simulate a compute-intensive task
@ -114,13 +115,20 @@
const duration = Date.now() - start; const duration = Date.now() - start;
console.log('Worker/Fallback: Computation completed in ' + duration + 'ms'); console.log('Worker/Fallback: Computation completed in ' + duration + 'ms');
const globalObj = typeof self !== 'undefined' ? self :
typeof window !== 'undefined' ? window :
{};
return { return {
result, result,
duration, duration,
iterations: data.iterations, iterations: data.iterations,
webWorkersAvailable: typeof window.Worker !== 'undefined' webWorkersAvailable: typeof globalObj.Worker !== 'undefined'
}; };
} }
// Return the function itself
computeTask;
` `
// Execute the function // Execute the function

View file

@ -6,7 +6,7 @@ This document explains how to publish both the @soulcraft/brainy and @soulcraft/
Before publishing, ensure you have: Before publishing, ensure you have:
1. Node.js >= 23.0.0 installed 1. Node.js >= 24.3.0 installed
2. An npm account with access to the @soulcraft organization 2. An npm account with access to the @soulcraft organization
3. Logged in to npm using `npm login` 3. Logged in to npm using `npm login`

View file

@ -41,8 +41,8 @@
"lint": "eslint --ext .ts,.js src/", "lint": "eslint --ext .ts,.js src/",
"lint:fix": "eslint --ext .ts,.js src/ --fix", "lint:fix": "eslint --ext .ts,.js src/ --fix",
"format": "prettier --write \"src/**/*.{ts,js}\"", "format": "prettier --write \"src/**/*.{ts,js}\"",
"check-format": "prettier --check \"src/**/*.{ts,js}\"", "check:format": "prettier --check \"src/**/*.{ts,js}\"",
"check-style": "node scripts/check-code-style.js", "check:style": "node scripts/check-code-style.js",
"prepare": "npm run build", "prepare": "npm run build",
"deploy": "npm run build && npm publish && node scripts/create-github-release.js", "deploy": "npm run build && npm publish && node scripts/create-github-release.js",
"deploy:cli": "node scripts/generate-version.js && cd cli-package && npm run build && npm publish", "deploy:cli": "node scripts/generate-version.js && cd cli-package && npm run build && npm publish",
@ -52,8 +52,8 @@
"deploy:cloud": "echo 'Please use one of the following commands to deploy to a specific cloud provider:' && echo ' npm run deploy:cloud:aws' && echo ' npm run deploy:cloud:gcp' && echo ' npm run deploy:cloud:cloudflare'", "deploy:cloud": "echo 'Please use one of the following commands to deploy to a specific cloud provider:' && echo ' npm run deploy:cloud:aws' && echo ' npm run deploy:cloud:gcp' && echo ' npm run deploy:cloud:cloudflare'",
"postinstall": "echo 'Note: If you encounter dependency conflicts with TensorFlow.js packages, please use: npm install --legacy-peer-deps'", "postinstall": "echo 'Note: If you encounter dependency conflicts with TensorFlow.js packages, please use: npm install --legacy-peer-deps'",
"dry-run": "npm pack --dry-run", "dry-run": "npm pack --dry-run",
"test-cli": "node scripts/test-cli-locally.js", "test:cli": "node scripts/test-cli-locally.js",
"test-all": "node scripts/test-all-environments.js" "test:all": "node scripts/test-all-environments.js"
}, },
"keywords": [ "keywords": [
"vector-database", "vector-database",
@ -93,7 +93,6 @@
"dist/utils/", "dist/utils/",
"LICENSE", "LICENSE",
"README.md", "README.md",
"CHANGELOG.md",
"brainy.png" "brainy.png"
], ],
"devDependencies": { "devDependencies": {

View file

@ -81,17 +81,15 @@ try {
console.log(`GitHub release v${version} created successfully!`) console.log(`GitHub release v${version} created successfully!`)
// Update CHANGELOG.md with the release notes // GitHub will automatically handle the changelog
console.log('Updating CHANGELOG.md with release notes...') console.log('GitHub release created with auto-generated notes')
execSync('node scripts/update-changelog.js', { stdio: 'inherit', cwd: rootDir })
} catch (error) { } catch (error) {
// If the release already exists, this is not a fatal error // If the release already exists, this is not a fatal error
if (error.message.includes('already exists')) { if (error.message.includes('already exists')) {
console.log(`GitHub release v${version} already exists, skipping creation.`) console.log(`GitHub release v${version} already exists, skipping creation.`)
// Still update CHANGELOG.md with the release notes // GitHub will automatically handle the changelog
console.log('Updating CHANGELOG.md with release notes...') console.log('GitHub release already exists with auto-generated notes')
execSync('node scripts/update-changelog.js', { stdio: 'inherit', cwd: rootDir })
} else { } else {
console.error('Error creating GitHub release:', error.message) console.error('Error creating GitHub release:', error.message)
// Don't exit with error to allow the npm publish to continue // Don't exit with error to allow the npm publish to continue

View file

@ -63,6 +63,28 @@ if (fs.existsSync(minifiedJsPath)) {
} }
} }
// Also patch the worker.js file if it exists
const workerJsPath = path.join(__dirname, '..', 'dist', 'worker.js')
if (fs.existsSync(workerJsPath)) {
console.log(`Reading ${workerJsPath}...`)
const workerContent = fs.readFileSync(workerJsPath, 'utf8')
// Apply the same replacement to the worker file
const patchedWorkerContent = workerContent.replace(pattern, replacement)
// Check if the patch was applied
if (patchedWorkerContent === workerContent) {
console.warn(
'No instances of "new this.util.TextEncoder()" found in the worker file.'
)
} else {
// Write the patched file
console.log('Writing patched worker file...')
fs.writeFileSync(workerJsPath, patchedWorkerContent, 'utf8')
console.log('Worker file patched successfully!')
}
}
// Also patch TextDecoder // Also patch TextDecoder
console.log('Patching TextDecoder references...') console.log('Patching TextDecoder references...')
content = fs.readFileSync(unifiedJsPath, 'utf8') content = fs.readFileSync(unifiedJsPath, 'utf8')
@ -99,3 +121,21 @@ if (fs.existsSync(minifiedJsPath)) {
console.log('TextDecoder patch applied to minified file successfully!') console.log('TextDecoder patch applied to minified file successfully!')
} }
} }
// Patch the worker.js file for TextDecoder as well
if (fs.existsSync(workerJsPath)) {
const workerContent = fs.readFileSync(workerJsPath, 'utf8')
const patchedWorkerDecoderContent = workerContent.replace(
decoderPattern,
decoderReplacement
)
if (patchedWorkerDecoderContent === workerContent) {
console.warn(
'No instances of "new this.util.TextDecoder()" found in the worker file.'
)
} else {
fs.writeFileSync(workerJsPath, patchedWorkerDecoderContent, 'utf8')
console.log('TextDecoder patch applied to worker file successfully!')
}
}

View file

@ -224,7 +224,7 @@ async function runAllTests() {
// Run CLI tests // Run CLI tests
log('Testing CLI package locally...', colors.yellow) log('Testing CLI package locally...', colors.yellow)
try { try {
runCommand('npm run test-cli') runCommand('npm run test:cli')
log('CLI test completed!', colors.green) log('CLI test completed!', colors.green)
// Run some basic CLI commands to verify functionality // Run some basic CLI commands to verify functionality
@ -245,7 +245,7 @@ async function runAllTests() {
colors.yellow colors.yellow
) )
log( log(
'You can run the CLI tests separately with: npm run test-cli', 'You can run the CLI tests separately with: npm run test:cli',
colors.yellow colors.yellow
) )
} }

View file

@ -1,138 +0,0 @@
#!/usr/bin/env node
/**
* Update Changelog Script
*
* This script updates the CHANGELOG.md file with the latest release notes
* from GitHub. It's designed to be called after creating a GitHub release.
*
* The script:
* 1. Gets the current version from package.json
* 2. Fetches the release notes from GitHub for that version
* 3. Updates the CHANGELOG.md file with the new release notes
*
* This ensures that the CHANGELOG.md file is always up-to-date with the
* latest release notes, which will be displayed on npmjs.com.
*/
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
// Get the directory of the current module
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Path to the root directory
const rootDir = path.join(__dirname, '..')
// Path to package.json
const packageJsonPath = path.join(rootDir, 'package.json')
// Path to CHANGELOG.md
const changelogPath = path.join(rootDir, 'CHANGELOG.md')
// Read package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const version = packageJson.version
// Check if GitHub CLI is installed
try {
execSync('gh --version', { stdio: 'ignore' })
} catch (error) {
console.error('Error: GitHub CLI (gh) is not installed or not in PATH')
console.error('Please install it from https://cli.github.com/ and authenticate with `gh auth login`')
process.exit(1)
}
// Fetch release notes from GitHub
try {
console.log(`Fetching release notes for v${version} from GitHub...`)
// Get the release notes using GitHub CLI
const releaseNotes = execSync(
`gh release view v${version} --json body --jq .body`,
{ encoding: 'utf8', cwd: rootDir }
).trim()
// Create or update the CHANGELOG.md file
let changelog = ''
// If CHANGELOG.md exists, read its content
if (fs.existsSync(changelogPath)) {
changelog = fs.readFileSync(changelogPath, 'utf8')
} else {
// Create a new CHANGELOG.md file with a header
changelog = '# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n'
}
// Format the new entry
const date = new Date().toISOString().split('T')[0]
const newEntry = `## [${version}] - ${date}\n\n${releaseNotes}\n\n`
// Check if this version is already in the changelog
if (changelog.includes(`## [${version}]`)) {
// Replace the existing entry
const versionRegex = new RegExp(`## \\[${version}\\].*?(?=## \\[|$)`, 's')
changelog = changelog.replace(versionRegex, newEntry)
} else {
// Add the new entry after the header (before the first version entry)
const firstVersionIndex = changelog.search(/## \[\d+\.\d+\.\d+\]/)
if (firstVersionIndex !== -1) {
// Insert before the first version entry
changelog = changelog.slice(0, firstVersionIndex) + newEntry + changelog.slice(firstVersionIndex)
} else {
// No existing version entries, append to the end
changelog += newEntry
}
}
// Write the updated changelog
fs.writeFileSync(changelogPath, changelog)
console.log(`CHANGELOG.md updated with release notes for v${version}`)
// Also update the CLI package's CHANGELOG.md
const cliChangelogPath = path.join(rootDir, 'cli-package', 'CHANGELOG.md')
// Create or update the CLI CHANGELOG.md file
let cliChangelog = ''
// If CLI CHANGELOG.md exists, read its content
if (fs.existsSync(cliChangelogPath)) {
cliChangelog = fs.readFileSync(cliChangelogPath, 'utf8')
} else {
// Create a new CHANGELOG.md file with a header
cliChangelog = '# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n'
}
// Check if this version is already in the changelog
if (cliChangelog.includes(`## [${version}]`)) {
// Replace the existing entry
const versionRegex = new RegExp(`## \\[${version}\\].*?(?=## \\[|$)`, 's')
cliChangelog = cliChangelog.replace(versionRegex, newEntry)
} else {
// Add the new entry after the header (before the first version entry)
const firstVersionIndex = cliChangelog.search(/## \[\d+\.\d+\.\d+\]/)
if (firstVersionIndex !== -1) {
// Insert before the first version entry
cliChangelog = cliChangelog.slice(0, firstVersionIndex) + newEntry + cliChangelog.slice(firstVersionIndex)
} else {
// No existing version entries, append to the end
cliChangelog += newEntry
}
}
// Write the updated CLI changelog
fs.writeFileSync(cliChangelogPath, cliChangelog)
console.log(`CLI package CHANGELOG.md updated with release notes for v${version}`)
} catch (error) {
console.error('Error updating CHANGELOG.md:', error.message)
// Don't exit with error to allow the process to continue
// process.exit(1)
}

View file

@ -114,54 +114,69 @@ export function getTextDecoder(): IUniversalTextDecoder {
* that uses our text encoding utilities instead of relying on TextEncoder/TextDecoder * that uses our text encoding utilities instead of relying on TextEncoder/TextDecoder
*/ */
export function applyTensorFlowPatch(): void { export function applyTensorFlowPatch(): void {
// Only apply in Node.js environment try {
if ( // Get encoders/decoders
typeof global !== 'undefined' && const encoder = getTextEncoder()
typeof process !== 'undefined' && const decoder = getTextDecoder()
process.versions &&
process.versions.node
) {
try {
// Get encoders/decoders
const encoder = getTextEncoder()
const decoder = getTextDecoder()
// Define a custom PlatformNode class // Define a custom Platform class that works in both Node.js and browser environments
class PlatformNode { class Platform {
util: any util: any
textEncoder: any textEncoder: any
textDecoder: any textDecoder: any
constructor() { constructor() {
// Create a util object with necessary methods and constructors // Create a util object with necessary methods and constructors
this.util = { this.util = {
isFloat32Array: (arr: any) => // Add TextEncoder and TextDecoder as constructors
!!( TextEncoder: UniversalTextEncoder,
arr instanceof Float32Array || TextDecoder: UniversalTextDecoder
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
),
isTypedArray: (arr: any) =>
!!(ArrayBuffer.isView(arr) && !(arr instanceof DataView)),
// Add TextEncoder and TextDecoder as constructors
TextEncoder: UniversalTextEncoder,
TextDecoder: UniversalTextDecoder
}
// Initialize using the constructors from util
this.textEncoder = new this.util.TextEncoder()
this.textDecoder = new this.util.TextDecoder()
} }
// Initialize using the constructors from util
this.textEncoder = new this.util.TextEncoder()
this.textDecoder = new this.util.TextDecoder()
} }
// Assign the PlatformNode class to the global object // Define isFloat32Array directly on the instance
;(global as any).PlatformNode = PlatformNode isFloat32Array(arr: any) {
return !!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
)
}
// Also create an instance and assign it to global.platformNode (lowercase p) // Define isTypedArray directly on the instance
;(global as any).platformNode = new PlatformNode() isTypedArray(arr: any) {
} catch (error) { return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
console.warn('Failed to apply TensorFlow.js platform patch:', error) }
} }
// Get the global object in a way that works in both Node.js and browser
const globalObj = typeof global !== 'undefined' ? global :
typeof window !== 'undefined' ? window :
typeof self !== 'undefined' ? self :
{};
// Only apply in Node.js environment
if (
typeof process !== 'undefined' &&
process.versions &&
process.versions.node
) {
// Assign the Platform class to the global object as PlatformNode for Node.js
(globalObj as any).PlatformNode = Platform;
// Also create an instance and assign it to global.platformNode (lowercase p)
(globalObj as any).platformNode = new Platform();
} else if (typeof window !== 'undefined' || typeof self !== 'undefined') {
// In browser environments, we might need to provide similar functionality
// but we'll use a different name to avoid conflicts
(globalObj as any).PlatformBrowser = Platform;
(globalObj as any).platformBrowser = new Platform();
}
} catch (error) {
console.warn('Failed to apply TensorFlow.js platform patch:', error)
} }
} }

View file

@ -3,4 +3,4 @@
* Do not modify this file directly. * Do not modify this file directly.
*/ */
export const VERSION = '0.9.37'; export const VERSION = '0.10.0';