Skip to content

Instantly share code, notes, and snippets.

@artalar
Created July 26, 2025 18:59
Show Gist options
  • Save artalar/0f4abc938175005efaa799d940b24aea to your computer and use it in GitHub Desktop.
Save artalar/0f4abc938175005efaa799d940b24aea to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
import { execSync } from "child_process"
import { createHash } from "crypto"
import { mkdir, readFile, writeFile } from "fs/promises"
const cacheDir = "./node_modules/.cache"
const cachePath = `${cacheDir}/deps_check_lock_hash.txt`
await mkdir(cacheDir, { recursive: true }).catch(() => {})
const lockContent = await readFile("package-lock.json", "utf-8").catch(() => "")
const lockHash = createHash("sha256").update(lockContent).digest("hex")
const lockHashCache = await readFile(cachePath, "utf-8").catch(() => "")
if (lockHashCache !== lockHash) {
execSync("npm i", { stdio: "inherit" })
await writeFile(cachePath, lockHash)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment