yargs 16.1.1 → 16.2.2-candidate.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [16.2.0](https://www.github.com/yargs/yargs/compare/v16.1.1...v16.2.0) (2020-12-05)
6
+
7
+
8
+ ### Features
9
+
10
+ * command() now accepts an array of modules ([f415388](https://www.github.com/yargs/yargs/commit/f415388cc454d02786c65c50dd6c7a0cf9d8b842))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * add package.json to module exports ([#1818](https://www.github.com/yargs/yargs/issues/1818)) ([d783a49](https://www.github.com/yargs/yargs/commit/d783a49a7f21c9bbd4eec2990268f3244c4d5662)), closes [#1817](https://www.github.com/yargs/yargs/issues/1817)
16
+
5
17
  ### [16.1.1](https://www.github.com/yargs/yargs/compare/v16.1.0...v16.1.1) (2020-11-15)
6
18
 
7
19
 
@@ -74,4 +86,3 @@ All notable changes to this project will be documented in this file. See [standa
74
86
  * **yargs:** add missing command(module) signature ([#1707](https://www.github.com/yargs/yargs/issues/1707)) ([0f81024](https://www.github.com/yargs/yargs/commit/0f810245494ccf13a35b7786d021b30fc95ecad5)), closes [#1704](https://www.github.com/yargs/yargs/issues/1704)
75
87
 
76
88
  [Older CHANGELOG Entries](https://github.com/yargs/yargs/blob/master/docs/CHANGELOG-historical.md)
77
-
package/build/index.cjs CHANGED
@@ -287,8 +287,14 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
287
287
  const middlewares = commandMiddlewareFactory(commandMiddleware);
288
288
  handler = handler || (() => { });
289
289
  if (Array.isArray(cmd)) {
290
- aliases = cmd.slice(1);
291
- cmd = cmd[0];
290
+ if (isCommandAndAliases(cmd)) {
291
+ [cmd, ...aliases] = cmd;
292
+ }
293
+ else {
294
+ for (const command of cmd) {
295
+ self.addHandler(command);
296
+ }
297
+ }
292
298
  }
293
299
  else if (isCommandHandlerDefinition(cmd)) {
294
300
  let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
@@ -299,45 +305,47 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
299
305
  self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
300
306
  return;
301
307
  }
302
- if (isCommandBuilderDefinition(builder)) {
308
+ else if (isCommandBuilderDefinition(builder)) {
303
309
  self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
304
310
  return;
305
311
  }
306
- const parsedCommand = parseCommand(cmd);
307
- aliases = aliases.map(alias => parseCommand(alias).cmd);
308
- let isDefault = false;
309
- const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
310
- if (DEFAULT_MARKER.test(c)) {
311
- isDefault = true;
312
- return false;
313
- }
314
- return true;
315
- });
316
- if (parsedAliases.length === 0 && isDefault)
317
- parsedAliases.push('$0');
318
- if (isDefault) {
319
- parsedCommand.cmd = parsedAliases[0];
320
- aliases = parsedAliases.slice(1);
321
- cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
312
+ if (typeof cmd === 'string') {
313
+ const parsedCommand = parseCommand(cmd);
314
+ aliases = aliases.map(alias => parseCommand(alias).cmd);
315
+ let isDefault = false;
316
+ const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
317
+ if (DEFAULT_MARKER.test(c)) {
318
+ isDefault = true;
319
+ return false;
320
+ }
321
+ return true;
322
+ });
323
+ if (parsedAliases.length === 0 && isDefault)
324
+ parsedAliases.push('$0');
325
+ if (isDefault) {
326
+ parsedCommand.cmd = parsedAliases[0];
327
+ aliases = parsedAliases.slice(1);
328
+ cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
329
+ }
330
+ aliases.forEach(alias => {
331
+ aliasMap[alias] = parsedCommand.cmd;
332
+ });
333
+ if (description !== false) {
334
+ usage.command(cmd, description, isDefault, aliases, deprecated);
335
+ }
336
+ handlers[parsedCommand.cmd] = {
337
+ original: cmd,
338
+ description,
339
+ handler,
340
+ builder: builder || {},
341
+ middlewares,
342
+ deprecated,
343
+ demanded: parsedCommand.demanded,
344
+ optional: parsedCommand.optional,
345
+ };
346
+ if (isDefault)
347
+ defaultCommand = handlers[parsedCommand.cmd];
322
348
  }
323
- aliases.forEach(alias => {
324
- aliasMap[alias] = parsedCommand.cmd;
325
- });
326
- if (description !== false) {
327
- usage.command(cmd, description, isDefault, aliases, deprecated);
328
- }
329
- handlers[parsedCommand.cmd] = {
330
- original: cmd,
331
- description,
332
- handler,
333
- builder: builder || {},
334
- middlewares,
335
- deprecated,
336
- demanded: parsedCommand.demanded,
337
- optional: parsedCommand.optional,
338
- };
339
- if (isDefault)
340
- defaultCommand = handlers[parsedCommand.cmd];
341
349
  };
342
350
  self.addDirectory = function addDirectory(dir, context, req, callerFile, opts) {
343
351
  opts = opts || {};
@@ -498,7 +506,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
498
506
  if (isCommandBuilderCallback(builder)) {
499
507
  builder(yargs);
500
508
  }
501
- else {
509
+ else if (!isCommandBuilderDefinition(builder)) {
502
510
  Object.keys(builder).forEach(key => {
503
511
  yargs.option(key, builder[key]);
504
512
  });
@@ -622,20 +630,28 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
622
630
  };
623
631
  return self;
624
632
  }
625
- function isCommandHandlerDefinition(cmd) {
626
- return typeof cmd === 'object';
627
- }
628
633
  function isCommandBuilderDefinition(builder) {
629
634
  return (typeof builder === 'object' &&
630
635
  !!builder.builder &&
631
636
  typeof builder.handler === 'function');
632
637
  }
638
+ function isCommandAndAliases(cmd) {
639
+ if (cmd.every(c => typeof c === 'string')) {
640
+ return true;
641
+ }
642
+ else {
643
+ return false;
644
+ }
645
+ }
633
646
  function isCommandBuilderCallback(builder) {
634
647
  return typeof builder === 'function';
635
648
  }
636
649
  function isCommandBuilderOptionDefinitions(builder) {
637
650
  return typeof builder === 'object';
638
651
  }
652
+ function isCommandHandlerDefinition(cmd) {
653
+ return typeof cmd === 'object' && !Array.isArray(cmd);
654
+ }
639
655
 
640
656
  function setBlocking(blocking) {
641
657
  if (typeof process === 'undefined')
@@ -15,8 +15,14 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
15
15
  const middlewares = commandMiddlewareFactory(commandMiddleware);
16
16
  handler = handler || (() => { });
17
17
  if (Array.isArray(cmd)) {
18
- aliases = cmd.slice(1);
19
- cmd = cmd[0];
18
+ if (isCommandAndAliases(cmd)) {
19
+ [cmd, ...aliases] = cmd;
20
+ }
21
+ else {
22
+ for (const command of cmd) {
23
+ self.addHandler(command);
24
+ }
25
+ }
20
26
  }
21
27
  else if (isCommandHandlerDefinition(cmd)) {
22
28
  let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
@@ -27,45 +33,47 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
27
33
  self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
28
34
  return;
29
35
  }
30
- if (isCommandBuilderDefinition(builder)) {
36
+ else if (isCommandBuilderDefinition(builder)) {
31
37
  self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
32
38
  return;
33
39
  }
34
- const parsedCommand = parseCommand(cmd);
35
- aliases = aliases.map(alias => parseCommand(alias).cmd);
36
- let isDefault = false;
37
- const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
38
- if (DEFAULT_MARKER.test(c)) {
39
- isDefault = true;
40
- return false;
40
+ if (typeof cmd === 'string') {
41
+ const parsedCommand = parseCommand(cmd);
42
+ aliases = aliases.map(alias => parseCommand(alias).cmd);
43
+ let isDefault = false;
44
+ const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
45
+ if (DEFAULT_MARKER.test(c)) {
46
+ isDefault = true;
47
+ return false;
48
+ }
49
+ return true;
50
+ });
51
+ if (parsedAliases.length === 0 && isDefault)
52
+ parsedAliases.push('$0');
53
+ if (isDefault) {
54
+ parsedCommand.cmd = parsedAliases[0];
55
+ aliases = parsedAliases.slice(1);
56
+ cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
41
57
  }
42
- return true;
43
- });
44
- if (parsedAliases.length === 0 && isDefault)
45
- parsedAliases.push('$0');
46
- if (isDefault) {
47
- parsedCommand.cmd = parsedAliases[0];
48
- aliases = parsedAliases.slice(1);
49
- cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
50
- }
51
- aliases.forEach(alias => {
52
- aliasMap[alias] = parsedCommand.cmd;
53
- });
54
- if (description !== false) {
55
- usage.command(cmd, description, isDefault, aliases, deprecated);
58
+ aliases.forEach(alias => {
59
+ aliasMap[alias] = parsedCommand.cmd;
60
+ });
61
+ if (description !== false) {
62
+ usage.command(cmd, description, isDefault, aliases, deprecated);
63
+ }
64
+ handlers[parsedCommand.cmd] = {
65
+ original: cmd,
66
+ description,
67
+ handler,
68
+ builder: builder || {},
69
+ middlewares,
70
+ deprecated,
71
+ demanded: parsedCommand.demanded,
72
+ optional: parsedCommand.optional,
73
+ };
74
+ if (isDefault)
75
+ defaultCommand = handlers[parsedCommand.cmd];
56
76
  }
57
- handlers[parsedCommand.cmd] = {
58
- original: cmd,
59
- description,
60
- handler,
61
- builder: builder || {},
62
- middlewares,
63
- deprecated,
64
- demanded: parsedCommand.demanded,
65
- optional: parsedCommand.optional,
66
- };
67
- if (isDefault)
68
- defaultCommand = handlers[parsedCommand.cmd];
69
77
  };
70
78
  self.addDirectory = function addDirectory(dir, context, req, callerFile, opts) {
71
79
  opts = opts || {};
@@ -226,7 +234,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
226
234
  if (isCommandBuilderCallback(builder)) {
227
235
  builder(yargs);
228
236
  }
229
- else {
237
+ else if (!isCommandBuilderDefinition(builder)) {
230
238
  Object.keys(builder).forEach(key => {
231
239
  yargs.option(key, builder[key]);
232
240
  });
@@ -350,17 +358,25 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
350
358
  };
351
359
  return self;
352
360
  }
353
- export function isCommandHandlerDefinition(cmd) {
354
- return typeof cmd === 'object';
355
- }
356
361
  export function isCommandBuilderDefinition(builder) {
357
362
  return (typeof builder === 'object' &&
358
363
  !!builder.builder &&
359
364
  typeof builder.handler === 'function');
360
365
  }
366
+ function isCommandAndAliases(cmd) {
367
+ if (cmd.every(c => typeof c === 'string')) {
368
+ return true;
369
+ }
370
+ else {
371
+ return false;
372
+ }
373
+ }
361
374
  export function isCommandBuilderCallback(builder) {
362
375
  return typeof builder === 'function';
363
376
  }
364
377
  function isCommandBuilderOptionDefinitions(builder) {
365
378
  return typeof builder === 'object';
366
379
  }
380
+ export function isCommandHandlerDefinition(cmd) {
381
+ return typeof cmd === 'object' && !Array.isArray(cmd);
382
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "16.1.1",
3
+ "version": "16.2.2-candidate.0",
4
4
  "description": "yargs the modern, pirate-themed, successor to optimist.",
5
5
  "main": "./index.cjs",
6
6
  "exports": {
7
+ "./package.json": "./package.json",
7
8
  ".": [
8
9
  {
9
10
  "import": "./index.mjs",
@@ -17,9 +18,9 @@
17
18
  },
18
19
  "./yargs": [
19
20
  {
20
- "require": "./yargs"
21
+ "require": "./yargs.cjs"
21
22
  },
22
- "./yargs"
23
+ "./yargs.cjs"
23
24
  ]
24
25
  },
25
26
  "type": "module",
@@ -37,6 +38,7 @@
37
38
  "helpers/*",
38
39
  "index.mjs",
39
40
  "yargs",
41
+ "yargs.cjs",
40
42
  "build",
41
43
  "locales",
42
44
  "LICENSE",
@@ -53,34 +55,35 @@
53
55
  "yargs-parser": "^20.2.2"
54
56
  },
55
57
  "devDependencies": {
56
- "@types/chai": "^4.2.11",
57
- "@types/mocha": "^8.0.0",
58
- "@types/node": "^14.11.2",
59
- "@wessberg/rollup-plugin-ts": "^1.3.2",
60
- "c8": "^7.0.0",
61
- "chai": "^4.2.0",
62
- "chalk": "^4.0.0",
63
- "coveralls": "^3.0.9",
64
- "cpr": "^3.0.1",
65
- "cross-env": "^7.0.2",
66
- "cross-spawn": "^7.0.0",
67
- "gts": "^3.0.0",
58
+ "@types/babel__traverse": "7.0.16",
59
+ "@types/chai": "4.2.14",
60
+ "@types/mocha": "8.0.4",
61
+ "@types/node": "14.14.0",
62
+ "@wessberg/rollup-plugin-ts": "1.3.8",
63
+ "chai": "4.2.0",
64
+ "chalk": "4.1.0",
65
+ "coveralls": "3.1.0",
66
+ "cpr": "3.0.1",
67
+ "cross-env": "7.0.2",
68
+ "cross-spawn": "7.0.3",
69
+ "gts": "3.0.3",
68
70
  "hashish": "0.0.4",
69
- "mocha": "^8.0.0",
70
- "rimraf": "^3.0.2",
71
- "rollup": "^2.23.0",
72
- "rollup-plugin-cleanup": "^3.1.1",
71
+ "mocha": "8.2.1",
72
+ "rimraf": "3.0.2",
73
+ "prettier": "2.2.1",
74
+ "rollup": "2.34.1",
75
+ "rollup-plugin-cleanup": "3.2.1",
73
76
  "standardx": "^5.0.0",
74
- "typescript": "^4.0.2",
75
- "which": "^2.0.0",
76
- "yargs-test-extends": "^1.0.1"
77
+ "typescript": "4.1.2",
78
+ "which": "2.0.2",
79
+ "yargs-test-extends": "1.0.1"
77
80
  },
78
81
  "scripts": {
79
82
  "fix": "gts fix && npm run fix:js",
80
83
  "fix:js": "standardx --fix '**/*.mjs' && standardx --fix '**/*.cjs' && standardx --fix './*.mjs' && standardx --fix './*.cjs'",
81
84
  "posttest": "npm run check",
82
- "test": "c8 mocha ./test/*.cjs --require ./test/before.cjs --timeout=12000 --check-leaks",
83
- "test:esm": "c8 mocha ./test/esm/*.mjs --check-leaks",
85
+ "test": "mocha ./test/*.cjs --require ./test/before.cjs --timeout=12000 --check-leaks",
86
+ "test:esm": "mocha ./test/esm/*.mjs --check-leaks",
84
87
  "coverage": "c8 report --check-coverage",
85
88
  "prepare": "npm run compile",
86
89
  "pretest": "npm run compile -- -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs",
@@ -88,8 +91,7 @@
88
91
  "postcompile": "npm run build:cjs",
89
92
  "build:cjs": "rollup -c rollup.config.cjs",
90
93
  "postbuild:cjs": "rimraf ./build/index.cjs.d.ts",
91
- "check": "gts lint && npm run check:js",
92
- "check:js": "standardx '**/*.mjs' && standardx '**/*.cjs' && standardx './*.mjs' && standardx './*.cjs'",
94
+ "check": "gts lint",
93
95
  "clean": "gts clean"
94
96
  },
95
97
  "repository": {
package/yargs CHANGED
@@ -1,9 +1,5 @@
1
- // TODO: consolidate on using a helpers file at some point in the future, which
2
- // is the approach currently used to export Parser and applyExtends for ESM:
3
- const {applyExtends, cjsPlatformShim, Parser, Yargs, processArgv} = require('./build/index.cjs')
4
- Yargs.applyExtends = (config, cwd, mergeExtends) => {
5
- return applyExtends(config, cwd, mergeExtends, cjsPlatformShim)
6
- }
7
- Yargs.hideBin = processArgv.hideBin
8
- Yargs.Parser = Parser
9
- module.exports = Yargs
1
+ // This file gets hit in node versions below node 12.17.0
2
+ // when require('yargs/yargs') from CommonJS
3
+ // because conditional exports not fully supported and treats as filename.
4
+
5
+ module.exports = require('./yargs.cjs');
package/yargs.cjs ADDED
@@ -0,0 +1,15 @@
1
+ // TODO: consolidate on using a helpers file at some point in the future, which
2
+ // is the approach currently used to export Parser and applyExtends for ESM:
3
+ const {
4
+ applyExtends,
5
+ cjsPlatformShim,
6
+ Parser,
7
+ Yargs,
8
+ processArgv,
9
+ } = require('./build/index.cjs');
10
+ Yargs.applyExtends = (config, cwd, mergeExtends) => {
11
+ return applyExtends(config, cwd, mergeExtends, cjsPlatformShim);
12
+ };
13
+ Yargs.hideBin = processArgv.hideBin;
14
+ Yargs.Parser = Parser;
15
+ module.exports = Yargs;