Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for --no-2fa flag #559

Merged
merged 4 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ $ np --help
--no-yarn Don't use Yarn
--contents Subdirectory to publish
--no-release-draft Skips opening a GitHub release draft
--no-2fa Don't enable 2FA on new packages (not recommended)

Examples
$ np
Expand Down Expand Up @@ -93,6 +94,7 @@ Currently, these are the flags you can configure:
- `yarn` - Use yarn if possible (`true` by default).
- `contents` - Subdirectory to publish (`.` by default).
- `releaseDraft` - Open a GitHub release draft after releasing (`true` by default).
- `2fa` - Enable 2FA on new packages (`true` by default) (not recommended).
G-Rath marked this conversation as resolved.
Show resolved Hide resolved

For example, this configures `np` to never use Yarn and to use `dist` as the subdirectory to publish:

Expand Down
11 changes: 10 additions & 1 deletion source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const cli = meow(`
--no-yarn Don't use Yarn
--contents Subdirectory to publish
--no-release-draft Skips opening a GitHub release draft
--no-2fa Don't enable 2FA on new packages (not recommended)

Examples
$ np
Expand Down Expand Up @@ -74,6 +75,9 @@ const cli = meow(`
},
preview: {
type: 'boolean'
},
'2fa': {
type: 'boolean'
}
}
});
Expand All @@ -88,7 +92,8 @@ updateNotifier({pkg: cli.pkg}).notify();
tests: true,
publish: true,
releaseDraft: true,
yarn: hasYarn()
yarn: hasYarn(),
'2fa': true
};

const localConfig = await config();
Expand All @@ -99,6 +104,10 @@ updateNotifier({pkg: cli.pkg}).notify();
...cli.flags
};

if ('2Fa' in flags) {
flags['2fa'] = flags['2Fa'];
}
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved

const runPublish = flags.publish && !pkg.private;

const availability = flags.publish ? await isPackageNameAvailable(pkg) : {
Expand Down
2 changes: 1 addition & 1 deletion source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ module.exports = async (input = 'patch', options) => {
]);

const isExternalRegistry = npm.isExternalRegistry(pkg);
if (options.availability.isAvailable && !options.availability.isUnknown && !pkg.private && !isExternalRegistry) {
if (options['2fa'] && options.availability.isAvailable && !options.availability.isUnknown && !pkg.private && !isExternalRegistry) {
tasks.add([
{
title: 'Enabling two-factor authentication',
Expand Down
28 changes: 28 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@ test('skip enabling 2FA if the package exists', async t => {

t.true(enable2faStub.notCalled);
});

test('skip enabling 2FA if the `2fa` option is false', async t => {
const enable2faStub = sinon.stub();

const np = proxyquire('../source', {
del: sinon.stub(),
execa: sinon.stub().returns({pipe: sinon.stub()}),
'./prerequisite-tasks': sinon.stub(),
'./git-tasks': sinon.stub(),
'./git-util': {
hasUpstream: sinon.stub().returns(true),
push: sinon.stub()
},
'./npm/enable-2fa': enable2faStub,
'./npm/publish': sinon.stub().returns({pipe: sinon.stub()})
});

await t.notThrowsAsync(np('1.0.0', {
...defaultOptions,
availability: {
isAvailable: true,
isUnknown: false
},
'2fa': false
}));

t.true(enable2faStub.notCalled);
});