Skip to content

Commit

Permalink
fix(owner): Fix the currently broken yarn owner command (#5593)
Browse files Browse the repository at this point in the history
**Summary**

* fixing currently broken owner command
* doesn't ask for npm username and password for list command
* adding basic test #3893 

**Test plan**

Yarn now correctly displays the list of package owners. Also added automated tests.
  • Loading branch information
rubycut authored and BYK committed Apr 13, 2018
1 parent a23cc8e commit 8a7ee77
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
8 changes: 8 additions & 0 deletions __tests__/commands/__snapshots__/owner.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`list should show owners 1`] = `
"{\\"type\\":\\"warning\\",\\"data\\":\\"package.json: No license field\\"}
{\\"type\\":\\"step\\",\\"data\\":{\\"message\\":\\"Getting owners for package \\\\\\"yarn\\\\\\"\\",\\"current\\":1,\\"total\\":1}}
{\\"type\\":\\"info\\",\\"data\\":\\"daniel15 <[email protected]>\\"}
"
`;
26 changes: 26 additions & 0 deletions __tests__/commands/owner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* @flow */

import {JSONReporter} from '../../src/reporters/index.js';
import {run as buildRun} from './_helpers.js';
import {run as owner} from '../../src/cli/commands/owner.js';

const path = require('path');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'owner');

const runOwner = buildRun.bind(
null,
JSONReporter,
fixturesLoc,
async (args, flags, config, reporter, lockfile, getStdout): Promise<string> => {
reporter.disableProgress();
await owner(config, reporter, flags, args);
return getStdout();
},
);

test('list should show owners', async (): Promise<void> => {
await runOwner(['list', 'yarn'], {nonInteractive: true}, '', (config, reporter, stdout) => {
expect(stdout).toMatchSnapshot();
});
});
3 changes: 3 additions & 0 deletions __tests__/fixtures/owner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "yarn"
}
Binary file not shown.
14 changes: 4 additions & 10 deletions src/cli/commands/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,11 @@ async function list(config: Config, reporter: Reporter, flags: Object, args: Arr
if (args.length > 1) {
return false;
}

const name = await getName(args, config);

reporter.step(1, 3, reporter.lang('loggingIn'));
const revoke = await getToken(config, reporter, name);

reporter.step(2, 3, reporter.lang('ownerGetting', name));
const pkg = await config.registries.npm.request(name);
reporter.step(1, 1, reporter.lang('ownerGetting', name));
const pkg = await config.registries.npm.request(name, {
headers: {Accept: 'application/json'},
});
if (pkg) {
const owners = pkg.maintainers;
if (!owners || !owners.length) {
Expand All @@ -108,9 +105,6 @@ async function list(config: Config, reporter: Reporter, flags: Object, args: Arr
reporter.error(reporter.lang('ownerGettingFailed'));
}

reporter.step(3, 3, reporter.lang('revokingToken'));
await revoke();

if (pkg) {
return true;
} else {
Expand Down

0 comments on commit 8a7ee77

Please sign in to comment.