cli-options.js
12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cliOptionsMap = void 0;
const lodash_1 = __importDefault(require("lodash"));
const cli_table_1 = __importDefault(require("cli-table"));
const chalk_1 = __importDefault(require("chalk"));
const constants_1 = require("./constants");
/**
* "newest" means most recently released in terms of release date, even if there are other version numbers that are higher. It includes prereleases.
* "greatest" means the highest version number, regardless of release date. It includes prereleases.
* "latest" is whatever the project's "latest" git tag points to. It's usually the non-prerelease version with the highest version number, but is ultimately decided by each project's maintainers.
* "minor" means the highest minor version without incrementing the current major.
* "patch" means the highest patch version without incrementing the current major or minor.
**/
const getHelpTargetTable = () => {
/* eslint-disable fp/no-mutating-methods */
const table = new cli_table_1.default({
colAligns: ['right', 'left'],
});
table.push([
'greatest',
`Upgrade to the highest version number, regardless of release date or tag.
Includes prereleases.`,
]);
table.push([
'latest',
`Upgrade to whatever the package's "latest" git tag points to. It's usually the
non-prerelease version with the highest version number, but is ultimately decided
by each project's maintainers. Default.`,
]);
table.push(['minor', 'Upgrade to the highest minor version without bumping the major version.']);
table.push([
'newest',
`Upgrade to the version with the most recent publish date, even if there are
other version numbers that are higher. Includes prereleases.`,
]);
table.push(['patch', `Upgrade to the highest patch version without bumping the minor or major versions.`]);
return `Set the target version that is upgraded to. (default: "latest")
${table.toString()}
You can also specify a custom function in your .ncurc.js file, or when importing npm-check-updates:
${chalk_1.default.gray(`/** Custom target.
@param dependencyName The name of the dependency.
@param parsedVersion A parsed Semver object from semver-utils.
(See https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
@returns One of the valid target values (specified in the table above).
*/`)}
${chalk_1.default.cyan('target')}: (dependencyName, [{ semver, version, operator, major, minor, patch, release, build }]) ${chalk_1.default.cyan('=>')} {
${chalk_1.default.red('if')} (major ${chalk_1.default.red('===')} ${chalk_1.default.blue('0')}) ${chalk_1.default.red('return')} ${chalk_1.default.yellow("'minor'")}
${chalk_1.default.red('return')} ${chalk_1.default.yellow("'latest'")}
}
`;
};
// store CLI options separately from bin file so that they can be used to build type definitions
const cliOptions = [
{
long: 'color',
description: 'Force color in terminal',
},
{
long: 'concurrency',
arg: 'n',
description: 'Max number of concurrent HTTP requests to registry.',
parse: s => parseInt(s, 10),
default: 8,
},
{
long: 'configFileName',
arg: 'filename',
description: 'Config file name. (default: .ncurc.{json,yml,js})',
},
{
long: 'configFilePath',
arg: 'path',
description: 'Directory of .ncurc config file. (default: directory of `packageFile`)',
},
{
long: 'cwd',
arg: 'path',
description: 'Working directory in which npm will be executed.',
},
{
long: 'deep',
description: `Run recursively in current working directory. Alias of (--packageFile '${constants_1.deepPatternPrefix}package.json').`,
type: 'boolean',
},
{
long: 'dep',
arg: 'value',
description: 'Check one or more sections of dependencies only: dev, optional, peer, prod, bundle (comma-delimited).',
default: 'prod,dev,bundle,optional',
},
{
long: 'deprecated',
description: 'Include deprecated packages.',
},
{
long: 'doctor',
description: 'Iteratively installs upgrades and runs tests to identify breaking upgrades. Run "ncu --doctor" for detailed help. Add "-u" to execute.',
},
{
long: 'doctorInstall',
arg: 'command',
description: 'Specifies the install script to use in doctor mode. (default: npm install/yarn)',
},
{
long: 'doctorTest',
arg: 'command',
description: 'Specifies the test script to use in doctor mode. (default: npm test)',
},
{
long: 'enginesNode',
description: 'Include only packages that satisfy engines.node as specified in the package file.',
},
{
long: 'errorLevel',
short: 'e',
arg: 'n',
description: '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).',
parse: s => parseInt(s, 10),
default: 1,
},
{
long: 'filter',
short: 'f',
arg: 'matches',
description: 'Include only package names matching the given string, wildcard, glob, comma-or-space-delimited list, or /regex/.',
type: 'string | string[] | RegExp | RegExp[] | Function',
},
{
long: 'filterVersion',
arg: 'matches',
description: 'Filter on package version using comma-or-space-delimited list, or /regex/.',
type: 'string | string[] | RegExp | RegExp[] | Function',
},
{
long: 'format',
arg: 'value',
description: 'Enable additional output data, string or comma-delimited list: ownerChanged, repo. ownerChanged: shows if the package owner changed between versions. repo: infers and displays links to source code repository.',
parse: value => (typeof value === 'string' ? value.split(',') : value),
default: [],
type: 'string[]',
},
{
long: 'global',
short: 'g',
description: 'Check global packages instead of in the current project.',
},
{
long: 'interactive',
short: 'i',
description: 'Enable interactive prompts for each dependency; implies -u unless one of the json options are set.',
},
{
// program.json is set to true in programInit if any options that begin with 'json' are true
long: 'jsonAll',
short: 'j',
description: 'Output new package file instead of human-readable message.',
},
{
long: 'jsonDeps',
description: 'Like `jsonAll` but only lists `dependencies`, `devDependencies`, `optionalDependencies`, etc of the new package data.',
},
{
long: 'jsonUpgraded',
description: 'Output upgraded dependencies in json.',
},
{
long: 'loglevel',
short: 'l',
arg: 'n',
description: 'Amount to log: silent, error, minimal, warn, info, verbose, silly.',
default: 'warn',
},
{
long: 'mergeConfig',
description: `Merges nested configs with the root config file for --deep or --packageFile options. (default: false)`,
type: 'boolean',
},
{
long: 'minimal',
short: 'm',
description: 'Do not upgrade newer versions that are already satisfied by the version range according to semver.',
},
{
long: 'packageData',
arg: 'value',
description: 'Package file data (you can also use stdin).',
},
{
long: 'packageFile',
arg: 'path|glob',
description: 'Package file(s) location. (default: ./package.json)',
},
{
long: 'packageManager',
short: 'p',
arg: 'name',
// manual default to allow overriding auto yarn detection
description: 'npm, yarn (default: "npm")',
},
{
long: 'peer',
description: 'Check peer dependencies of installed packages and filter updates to compatible versions. Run "ncu --help --peer" for details.',
type: 'boolean',
help: `Check peer dependencies of installed packages and filter updates to compatible versions.
${chalk_1.default.bold('Example')}
The following example demonstrates how --peer works, and how it uses peer dependencies from upgraded modules.
The package ${chalk_1.default.bold('ncu-test-peer-update')} has two versions published:
- 1.0.0 has peer dependency "ncu-test-return-version": "1.0.x"
- 1.1.0 has peer dependency "ncu-test-return-version": "1.1.x"
Our test app has the following dependencies:
"ncu-test-peer-update": "1.0.0",
"ncu-test-return-version": "1.0.0"
The latest versions of these packages are:
"ncu-test-peer-update": "1.1.0",
"ncu-test-return-version": "2.0.0"
${chalk_1.default.bold('With --peer')}
ncu upgrades packages to the highest version that still adheres to the peer dependency constraints:
ncu-test-peer-update 1.0.0 → 1.${chalk_1.default.cyan('1.0')}
ncu-test-return-version 1.0.0 → 1.${chalk_1.default.cyan('1.0')}
${chalk_1.default.bold('Without --peer')}
As a comparison: without using the --peer option, ncu will suggest the latest versions, ignoring peer dependencies:
ncu-test-peer-update 1.0.0 → 1.${chalk_1.default.cyan('1.0')}
ncu-test-return-version 1.0.0 → ${chalk_1.default.red('2.0.0')}
`,
},
{
long: 'pre',
arg: 'n',
description: 'Include -alpha, -beta, -rc. (default: 0; default with --newest and --greatest: 1)',
type: 'number',
parse: s => !!parseInt(s, 10),
},
{
long: 'prefix',
arg: 'path',
description: 'Current working directory of npm.',
},
{
long: 'registry',
short: 'r',
arg: 'url',
description: 'Third-party npm registry.',
},
{
long: 'reject',
short: 'x',
arg: 'matches',
description: 'Exclude packages matching the given string, wildcard, glob, comma-or-space-delimited list, or /regex/.',
type: 'string | string[] | RegExp | RegExp[] | Function',
parse: (s, p) => p.concat([s]),
default: [],
},
{
long: 'rejectVersion',
arg: 'matches',
description: 'Exclude package.json versions using comma-or-space-delimited list, or /regex/.',
type: 'string | string[] | RegExp | RegExp[] | Function',
},
{
long: 'removeRange',
description: 'Remove version ranges from the final package version.',
},
{
long: 'retry',
arg: 'n',
description: 'Number of times to retry failed requests for package info.',
parse: s => parseInt(s, 10),
default: 3,
},
{
long: 'silent',
short: 's',
description: "Don't output anything (--loglevel silent).",
},
{
long: 'target',
short: 't',
arg: 'value',
description: 'Target version or function that returns version to upgrade to: latest, newest, greatest, minor, patch. Run "ncu --help --target" for details. (default: "latest")',
help: getHelpTargetTable(),
type: 'string | TargetFunction',
},
{
long: 'timeout',
arg: 'ms',
description: 'Global timeout in milliseconds. (default: no global timeout and 30 seconds per npm-registry-fetch)',
},
{
long: 'upgrade',
short: 'u',
description: 'Overwrite package file with upgraded versions instead of just outputting to console.',
},
];
// put cliOptions into an object for O(1) lookups
exports.cliOptionsMap = cliOptions.reduce((accum, option) => ({
...accum,
...(option.short ? { [option.short]: option } : null),
...(option.long ? { [option.long]: option } : null),
}), {});
const cliOptionsSorted = lodash_1.default.sortBy(cliOptions, 'long');
exports.default = cliOptionsSorted;
//# sourceMappingURL=cli-options.js.map