# NPM Publishing Guide - @ruvector/core **Date:** 2025-11-21 **Status:** โœ… Package Configuration Complete ## ๐Ÿ“ฆ Package Structure ### Main Package: @ruvector/core Located in `/workspaces/ruvector/npm/core` ``` @ruvector/core/ โ”œโ”€โ”€ package.json # Main package with platform detection โ”œโ”€โ”€ dist/ # TypeScript compiled output โ”‚ โ”œโ”€โ”€ index.js โ”‚ โ”œโ”€โ”€ index.cjs โ”‚ โ””โ”€โ”€ index.d.ts โ””โ”€โ”€ platforms/ # Platform-specific binaries โ”œโ”€โ”€ linux-x64-gnu/ โ”œโ”€โ”€ linux-arm64-gnu/ โ”œโ”€โ”€ darwin-x64/ โ”œโ”€โ”€ darwin-arm64/ โ””โ”€โ”€ win32-x64-msvc/ ``` ### Platform Package Structure Each platform package (e.g., `@ruvector/core-linux-x64-gnu`) contains: ``` @ruvector/core-linux-x64-gnu/ โ”œโ”€โ”€ package.json # Platform-specific configuration โ”œโ”€โ”€ index.js # Native module loader โ”œโ”€โ”€ ruvector.node # Native binary (4.3MB) โ””โ”€โ”€ README.md # Platform documentation ``` ## ๐Ÿ”ง Package Configuration ### Main package.json (@ruvector/core) ```json { "name": "@ruvector/core", "version": "0.1.1", "description": "High-performance Rust vector database for Node.js", "main": "./dist/index.js", "types": "./dist/index.d.ts", "type": "module", "exports": { ".": { "import": "./dist/index.js", "require": "./dist/index.cjs", "types": "./dist/index.d.ts" } }, "engines": { "node": ">= 18" }, "files": [ "dist", "platforms", "native", "*.node", "README.md", "LICENSE" ], "optionalDependencies": { "@ruvector/core-darwin-arm64": "0.1.1", "@ruvector/core-darwin-x64": "0.1.1", "@ruvector/core-linux-arm64-gnu": "0.1.1", "@ruvector/core-linux-x64-gnu": "0.1.1", "@ruvector/core-win32-x64-msvc": "0.1.1" } } ``` ### Platform package.json (e.g., linux-x64-gnu) ```json { "name": "@ruvector/core-linux-x64-gnu", "version": "0.1.1", "description": "Linux x64 GNU native binding for @ruvector/core", "main": "index.js", "type": "commonjs", "os": ["linux"], "cpu": ["x64"], "engines": { "node": ">= 18" }, "files": [ "index.js", "ruvector.node", "*.node", "README.md" ] } ``` ## ๐Ÿ“‹ Pre-Publishing Checklist ### 1. Build Native Binaries โœ… ```bash # Option A: Local build (current platform only) cd npm/core npm run build # Option B: Multi-platform via GitHub Actions git push origin main # Workflow: .github/workflows/build-native.yml ``` ### 2. Verify Binary Inclusion โœ… ```bash cd npm/core/platforms/linux-x64-gnu npm pack --dry-run # Expected output: # - 4 files total # - 4.5 MB unpacked size # - ruvector.node (4.3MB) # - index.js (330B) # - package.json (612B) # - README.md (272B) ``` ### 3. Test Package Locally โœ… ```bash cd npm/core node test-package.js # Expected output: # โœ… File structure test PASSED # โœ… Native module test PASSED # โœ… Database creation test PASSED # โœ… Basic operations test PASSED ``` ### 4. Update Version Numbers ```bash # Update all package.json files to same version npm version patch # or minor, major ``` ## ๐Ÿš€ Publishing Process ### Step 1: Login to NPM ```bash # If not already logged in npm login # Verify authentication npm whoami ``` ### Step 2: Publish Platform Packages ```bash # Publish each platform package cd npm/core/platforms/linux-x64-gnu npm publish --access public cd ../linux-arm64-gnu npm publish --access public cd ../darwin-x64 npm publish --access public cd ../darwin-arm64 npm publish --access public cd ../win32-x64-msvc npm publish --access public ``` ### Step 3: Build Main Package ```bash cd npm/core npm run build # Compile TypeScript ``` ### Step 4: Publish Main Package ```bash npm publish --access public ``` ## ๐Ÿงช Testing Installation ### Test on Current Platform ```bash # In a test directory npm install @ruvector/core # Create test.js node -e " const { VectorDB } = require('@ruvector/core'); const db = new VectorDB({ dimensions: 3 }); console.log('โœ… Package installed and working!'); " ``` ### Test Platform Detection ```bash # Should auto-select correct platform package npm install @ruvector/core # Verify correct platform loaded node -e " const path = require('path'); const pkg = require('@ruvector/core/package.json'); console.log('Platform packages:', Object.keys(pkg.optionalDependencies)); " ``` ## ๐Ÿ“Š Package Sizes | Package | Unpacked Size | Compressed Size | |---------|--------------|-----------------| | @ruvector/core | ~10 KB | ~3 KB | | @ruvector/core-linux-x64-gnu | 4.5 MB | 1.9 MB | | @ruvector/core-linux-arm64-gnu | ~4.5 MB | ~1.9 MB | | @ruvector/core-darwin-x64 | ~4.5 MB | ~1.9 MB | | @ruvector/core-darwin-arm64 | ~4.5 MB | ~1.9 MB | | @ruvector/core-win32-x64-msvc | ~4.5 MB | ~1.9 MB | **Total when all platforms installed:** ~22 MB unpacked, ~9 MB compressed **Per-platform install:** ~4.5 MB (only installs matching platform) ## ๐Ÿ” Security Notes 1. **Native Binaries**: All .node files are compiled Rust code (safe) 2. **No Postinstall Scripts**: No automatic code execution 3. **Optional Dependencies**: Platforms install only when needed 4. **Scoped Package**: Published under @ruvector namespace ## ๐Ÿ› Troubleshooting ### Binary Not Found Error ``` Error: Failed to load native binding for linux-x64-gnu ``` **Solution:** 1. Check platform package is installed: `npm ls @ruvector/core-linux-x64-gnu` 2. Verify binary exists: `ls node_modules/@ruvector/core-linux-x64-gnu/ruvector.node` 3. Reinstall: `npm install --force` ### Wrong Platform Detected ``` Error: Unsupported platform: freebsd-x64 ``` **Solution:** The package only supports: linux (x64/arm64), darwin (x64/arm64), win32 (x64) ### Module Load Failed ``` Error: dlopen failed: cannot open shared object file ``` **Solution:** - Ensure Node.js >= 18 - Check system dependencies: `ldd ruvector.node` - May need: glibc 2.31+, libstdc++ ## ๐Ÿ“ˆ Maintenance ### Updating Package Version 1. Update version in all package.json files (root + all platforms) 2. Rebuild native binaries with GitHub Actions 3. Test locally with `npm pack --dry-run` 4. Publish platform packages first 5. Publish main package last ### Adding New Platform 1. Add platform to GitHub Actions matrix 2. Create new platform package directory 3. Add to optionalDependencies in main package.json 4. Update platform detection logic 5. Build and publish ## ๐Ÿ”— Related Documentation - [Build Process](./BUILD_PROCESS.md) - Multi-platform build details - [Publishing Complete](./PUBLISHING_COMPLETE.md) - Rust crates on crates.io - [Phase 2 Complete](./PHASE2_MULTIPLATFORM_COMPLETE.md) - Multi-platform architecture - [Phase 3 WASM Status](./PHASE3_WASM_STATUS.md) - WebAssembly implementation ## โœ… Verification Commands ```bash # Verify package contents npm pack --dry-run # Check file sizes du -sh npm/core/platforms/*/ruvector.node # Test all platforms (if binaries available) for platform in linux-x64-gnu linux-arm64-gnu darwin-x64 darwin-arm64 win32-x64-msvc; do echo "Testing $platform..." cd npm/core/platforms/$platform && npm pack --dry-run cd - done # Verify TypeScript compilation cd npm/core && npm run build && ls -la dist/ ``` ## ๐ŸŽฏ Success Criteria - โœ… All platform packages include 4.3MB+ ruvector.node binary - โœ… npm pack shows correct file sizes (4.5MB unpacked) - โœ… Test script passes all 4 tests - โœ… TypeScript definitions generated - โœ… Package.json files array includes all required files - โœ… Platform detection works correctly - โณ Published to npm registry (pending) - โณ Installation tested on all platforms (pending) --- **Last Updated:** 2025-11-21 **Next Steps:** Publish platform packages to npm registry