Skip to content

Commit 5cc5afc

Browse files
authored
feat: improve Metro caching support (#74)
Metro cache is now stored under `.harness/metro-cache` in the project root. Set `unstable__enableMetroCache: true` in your config to use it; Harness will log when reusing the cache between runs. In CI, you can cache `.harness/metro-cache` to speed up Metro bundling.
1 parent 7451764 commit 5cc5afc

24 files changed

Lines changed: 295 additions & 48 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') || (github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android')) }}
3131
env:
3232
HARNESS_DEBUG: true
33+
DEBUG: 'Metro:*'
3334
steps:
3435
- name: Checkout code
3536
uses: actions/checkout@v4
@@ -59,10 +60,10 @@ jobs:
5960
- name: Metro cache
6061
uses: actions/cache@v4
6162
with:
62-
path: apps/playground/node_modules/.cache/rn-harness/metro-cache
63-
key: metro-cache-${{ hashFiles('apps/playground/node_modules/.cache/rn-harness/metro-cache/**/*') }}
63+
path: apps/playground/.harness/metro-cache
64+
key: ${{ runner.os }}-metro-cache-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/pnpm-lock.yaml', '**/yarn.lock', '**/metro.config.js', '**/metro.config.cjs', '**/metro.config.mjs', '**/metro.config.ts', '**/babel.config.js', '**/babel.config.cjs', '**/babel.config.mjs', '**/babel.config.ts', '**/babel.config.json') }}
6465
restore-keys: |
65-
metro-cache
66+
${{ runner.os }}-metro-cache-
6667
6768
- name: Install dependencies
6869
run: |
@@ -110,6 +111,8 @@ jobs:
110111
runs-on: macos-latest
111112
timeout-minutes: 30
112113
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') || (github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'ios')) }}
114+
env:
115+
DEBUG: 'Metro:*'
113116
steps:
114117
- name: Checkout code
115118
uses: actions/checkout@v4
@@ -131,10 +134,10 @@ jobs:
131134
- name: Metro cache
132135
uses: actions/cache@v4
133136
with:
134-
path: apps/playground/node_modules/.cache/rn-harness/metro-cache
135-
key: metro-cache-${{ hashFiles('apps/playground/node_modules/.cache/rn-harness/metro-cache/**/*') }}
137+
path: apps/playground/.harness/metro-cache
138+
key: ${{ runner.os }}-metro-cache-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/pnpm-lock.yaml', '**/yarn.lock', '**/metro.config.js', '**/metro.config.cjs', '**/metro.config.mjs', '**/metro.config.ts', '**/babel.config.js', '**/babel.config.cjs', '**/babel.config.mjs', '**/babel.config.ts', '**/babel.config.json') }}
136139
restore-keys: |
137-
metro-cache
140+
${{ runner.os }}-metro-cache-
138141
139142
- name: Install Watchman
140143
run: brew install watchman
@@ -199,6 +202,7 @@ jobs:
199202
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') || (github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'web')) }}
200203
env:
201204
HARNESS_DEBUG: true
205+
DEBUG: 'Metro:*'
202206
steps:
203207
- name: Checkout code
204208
uses: actions/checkout@v4
@@ -220,10 +224,10 @@ jobs:
220224
- name: Metro cache
221225
uses: actions/cache@v4
222226
with:
223-
path: apps/playground/node_modules/.cache/rn-harness/metro-cache
224-
key: metro-cache-${{ hashFiles('apps/playground/node_modules/.cache/rn-harness/metro-cache/**/*') }}
227+
path: apps/playground/.harness/metro-cache
228+
key: ${{ runner.os }}-metro-cache-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/pnpm-lock.yaml', '**/yarn.lock', '**/metro.config.js', '**/metro.config.cjs', '**/metro.config.mjs', '**/metro.config.ts', '**/babel.config.js', '**/babel.config.cjs', '**/babel.config.mjs', '**/babel.config.ts', '**/babel.config.json') }}
225229
restore-keys: |
226-
metro-cache
230+
${{ runner.os }}-metro-cache-
227231
228232
- name: Install dependencies
229233
run: |
@@ -246,6 +250,7 @@ jobs:
246250
if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android') }}
247251
env:
248252
HARNESS_DEBUG: true
253+
DEBUG: 'Metro:*'
249254

250255
steps:
251256
- name: Checkout code
@@ -276,10 +281,10 @@ jobs:
276281
- name: Metro cache
277282
uses: actions/cache@v4
278283
with:
279-
path: apps/playground/node_modules/.cache/rn-harness/metro-cache
280-
key: metro-cache-${{ hashFiles('apps/playground/node_modules/.cache/rn-harness/metro-cache/**/*') }}
284+
path: apps/playground/.harness/metro-cache
285+
key: ${{ runner.os }}-metro-cache-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/pnpm-lock.yaml', '**/yarn.lock', '**/metro.config.js', '**/metro.config.cjs', '**/metro.config.mjs', '**/metro.config.ts', '**/babel.config.js', '**/babel.config.cjs', '**/babel.config.mjs', '**/babel.config.ts', '**/babel.config.json') }}
281286
restore-keys: |
282-
metro-cache
287+
${{ runner.os }}-metro-cache-
283288
284289
- name: Install dependencies
285290
run: |
@@ -351,6 +356,8 @@ jobs:
351356
runs-on: macos-latest
352357
timeout-minutes: 30
353358
if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'ios') }}
359+
env:
360+
DEBUG: 'Metro:*'
354361
steps:
355362
- name: Checkout code
356363
uses: actions/checkout@v4
@@ -372,10 +379,10 @@ jobs:
372379
- name: Metro cache
373380
uses: actions/cache@v4
374381
with:
375-
path: apps/playground/node_modules/.cache/rn-harness/metro-cache
376-
key: metro-cache-${{ hashFiles('apps/playground/node_modules/.cache/rn-harness/metro-cache/**/*') }}
382+
path: apps/playground/.harness/metro-cache
383+
key: ${{ runner.os }}-metro-cache-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/pnpm-lock.yaml', '**/yarn.lock', '**/metro.config.js', '**/metro.config.cjs', '**/metro.config.mjs', '**/metro.config.ts', '**/babel.config.js', '**/babel.config.cjs', '**/babel.config.mjs', '**/babel.config.ts', '**/babel.config.json') }}
377384
restore-keys: |
378-
metro-cache
385+
${{ runner.os }}-metro-cache-
379386
380387
- name: Install Watchman
381388
run: brew install watchman
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
__default__: patch
3+
---
4+
5+
Metro cache is now stored under `.harness/metro-cache` in the project root. Set `unstable__enableMetroCache: true` in your config to use it; Harness will log when reusing the cache between runs. In CI, you can cache `.harness/metro-cache` to speed up Metro bundling.

actions/android/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ runs:
117117
elif [ -f "yarn.lock" ]; then
118118
echo "manager=yarn" >> $GITHUB_OUTPUT
119119
echo "runner=yarn " >> $GITHUB_OUTPUT
120-
elif [ -f "bun.lockb" ]; then
120+
elif [ -f "bun.lock" ] || [ -f "bun.lockb" ]; then
121121
echo "manager=bun" >> $GITHUB_OUTPUT
122122
echo "runner=bunx " >> $GITHUB_OUTPUT
123123
elif [ -f "deno.lock" ]; then

actions/ios/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ runs:
5555
elif [ -f "yarn.lock" ]; then
5656
echo "manager=yarn" >> $GITHUB_OUTPUT
5757
echo "runner=yarn " >> $GITHUB_OUTPUT
58-
elif [ -f "bun.lockb" ]; then
58+
elif [ -f "bun.lock" ] || [ -f "bun.lockb" ]; then
5959
echo "manager=bun" >> $GITHUB_OUTPUT
6060
echo "runner=bunx " >> $GITHUB_OUTPUT
6161
elif [ -f "deno.lock" ]; then

actions/web/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ runs:
4343
elif [ -f "yarn.lock" ]; then
4444
echo "manager=yarn" >> $GITHUB_OUTPUT
4545
echo "runner=yarn " >> $GITHUB_OUTPUT
46-
elif [ -f "bun.lockb" ]; then
46+
elif [ -f "bun.lock" ] || [ -f "bun.lockb" ]; then
4747
echo "manager=bun" >> $GITHUB_OUTPUT
4848
echo "runner=bunx " >> $GITHUB_OUTPUT
4949
elif [ -f "deno.lock" ]; then

apps/playground/rn-harness.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export default {
117117
webSocketPort: 3002,
118118

119119
resetEnvironmentBetweenTestFiles: true,
120+
unstable__enableMetroCache: true,
120121
unstable__skipAlreadyIncludedModules: false,
121122
forwardClientLogs: true,
122123
disableViewFlattening: true,

packages/github-action/src/android/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ runs:
117117
elif [ -f "yarn.lock" ]; then
118118
echo "manager=yarn" >> $GITHUB_OUTPUT
119119
echo "runner=yarn " >> $GITHUB_OUTPUT
120-
elif [ -f "bun.lockb" ]; then
120+
elif [ -f "bun.lock" ] || [ -f "bun.lockb" ]; then
121121
echo "manager=bun" >> $GITHUB_OUTPUT
122122
echo "runner=bunx " >> $GITHUB_OUTPUT
123123
elif [ -f "deno.lock" ]; then

packages/github-action/src/ios/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ runs:
5555
elif [ -f "yarn.lock" ]; then
5656
echo "manager=yarn" >> $GITHUB_OUTPUT
5757
echo "runner=yarn " >> $GITHUB_OUTPUT
58-
elif [ -f "bun.lockb" ]; then
58+
elif [ -f "bun.lock" ] || [ -f "bun.lockb" ]; then
5959
echo "manager=bun" >> $GITHUB_OUTPUT
6060
echo "runner=bunx " >> $GITHUB_OUTPUT
6161
elif [ -f "deno.lock" ]; then

packages/github-action/src/web/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ runs:
4343
elif [ -f "yarn.lock" ]; then
4444
echo "manager=yarn" >> $GITHUB_OUTPUT
4545
echo "runner=yarn " >> $GITHUB_OUTPUT
46-
elif [ -f "bun.lockb" ]; then
46+
elif [ -f "bun.lock" ] || [ -f "bun.lockb" ]; then
4747
echo "manager=bun" >> $GITHUB_OUTPUT
4848
echo "runner=bunx " >> $GITHUB_OUTPUT
4949
elif [ -f "deno.lock" ]; then

packages/jest/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@react-native-harness/bridge": "workspace:*",
3838
"@react-native-harness/bundler-metro": "workspace:*",
3939
"@react-native-harness/config": "workspace:*",
40+
"@react-native-harness/metro": "workspace:*",
4041
"@react-native-harness/platforms": "workspace:*",
4142
"@react-native-harness/tools": "workspace:*",
4243
"chalk": "^4.1.2",

0 commit comments

Comments
 (0)