百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Y

yarn-audit-fix

> 包管理
开源

缺少 `yarn audit fix`

196 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

缺少 `yarn audit fix`

yarn-audit-fix The missing yarn audit fix

  • Digest
    • Problem
    • Solution
    • Key features
  • Getting started
    • Requirements
    • Install
    • CLI
    • ENV
    • JS API
  • Migration notes
    • ^11.0.0
    • ^10.0.0
    • ^9.0.0
    • ^8.0.0
    • ^7.0.0
    • ^6.0.0
    • ^4.0.0
  • ⚠️ Troubleshooting
  • Contributing
  • License

Digest

Problem

  1. yarn audit detects vulnerabilities but cannot fix them. The authors suggest Dependabot or Snyk, which is inconvenient in many setups. Discussion: yarn/issues/7075.
  2. yarn audit does not support custom (in-house) registries — see this issue & PR, still unmerged.

Solution

yarn-audit-fix fetches advisories straight from the registry (the npm bulk advisory endpoint) and patches the lockfile graph directly via lockgraph (kudos to G. Kosev, code reference). Full description: dev.to/yarn-audit-fix-for-yarn-2-berry

Key features

  • Supports every yarn lockfile schema in the wild: Yarn 1 Classic, Yarn 2/3 (berry v4–v6) and Yarn 4+ (berry v8/v9/v10), auto-detected via lockgraph.
  • Fixes vulnerabilities by patching the lockfile graph directly
  • Opt-in engine & license constraints — only apply a fix whose dependency closure runs on your target Node and passes your license policy
  • macOS / Linux / Windows
  • CLI and JS API
  • TypeScript typings

Lockfile compatibility

Yarn Lockfile schema Supported
1.x yarn-classic ✅
2.x yarn-berry-v4 ✅
3.0 yarn-berry-v5 ✅
3.1+ yarn-berry-v6 ✅
4.0–4.13 yarn-berry-v8 ✅
4.14+ yarn-berry-v9 ✅
5.x dev yarn-berry-v10 ✅

Getting started

Requirements

Node.js: >=18.12 — the highest floor in the shipped dependency closure (@yarnpkg/libzip / @yarnpkg/fslib); lockgraph itself needs only >=14.18. yaf declares no engines of its own.

Install

bash
yarn add yarn-audit-fix -D

or run it directly:

bash
npm_config_yes=true npx yarn-audit-fix

CLI

$ yarn-audit-fix [--opts]

Verifying package structure... Patching yarn.lock with audit data... Upgraded deps (1): [email protected] → 1.2.6 [critical, CVSS 9.8] GHSA-xvch-5gv4-984h Done

The lockfile is patched in place — the fix versions, their new transitive dependencies, and (for yarn berry) the package checksums are all resolved straight from the registry, so there's no reconcile yarn install step.

