Skip to content

Commit

Permalink
Dependency updates and other cleanups
Browse files Browse the repository at this point in the history
* Bumping all dependencies to latest version
* Removing unused dependencies
* Additional checks for different ways of spelling "license" in the package.json file
* Tweak to npmLs.js to filter out cli option that cause issues
* Change to the "unknown" license ID
* Updating unit tests
  • Loading branch information
morficus committed Feb 18, 2020
1 parent f5d707f commit 0eaeaf9
Show file tree
Hide file tree
Showing 9 changed files with 1,452 additions and 3,849 deletions.
2 changes: 1 addition & 1 deletion cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
include: {
description: 'List of properties to include',
type: 'array',
choices: ['id', 'name', 'version', 'license', 'licenseId', 'licenseFullName', 'licenseFilePath', 'path', 'repository', 'author', 'homepage', 'path', 'dependencyLevel'],
choices: ['id', 'name', 'version', 'license', 'licenseId', 'licenseFullName', 'licenseFilePath', 'path', 'repository', 'author', 'homepage', 'dependencyLevel'],
default: ['id', 'name', 'version', 'license', 'repository', 'author', 'homepage', 'dependencyLevel']
},
production: {
Expand Down
7 changes: 7 additions & 0 deletions formatters/table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { table } = require('table')
const { isEmpty } = require('lodash')


/**
* Prints the given object in an ASCII table.
Expand All @@ -9,6 +11,11 @@ const { table } = require('table')
*/
module.exports = function ({data, header}) {

if (isEmpty(data)) {
return 'No data was present so no table was generated'
}


const defaultLabels = {
id: 'Row #',
name: 'Package Name',
Expand Down
3 changes: 1 addition & 2 deletions helpers/get-package-details.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { promisify } = require('util')
const readPackageTree = promisify(require('read-package-tree'))
const readPackageTree = require('read-package-tree')

/**
* Gte full package information for a module at the given path
Expand Down
7 changes: 5 additions & 2 deletions helpers/npm-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ const package = require('../package.json')
const debug = require('debug')(package.name)
const optionsToArgv = require('./options-to-args')


/**
* Wrapper to allow programmatic usage of the `npm ls` command
*
* @param {Object} opts
* @returns {Promise<Array<Object>>}
*/
module.exports = function (opts = {}) {
const options = optionsToArgv(opts)
const blackListOpts = ['format']
const options = optionsToArgv(opts, blackListOpts)

return new Promise((resolve, reject) => {

debug('Got these options: %s', options)
debug('Got these options: %s', JSON.stringify(options, null, 2))

// always pass in the `parseable` flag so that the value can be used programmatically
const cmdNpmList = spawn('npm', ['list', '--parseable', ...options])
Expand Down
7 changes: 5 additions & 2 deletions helpers/options-to-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
* Converts an options object in to an Array of strings similar to what you would get from `process.argv`
*
* @param {Object} options
* @param {Array} ignoreList
* @returns {Array<String>}
*/
module.exports = function (options) {
module.exports = function (options = {}, ignoreList = []) {
return Object.entries(options)
// remove anything with a value of false
// remove anything with a value of false
.filter(([key, value]) => value !== false)
// remove items based on ignore-list
.filter(([key, value]) => !ignoreList.includes(key))
// convert in to an array of CLI arguments that can be accepted by `npm ls`
.map(([key, value]) => `--${key}=${value}`)
}
4 changes: 2 additions & 2 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async function (options = {}) {
const pathList = await npmLs(options)
return await Promise.all(pathList.map(async (path, index) => {
const pkg = await getPackageDetails(path)
const licShortName = extractLicenseText(pkg.license || pkg.licenses)
const licShortName = extractLicenseText(pkg.license || pkg.licenses || pkg.licence || pkg.licences)
const licLongName = getExpandedLicName(licShortName) || 'unknown'

// find any local licences files and build a path to them
Expand All @@ -28,7 +28,7 @@ module.exports = async function (options = {}) {
licenseId: licShortName,
licenseFullName: licLongName,
licenseFilePath: licFilePath || [],
license: `${licLongName} (${licShortName})`,
license: `${licLongName} (${licShortName || '?'})`,
repository: (pkg.repository || {}).url,
author: (pkg.author || {}).name,
homepage: pkg.homepage,
Expand Down
Loading

0 comments on commit 0eaeaf9

Please sign in to comment.