11import fs from 'fs/promises'
22import os from 'os'
3- import { join } from 'path'
3+ import { join , dirname } from 'path'
4+ import { createHash } from 'crypto'
5+ import { fileURLToPath } from 'url'
46import {
57 saveCache ,
68 restoreCache
@@ -9,14 +11,27 @@ import { exec } from '@actions/exec'
911import { getQuery } from '@simple-release/config'
1012import requireResolve from './resolve.cjs'
1113
12- const NPM_CLI = requireResolve ( 'npm' ) . replace ( 'index.js' , join ( 'bin' , 'npm-cli.js' ) )
14+ const DIR = dirname ( fileURLToPath ( import . meta . url ) )
1315const DEPENDENCIES_DIR = join ( os . homedir ( ) , '.simple-release-dependencies' )
16+ const NPM_CLI = requireResolve ( 'npm' ) . replace ( 'index.js' , join ( 'bin' , 'npm-cli.js' ) )
17+
18+ async function getDependenciesHash ( ) {
19+ try {
20+ const packageLockPath = join ( DIR , '..' , 'package-lock.json' )
21+ const packageLockContent = await fs . readFile ( packageLockPath , 'utf8' )
22+
23+ return createHash ( 'sha256' ) . update ( packageLockContent ) . digest ( 'hex' ) . substring ( 0 , 8 )
24+ } catch {
25+ return ''
26+ }
27+ }
1428
15- function getCacheKeyFromConfig ( config ) {
29+ async function getCacheKeyFromConfig ( config ) {
1630 const projectQuery = getQuery ( config . project )
1731 const hostingQuery = getQuery ( config . hosting )
32+ const packageLockHash = await getDependenciesHash ( )
1833
19- return [ projectQuery , hostingQuery ] . filter ( Boolean ) . join ( '+' )
34+ return [ projectQuery , hostingQuery , packageLockHash ] . filter ( Boolean ) . join ( '+' )
2035}
2136
2237async function install ( pkg , version ) {
@@ -55,7 +70,7 @@ let cacheKey = null
5570
5671export async function lazyDependencyImport ( pkg , version , config ) {
5772 if ( cacheStatus === CACHE_NOT_CHECKED ) {
58- cacheKey = getCacheKeyFromConfig ( config )
73+ cacheKey = await getCacheKeyFromConfig ( config )
5974
6075 const hit = await restoreCache (
6176 [ DEPENDENCIES_DIR ] ,
0 commit comments