Skip to content

Commit

Permalink
feat: let --npm-v7 flag be applied to regular repos
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Sep 26, 2020
1 parent 13fbe34 commit 2e648fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ success Already up-to-date.
|`--only` | Set package [updating scope](https://docs.npmjs.com/cli/audit): `dev`/`prod`
|`--force` | Have audit fix install semver-major updates to toplevel dependencies, not just semver-compatible ones | false
|`--audit-level` | Include a vulnerability with a level as defined or higher. Supported values: low, moderate, high, critical | low
|`--npm-v7` | Use the latest `[email protected]` version. Applicable to monorepos only | false
|`--npm-v7` | Use the latest `[email protected]` version. Recommended for monorepos | false

## Troubleshooting
### enoent: no such file or directory
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const yarnLockToPkgLock: TCallback = ({temp}) => {
*/
const npmAuditFix: TCallback = ({temp, flags, cwd, manifest}) => {
const requireNpmBeta = !!manifest.workspaces
const npm = getNpm(requireNpmBeta, flags['npm-v7'])
const npm = getNpm(requireNpmBeta, flags['npm-v7'], flags.silent)
const defaultFlags = {
'package-lock-only': true,
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ export const getClosestNpm = (cmd: string): string => {
}, {cwd: pkgRoot}) + ''
}

export const getNpm = (requireNpmBeta?: boolean, allowNpmBeta?: boolean, isWin = isWindows()) => {
export const getNpm = (requireNpmBeta?: boolean, allowNpmBeta?: boolean, silent = false, isWin = isWindows()) => {
const cmd = isWin ? 'npm.cmd' : 'npm'

return requireNpmBeta && allowNpmBeta
if (requireNpmBeta && !allowNpmBeta && !silent) {
console.warn('The project looks like monorepo, so it is recommended to use `--npm-v7` flag')
}

return allowNpmBeta
? getClosestNpm(cmd)
: cmd
}
Expand Down
13 changes: 7 additions & 6 deletions src/test/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ describe('util', () => {
it('properly resolves npm ref', () => {
const cmd = isWindows() ? 'npm.cmd' : 'npm'
const localNpm = resolve(__dirname, '../../../node_modules/.bin', cmd)
const cases: [boolean, boolean, string][] = [
[true, true, localNpm],
[true, false, cmd],
[false, true, cmd],
const cases: [boolean, boolean, boolean, string][] = [
[true, true, true, localNpm],
[false, true, true, localNpm],
[true, false, true, cmd],
[false, false, true, cmd],
]

cases.forEach(([requireNpm7, allowNpm7, result]) => {
expect(getNpm(requireNpm7, allowNpm7)).toBe(result)
cases.forEach(([requireNpm7, allowNpm7, silent, result]) => {
expect(getNpm(requireNpm7, allowNpm7, silent)).toBe(result)
})

})
Expand Down

0 comments on commit 2e648fd

Please sign in to comment.