Skip to content

Conversation

@r-near
Copy link
Contributor

@r-near r-near commented Oct 24, 2025

Summary

This PR transforms near-api-js into a unified, tree-shakeable package that bundles all @near-js/* packages, similar to how Zod works.

Breaking Changes

⚠️ BREAKING CHANGE: Major refactor for v7.0.0

  • Removed deprecated Near class
  • Removed deprecated connect() function
  • All @near-js/* packages are now bundled into the main package

Changes

Package Structure

  • ✨ Created unified src/index.ts that exports from all @near-js/* packages
  • 📦 Bundle all @near-js/* code into single package (300KB ESM, 309KB CJS)
  • 🗑️ Removed duplicate source files (all now re-export from workspace packages)

Configuration

  • ⚙️ Updated tsup.config.ts to bundle @near-js/* while keeping external deps external
  • 📝 Configured proper package.json exports for ESM/CJS compatibility
  • 🔧 Added type: "module" with dual format support
  • 🎯 Updated lint scripts to use proper ESLint configuration

Dependencies

  • ➕ Added all necessary dependencies from bundled packages
  • 🔗 Updated to include randombytes, secp256k1, and other peer deps

Benefits

Single package installation - no need to install multiple @near-js/* packages
Tree-shakeable - bundlers only include what you import
Modern ESM + CJS - dual format with proper exports field
163 total exports - all functionality from all packages
Works like popular packages - similar to Zod, etc.

Usage

// Tree-shakeable - only imports what you use!
import { Account, JsonRpcProvider, KeyPair } from 'near-api-js';

// Or CommonJS
const { Account, JsonRpcProvider } = require('near-api-js');

Testing

  • ✅ Build passes
  • ✅ Linting passes
  • ✅ Exports verified (163 exports)
  • ✅ CJS and ESM formats both work

Migration Guide

For users upgrading from v6:

Before:

import { Near, connect } from 'near-api-js';
const near = await connect(config);

After:

import { Account, Connection } from 'near-api-js';
const connection = Connection.fromConfig({...});
const account = new Account('accountId', connection.provider, connection.signer);

Next Steps

  • Update documentation
  • Add migration guide to docs
  • Update examples
  • Consider publishing as v7.0.0-beta for testing

BREAKING CHANGE: This is a major refactor that unifies all @near-js/*
packages into a single near-api-js package with tree-shaking support.

Changes:
- Replace duplicate source files with unified index.ts exporting from
  @near-js/* packages
- Bundle all @near-js/* code into main package (300KB ESM, 309KB CJS)
- Configure proper package.json exports for ESM/CJS compatibility
- Update tsup config to bundle @near-js/* while keeping external deps
  external
- Remove deprecated Near class and connect() function
- Add all necessary dependencies from bundled packages

Benefits:
- Single package installation (no multiple @near-js/* packages needed)
- Tree-shakeable: bundlers only include what you import
- Modern ESM + CJS dual format with proper exports
- 163 total exports from all packages
- Works like popular packages (Zod, etc.)

Usage:
import { Account, JsonRpcProvider, KeyPair } from 'near-api-js';
@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2025

⚠️ No Changeset found

Latest commit: 8ddf3fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@r-near
Copy link
Contributor Author

r-near commented Nov 10, 2025

Closing in favor of #1665

@r-near r-near closed this Nov 10, 2025
@github-project-automation github-project-automation bot moved this from NEW❗ to Shipped 🚀 in DevTools Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Shipped 🚀

Development

Successfully merging this pull request may close these issues.

2 participants