Skip to content

Commit e2fe257

Browse files
authored
chore: migrate to pnpm for improved monorepo management (openai#287)
# Migrate to pnpm for improved monorepo management ## Summary This PR migrates the Codex repository from npm to pnpm, providing faster dependency installation, better disk space usage, and improved monorepo management. ## Changes - Added `pnpm-workspace.yaml` to define workspace packages - Added `.npmrc` with optimal pnpm configuration - Updated root package.json with workspace scripts - Moved resolutions and overrides to the root package.json - Updated scripts to use pnpm instead of npm - Added documentation for the migration - Updated GitHub Actions workflow for pnpm ## Benefits - **Faster installations**: pnpm is significantly faster than npm - **Disk space savings**: pnpm's content-addressable store avoids duplication - **Strict dependency management**: prevents phantom dependencies - **Simplified monorepo management**: better workspace coordination - **Preparation for Turborepo**: as discussed, this is the first step before adding Turborepo ## Testing - Verified that `pnpm install` works correctly - Verified that `pnpm run build` completes successfully - Ensured all existing functionality is preserved ## Documentation Added a detailed migration guide in `PNPM_MIGRATION.md` explaining: - Why we're migrating to pnpm - How to use pnpm with this repository - Common commands and workspace-specific commands - Monorepo structure and configuration ## Next Steps As discussed, once this change is stable, we can consider adding Turborepo as a follow-up enhancement.
1 parent 9a046df commit e2fe257

12 files changed

Lines changed: 149 additions & 7771 deletions

File tree

.github/workflows/ci.yml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,47 @@ jobs:
1919
with:
2020
node-version: 22
2121

22-
# Run codex-cli/ tasks first because they are higher signal.
22+
- name: Setup pnpm
23+
uses: pnpm/action-setup@v4
24+
with:
25+
version: 10.8.1
26+
run_install: false
27+
28+
- name: Get pnpm store directory
29+
id: pnpm-cache
30+
shell: bash
31+
run: |
32+
echo "store_path=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
33+
34+
- name: Setup pnpm cache
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ steps.pnpm-cache.outputs.store_path }}
38+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: |
40+
${{ runner.os }}-pnpm-store-
2341
24-
- name: Install dependencies (codex-cli)
25-
working-directory: codex-cli
26-
run: npm ci
42+
- name: Install dependencies
43+
run: pnpm install
2744

28-
- name: Check formatting (codex-cli)
29-
working-directory: codex-cli
30-
run: npm run format
45+
# Run all tasks using workspace filters
3146

32-
- name: Run tests (codex-cli)
33-
working-directory: codex-cli
34-
run: npm run test
47+
- name: Check formatting
48+
run: pnpm run format
3549

36-
- name: Lint (codex-cli)
37-
working-directory: codex-cli
50+
- name: Run tests
51+
run: pnpm run test
52+
53+
- name: Lint
3854
run: |
39-
npm run lint -- \
55+
pnpm --filter @openai/codex exec -- eslint src tests --ext ts --ext tsx \
56+
--report-unused-disable-directives \
4057
--rule "no-console:error" \
4158
--rule "no-debugger:error" \
4259
--max-warnings=-1
4360
44-
- name: Type‑check (codex-cli)
45-
working-directory: codex-cli
46-
run: npm run typecheck
47-
48-
- name: Build (codex-cli)
49-
working-directory: codex-cli
50-
run: npm run build
51-
52-
# Run formatting checks in the root directory last.
53-
54-
- name: Install dependencies (root)
55-
run: npm ci
61+
- name: Type-check
62+
run: pnpm run typecheck
5663

57-
- name: Check formatting (root)
58-
run: npm run format
64+
- name: Build
65+
run: pnpm run build

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# deps
2+
# Node.js dependencies
23
node_modules
4+
.pnpm-store
5+
.pnpm-debug.log
6+
7+
# Keep pnpm-lock.yaml
8+
!pnpm-lock.yaml
39

410
# build
511
dist/

.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
shamefully-hoist=true
2+
strict-peer-dependencies=false
3+
node-linker=hoisted
4+
prefer-workspace-packages=true

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/codex-cli/dist
22
/codex-cli/node_modules
3+
pnpm-lock.yaml

PNPM_MIGRATION.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Migration to pnpm
2+
3+
This project has been migrated from npm to pnpm to improve dependency management and developer experience.
4+
5+
## Why pnpm?
6+
7+
- **Faster installation**: pnpm is significantly faster than npm and yarn
8+
- **Disk space savings**: pnpm uses a content-addressable store to avoid duplication
9+
- **Phantom dependency prevention**: pnpm creates a strict node_modules structure
10+
- **Native workspaces support**: simplified monorepo management
11+
12+
## How to use pnpm
13+
14+
### Installation
15+
16+
```bash
17+
# Global installation of pnpm
18+
npm install -g pnpm@10.8.1
19+
20+
# Or with corepack (available with Node.js 22+)
21+
corepack enable
22+
corepack prepare pnpm@10.8.1 --activate
23+
```
24+
25+
### Common commands
26+
27+
| npm command | pnpm equivalent |
28+
| --------------- | ---------------- |
29+
| `npm install` | `pnpm install` |
30+
| `npm run build` | `pnpm run build` |
31+
| `npm test` | `pnpm test` |
32+
| `npm run lint` | `pnpm run lint` |
33+
34+
### Workspace-specific commands
35+
36+
| Action | Command |
37+
| ------------------------------------------ | ---------------------------------------- |
38+
| Run a command in a specific package | `pnpm --filter @openai/codex run build` |
39+
| Install a dependency in a specific package | `pnpm --filter @openai/codex add lodash` |
40+
| Run a command in all packages | `pnpm -r run test` |
41+
42+
## Monorepo structure
43+
44+
```
45+
codex/
46+
├── pnpm-workspace.yaml # Workspace configuration
47+
├── .npmrc # pnpm configuration
48+
├── package.json # Root dependencies and scripts
49+
├── codex-cli/ # Main package
50+
│ └── package.json # codex-cli specific dependencies
51+
└── docs/ # Documentation (future package)
52+
```
53+
54+
## Configuration files
55+
56+
- **pnpm-workspace.yaml**: Defines the packages included in the monorepo
57+
- **.npmrc**: Configures pnpm behavior
58+
- **Root package.json**: Contains shared scripts and dependencies
59+
60+
## CI/CD
61+
62+
CI/CD workflows have been updated to use pnpm instead of npm. Make sure your CI environments use pnpm 10.8.1 or higher.
63+
64+
## Known issues
65+
66+
If you encounter issues with pnpm, try the following solutions:
67+
68+
1. Remove the `node_modules` folder and `pnpm-lock.yaml` file, then run `pnpm install`
69+
2. Make sure you're using pnpm 10.8.1 or higher
70+
3. Verify that Node.js 22 or higher is installed

0 commit comments

Comments
 (0)