diff --git a/README.md b/README.md index 8482a1b..bad0de0 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ usage: updates [options] -i, --include Include only given packages -e, --exclude Exclude given packages -t, --types Check only given dependency types - -s, --semver patch|minor Consider only up to given semver level + -P, --patch [] Consider only up to semver-patch + -m, --minor [] Consider only up to semver-minor -E, --error-on-outdated Exit with error code 2 on outdated packages -r, --registry Use given registry URL -f, --file Use given package.json file or module directory @@ -48,18 +49,18 @@ usage: updates [options] ### Check for updates ```console $ updates -NAME OLD NEW -chalk 1.3.0 2.3.0 -got ^7.0.1 ^8.0.1 -minimist ^1.0.0 ^1.2.0 +NAME OLD NEW INFO +string-width 2.1.1 3.0.0 https://github.com/sindresorhus/string-width +eslint 5.9.0 5.10.0 https://github.com/eslint/eslint +eslint-config-silverwind 2.0.11 2.0.12 https://github.com/silverwind/eslint-config-silverwind ``` ### Update package.json ```console $ updates -u -NAME OLD NEW -chalk 1.3.0 2.3.0 -got ^7.0.1 ^8.0.1 -minimist ^1.0.0 ^1.2.0 +NAME OLD NEW INFO +string-width 2.1.1 3.0.0 https://github.com/sindresorhus/string-width +eslint 5.9.0 5.10.0 https://github.com/eslint/eslint +eslint-config-silverwind 2.0.11 2.0.12 https://github.com/silverwind/eslint-config-silverwind ╭────────────────────────╮ │ package.json updated │ ╰────────────────────────╯ @@ -72,17 +73,20 @@ The JSON output is an object with possible properties `results`, `message` and ` $ updates -j | jq { "results": { - "chalk": { - "old": "1.3.0", - "new": "2.3.0" + "string-width": { + "old": "2.1.1", + "new": "3.0.0", + "info": "https://github.com/sindresorhus/string-width" }, - "got": { - "old": "^7.0.1", - "new": "^8.0.1" + "eslint": { + "old": "5.9.0", + "new": "5.10.0", + "info": "https://github.com/eslint/eslint" }, - "minimist": { - "old": "^1.0.0", - "new": "^1.2.0" + "eslint-config-silverwind": { + "old": "2.0.11", + "new": "2.0.12", + "info": "https://github.com/silverwind/eslint-config-silverwind" } } } diff --git a/updates.js b/updates.js index 95b40ae..1e58010 100755 --- a/updates.js +++ b/updates.js @@ -16,10 +16,11 @@ const args = require("minimist")(process.argv.slice(2), { string: [ "f", "file", "g", "greatest", + "m", "minor", + "P", "patch", "p", "prerelease", "r", "registry", "t", "types", - "s", "semver", ], default: { "registry": "https://registry.npmjs.org/", @@ -33,7 +34,9 @@ const args = require("minimist")(process.argv.slice(2), { h: "help", i: "include", j: "json", + m: "minor", n: "no-color", + P: "patch", p: "prerelease", r: "registry", s: "semver", @@ -53,7 +56,8 @@ if (args.help) { -i, --include Include only given packages -e, --exclude Exclude given packages -t, --types Check only given dependency types - -s, --semver patch|minor Consider only up to given semver level + -P, --patch [] Consider only up to semver-patch + -m, --minor [] Consider only up to semver-minor -E, --error-on-outdated Exit with error code 2 on outdated packages -r, --registry Use given registry URL -f, --file Use given package.json file or module directory @@ -85,6 +89,8 @@ if (args["no-color"]) process.env.FORCE_COLOR = "0"; const greatest = parseMixedArg(args.greatest); const prerelease = parseMixedArg(args.prerelease); +const patch = parseMixedArg(args.patch); +const minor = parseMixedArg(args.minor); const registry = args.registry.endsWith("/") ? args.registry : args.registry + "/"; @@ -111,15 +117,6 @@ if (args.types) { ]; } -let semvers; -if (args.semver === "patch") { - semvers = ["patch"]; -} else if (args.semver === "minor") { - semvers = ["patch", "minor"]; -} else { - semvers = ["patch", "minor", "major"]; -} - const fs = require("fs"); let pkg, pkgStr; const deps = {}; @@ -193,8 +190,18 @@ Promise.all(Object.keys(deps).map(name => get(name))).then(dati => { for (const data of dati) { const useGreatest = typeof greatest === "boolean" ? greatest : greatest.includes(data.name); const usePre = typeof prerelease === "boolean" ? prerelease : prerelease.includes(data.name); + + let semvers; + if (patch === true || Array.isArray(patch) && patch.includes(data.name)) { + semvers = ["patch"]; + } else if (minor === true || Array.isArray(minor) && minor.includes(data.name)) { + semvers = ["patch", "minor"]; + } else { + semvers = ["patch", "minor", "major"]; + } + const oldRange = deps[data.name].old; - const newVersion = findNewVersion(data, {usePre, useGreatest, range: oldRange}); + const newVersion = findNewVersion(data, {usePre, useGreatest, semvers, range: oldRange}); const newRange = updateRange(oldRange, newVersion); if (!newVersion || oldRange === newRange) { @@ -335,7 +342,7 @@ function findNewVersion(data, opts) { } if ((diff === null) || - (semvers.includes(diff) && semver.gte(parsed.version, newVersion[0])) || + (opts.semvers.includes(diff) && semver.gte(parsed.version, newVersion[0])) || (opts.usePre && diff === "prerelease")) { if (opts.useGreatest && semver.gt(parsed.version, newVersion[0])) { newVersion[0] = parsed.version;