Skip to content

Commit

Permalink
feat(cli): let --package-lock-only be configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Aug 22, 2020
1 parent 1d926bd commit c457a18
Show file tree
Hide file tree
Showing 5 changed files with 639 additions and 606 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ success Already up-to-date.
| Flag | Description | Default |
|---|---|---|
|`--verbose` | Switch log level to verbose/debug | false |
|`--package-lock-only` | Run audit fix without modifying `node_modules` | false |
|`--silent` | Disable log output | false |
|`--loglevel` | Set custom [log level](https://docs.npmjs.com/misc/config#shorthands-and-other-cli-niceties)
|`--only` | Set package [updating scope](https://docs.npmjs.com/cli/audit): `dev`/`prod`
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const audit = (auditArgs: string[], cwd: string, silent: boolean) => {
prefix: cwd,
}

!silent && console.log(chalk.bold('invoke'), 'npm', ...auditArgs, '--prefix', cwd)
!silent && console.log(chalk.bold('invoke'), 'npm', 'audit', ...auditArgs, '--prefix', cwd)

npm.load(config, (err) => {
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const yarnLockToPkgLock: TCallback = ({temp}) => {
*/
const npmAuditFix: TCallback = async({temp, flags}) => {
const auditArgs = [
'audit', 'fix', '--package-lock-only',
...formatFlags(flags, 'verbose', 'loglevel', 'only', 'force', 'audit-level', 'silent'),
'fix',
...formatFlags(flags, 'package-lock-only', 'verbose', 'loglevel', 'only', 'force', 'audit-level', 'silent'),
]

await audit(auditArgs, temp, flags.silent)
Expand Down
6 changes: 3 additions & 3 deletions src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('yarn-audit-fix', () => {
expect(npm.load).toHaveBeenCalledWith({prefix: temp}, expect.any(Function))

// @ts-ignore
expect(npm.commands.audit).toHaveBeenCalledWith(['audit', 'fix', '--package-lock-only', '--verbose'], expect.any(Function))
expect(npm.commands.audit).toHaveBeenCalledWith(['fix', '--verbose', '--package-lock-only'], expect.any(Function))

// Updating yarn.lock from package-lock.json...
expect(fs.copyFileSync).toHaveBeenCalledWith(join(temp, 'yarn.lock'), 'yarn.lock')
Expand All @@ -77,7 +77,7 @@ describe('yarn-audit-fix', () => {

describe('runner', () => {
it('invokes cmd queue with proper args', async() => {
await run({verbose: true, foo: 'bar'})
await run({verbose: true, foo: 'bar', ['package-lock-only']: true})
checkFlow()
})

Expand Down Expand Up @@ -123,7 +123,7 @@ describe('yarn-audit-fix', () => {
describe('cli', () => {
it('invokes cmd queue with proper args', () => {
jest.isolateModules(() => {
process.argv.push('--verbose')
process.argv.push('--verbose --package-lock-only')
require('../../main/ts/cli')
})
})
Expand Down
Loading

0 comments on commit c457a18

Please sign in to comment.