@gilangjavier/lockscript-guard
v0.1.0
Published
Detect newly introduced npm lifecycle scripts across lockfile changes.
Maintainers
Readme
lockscript-guard
Detect newly introduced npm lifecycle scripts (preinstall, install, postinstall, prepare) when dependencies change.
lockscript-guard helps teams review lockfile-heavy pull requests by surfacing script changes that can execute during install.
Why this exists
Dependency updates can silently introduce install-time code. Reviewing this manually in large package-lock.json diffs is painful and error-prone.
lockscript-guard turns that diff into a focused report.
Install
npm i -D @gilangjavier/lockscript-guardOr run without installing:
npx @gilangjavier/lockscript-guard scanCLI usage
lockscript scan [--lockfile package-lock.json] [--format text|json] [--fail-on-risk medium|high]
lockscript diff --base <git-ref> [--head <git-ref>] \
[--lockfile package-lock.json] \
[--format text|json] \
[--fail-on-change] \
[--fail-on-risk medium|high]Example: fail CI if new lifecycle scripts appear
lockscript diff --base origin/main --fail-on-changeExample: fail CI on medium/high risk scripts
lockscript diff --base origin/main --fail-on-risk mediumLibrary API
import {
parseLockfile,
collectLifecycleScripts,
diffLifecycleScripts,
} from "@gilangjavier/lockscript-guard";
const base = collectLifecycleScripts(parseLockfile(baseLockfileText));
const head = collectLifecycleScripts(parseLockfile(headLockfileText));
const issues = diffLifecycleScripts(base, head);For AI agents
- Use
lockscript diff --base <trusted-ref> --format json. - If
count > 0, inspectissues[]and include only changed packages in your report. - For strict gates, run with
--fail-on-changeor--fail-on-risk medium.
Example:
lockscript diff --base origin/main --format json --fail-on-risk mediumFor humans
- Run this in dependency-update PRs (Renovate/Dependabot or manual updates).
- Prefer
diffoverscanin CI, because it focuses on newly introduced behavior. - If a package is flagged, review the script command and changelog before merging.
Example:
lockscript diff --base origin/mainGitHub Actions example
- name: Detect new lifecycle scripts
run: npx @gilangjavier/lockscript-guard diff --base origin/main --fail-on-changeLicense
MIT
