@@ -11,15 +11,16 @@ jobs:
1111 os : [ubuntu-latest, macos-latest, windows-latest]
1212
1313 steps :
14- - uses : actions/checkout@v4
14+ - uses : actions/checkout@v6
1515
1616 - name : Setup Node.js
1717 id : setup-node
1818 uses : actions/setup-node@v6
1919 with :
2020 node-version : ' 21'
21+ cache : false
2122
22- # Normalize runner.arch to lowercase for consistent cache keys
23+ # Normalize runner.arch to lowercase (same as Go)
2324 - name : Normalize runner architecture (Linux/macOS)
2425 if : runner.os != 'Windows'
2526 shell : bash
@@ -33,27 +34,36 @@ jobs:
3334 $arch = "${{ runner.arch }}".ToLower()
3435 echo "ARCH=$arch" | Out-File $env:GITHUB_ENV -Append
3536
36- # Capture npm cache directory
37- - name : Set npm cache path (Linux/macOS)
38- if : runner.os != 'Windows'
37+ # Detect package-manager and cache location (Node equivalent of `go env`)
38+ - name : Set Node cache variables
39+ shell : bash
3940 run : |
40- echo "NPM_CACHE=$(npm config get cache)" >> $GITHUB_ENV
41+ const fs = require('fs');
42+ const { execSync } = require('child_process');
4143
42- - name : Set npm cache path (Windows)
43- if : runner.os == 'Windows'
44- shell : pwsh
45- run : |
46- echo "NPM_CACHE=$(npm config get cache)" | Out-File $env:GITHUB_ENV -Append
44+ let cache;
45+
46+ if (fs.existsSync('pnpm-lock.yaml')) {
47+ cache = execSync('pnpm store path').toString().trim();
48+ } else if (fs.existsSync('yarn.lock')) {
49+ cache = execSync('yarn cache dir').toString().trim();
50+ } else {
51+ cache = execSync('npm config get cache').toString().trim();
52+ }
4753
48- # Restore npm cache explicitly (optional if using cache: 'npm')
49- - name : Restore npm cache
54+ fs.appendFileSync(process.env.GITHUB_ENV, `NODE_CACHE=${cache}\n`);
55+
56+ # Restore Node cache (mirrors Restore Go cache)
57+ - name : Restore Node cache
58+ id : node-cache
5059 uses : actions/cache/restore@v5
5160 with :
52- path : ${{ env.NPM_CACHE }}
53- key : node-cache- ${{ runner.os }}-${{ env.ARCH }}-${{ env.packagemanager }}-${{ hashFiles('**/package- lock.json ') }}
61+ path : ${{ env.NODE_CACHE }}
62+ key : setup- node-${{ runner.os }}-${{ env.ARCH }}-node- ${{ steps.setup-node.outputs.node-version }}-${{ hashFiles('**/* lock* ') }}
5463
5564 - name : Install dependencies
5665 run : npm ci
5766
5867 - name : Build
5968 run : npm run build --if-present
69+
0 commit comments