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

Feat: repo owner changed option #621

Merged
merged 16 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'master' into feat/repo-owner-column
  • Loading branch information
KingDarBoja committed Aug 22, 2020
commit 31b684a752ec0dbe7e87dcde61dcf080773c95c9
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

140 changes: 74 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,58 +80,67 @@ $ ncu "/^(?!gulp-).*$/" # windows
## Options

```text
--concurrency max number of concurrent HTTP requests to npm registry
(default: 8)
--configFilePath rc config file path (default: directory of
`packageFile` or ./ otherwise)
--configFileName rc config file name (default: .ncurc.{json,yml,js}) --cwd
Used as current working directory for `spawn` in npm listing
--dep check only a specific section(s) of dependencies:
prod|dev|peer|optional|bundle (comma-delimited)
--engines-node include only packages that satisfy engines.node as
specified in the package file
-e, --error-level 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)
-f, --filter include only package names matching the given string,
comma-or-space-delimited list, or /regex/
-g, --global check global packages instead of in the current project
-i, --interactive Enable interactive prompts for each dependency;
Implies -u unless one of the json options are set
-j, --jsonAll output new package file instead of human-readable
message
--jsonDeps returns output like `jsonAll` but only lists
`dependencies`, `devDependencies`, and
`optionalDependencies` of the new package data.
--jsonUpgraded output upgraded dependencies in json
-l, --loglevel what level of logs to report: silent, error, warn,
info, verbose, silly (default: warn)
-m, --minimal do not upgrade to newer versions that are already
satisfied by the existing version range (v2 behavior).
-n, --newest find the newest published versions available instead
of the latest stable versions
-o, --ownerChanged check if the package owner changed between current
and next version.
-p, --packageManager npm (default: npm)
--packageData include stringified package file (use stdin instead)
--packageFile package file location (default: ./package.json)
--pre include -alpha, -beta, -rc. (default: 0; default
with --newest and --greatest: 1)
--prefix Used as current working directory in npm
-r, --registry specify third-party NPM registry
--removeRange remove version ranges from the final package version
-s, --silent don't output anything (--loglevel silent)
--semverLevel find the highest version within "major" or "minor"
-t, --greatest find the highest versions available instead of the
latest stable versions
--timeout a global timeout in milliseconds. (default: no global
timeout and 30 seconds per npm-registery-fetch)
-u, --upgrade overwrite package file
-v, --version get version
-V get version
-x, --reject exclude packages matching the given string, comma-
delimited list, or regex
--concurrency <n> Max number of concurrent HTTP requests to
registry. (default: 8)
--configFilePath <path> Directory of .ncurc config file (default:
directory of `packageFile`).
--configFileName <filename> Config file name (default: .ncurc.{json,yml,js})
--cwd <path> Working directory in which npm will be executed.
--dep <dep> Check one or more sections of dependencies only:
prod, dev, peer, optional, bundle
(comma-delimited).
--enginesNode Include only packages that satisfy engines.node
as specified in the package file.
-e, --errorLevel <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). (default: 1)
-f, --filter <matches> Include only package names matching the given
string, comma-or-space-delimited list, or
/regex/.
-g, --global Check global packages instead of in the current
project.
--greatest DEPRECATED. Renamed to "--target greatest".
-i, --interactive Enable interactive prompts for each dependency;
implies -u unless one of the json options are
set,
-j, --jsonAll Output new package file instead of
human-readable message.
--jsonDeps Like `jsonAll` but only lists `dependencies`,
`devDependencies`, `optionalDependencies`, etc
of the new package data.
--jsonUpgraded Output upgraded dependencies in json.
-l, --loglevel <n> Amount to log: silent, error, minimal, warn,
info, verbose, silly. (default: "warn")
-m, --minimal Do not upgrade newer versions that are already
satisfied by the version range according to
semver.
-n, --newest DEPRECATED. Renamed to "--target newest".
-o, --ownerChanged Check if the package owner changed between current
and next version.
-p, --packageManager <name> npm, yarn (default: "npm")
--packageData Include stringified package file (you can also
send to stdin).
--packageFile <path> Package file location (default: ./package.json).
--pre <n> Include -alpha, -beta, -rc. (default: 0; default
with --newest and --greatest: 1).
--prefix <path> Current working directory of npm.
-r, --registry <url> Third-party npm registry.
--removeRange Remove version ranges from the final package
version.
--semverLevel <value> DEPRECATED. Renamed to --target.
-s, --silent Don't output anything (--loglevel silent).
-t, --target <value> Target version to upgrade to: latest, newest,
greatest, minor, patch. (default: "latest")
--timeout <ms> Global timeout in milliseconds. (default: no
global timeout and 30 seconds per
npm-registery-fetch).
-u, --upgrade Overwrite package file with upgraded versions
instead of just outputting to console.
-x, --reject <matches> Exclude packages matching the given string,
comma-or-space-delimited list, or /regex/.
-V, --version output the version number
-h, --help display help for command
```

## How dependency updates are determined
Expand All @@ -149,9 +158,9 @@ $ ncu "/^(?!gulp-).*$/" # windows
- `1.0.0 < 2.0.0` → `^3.0.0`
- "Any version" is preserved:
- `*` → `*`
- with `--semverLevel major`, the major version is preserved:
- with `--target minor`, only update patch and minor:
- `0.1.0` → `0.2.1`
- with `--semverLevel minor`, the major and minor versions are preserved:
- with `--target patch`, only update patch:
- `0.1.0` → `0.1.2`

## Configuration Files
Expand All @@ -178,22 +187,21 @@ For example, `.ncurc.json`:
npm-check-updates can be required:

