Skip to content

Commit d2830f2

Browse files
feat: integrate lerna cache
TICKET: WP-6096
1 parent 1f7bcd8 commit d2830f2

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ modules/**/pack-scoped/
1818
coverage
1919
/.direnv/
2020
.claude/
21+
.nx/
22+
CLAUDE.sessions.md
23+
sessions/

CLAUDE.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,45 @@ yarn integration-test
5454
yarn coverage
5555
```
5656

57+
### Test Caching
58+
BitGoJS uses Lerna + Nx for local test caching to speed up development:
59+
60+
```bash
61+
# Tests are automatically cached when you run them
62+
yarn unit-test
63+
64+
# Cache status is shown in output:
65+
# - Fresh run: Tests execute normally
66+
# - Cache hit: "[existing outputs match the cache, left as is]"
67+
68+
# Clear cache if needed
69+
rm -rf .nx/cache
70+
71+
# Cache works with all test commands
72+
yarn unit-test --scope @bitgo/sdk-core # Caches per package
73+
yarn unit-test-changed # Caches changed packages
74+
```
75+
76+
The cache automatically invalidates when:
77+
- Source files change
78+
- Test files change
79+
- Dependencies change
80+
- Configuration files change (tsconfig.json, .mocharc.*, package.json)
81+
82+
**Note for CI**: Nx caching requires proper dependency management. Tests depend on build outputs, so ensure packages are built before running tests. The `yarn postinstall` step must run even when node_modules are cached.
83+
84+
If you encounter TypeScript module resolution errors in CI, you can disable Nx caching by:
85+
```bash
86+
# Option 1: Use --skip-nx-cache flag
87+
yarn unit-test --skip-nx-cache
88+
89+
# Option 2: Set environment variable
90+
NX_SKIP_NX_CACHE=true yarn unit-test
91+
92+
# Option 3: Temporarily disable in lerna.json
93+
# Set "useNx": false
94+
```
95+
5796
### Browser Compatibility
5897
```bash
5998
# Run browser tests
@@ -121,3 +160,7 @@ This will generate the necessary boilerplate for a new coin implementation.
121160
## Node.js Version Support
122161

123162
BitGoJS supports Node.js versions >=20 and <23, with NPM >=3.10.10.
163+
164+
## Sessions System Behaviors
165+
166+
@CLAUDE.sessions.md

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
}
88
},
99
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
10-
"useNx": false
10+
"useNx": true
1111
}

nx.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"$schema": "./node_modules/nx/schemas/nx-schema.json",
3+
"tasksRunnerOptions": {
4+
"default": {
5+
"runner": "nx/tasks-runners/default",
6+
"options": {
7+
"cacheableOperations": ["build", "unit-test", "integration-test"],
8+
"cacheDirectory": ".nx/cache",
9+
"parallel": 3,
10+
"skipNxCache": false
11+
}
12+
}
13+
},
14+
"targetDefaults": {
15+
"build": {
16+
"cache": true,
17+
"dependsOn": ["^build"],
18+
"inputs": [
19+
"production",
20+
"{projectRoot}/**/*.json",
21+
"{projectRoot}/tsconfig.json",
22+
"{projectRoot}/package.json",
23+
"{workspaceRoot}/tsconfig.json",
24+
"{workspaceRoot}/tsconfig.packages.json"
25+
],
26+
"outputs": [
27+
"{projectRoot}/dist"
28+
]
29+
},
30+
"unit-test": {
31+
"cache": true,
32+
"dependsOn": ["build"],
33+
"inputs": [
34+
"default",
35+
"{projectRoot}/**/*.ts",
36+
"{projectRoot}/**/*.js",
37+
"{projectRoot}/**/*.json",
38+
"{projectRoot}/.mocharc.*",
39+
"{projectRoot}/tsconfig.json",
40+
"{projectRoot}/package.json",
41+
"{workspaceRoot}/tsconfig.json"
42+
],
43+
"outputs": [
44+
"{projectRoot}/.nyc_output",
45+
"{projectRoot}/coverage"
46+
]
47+
},
48+
"integration-test": {
49+
"cache": true,
50+
"dependsOn": ["build"],
51+
"inputs": [
52+
"default",
53+
"{projectRoot}/**/*.ts",
54+
"{projectRoot}/**/*.js",
55+
"{projectRoot}/**/*.json",
56+
"{projectRoot}/.mocharc.*",
57+
"{projectRoot}/tsconfig.json",
58+
"{projectRoot}/package.json",
59+
"{workspaceRoot}/tsconfig.json"
60+
],
61+
"outputs": [
62+
"{projectRoot}/.nyc_output",
63+
"{projectRoot}/coverage"
64+
]
65+
}
66+
},
67+
"namedInputs": {
68+
"default": [
69+
"{projectRoot}/**/*",
70+
"!{projectRoot}/**/*.md",
71+
"!{projectRoot}/**/*.spec.ts",
72+
"!{projectRoot}/**/*.spec.js",
73+
"!{projectRoot}/**/test/**",
74+
"!{projectRoot}/.nyc_output/**",
75+
"!{projectRoot}/coverage/**",
76+
"!{projectRoot}/dist/**",
77+
"!{projectRoot}/lib/**",
78+
"!{projectRoot}/node_modules/**"
79+
],
80+
"production": [
81+
"default",
82+
"!{projectRoot}/**/*.spec.ts",
83+
"!{projectRoot}/**/test/**"
84+
]
85+
}
86+
}

0 commit comments

Comments
 (0)