diff --git a/__tests__/commands/licenses.js b/__tests__/commands/licenses.js new file mode 100644 index 0000000000..10ebe9ae77 --- /dev/null +++ b/__tests__/commands/licenses.js @@ -0,0 +1,26 @@ +/* @flow */ + +import {JSONReporter} from '../../src/reporters/index.js'; +import {run as buildRun} from './_helpers.js'; +import {run as licenses} from '../../src/cli/commands/licenses.js'; + +const path = require('path'); + +const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'licenses'); +const expectedTable = require('../fixtures/licenses/expected-table.json'); + +const runLicenses = buildRun.bind( + null, + JSONReporter, + fixturesLoc, + async (args, flags, config, reporter, lockfile, getStdout): Promise => { + await licenses(config, reporter, flags, args); + return getStdout(); + }, +); + +test('lists all licenses of the dependencies with the --json argument', async(): Promise => { + await runLicenses(['ls'], {json: true}, '', (config, reporter, stdout) => { + expect(stdout).toContain(JSON.stringify(expectedTable)); + }); +}); diff --git a/__tests__/fixtures/licenses/expected-table.json b/__tests__/fixtures/licenses/expected-table.json new file mode 100644 index 0000000000..6c3b2575ba --- /dev/null +++ b/__tests__/fixtures/licenses/expected-table.json @@ -0,0 +1,23 @@ +{ + "type": "table", + "data": { + "head": [ + "Name", + "Version", + "License", + "URL", + "VendorUrl", + "VendorName" + ], + "body": [ + [ + "is-plain-obj", + "1.1.0", + "MIT", + "https://github.com/sindresorhus/is-plain-obj.git", + "sindresorhus.com", + "Sindre Sorhus" + ] + ] + } +} \ No newline at end of file diff --git a/__tests__/fixtures/licenses/package.json b/__tests__/fixtures/licenses/package.json new file mode 100644 index 0000000000..41999cd4a7 --- /dev/null +++ b/__tests__/fixtures/licenses/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": {}, + "dependencies": { + "is-plain-obj": "^1.1.0" + } +} diff --git a/__tests__/fixtures/licenses/yarn.lock b/__tests__/fixtures/licenses/yarn.lock new file mode 100644 index 0000000000..9019fcc3c1 --- /dev/null +++ b/__tests__/fixtures/licenses/yarn.lock @@ -0,0 +1,7 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +is-plain-obj@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e" diff --git a/src/cli/commands/licenses.js b/src/cli/commands/licenses.js index 9526e97547..73f67a4e19 100644 --- a/src/cli/commands/licenses.js +++ b/src/cli/commands/licenses.js @@ -59,12 +59,16 @@ export const {run, setFlags, examples} = buildSubCommands('licenses', { if (flags.json) { const body = []; - for (const {name, version, license, repository, homepage} of manifests) { + for (const {name, version, license, repository, homepage, author} of manifests) { + const url = repository ? repository.url : homepage; - body.push([name, version, license || 'Unknown', url || 'Unknown']); + const vendorUrl = homepage || (author && author.url); + const vendorName = (author && author.name); + body.push([name, version, license || 'Unknown', url || 'Unknown', + vendorUrl || 'Unknown', vendorName || 'Unknown']); } - reporter.table(['Name', 'Version', 'License', 'URL'], body); + reporter.table(['Name', 'Version', 'License', 'URL', 'VendorUrl', 'VendorName'], body); } else { const trees = []; diff --git a/src/types.js b/src/types.js index a02b2c1e0d..baa0f31696 100644 --- a/src/types.js +++ b/src/types.js @@ -57,6 +57,12 @@ export type Manifest = { name: string, version: string, + author?: { + name?: string, + email?: string, + url?: string + }, + homepage?: string, flat?: boolean, license?: string,