Skip to content

Commit

Permalink
feat: force option for patch flow
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 6, 2021
1 parent 783f4e1 commit 0bfc6bc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Default fix strategy [has been changed](https://github.com/antongolub/yarn-audit
|`--flow` | Define how `yarn.lock` is modified. `convert` — to compose `npm audit fix` with two-way lockfile conversion (legacy flow). `patch` — to directly inject audit json data | `patch`
|`--audit-level` | Include a vulnerability with a level as defined or higher. Supported values: low, moderate, high, critical | `low` | ✔ | ✔
|`--dry-run` | Get an idea of what audit fix will do | ||
|`--force` | Have audit fix install semver-major updates to toplevel dependencies, not just semver-compatible ones | `false` | ✔
|`--force` | Have audit fix install semver-major updates to toplevel dependencies, not just semver-compatible ones | `false` | ✔ | ✔
|`--help/-h`| Print help message |
|`--legacy-peer-deps` | Accept an incorrect (potentially broken) deps resolution | | ✔
|`--loglevel` | Set custom [log level](https://docs.npmjs.com/cli/v7/using-npm/config#loglevel) | | ✔
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/lockfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const patch = (
)
continue
}
if (!sv.satisfies(fix, desiredRange)) {
if (!sv.satisfies(fix, desiredRange) && !flags.force) {
console.error(
"Can't find patched version that satisfies",
depSpec,
Expand Down
7 changes: 5 additions & 2 deletions src/main/ts/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from 'chalk'
import { join } from 'path'

import { getFlow } from './flows'
import {TCallback, TContext, TFlags, TFlow, TStage} from './ifaces'
import { TCallback, TContext, TFlags, TFlow, TStage } from './ifaces'
import { getTemp, normalizeFlags, readJson } from './util'

/**
Expand Down Expand Up @@ -39,7 +39,10 @@ export const exec = (stages: TStage[], ctx: TContext): void => {
/**
* Public static void main.
*/
export const run = async (_flags: TFlags = {}, _flow?: TFlow): Promise<void> => {
export const run = async (
_flags: TFlags = {},
_flow?: TFlow,
): Promise<void> => {
const flags = normalizeFlags(_flags)
const ctx = getContext(flags)
const flow = _flow || getFlow(flags.flow)
Expand Down
4 changes: 2 additions & 2 deletions src/test/ts/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { factory as iop } from 'inside-out-promise'
import { basename, join, resolve } from 'path'
import synp from 'synp'

import {createSymlinks, run, TContext, TFlow} from '../../main/ts'
import { createSymlinks, run, TContext, TFlow } from '../../main/ts'
import * as lf from '../../main/ts/lockfile'
import { getNpm, getYarn } from '../../main/ts/util'

Expand Down Expand Up @@ -185,7 +185,7 @@ describe('yarn-audit-fix', () => {
const handler = jest.fn(noop)
const flow: TFlow = {
main: [['Test', handler]],
fallback: []
fallback: [],
}
await run({}, flow)

Expand Down

0 comments on commit 0bfc6bc

Please sign in to comment.