Option Description Default
--audit-level Include a vulnerability with a level as defined or higher. Supported values: low, moderate, high, critical all
--cwd Current working dir process.cwd()
--dry-run Get an idea of what audit fix will do
--json Print the outcome as JSON — { dryRun, upgraded, skipped, excluded, noFix } — instead of the human summary; pairs with --dry-run for a machine-readable preview. false
--force Apply cross-major fixes: bump past a consumer's declared range, and rewrite a direct-dep range in package.json (root or a workspace) that the fix falls outside. See Direct-dependency pins false
--help/-h Print help message
--npm-path Switch to project's local npm version instead of system default. Or provide a custom path. system / local / system
--registry Custom registry url
--silent Disable log output false
--verbose Switch log level to verbose/debug false
--exclude Packages to skip updating — comma-separated glob[@range] rules (e.g. lodash,@scope/*@>=2 Only apply a fix whose completed dependency closure runs on the given engine — --engines.node='>=18', =floor (infer from the installed tree), or bare --engines.node (the Node running the CLI). Repeatable per engine. See Constraints.
--license.allow / --license.deny Only apply a fix whose closure's SPDX licenses pass the policy — --license.allow=MIT,ISC (or bare --license=MIT,ISC) / --license.deny=GPL-3.0. See Constraints.
--package-type Only apply a fix whose closure stays require-able — cjs rejects an ESM-only dependency a CommonJS tree can't require(). See Constraints.
--on-conflict What to do when a fix can't satisfy the engine / license / package-type constraints: skip (leave it, report) or stop (error). skip
--safe Fix only what's safe on every automatable axis (the opposite of --force): bundles --engines.node=floor + --package-type=cjs (the latter only in a CommonJS project). See Constraints.
--production / --prod Fix only advisories reachable from production dependencies (dependencies / optionalDependencies / peerDependencies); dev-only ones are left and reported. See Scope. false
--workspace Monorepo: fix only the selected workspaces' closures — comma-separated globs on a workspace's name / path / path-basename (e.g. @scope/core, packages/*, core,cli). See Scope.

Constraints (engines & licenses)

By default a fix is the lowest published version that clears the advisory. You can add opt-in acceptance gates so a fix is only applied when its completed dependency closure also satisfies a policy — otherwise the vulnerability is left in place and reported (or, with --on-conflict=stop, the run errors).

  • Engines — --engines.node='>=18' accepts a fix only if every new package it pulls in runs on Node ≥ 18. This catches the case where a security bump quietly drags in a transitive that needs a newer runtime than your project targets — the install passes, but CI/production on the old Node breaks. A bare --engines.node uses the Node running the CLI (printed in the report, since that may differ from your project's target); pass an explicit range to be sure, or --engines.node=floor to infer it from what your tree already requires (the highest engines floor across the root package.json + installed node_modules) — a fix is then rejected only if it would raise that floor. Any engine works (--engines.npm='>=9'), lenient by npm parity — a package that declares no engines is accepted.
  • Licenses — --license.allow=MIT,ISC,Apache-2.0 (or --license.deny=GPL-3.0) accepts a fix only if the SPDX license of every new package it pulls in passes the allow/deny policy. A bare --license=MIT,ISC is an allow list. An unresolvable SPDX expression ((MIT OR X)) is flagged, not silently accepted.
  • Package format — --package-type=cjs accepts a fix only if every new package it pulls in stays require-able: a dependency that has gone ESM-only ("type": "module" with no CJS main/exports) would break every require() of it in a CommonJS tree, so the fix is left for you to take deliberately. It's a consistency check on entry points, not a runtime one — yaf can't prove your code runs, but it can catch a fix that flips a dependency's module format.

Every skip is attributed in the report — the axis, the blocking package, and the versions tried — so you can widen the target, --exclude the package, or accept the newer dependency:

Constraints: node >=18
Skipped (constraints — no fix keeps the closure within the policy [node >=18]; …):
  [email protected] → 4.18.0 — needs some-dep@^2.0.0

Constraints gate a fix's dependency closure (the transitives it pulls in), not the fixed package's own engines/license.

--safe rolls the automatable gates into one flag — the opposite of --force. It's shorthand for --engines.node=floor (don't raise the engine floor your tree already stands on) plus --package-type=cjs in a CommonJS project (don't introduce an ESM-only dependency). So yarn-audit-fix --safe means fix everything you can without changing what my project runs on or how it loads — and flags the rest for a deliberate follow-up. (License stays an explicit policy; --safe doesn't guess it.)

Direct-dependency pins

If a fix falls outside a direct dependency's declared range in package.json (an exact pin like "lodash": "4.17.11", or a range that can't reach the fix), the package is flagged and skipped by default — the fix is never silently applied behind a manifest that forbids it. Re-run with --force to rewrite that range in place (preserving the ^ / ~ / exact operator) and apply the bump, matching npm audit fix --force. In a monorepo the pin is found and rewritten in the workspace package.json that declares it — the report names the file:

Skipped (pa

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptlockfilesecurityvulnerabilityyarn

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image