Skip to content

Commit

Permalink
Merge pull request #677 from raineorshine/replace-cint
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine authored May 25, 2020
2 parents ecaeed3 + 8df9d91 commit 5ef858f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
5 changes: 2 additions & 3 deletions bin/ncu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

const program = require('commander')
const updateNotifier = require('update-notifier')
const cint = require('cint')
const _ = require('lodash')
const ncu = require('../lib/npm-check-updates')
const pkg = require('../package.json')
Expand All @@ -19,12 +18,12 @@ program
.description('[filter] is a list or regex of package names to check (all others will be ignored).')
.usage('[options] [filter]')
.version(pkg.version)
.option('--concurrency <n>', 'max number of concurrent HTTP requests to npm registry.', cint.partialAt(parseInt, 1, 10), 8)
.option('--concurrency <n>', 'max number of concurrent HTTP requests to npm registry.', _.partialRight(parseInt, 10), 8)
.option('--configFilePath <path>', 'rc config file path (default: directory of `packageFile` or ./ otherwise)')
.option('--configFileName <path>', 'rc config file name (default: .ncurc.{json,yml,js})')
.option('--cwd <path>', 'Used as current working directory for `spawn` in npm listing')
.option('--dep <dep>', 'check only a specific section(s) of dependencies: prod|dev|peer|optional|bundle (comma-delimited)')
.option('-e, --error-level <n>', 'set the error-level. 1: exits with error code 0 if no errors occur. 2: exits with error code 0 if no packages need updating (useful for continuous integration).', cint.partialAt(parseInt, 1, 10), 1)
.option('-e, --error-level <n>', 'set the error-level. 1: exits with error code 0 if no errors occur. 2: exits with error code 0 if no packages need updating (useful for continuous integration).', _.partialRight(parseInt, 10), 1)
.option('--engines-node', 'upgrade to version which satisfies engines.node range')
.option('-f, --filter <matches>', 'include only package names matching the given string, comma-or-space-delimited list, or /regex/')
.option('-g, --global', 'check global packages instead of in the current project')
Expand Down
10 changes: 5 additions & 5 deletions lib/npm-check-updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function toDependencyTable(args) {
return table
}

const readPackageFile = cint.partialAt(promisify(fs.readFile), 1, 'utf8')
const readPackageFile = _.partialRight(promisify(fs.readFile), 'utf8')
const writePackageFile = promisify(fs.writeFile)

//
Expand Down Expand Up @@ -224,12 +224,12 @@ function analyzeProjectDependencies(options, pkgData, pkgFile) {

// split the deps into satisfied and unsatisfied to display in two separate tables
const deps = Object.keys(selectedNewDependencies)
const satisfied = cint.toObject(deps, dep =>
cint.keyValue(dep, vm.isSatisfied(latest[dep], current[dep]))
)
const satisfied = cint.toObject(deps, dep => ({
[dep]: vm.isSatisfied(latest[dep], current[dep])
}))

const isSatisfied = _.propertyOf(satisfied)
const filteredUpgraded = options.minimal ? cint.filterObject(selectedNewDependencies, cint.not(isSatisfied)) : selectedNewDependencies
const filteredUpgraded = options.minimal ? cint.filterObject(selectedNewDependencies, dep => !isSatisfied(dep)) : selectedNewDependencies
const numUpgraded = Object.keys(filteredUpgraded).length

// print
Expand Down
6 changes: 3 additions & 3 deletions lib/package-managers/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ module.exports = {
const json = parseJson(result, {
command: 'npm ls'
})
return cint.mapObject(json.dependencies, (name, info) =>
return cint.mapObject(json.dependencies, (name, info) => ({
// unmet peer dependencies have a different structure
cint.keyValue(name, info.version || (info.required && info.required.version))
)
[name]: info.version || (info.required && info.required.version)
}))
})
},

Expand Down
18 changes: 9 additions & 9 deletions lib/versionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ function upgradeDependencyDeclaration(declaration, latestVersion, options = {})
}

// create a new semver object with major, minor, patch, build, and release parts
const newSemver = cint.toObject(versionUtil.VERSION_PARTS, part =>
cint.keyValue(part, chooseVersion(part))
)
const newSemver = cint.toObject(versionUtil.VERSION_PARTS, part => ({
[part]: chooseVersion(part)
}))
const newSemverString = versionUtil.stringify(newSemver)
const version = v(declaredSemver.semver) + newSemverString

Expand Down Expand Up @@ -215,7 +215,7 @@ function packageNameFilter(filter) {
}
else if (typeof filter === 'string') {
// RegExp filter
if (filter[0] === '/' && cint.index(filter, -1) === '/') {
if (filter[0] === '/' && filter[filter.length - 1] === '/') {
const regexp = new RegExp(filter.slice(1, -1))
filterPackages = regexp.test.bind(regexp)
}
Expand All @@ -237,8 +237,8 @@ function packageNameFilter(filter) {
throw new TypeError('Invalid packages filter. Must be a RegExp, array, or comma-or-space-delimited list.')
}

// (limit the arity to 1 to avoid passing the value)
return cint.aritize(filterPackages, 1)
// limit the arity to 1 to avoid passing the value
return dep => filterPackages(dep)
}

/**
Expand Down Expand Up @@ -485,9 +485,9 @@ function queryVersions(packageMap, options = {}) {
* @returns
*/
function zipVersions(versionList) {
return cint.toObject(versionList, (version, i) => {
return cint.keyValue(packageList[i], version)
})
return cint.toObject(versionList, (version, i) => ({
[packageList[i]]: version
}))
}
return pMap(packageList, getPackageVersionProtected, { concurrency: options.concurrency })
.then(zipVersions)
Expand Down

0 comments on commit 5ef858f

Please sign in to comment.