```js
const ncu = require('npm-check-updates');

ncu.run({
// Any command-line option can be specified here.
// These are set by default:
jsonUpgraded: true,
packageManager: 'npm',
silent: true
}).then((upgraded) => {
console.log('dependencies to upgrade:', upgraded);
});
const ncu = require('npm-check-updates')

const upgraded = await ncu.run({
// Any command-line option can be specified here.
// These are set by default:
jsonUpgraded: true,
silent: true
})

console.log('dependencies to upgrade:', upgraded)
```

## Known Issues

- Windows: If npm-check-updates hangs, run `ncu --loglevel verbose` to see if it is waiting for stdin. If so, try setting the package file explicitly: `ncu -g --packageFile package.json`. See [#136](https://github.com/raineorshine/npm-check-updates/issues/136#issuecomment-155721102).
- Windows: If npm-check-updates hangs, run `ncu --loglevel verbose` to see if it is waiting for stdin. If so, try setting the package file explicitly: `ncu --packageFile package.json`. See [#136](https://github.com/raineorshine/npm-check-updates/issues/136#issuecomment-155721102).

Also search the [issues page](https://github.com/raineorshine/npm-check-updates/issues).

Expand Down
79 changes: 79 additions & 0 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const fs = require('fs')
const path = require('path')
const spawn = require('spawn-please')
const { cliOptions } = require('../lib/constants')

/** Extracts CLI options from the bin output. */
const readOptions = async () => {
const optionsBinLabel = 'Options:\n'
const helpOutput = await spawn('./bin/cli.js', ['--help'])
return helpOutput.slice(helpOutput.indexOf(optionsBinLabel) + optionsBinLabel.length)
// outdent
.split('\n').map(s => s.slice(2)).join('\n')
}

/** Replaces the "Options" section of the README with direct output from "ncu --help". */
const writeReadme = helpOptionsNew => {

const optionsLabelStart = '## Options\n\n```text\n'
const optionsLabelEnd = '```'

// find insertion point for options into README
const readme = fs.readFileSync('README.md', 'utf8')
const optionsLabelStartIndex = readme.indexOf(optionsLabelStart)
const optionsStart = optionsLabelStartIndex + optionsLabelStart.length
const optionsEnd = readme.indexOf(optionsLabelEnd, optionsStart)

// insert new options into README
const readmeNew = readme.slice(0, optionsStart)
+ helpOptionsNew
+ readme.slice(optionsEnd)
fs.writeFileSync('README.md', readmeNew)
}

/** Writes CLI options to type definitions file (npm-check-updates.d.ts). */
const writeTypeDefinitions = helpOptionsNew => {

const typedefsStart = `declare namespace ncu {

interface RunOptions {
`
const typedefsEnd = `
}

type RunResults = Record<string, string>

function run(options?: RunOptions): Promise<RunResults>
}

export = ncu
`

// parse commander values
const optionTypes = cliOptions.map(({ name, description, default: defaultValue, type: typeValue }) => {
const tsName = name.replace(/(?:-\w, )?--([^ ]+)(?: <.*>)?/, (_, m) => m)
const tsType = typeValue || (
defaultValue ? typeof defaultValue
: name.includes(' <n>') || name.includes(' <ms>') ? 'number'
: !name.includes(' <') ? 'boolean'
: 'string'
)
const tsDefault = defaultValue ? ' (default: ' + JSON.stringify(defaultValue) + ')' : ''
return `
/** ${description}${tsDefault} */
${tsName}?: ${tsType};
`
})
.join('')

const typedefsNew = typedefsStart + optionTypes + typedefsEnd
fs.writeFileSync(path.join(__dirname, '../lib/npm-check-updates.d.ts'), typedefsNew)
}

(async () => {

const helpOptionsNew = await readOptions()
writeReadme(helpOptionsNew)
writeTypeDefinitions(helpOptionsNew)

})()
58 changes: 58 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env node

'use strict'

const program = require('commander')
const updateNotifier = require('update-notifier')
const _ = require('lodash')
const ncu = require('../lib/npm-check-updates')
const pkg = require('../package.json')
const { cliOptions } = require('../lib/constants')

// check if a new version of ncu is available and print an update notification
const notifier = updateNotifier({ pkg })
if (notifier.update && notifier.update.latest !== pkg.version) {
notifier.notify({ defer: false, isGlobal: true })
}

// start commander program
program
.description('[filter] is a list or regex of package names to check (all others will be ignored).')
.usage('[options] [filter]')

// add cli options
cliOptions.forEach(({ name, description, default: defaultValue, parse }) =>
// handle 3rd/4th argument polymorphism
program.option(name, description, parse || defaultValue, parse ? defaultValue : undefined))

// set version option at the end
program.version(pkg.version)

program.parse(process.argv)

const { configFileName, configFilePath, packageFile } = program

// load .ncurc
// NOTE: Do not load .ncurc from project directory when tests are running
// Can be overridden if configFilePath is set explicitly
let rcArguments = []
if (!process.env.NCU_TESTS || configFilePath) {
const rcConfig = ncu.getNcurc({
configFileName,
configFilePath,
packageFile
})
rcArguments = rcConfig ?
_.flatten(_.map(rcConfig, (value, name) =>
value === true ? [`--${name}`] : [`--${name}`, value]
)) : []

}
const combinedArguments = process.argv.slice(0, 2).concat(rcArguments, process.argv.slice(2))

program.parse(combinedArguments)

program.cli = true
program.filter = program.args.join(' ') || program.filter

ncu.run(program)
80 changes: 0 additions & 80 deletions bin/ncu.js

This file was deleted.

5 changes: 0 additions & 5 deletions bin/npm-check-updates.js

This file was deleted.

Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.