Skip to content

Commit

Permalink
feat: add cwd option
Browse files Browse the repository at this point in the history
closes #135
  • Loading branch information
antongolub committed Oct 11, 2021
1 parent 72563ba commit 4ff467b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ success Already up-to-date.
|---|---|---|---|
|`--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`
|`--cwd` | Current working dir | `process.cwd()`
|`--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`
|`--help/-h`| Print help message |
Expand All @@ -121,7 +122,7 @@ Typedoc: [https://antongolub.github.io/yarn-audit-fix/modules/](https://antongol
```ts
import { run, runSync } from 'yarn-audit-fix'

// NOTE actually it's promisified run.sync
// NOTE actually it's promisified `run.sync`
await run({
flow: 'patch',
verbose: true
Expand Down
5 changes: 5 additions & 0 deletions src/main/ts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const flags = new Command()
.choices(['low', 'moderate', 'high', 'critical'])
.default(env.YAF_AUDIT_LEVEL),
)
.option(
'--cwd [path]',
'CWD. Defaults to `process.cwd()`',
env.YAF_CWD,
)
.option(
'--dry-run [bool]',
'Get an idea of what audit fix will do',
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getTemp, normalizeFlags, readJson } from './util'
* Build running context.
*/
export const getContext = (flags: TFlags = {}): TContext => {
const cwd = process.cwd()
const cwd = flags.cwd || process.cwd()
const manifest = readJson(join(cwd, 'package.json'))
const temp = getTemp(cwd, flags.temp)
const ctx = {
Expand Down
25 changes: 24 additions & 1 deletion src/test/ts/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fs = (await import('fs-extra')).default
const synp = (await import('synp')).default

const lf = (await import('../../main/ts/lockfile'))._internal
const { createSymlinks, run } = await import('../../main/ts')
const { createSymlinks, getContext, run, runSync } = await import('../../main/ts')
const { getNpm, getYarn } = await import('../../main/ts/util')

const __dirname = dirname(fileURLToPath(import.meta.url))
Expand Down Expand Up @@ -330,4 +330,27 @@ describe('yarn-audit-fix', () => {
})
})
})

describe('#getContext', () => {
it('parses flags, returns ctx entry', () => {
const cwd = '/foo/bar'
const bar = 'baz'
const ctx = getContext({
cwd,
bar
})

expect(ctx).toEqual(expect.objectContaining({
cwd,
flags: { cwd, bar },
manifest: { version: '1.0.0' }
}))
})
})

describe('aliases', () => {
it('runSync eq run.sync', () => {
expect(run.sync).toBe(runSync)
})
})
})

0 comments on commit 4ff467b

Please sign in to comment.