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

fix(owner): Fix the currently broken yarn owner command #5593

Merged
merged 2 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to specify the headers? Isn't config.registries.npm doing it for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried without headers and it didn't work, and such json headers appear in other commands also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arcanis - maybe we can add this by default in a separate diff if it is not done already?

});
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