Files
gru_emoney_token-factory/api/PNPM_SETUP.md
defiQUG 651ff4f7eb Initial project setup: Add contracts, API definitions, tests, and documentation
- Add Foundry project configuration (foundry.toml, foundry.lock)
- Add Solidity contracts (TokenFactory138, BridgeVault138, ComplianceRegistry, etc.)
- Add API definitions (OpenAPI, GraphQL, gRPC, AsyncAPI)
- Add comprehensive test suite (unit, integration, fuzz, invariants)
- Add API services (REST, GraphQL, orchestrator, packet service)
- Add documentation (ISO20022 mapping, runbooks, adapter guides)
- Add development tools (RBC tool, Swagger UI, mock server)
- Update OpenZeppelin submodules to v5.0.0
2025-12-12 10:59:41 -08:00

3.1 KiB

pnpm Workspace Setup

This API project uses pnpm as the package manager with workspace support.

Why pnpm?

  • Faster: Up to 2x faster than npm
  • Disk efficient: Shared dependency store
  • Strict: Better dependency resolution
  • Workspace support: Native monorepo support
  • Security: Better handling of peer dependencies

Installation

Install pnpm

# Using npm
npm install -g pnpm

# Using curl (Linux/Mac)
curl -fsSL https://get.pnpm.io/install.sh | sh -

# Using Homebrew (Mac)
brew install pnpm

# Verify
pnpm --version

Workspace Structure

The api/ directory is a pnpm workspace containing:

api/
├── services/          # Service packages
├── shared/            # Shared utility packages
├── packages/          # Specification packages
└── tools/             # Development tool packages

Workspace Configuration

  • pnpm-workspace.yaml: Defines workspace packages
  • .npmrc: pnpm configuration
  • .pnpmfile.cjs: Workspace hooks for dependency management

Common Commands

Install Dependencies

# Install all workspace dependencies
cd api
pnpm install

# Install for specific package
cd api/services/rest-api
pnpm install

Add Dependencies

# Add to specific package
cd api/services/rest-api
pnpm add express

# Add dev dependency to workspace root
cd api
pnpm add -D -w typescript

# Add workspace package
cd api/services/rest-api
pnpm add @emoney/blockchain
# (automatically uses workspace:*)

Run Scripts

# Run script in specific package
cd api/services/rest-api
pnpm run dev

# Run script in all packages
cd api
pnpm -r run build

# Run script in filtered packages
cd api
pnpm --filter "@emoney/*" run test

Build

# Build all packages
cd api
pnpm run build:all

# Build specific package
cd api/services/rest-api
pnpm run build

Workspace Protocol

Internal packages use workspace:* protocol:

{
  "dependencies": {
    "@emoney/blockchain": "workspace:*",
    "@emoney/validation": "workspace:*"
  }
}

This is automatically handled by .pnpmfile.cjs.

Lock File

The pnpm-lock.yaml file should be committed to version control. It ensures:

  • Consistent dependency versions across environments
  • Reproducible builds
  • Faster installs in CI/CD

Troubleshooting

Clear Cache

pnpm store prune

Reinstall Everything

cd api
rm -rf node_modules
rm pnpm-lock.yaml
pnpm install

Check Workspace

cd api
pnpm list -r --depth=0

Migration from npm

If migrating from npm:

  1. Remove package-lock.json files
  2. Remove node_modules directories
  3. Install with pnpm: pnpm install
  4. Commit pnpm-lock.yaml

CI/CD

GitHub Actions Example

- name: Setup pnpm
  uses: pnpm/action-setup@v2
  with:
    version: 8

- name: Setup Node.js
  uses: actions/setup-node@v3
  with:
    node-version: 18
    cache: 'pnpm'

- name: Install dependencies
  run: pnpm install --frozen-lockfile

- name: Build
  run: pnpm run build:all

Resources