Skip to content

Commit 9cb4bfd

Browse files
authored
Add 2FA support for npm version 9+ (#693)
1 parent eba203f commit 9cb4bfd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

source/npm/enable-2fa.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import {execa} from 'execa';
22
import {from, catchError} from 'rxjs';
3+
import semver from 'semver';
34
import handleNpmError from './handle-npm-error.js';
5+
import {version as npmVersionCheck} from './util.js';
46

5-
export const getEnable2faArgs = (packageName, options) => {
6-
const args = ['access', '2fa-required', packageName];
7+
export const getEnable2faArgs = async (packageName, options) => {
8+
const npmVersion = await npmVersionCheck();
9+
const args = semver.satisfies(npmVersion, '>=9.0.0') ? ['access', 'set', 'mfa=publish', packageName] : ['access', '2fa-required', packageName];
710

811
if (options && options.otp) {
912
args.push('--otp', options.otp);

0 commit comments

Comments
 (0)