@form8ion/utils-cli 13.1.17 → 13.1.19

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.
@@ -1,10 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import yargs from 'yargs';
3
- import { format } from 'util';
4
- import { resolve, normalize } from 'path';
5
- import { readFileSync, writeFile, statSync } from 'fs';
6
- import 'assert';
7
- import { fileURLToPath } from 'url';
3
+ import { hideBin } from 'yargs/helpers';
8
4
  import updateNotifier from 'update-notifier';
9
5
  import { promptConstants as promptConstants$1, questionNames as questionNames$1, scaffold as scaffold$2 } from '@form8ion/project';
10
6
  import * as renovatePlugin from '@form8ion/renovate-scaffolder';
@@ -35,1450 +31,10 @@ import { scaffold as scaffold$4 } from '@form8ion/ossf-scorecard';
35
31
  import { lift as lift$2, test } from '@form8ion/jetbrains';
36
32
  import { scaffold as scaffold$3 } from '@form8ion/codecov';
37
33
 
38
- function getProcessArgvBinIndex() {
39
- if (isBundledElectronApp())
40
- return 0;
41
- return 1;
42
- }
43
- function isBundledElectronApp() {
44
- return isElectronApp() && !process.defaultApp;
45
- }
46
- function isElectronApp() {
47
- return !!process.versions.electron;
48
- }
49
- function hideBin(argv) {
50
- return argv.slice(getProcessArgvBinIndex() + 1);
51
- }
52
-
53
- /**
54
- * @license
55
- * Copyright (c) 2016, Contributors
56
- * SPDX-License-Identifier: ISC
57
- */
58
- function camelCase(str) {
59
- // Handle the case where an argument is provided as camel case, e.g., fooBar.
60
- // by ensuring that the string isn't already mixed case:
61
- const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();
62
- if (!isCamelCase) {
63
- str = str.toLowerCase();
64
- }
65
- if (str.indexOf('-') === -1 && str.indexOf('_') === -1) {
66
- return str;
67
- }
68
- else {
69
- let camelcase = '';
70
- let nextChrUpper = false;
71
- const leadingHyphens = str.match(/^-+/);
72
- for (let i = leadingHyphens ? leadingHyphens[0].length : 0; i < str.length; i++) {
73
- let chr = str.charAt(i);
74
- if (nextChrUpper) {
75
- nextChrUpper = false;
76
- chr = chr.toUpperCase();
77
- }
78
- if (i !== 0 && (chr === '-' || chr === '_')) {
79
- nextChrUpper = true;
80
- }
81
- else if (chr !== '-' && chr !== '_') {
82
- camelcase += chr;
83
- }
84
- }
85
- return camelcase;
86
- }
87
- }
88
- function decamelize(str, joinString) {
89
- const lowercase = str.toLowerCase();
90
- joinString = joinString || '-';
91
- let notCamelcase = '';
92
- for (let i = 0; i < str.length; i++) {
93
- const chrLower = lowercase.charAt(i);
94
- const chrString = str.charAt(i);
95
- if (chrLower !== chrString && i > 0) {
96
- notCamelcase += `${joinString}${lowercase.charAt(i)}`;
97
- }
98
- else {
99
- notCamelcase += chrString;
100
- }
101
- }
102
- return notCamelcase;
103
- }
104
- function looksLikeNumber(x) {
105
- if (x === null || x === undefined)
106
- return false;
107
- // if loaded from config, may already be a number.
108
- if (typeof x === 'number')
109
- return true;
110
- // hexadecimal.
111
- if (/^0x[0-9a-f]+$/i.test(x))
112
- return true;
113
- // don't treat 0123 as a number; as it drops the leading '0'.
114
- if (/^0[^.]/.test(x))
115
- return false;
116
- return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
117
- }
118
-
119
- /**
120
- * @license
121
- * Copyright (c) 2016, Contributors
122
- * SPDX-License-Identifier: ISC
123
- */
124
- // take an un-split argv string and tokenize it.
125
- function tokenizeArgString(argString) {
126
- if (Array.isArray(argString)) {
127
- return argString.map(e => typeof e !== 'string' ? e + '' : e);
128
- }
129
- argString = argString.trim();
130
- let i = 0;
131
- let prevC = null;
132
- let c = null;
133
- let opening = null;
134
- const args = [];
135
- for (let ii = 0; ii < argString.length; ii++) {
136
- prevC = c;
137
- c = argString.charAt(ii);
138
- // split on spaces unless we're in quotes.
139
- if (c === ' ' && !opening) {
140
- if (!(prevC === ' ')) {
141
- i++;
142
- }
143
- continue;
144
- }
145
- // don't split the string if we're in matching
146
- // opening or closing single and double quotes.
147
- if (c === opening) {
148
- opening = null;
149
- }
150
- else if ((c === "'" || c === '"') && !opening) {
151
- opening = c;
152
- }
153
- if (!args[i])
154
- args[i] = '';
155
- args[i] += c;
156
- }
157
- return args;
158
- }
159
-
160
- /**
161
- * @license
162
- * Copyright (c) 2016, Contributors
163
- * SPDX-License-Identifier: ISC
164
- */
165
- var DefaultValuesForTypeKey;
166
- (function (DefaultValuesForTypeKey) {
167
- DefaultValuesForTypeKey["BOOLEAN"] = "boolean";
168
- DefaultValuesForTypeKey["STRING"] = "string";
169
- DefaultValuesForTypeKey["NUMBER"] = "number";
170
- DefaultValuesForTypeKey["ARRAY"] = "array";
171
- })(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));
172
-
173
- /**
174
- * @license
175
- * Copyright (c) 2016, Contributors
176
- * SPDX-License-Identifier: ISC
177
- */
178
- let mixin;
179
- class YargsParser {
180
- constructor(_mixin) {
181
- mixin = _mixin;
182
- }
183
- parse(argsInput, options) {
184
- const opts = Object.assign({
185
- alias: undefined,
186
- array: undefined,
187
- boolean: undefined,
188
- config: undefined,
189
- configObjects: undefined,
190
- configuration: undefined,
191
- coerce: undefined,
192
- count: undefined,
193
- default: undefined,
194
- envPrefix: undefined,
195
- narg: undefined,
196
- normalize: undefined,
197
- string: undefined,
198
- number: undefined,
199
- __: undefined,
200
- key: undefined
201
- }, options);
202
- // allow a string argument to be passed in rather
203
- // than an argv array.
204
- const args = tokenizeArgString(argsInput);
205
- // tokenizeArgString adds extra quotes to args if argsInput is a string
206
- // only strip those extra quotes in processValue if argsInput is a string
207
- const inputIsString = typeof argsInput === 'string';
208
- // aliases might have transitive relationships, normalize this.
209
- const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
210
- const configuration = Object.assign({
211
- 'boolean-negation': true,
212
- 'camel-case-expansion': true,
213
- 'combine-arrays': false,
214
- 'dot-notation': true,
215
- 'duplicate-arguments-array': true,
216
- 'flatten-duplicate-arrays': true,
217
- 'greedy-arrays': true,
218
- 'halt-at-non-option': false,
219
- 'nargs-eats-options': false,
220
- 'negation-prefix': 'no-',
221
- 'parse-numbers': true,
222
- 'parse-positional-numbers': true,
223
- 'populate--': false,
224
- 'set-placeholder-key': false,
225
- 'short-option-groups': true,
226
- 'strip-aliased': false,
227
- 'strip-dashed': false,
228
- 'unknown-options-as-args': false
229
- }, opts.configuration);
230
- const defaults = Object.assign(Object.create(null), opts.default);
231
- const configObjects = opts.configObjects || [];
232
- const envPrefix = opts.envPrefix;
233
- const notFlagsOption = configuration['populate--'];
234
- const notFlagsArgv = notFlagsOption ? '--' : '_';
235
- const newAliases = Object.create(null);
236
- const defaulted = Object.create(null);
237
- // allow a i18n handler to be passed in, default to a fake one (util.format).
238
- const __ = opts.__ || mixin.format;
239
- const flags = {
240
- aliases: Object.create(null),
241
- arrays: Object.create(null),
242
- bools: Object.create(null),
243
- strings: Object.create(null),
244
- numbers: Object.create(null),
245
- counts: Object.create(null),
246
- normalize: Object.create(null),
247
- configs: Object.create(null),
248
- nargs: Object.create(null),
249
- coercions: Object.create(null),
250
- keys: []
251
- };
252
- const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
253
- const negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)');
254
- [].concat(opts.array || []).filter(Boolean).forEach(function (opt) {
255
- const key = typeof opt === 'object' ? opt.key : opt;
256
- // assign to flags[bools|strings|numbers]
257
- const assignment = Object.keys(opt).map(function (key) {
258
- const arrayFlagKeys = {
259
- boolean: 'bools',
260
- string: 'strings',
261
- number: 'numbers'
262
- };
263
- return arrayFlagKeys[key];
264
- }).filter(Boolean).pop();
265
- // assign key to be coerced
266
- if (assignment) {
267
- flags[assignment][key] = true;
268
- }
269
- flags.arrays[key] = true;
270
- flags.keys.push(key);
271
- });
272
- [].concat(opts.boolean || []).filter(Boolean).forEach(function (key) {
273
- flags.bools[key] = true;
274
- flags.keys.push(key);
275
- });
276
- [].concat(opts.string || []).filter(Boolean).forEach(function (key) {
277
- flags.strings[key] = true;
278
- flags.keys.push(key);
279
- });
280
- [].concat(opts.number || []).filter(Boolean).forEach(function (key) {
281
- flags.numbers[key] = true;
282
- flags.keys.push(key);
283
- });
284
- [].concat(opts.count || []).filter(Boolean).forEach(function (key) {
285
- flags.counts[key] = true;
286
- flags.keys.push(key);
287
- });
288
- [].concat(opts.normalize || []).filter(Boolean).forEach(function (key) {
289
- flags.normalize[key] = true;
290
- flags.keys.push(key);
291
- });
292
- if (typeof opts.narg === 'object') {
293
- Object.entries(opts.narg).forEach(([key, value]) => {
294
- if (typeof value === 'number') {
295
- flags.nargs[key] = value;
296
- flags.keys.push(key);
297
- }
298
- });
299
- }
300
- if (typeof opts.coerce === 'object') {
301
- Object.entries(opts.coerce).forEach(([key, value]) => {
302
- if (typeof value === 'function') {
303
- flags.coercions[key] = value;
304
- flags.keys.push(key);
305
- }
306
- });
307
- }
308
- if (typeof opts.config !== 'undefined') {
309
- if (Array.isArray(opts.config) || typeof opts.config === 'string') {
310
- [].concat(opts.config).filter(Boolean).forEach(function (key) {
311
- flags.configs[key] = true;
312
- });
313
- }
314
- else if (typeof opts.config === 'object') {
315
- Object.entries(opts.config).forEach(([key, value]) => {
316
- if (typeof value === 'boolean' || typeof value === 'function') {
317
- flags.configs[key] = value;
318
- }
319
- });
320
- }
321
- }
322
- // create a lookup table that takes into account all
323
- // combinations of aliases: {f: ['foo'], foo: ['f']}
324
- extendAliases(opts.key, aliases, opts.default, flags.arrays);
325
- // apply default values to all aliases.
326
- Object.keys(defaults).forEach(function (key) {
327
- (flags.aliases[key] || []).forEach(function (alias) {
328
- defaults[alias] = defaults[key];
329
- });
330
- });
331
- let error = null;
332
- checkConfiguration();
333
- let notFlags = [];
334
- const argv = Object.assign(Object.create(null), { _: [] });
335
- // TODO(bcoe): for the first pass at removing object prototype we didn't
336
- // remove all prototypes from objects returned by this API, we might want
337
- // to gradually move towards doing so.
338
- const argvReturn = {};
339
- for (let i = 0; i < args.length; i++) {
340
- const arg = args[i];
341
- const truncatedArg = arg.replace(/^-{3,}/, '---');
342
- let broken;
343
- let key;
344
- let letters;
345
- let m;
346
- let next;
347
- let value;
348
- // any unknown option (except for end-of-options, "--")
349
- if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
350
- pushPositional(arg);
351
- // ---, ---=, ----, etc,
352
- }
353
- else if (truncatedArg.match(/^---+(=|$)/)) {
354
- // options without key name are invalid.
355
- pushPositional(arg);
356
- continue;
357
- // -- separated by =
358
- }
359
- else if (arg.match(/^--.+=/) || (!configuration['short-option-groups'] && arg.match(/^-.+=/))) {
360
- // Using [\s\S] instead of . because js doesn't support the
361
- // 'dotall' regex modifier. See:
362
- // http://stackoverflow.com/a/1068308/13216
363
- m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
364
- // arrays format = '--f=a b c'
365
- if (m !== null && Array.isArray(m) && m.length >= 3) {
366
- if (checkAllAliases(m[1], flags.arrays)) {
367
- i = eatArray(i, m[1], args, m[2]);
368
- }
369
- else if (checkAllAliases(m[1], flags.nargs) !== false) {
370
- // nargs format = '--f=monkey washing cat'
371
- i = eatNargs(i, m[1], args, m[2]);
372
- }
373
- else {
374
- setArg(m[1], m[2], true);
375
- }
376
- }
377
- }
378
- else if (arg.match(negatedBoolean) && configuration['boolean-negation']) {
379
- m = arg.match(negatedBoolean);
380
- if (m !== null && Array.isArray(m) && m.length >= 2) {
381
- key = m[1];
382
- setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);
383
- }
384
- // -- separated by space.
385
- }
386
- else if (arg.match(/^--.+/) || (!configuration['short-option-groups'] && arg.match(/^-[^-]+/))) {
387
- m = arg.match(/^--?(.+)/);
388
- if (m !== null && Array.isArray(m) && m.length >= 2) {
389
- key = m[1];
390
- if (checkAllAliases(key, flags.arrays)) {
391
- // array format = '--foo a b c'
392
- i = eatArray(i, key, args);
393
- }
394
- else if (checkAllAliases(key, flags.nargs) !== false) {
395
- // nargs format = '--foo a b c'
396
- // should be truthy even if: flags.nargs[key] === 0
397
- i = eatNargs(i, key, args);
398
- }
399
- else {
400
- next = args[i + 1];
401
- if (next !== undefined && (!next.match(/^-/) ||
402
- next.match(negative)) &&
403
- !checkAllAliases(key, flags.bools) &&
404
- !checkAllAliases(key, flags.counts)) {
405
- setArg(key, next);
406
- i++;
407
- }
408
- else if (/^(true|false)$/.test(next)) {
409
- setArg(key, next);
410
- i++;
411
- }
412
- else {
413
- setArg(key, defaultValue(key));
414
- }
415
- }
416
- }
417
- // dot-notation flag separated by '='.
418
- }
419
- else if (arg.match(/^-.\..+=/)) {
420
- m = arg.match(/^-([^=]+)=([\s\S]*)$/);
421
- if (m !== null && Array.isArray(m) && m.length >= 3) {
422
- setArg(m[1], m[2]);
423
- }
424
- // dot-notation flag separated by space.
425
- }
426
- else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
427
- next = args[i + 1];
428
- m = arg.match(/^-(.\..+)/);
429
- if (m !== null && Array.isArray(m) && m.length >= 2) {
430
- key = m[1];
431
- if (next !== undefined && !next.match(/^-/) &&
432
- !checkAllAliases(key, flags.bools) &&
433
- !checkAllAliases(key, flags.counts)) {
434
- setArg(key, next);
435
- i++;
436
- }
437
- else {
438
- setArg(key, defaultValue(key));
439
- }
440
- }
441
- }
442
- else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {
443
- letters = arg.slice(1, -1).split('');
444
- broken = false;
445
- for (let j = 0; j < letters.length; j++) {
446
- next = arg.slice(j + 2);
447
- if (letters[j + 1] && letters[j + 1] === '=') {
448
- value = arg.slice(j + 3);
449
- key = letters[j];
450
- if (checkAllAliases(key, flags.arrays)) {
451
- // array format = '-f=a b c'
452
- i = eatArray(i, key, args, value);
453
- }
454
- else if (checkAllAliases(key, flags.nargs) !== false) {
455
- // nargs format = '-f=monkey washing cat'
456
- i = eatNargs(i, key, args, value);
457
- }
458
- else {
459
- setArg(key, value);
460
- }
461
- broken = true;
462
- break;
463
- }
464
- if (next === '-') {
465
- setArg(letters[j], next);
466
- continue;
467
- }
468
- // current letter is an alphabetic character and next value is a number
469
- if (/[A-Za-z]/.test(letters[j]) &&
470
- /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) &&
471
- checkAllAliases(next, flags.bools) === false) {
472
- setArg(letters[j], next);
473
- broken = true;
474
- break;
475
- }
476
- if (letters[j + 1] && letters[j + 1].match(/\W/)) {
477
- setArg(letters[j], next);
478
- broken = true;
479
- break;
480
- }
481
- else {
482
- setArg(letters[j], defaultValue(letters[j]));
483
- }
484
- }
485
- key = arg.slice(-1)[0];
486
- if (!broken && key !== '-') {
487
- if (checkAllAliases(key, flags.arrays)) {
488
- // array format = '-f a b c'
489
- i = eatArray(i, key, args);
490
- }
491
- else if (checkAllAliases(key, flags.nargs) !== false) {
492
- // nargs format = '-f a b c'
493
- // should be truthy even if: flags.nargs[key] === 0
494
- i = eatNargs(i, key, args);
495
- }
496
- else {
497
- next = args[i + 1];
498
- if (next !== undefined && (!/^(-|--)[^-]/.test(next) ||
499
- next.match(negative)) &&
500
- !checkAllAliases(key, flags.bools) &&
501
- !checkAllAliases(key, flags.counts)) {
502
- setArg(key, next);
503
- i++;
504
- }
505
- else if (/^(true|false)$/.test(next)) {
506
- setArg(key, next);
507
- i++;
508
- }
509
- else {
510
- setArg(key, defaultValue(key));
511
- }
512
- }
513
- }
514
- }
515
- else if (arg.match(/^-[0-9]$/) &&
516
- arg.match(negative) &&
517
- checkAllAliases(arg.slice(1), flags.bools)) {
518
- // single-digit boolean alias, e.g: xargs -0
519
- key = arg.slice(1);
520
- setArg(key, defaultValue(key));
521
- }
522
- else if (arg === '--') {
523
- notFlags = args.slice(i + 1);
524
- break;
525
- }
526
- else if (configuration['halt-at-non-option']) {
527
- notFlags = args.slice(i);
528
- break;
529
- }
530
- else {
531
- pushPositional(arg);
532
- }
533
- }
534
- // order of precedence:
535
- // 1. command line arg
536
- // 2. value from env var
537
- // 3. value from config file
538
- // 4. value from config objects
539
- // 5. configured default value
540
- applyEnvVars(argv, true); // special case: check env vars that point to config file
541
- applyEnvVars(argv, false);
542
- setConfig(argv);
543
- setConfigObjects();
544
- applyDefaultsAndAliases(argv, flags.aliases, defaults, true);
545
- applyCoercions(argv);
546
- if (configuration['set-placeholder-key'])
547
- setPlaceholderKeys(argv);
548
- // for any counts either not in args or without an explicit default, set to 0
549
- Object.keys(flags.counts).forEach(function (key) {
550
- if (!hasKey(argv, key.split('.')))
551
- setArg(key, 0);
552
- });
553
- // '--' defaults to undefined.
554
- if (notFlagsOption && notFlags.length)
555
- argv[notFlagsArgv] = [];
556
- notFlags.forEach(function (key) {
557
- argv[notFlagsArgv].push(key);
558
- });
559
- if (configuration['camel-case-expansion'] && configuration['strip-dashed']) {
560
- Object.keys(argv).filter(key => key !== '--' && key.includes('-')).forEach(key => {
561
- delete argv[key];
562
- });
563
- }
564
- if (configuration['strip-aliased']) {
565
- [].concat(...Object.keys(aliases).map(k => aliases[k])).forEach(alias => {
566
- if (configuration['camel-case-expansion'] && alias.includes('-')) {
567
- delete argv[alias.split('.').map(prop => camelCase(prop)).join('.')];
568
- }
569
- delete argv[alias];
570
- });
571
- }
572
- // Push argument into positional array, applying numeric coercion:
573
- function pushPositional(arg) {
574
- const maybeCoercedNumber = maybeCoerceNumber('_', arg);
575
- if (typeof maybeCoercedNumber === 'string' || typeof maybeCoercedNumber === 'number') {
576
- argv._.push(maybeCoercedNumber);
577
- }
578
- }
579
- // how many arguments should we consume, based
580
- // on the nargs option?
581
- function eatNargs(i, key, args, argAfterEqualSign) {
582
- let ii;
583
- let toEat = checkAllAliases(key, flags.nargs);
584
- // NaN has a special meaning for the array type, indicating that one or
585
- // more values are expected.
586
- toEat = typeof toEat !== 'number' || isNaN(toEat) ? 1 : toEat;
587
- if (toEat === 0) {
588
- if (!isUndefined(argAfterEqualSign)) {
589
- error = Error(__('Argument unexpected for: %s', key));
590
- }
591
- setArg(key, defaultValue(key));
592
- return i;
593
- }
594
- let available = isUndefined(argAfterEqualSign) ? 0 : 1;
595
- if (configuration['nargs-eats-options']) {
596
- // classic behavior, yargs eats positional and dash arguments.
597
- if (args.length - (i + 1) + available < toEat) {
598
- error = Error(__('Not enough arguments following: %s', key));
599
- }
600
- available = toEat;
601
- }
602
- else {
603
- // nargs will not consume flag arguments, e.g., -abc, --foo,
604
- // and terminates when one is observed.
605
- for (ii = i + 1; ii < args.length; ii++) {
606
- if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii]))
607
- available++;
608
- else
609
- break;
610
- }
611
- if (available < toEat)
612
- error = Error(__('Not enough arguments following: %s', key));
613
- }
614
- let consumed = Math.min(available, toEat);
615
- if (!isUndefined(argAfterEqualSign) && consumed > 0) {
616
- setArg(key, argAfterEqualSign);
617
- consumed--;
618
- }
619
- for (ii = i + 1; ii < (consumed + i + 1); ii++) {
620
- setArg(key, args[ii]);
621
- }
622
- return (i + consumed);
623
- }
624
- // if an option is an array, eat all non-hyphenated arguments
625
- // following it... YUM!
626
- // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
627
- function eatArray(i, key, args, argAfterEqualSign) {
628
- let argsToSet = [];
629
- let next = argAfterEqualSign || args[i + 1];
630
- // If both array and nargs are configured, enforce the nargs count:
631
- const nargsCount = checkAllAliases(key, flags.nargs);
632
- if (checkAllAliases(key, flags.bools) && !(/^(true|false)$/.test(next))) {
633
- argsToSet.push(true);
634
- }
635
- else if (isUndefined(next) ||
636
- (isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))) {
637
- // for keys without value ==> argsToSet remains an empty []
638
- // set user default value, if available
639
- if (defaults[key] !== undefined) {
640
- const defVal = defaults[key];
641
- argsToSet = Array.isArray(defVal) ? defVal : [defVal];
642
- }
643
- }
644
- else {
645
- // value in --option=value is eaten as is
646
- if (!isUndefined(argAfterEqualSign)) {
647
- argsToSet.push(processValue(key, argAfterEqualSign, true));
648
- }
649
- for (let ii = i + 1; ii < args.length; ii++) {
650
- if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||
651
- (nargsCount && typeof nargsCount === 'number' && argsToSet.length >= nargsCount))
652
- break;
653
- next = args[ii];
654
- if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
655
- break;
656
- i = ii;
657
- argsToSet.push(processValue(key, next, inputIsString));
658
- }
659
- }
660
- // If both array and nargs are configured, create an error if less than
661
- // nargs positionals were found. NaN has special meaning, indicating
662
- // that at least one value is required (more are okay).
663
- if (typeof nargsCount === 'number' && ((nargsCount && argsToSet.length < nargsCount) ||
664
- (isNaN(nargsCount) && argsToSet.length === 0))) {
665
- error = Error(__('Not enough arguments following: %s', key));
666
- }
667
- setArg(key, argsToSet);
668
- return i;
669
- }
670
- function setArg(key, val, shouldStripQuotes = inputIsString) {
671
- if (/-/.test(key) && configuration['camel-case-expansion']) {
672
- const alias = key.split('.').map(function (prop) {
673
- return camelCase(prop);
674
- }).join('.');
675
- addNewAlias(key, alias);
676
- }
677
- const value = processValue(key, val, shouldStripQuotes);
678
- const splitKey = key.split('.');
679
- setKey(argv, splitKey, value);
680
- // handle populating aliases of the full key
681
- if (flags.aliases[key]) {
682
- flags.aliases[key].forEach(function (x) {
683
- const keyProperties = x.split('.');
684
- setKey(argv, keyProperties, value);
685
- });
686
- }
687
- // handle populating aliases of the first element of the dot-notation key
688
- if (splitKey.length > 1 && configuration['dot-notation']) {
689
- (flags.aliases[splitKey[0]] || []).forEach(function (x) {
690
- let keyProperties = x.split('.');
691
- // expand alias with nested objects in key
692
- const a = [].concat(splitKey);
693
- a.shift(); // nuke the old key.
694
- keyProperties = keyProperties.concat(a);
695
- // populate alias only if is not already an alias of the full key
696
- // (already populated above)
697
- if (!(flags.aliases[key] || []).includes(keyProperties.join('.'))) {
698
- setKey(argv, keyProperties, value);
699
- }
700
- });
701
- }
702
- // Set normalize getter and setter when key is in 'normalize' but isn't an array
703
- if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
704
- const keys = [key].concat(flags.aliases[key] || []);
705
- keys.forEach(function (key) {
706
- Object.defineProperty(argvReturn, key, {
707
- enumerable: true,
708
- get() {
709
- return val;
710
- },
711
- set(value) {
712
- val = typeof value === 'string' ? mixin.normalize(value) : value;
713
- }
714
- });
715
- });
716
- }
717
- }
718
- function addNewAlias(key, alias) {
719
- if (!(flags.aliases[key] && flags.aliases[key].length)) {
720
- flags.aliases[key] = [alias];
721
- newAliases[alias] = true;
722
- }
723
- if (!(flags.aliases[alias] && flags.aliases[alias].length)) {
724
- addNewAlias(alias, key);
725
- }
726
- }
727
- function processValue(key, val, shouldStripQuotes) {
728
- // strings may be quoted, clean this up as we assign values.
729
- if (shouldStripQuotes) {
730
- val = stripQuotes(val);
731
- }
732
- // handle parsing boolean arguments --foo=true --bar false.
733
- if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
734
- if (typeof val === 'string')
735
- val = val === 'true';
736
- }
737
- let value = Array.isArray(val)
738
- ? val.map(function (v) { return maybeCoerceNumber(key, v); })
739
- : maybeCoerceNumber(key, val);
740
- // increment a count given as arg (either no value or value parsed as boolean)
741
- if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) {
742
- value = increment();
743
- }
744
- // Set normalized value when key is in 'normalize' and in 'arrays'
745
- if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
746
- if (Array.isArray(val))
747
- value = val.map((val) => { return mixin.normalize(val); });
748
- else
749
- value = mixin.normalize(val);
750
- }
751
- return value;
752
- }
753
- function maybeCoerceNumber(key, value) {
754
- if (!configuration['parse-positional-numbers'] && key === '_')
755
- return value;
756
- if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
757
- const shouldCoerceNumber = looksLikeNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(Math.floor(parseFloat(`${value}`))));
758
- if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) {
759
- value = Number(value);
760
- }
761
- }
762
- return value;
763
- }
764
- // set args from config.json file, this should be
765
- // applied last so that defaults can be applied.
766
- function setConfig(argv) {
767
- const configLookup = Object.create(null);
768
- // expand defaults/aliases, in-case any happen to reference
769
- // the config.json file.
770
- applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
771
- Object.keys(flags.configs).forEach(function (configKey) {
772
- const configPath = argv[configKey] || configLookup[configKey];
773
- if (configPath) {
774
- try {
775
- let config = null;
776
- const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath);
777
- const resolveConfig = flags.configs[configKey];
778
- if (typeof resolveConfig === 'function') {
779
- try {
780
- config = resolveConfig(resolvedConfigPath);
781
- }
782
- catch (e) {
783
- config = e;
784
- }
785
- if (config instanceof Error) {
786
- error = config;
787
- return;
788
- }
789
- }
790
- else {
791
- config = mixin.require(resolvedConfigPath);
792
- }
793
- setConfigObject(config);
794
- }
795
- catch (ex) {
796
- // Deno will receive a PermissionDenied error if an attempt is
797
- // made to load config without the --allow-read flag:
798
- if (ex.name === 'PermissionDenied')
799
- error = ex;
800
- else if (argv[configKey])
801
- error = Error(__('Invalid JSON config file: %s', configPath));
802
- }
803
- }
804
- });
805
- }
806
- // set args from config object.
807
- // it recursively checks nested objects.
808
- function setConfigObject(config, prev) {
809
- Object.keys(config).forEach(function (key) {
810
- const value = config[key];
811
- const fullKey = prev ? prev + '.' + key : key;
812
- // if the value is an inner object and we have dot-notation
813
- // enabled, treat inner objects in config the same as
814
- // heavily nested dot notations (foo.bar.apple).
815
- if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
816
- // if the value is an object but not an array, check nested object
817
- setConfigObject(value, fullKey);
818
- }
819
- else {
820
- // setting arguments via CLI takes precedence over
821
- // values within the config file.
822
- if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {
823
- setArg(fullKey, value);
824
- }
825
- }
826
- });
827
- }
828
- // set all config objects passed in opts
829
- function setConfigObjects() {
830
- if (typeof configObjects !== 'undefined') {
831
- configObjects.forEach(function (configObject) {
832
- setConfigObject(configObject);
833
- });
834
- }
835
- }
836
- function applyEnvVars(argv, configOnly) {
837
- if (typeof envPrefix === 'undefined')
838
- return;
839
- const prefix = typeof envPrefix === 'string' ? envPrefix : '';
840
- const env = mixin.env();
841
- Object.keys(env).forEach(function (envVar) {
842
- if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
843
- // get array of nested keys and convert them to camel case
844
- const keys = envVar.split('__').map(function (key, i) {
845
- if (i === 0) {
846
- key = key.substring(prefix.length);
847
- }
848
- return camelCase(key);
849
- });
850
- if (((configOnly && flags.configs[keys.join('.')]) || !configOnly) && !hasKey(argv, keys)) {
851
- setArg(keys.join('.'), env[envVar]);
852
- }
853
- }
854
- });
855
- }
856
- function applyCoercions(argv) {
857
- let coerce;
858
- const applied = new Set();
859
- Object.keys(argv).forEach(function (key) {
860
- if (!applied.has(key)) { // If we haven't already coerced this option via one of its aliases
861
- coerce = checkAllAliases(key, flags.coercions);
862
- if (typeof coerce === 'function') {
863
- try {
864
- const value = maybeCoerceNumber(key, coerce(argv[key]));
865
- ([].concat(flags.aliases[key] || [], key)).forEach(ali => {
866
- applied.add(ali);
867
- argv[ali] = value;
868
- });
869
- }
870
- catch (err) {
871
- error = err;
872
- }
873
- }
874
- }
875
- });
876
- }
877
- function setPlaceholderKeys(argv) {
878
- flags.keys.forEach((key) => {
879
- // don't set placeholder keys for dot notation options 'foo.bar'.
880
- if (~key.indexOf('.'))
881
- return;
882
- if (typeof argv[key] === 'undefined')
883
- argv[key] = undefined;
884
- });
885
- return argv;
886
- }
887
- function applyDefaultsAndAliases(obj, aliases, defaults, canLog = false) {
888
- Object.keys(defaults).forEach(function (key) {
889
- if (!hasKey(obj, key.split('.'))) {
890
- setKey(obj, key.split('.'), defaults[key]);
891
- if (canLog)
892
- defaulted[key] = true;
893
- (aliases[key] || []).forEach(function (x) {
894
- if (hasKey(obj, x.split('.')))
895
- return;
896
- setKey(obj, x.split('.'), defaults[key]);
897
- });
898
- }
899
- });
900
- }
901
- function hasKey(obj, keys) {
902
- let o = obj;
903
- if (!configuration['dot-notation'])
904
- keys = [keys.join('.')];
905
- keys.slice(0, -1).forEach(function (key) {
906
- o = (o[key] || {});
907
- });
908
- const key = keys[keys.length - 1];
909
- if (typeof o !== 'object')
910
- return false;
911
- else
912
- return key in o;
913
- }
914
- function setKey(obj, keys, value) {
915
- let o = obj;
916
- if (!configuration['dot-notation'])
917
- keys = [keys.join('.')];
918
- keys.slice(0, -1).forEach(function (key) {
919
- // TODO(bcoe): in the next major version of yargs, switch to
920
- // Object.create(null) for dot notation:
921
- key = sanitizeKey(key);
922
- if (typeof o === 'object' && o[key] === undefined) {
923
- o[key] = {};
924
- }
925
- if (typeof o[key] !== 'object' || Array.isArray(o[key])) {
926
- // ensure that o[key] is an array, and that the last item is an empty object.
927
- if (Array.isArray(o[key])) {
928
- o[key].push({});
929
- }
930
- else {
931
- o[key] = [o[key], {}];
932
- }
933
- // we want to update the empty object at the end of the o[key] array, so set o to that object
934
- o = o[key][o[key].length - 1];
935
- }
936
- else {
937
- o = o[key];
938
- }
939
- });
940
- // TODO(bcoe): in the next major version of yargs, switch to
941
- // Object.create(null) for dot notation:
942
- const key = sanitizeKey(keys[keys.length - 1]);
943
- const isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);
944
- const isValueArray = Array.isArray(value);
945
- let duplicate = configuration['duplicate-arguments-array'];
946
- // nargs has higher priority than duplicate
947
- if (!duplicate && checkAllAliases(key, flags.nargs)) {
948
- duplicate = true;
949
- if ((!isUndefined(o[key]) && flags.nargs[key] === 1) || (Array.isArray(o[key]) && o[key].length === flags.nargs[key])) {
950
- o[key] = undefined;
951
- }
952
- }
953
- if (value === increment()) {
954
- o[key] = increment(o[key]);
955
- }
956
- else if (Array.isArray(o[key])) {
957
- if (duplicate && isTypeArray && isValueArray) {
958
- o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);
959
- }
960
- else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
961
- o[key] = value;
962
- }
963
- else {
964
- o[key] = o[key].concat([value]);
965
- }
966
- }
967
- else if (o[key] === undefined && isTypeArray) {
968
- o[key] = isValueArray ? value : [value];
969
- }
970
- else if (duplicate && !(o[key] === undefined ||
971
- checkAllAliases(key, flags.counts) ||
972
- checkAllAliases(key, flags.bools))) {
973
- o[key] = [o[key], value];
974
- }
975
- else {
976
- o[key] = value;
977
- }
978
- }
979
- // extend the aliases list with inferred aliases.
980
- function extendAliases(...args) {
981
- args.forEach(function (obj) {
982
- Object.keys(obj || {}).forEach(function (key) {
983
- // short-circuit if we've already added a key
984
- // to the aliases array, for example it might
985
- // exist in both 'opts.default' and 'opts.key'.
986
- if (flags.aliases[key])
987
- return;
988
- flags.aliases[key] = [].concat(aliases[key] || []);
989
- // For "--option-name", also set argv.optionName
990
- flags.aliases[key].concat(key).forEach(function (x) {
991
- if (/-/.test(x) && configuration['camel-case-expansion']) {
992
- const c = camelCase(x);
993
- if (c !== key && flags.aliases[key].indexOf(c) === -1) {
994
- flags.aliases[key].push(c);
995
- newAliases[c] = true;
996
- }
997
- }
998
- });
999
- // For "--optionName", also set argv['option-name']
1000
- flags.aliases[key].concat(key).forEach(function (x) {
1001
- if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
1002
- const c = decamelize(x, '-');
1003
- if (c !== key && flags.aliases[key].indexOf(c) === -1) {
1004
- flags.aliases[key].push(c);
1005
- newAliases[c] = true;
1006
- }
1007
- }
1008
- });
1009
- flags.aliases[key].forEach(function (x) {
1010
- flags.aliases[x] = [key].concat(flags.aliases[key].filter(function (y) {
1011
- return x !== y;
1012
- }));
1013
- });
1014
- });
1015
- });
1016
- }
1017
- function checkAllAliases(key, flag) {
1018
- const toCheck = [].concat(flags.aliases[key] || [], key);
1019
- const keys = Object.keys(flag);
1020
- const setAlias = toCheck.find(key => keys.includes(key));
1021
- return setAlias ? flag[setAlias] : false;
1022
- }
1023
- function hasAnyFlag(key) {
1024
- const flagsKeys = Object.keys(flags);
1025
- const toCheck = [].concat(flagsKeys.map(k => flags[k]));
1026
- return toCheck.some(function (flag) {
1027
- return Array.isArray(flag) ? flag.includes(key) : flag[key];
1028
- });
1029
- }
1030
- function hasFlagsMatching(arg, ...patterns) {
1031
- const toCheck = [].concat(...patterns);
1032
- return toCheck.some(function (pattern) {
1033
- const match = arg.match(pattern);
1034
- return match && hasAnyFlag(match[1]);
1035
- });
1036
- }
1037
- // based on a simplified version of the short flag group parsing logic
1038
- function hasAllShortFlags(arg) {
1039
- // if this is a negative number, or doesn't start with a single hyphen, it's not a short flag group
1040
- if (arg.match(negative) || !arg.match(/^-[^-]+/)) {
1041
- return false;
1042
- }
1043
- let hasAllFlags = true;
1044
- let next;
1045
- const letters = arg.slice(1).split('');
1046
- for (let j = 0; j < letters.length; j++) {
1047
- next = arg.slice(j + 2);
1048
- if (!hasAnyFlag(letters[j])) {
1049
- hasAllFlags = false;
1050
- break;
1051
- }
1052
- if ((letters[j + 1] && letters[j + 1] === '=') ||
1053
- next === '-' ||
1054
- (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) ||
1055
- (letters[j + 1] && letters[j + 1].match(/\W/))) {
1056
- break;
1057
- }
1058
- }
1059
- return hasAllFlags;
1060
- }
1061
- function isUnknownOptionAsArg(arg) {
1062
- return configuration['unknown-options-as-args'] && isUnknownOption(arg);
1063
- }
1064
- function isUnknownOption(arg) {
1065
- arg = arg.replace(/^-{3,}/, '--');
1066
- // ignore negative numbers
1067
- if (arg.match(negative)) {
1068
- return false;
1069
- }
1070
- // if this is a short option group and all of them are configured, it isn't unknown
1071
- if (hasAllShortFlags(arg)) {
1072
- return false;
1073
- }
1074
- // e.g. '--count=2'
1075
- const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;
1076
- // e.g. '-a' or '--arg'
1077
- const normalFlag = /^-+([^=]+?)$/;
1078
- // e.g. '-a-'
1079
- const flagEndingInHyphen = /^-+([^=]+?)-$/;
1080
- // e.g. '-abc123'
1081
- const flagEndingInDigits = /^-+([^=]+?\d+)$/;
1082
- // e.g. '-a/usr/local'
1083
- const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
1084
- // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
1085
- return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);
1086
- }
1087
- // make a best effort to pick a default value
1088
- // for an option based on name and type.
1089
- function defaultValue(key) {
1090
- if (!checkAllAliases(key, flags.bools) &&
1091
- !checkAllAliases(key, flags.counts) &&
1092
- `${key}` in defaults) {
1093
- return defaults[key];
1094
- }
1095
- else {
1096
- return defaultForType(guessType(key));
1097
- }
1098
- }
1099
- // return a default value, given the type of a flag.,
1100
- function defaultForType(type) {
1101
- const def = {
1102
- [DefaultValuesForTypeKey.BOOLEAN]: true,
1103
- [DefaultValuesForTypeKey.STRING]: '',
1104
- [DefaultValuesForTypeKey.NUMBER]: undefined,
1105
- [DefaultValuesForTypeKey.ARRAY]: []
1106
- };
1107
- return def[type];
1108
- }
1109
- // given a flag, enforce a default type.
1110
- function guessType(key) {
1111
- let type = DefaultValuesForTypeKey.BOOLEAN;
1112
- if (checkAllAliases(key, flags.strings))
1113
- type = DefaultValuesForTypeKey.STRING;
1114
- else if (checkAllAliases(key, flags.numbers))
1115
- type = DefaultValuesForTypeKey.NUMBER;
1116
- else if (checkAllAliases(key, flags.bools))
1117
- type = DefaultValuesForTypeKey.BOOLEAN;
1118
- else if (checkAllAliases(key, flags.arrays))
1119
- type = DefaultValuesForTypeKey.ARRAY;
1120
- return type;
1121
- }
1122
- function isUndefined(num) {
1123
- return num === undefined;
1124
- }
1125
- // check user configuration settings for inconsistencies
1126
- function checkConfiguration() {
1127
- // count keys should not be set as array/narg
1128
- Object.keys(flags.counts).find(key => {
1129
- if (checkAllAliases(key, flags.arrays)) {
1130
- error = Error(__('Invalid configuration: %s, opts.count excludes opts.array.', key));
1131
- return true;
1132
- }
1133
- else if (checkAllAliases(key, flags.nargs)) {
1134
- error = Error(__('Invalid configuration: %s, opts.count excludes opts.narg.', key));
1135
- return true;
1136
- }
1137
- return false;
1138
- });
1139
- }
1140
- return {
1141
- aliases: Object.assign({}, flags.aliases),
1142
- argv: Object.assign(argvReturn, argv),
1143
- configuration: configuration,
1144
- defaulted: Object.assign({}, defaulted),
1145
- error: error,
1146
- newAliases: Object.assign({}, newAliases)
1147
- };
1148
- }
1149
- }
1150
- // if any aliases reference each other, we should
1151
- // merge them together.
1152
- function combineAliases(aliases) {
1153
- const aliasArrays = [];
1154
- const combined = Object.create(null);
1155
- let change = true;
1156
- // turn alias lookup hash {key: ['alias1', 'alias2']} into
1157
- // a simple array ['key', 'alias1', 'alias2']
1158
- Object.keys(aliases).forEach(function (key) {
1159
- aliasArrays.push([].concat(aliases[key], key));
1160
- });
1161
- // combine arrays until zero changes are
1162
- // made in an iteration.
1163
- while (change) {
1164
- change = false;
1165
- for (let i = 0; i < aliasArrays.length; i++) {
1166
- for (let ii = i + 1; ii < aliasArrays.length; ii++) {
1167
- const intersect = aliasArrays[i].filter(function (v) {
1168
- return aliasArrays[ii].indexOf(v) !== -1;
1169
- });
1170
- if (intersect.length) {
1171
- aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);
1172
- aliasArrays.splice(ii, 1);
1173
- change = true;
1174
- break;
1175
- }
1176
- }
1177
- }
1178
- }
1179
- // map arrays back to the hash-lookup (de-dupe while
1180
- // we're at it).
1181
- aliasArrays.forEach(function (aliasArray) {
1182
- aliasArray = aliasArray.filter(function (v, i, self) {
1183
- return self.indexOf(v) === i;
1184
- });
1185
- const lastAlias = aliasArray.pop();
1186
- if (lastAlias !== undefined && typeof lastAlias === 'string') {
1187
- combined[lastAlias] = aliasArray;
1188
- }
1189
- });
1190
- return combined;
1191
- }
1192
- // this function should only be called when a count is given as an arg
1193
- // it is NOT called to set a default value
1194
- // thus we can start the count at 1 instead of 0
1195
- function increment(orig) {
1196
- return orig !== undefined ? orig + 1 : 1;
1197
- }
1198
- // TODO(bcoe): in the next major version of yargs, switch to
1199
- // Object.create(null) for dot notation:
1200
- function sanitizeKey(key) {
1201
- if (key === '__proto__')
1202
- return '___proto___';
1203
- return key;
1204
- }
1205
- function stripQuotes(val) {
1206
- return (typeof val === 'string' &&
1207
- (val[0] === "'" || val[0] === '"') &&
1208
- val[val.length - 1] === val[0])
1209
- ? val.substring(1, val.length - 1)
1210
- : val;
1211
- }
1212
-
1213
- /**
1214
- * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
1215
- * CJS and ESM environments.
1216
- *
1217
- * @license
1218
- * Copyright (c) 2016, Contributors
1219
- * SPDX-License-Identifier: ISC
1220
- */
1221
- var _a, _b, _c;
1222
- // See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
1223
- // version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
1224
- const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
1225
- ? Number(process.env.YARGS_MIN_NODE_VERSION)
1226
- : 12;
1227
- const nodeVersion = (_b = (_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : (_c = process === null || process === void 0 ? void 0 : process.version) === null || _c === void 0 ? void 0 : _c.slice(1);
1228
- if (nodeVersion) {
1229
- const major = Number(nodeVersion.match(/^([^.]+)/)[1]);
1230
- if (major < minNodeVersion) {
1231
- throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
1232
- }
1233
- }
1234
- // Creates a yargs-parser instance using Node.js standard libraries:
1235
- const env = process ? process.env : {};
1236
- new YargsParser({
1237
- cwd: process.cwd,
1238
- env: () => {
1239
- return env;
1240
- },
1241
- format,
1242
- normalize,
1243
- resolve,
1244
- // TODO: figure out a way to combine ESM and CJS coverage, such that
1245
- // we can exercise all the lines below:
1246
- require: (path) => {
1247
- if (typeof require !== 'undefined') {
1248
- return require(path);
1249
- }
1250
- else if (path.match(/\.json$/)) {
1251
- // Addresses: https://github.com/yargs/yargs/issues/2040
1252
- return JSON.parse(readFileSync(path, 'utf8'));
1253
- }
1254
- else {
1255
- throw Error('only .json config files are supported in ESM');
1256
- }
1257
- }
1258
- });
1259
-
1260
- var shim$1 = {
1261
- fs: {
1262
- readFileSync,
1263
- writeFile
1264
- },
1265
- format,
1266
- resolve,
1267
- exists: (file) => {
1268
- try {
1269
- return statSync(file).isFile();
1270
- }
1271
- catch (err) {
1272
- return false;
1273
- }
1274
- }
1275
- };
1276
-
1277
- let shim;
1278
- class Y18N {
1279
- constructor(opts) {
1280
- // configurable options.
1281
- opts = opts || {};
1282
- this.directory = opts.directory || './locales';
1283
- this.updateFiles = typeof opts.updateFiles === 'boolean' ? opts.updateFiles : true;
1284
- this.locale = opts.locale || 'en';
1285
- this.fallbackToLanguage = typeof opts.fallbackToLanguage === 'boolean' ? opts.fallbackToLanguage : true;
1286
- // internal stuff.
1287
- this.cache = Object.create(null);
1288
- this.writeQueue = [];
1289
- }
1290
- __(...args) {
1291
- if (typeof arguments[0] !== 'string') {
1292
- return this._taggedLiteral(arguments[0], ...arguments);
1293
- }
1294
- const str = args.shift();
1295
- let cb = function () { }; // start with noop.
1296
- if (typeof args[args.length - 1] === 'function')
1297
- cb = args.pop();
1298
- cb = cb || function () { }; // noop.
1299
- if (!this.cache[this.locale])
1300
- this._readLocaleFile();
1301
- // we've observed a new string, update the language file.
1302
- if (!this.cache[this.locale][str] && this.updateFiles) {
1303
- this.cache[this.locale][str] = str;
1304
- // include the current directory and locale,
1305
- // since these values could change before the
1306
- // write is performed.
1307
- this._enqueueWrite({
1308
- directory: this.directory,
1309
- locale: this.locale,
1310
- cb
1311
- });
1312
- }
1313
- else {
1314
- cb();
1315
- }
1316
- return shim.format.apply(shim.format, [this.cache[this.locale][str] || str].concat(args));
1317
- }
1318
- __n() {
1319
- const args = Array.prototype.slice.call(arguments);
1320
- const singular = args.shift();
1321
- const plural = args.shift();
1322
- const quantity = args.shift();
1323
- let cb = function () { }; // start with noop.
1324
- if (typeof args[args.length - 1] === 'function')
1325
- cb = args.pop();
1326
- if (!this.cache[this.locale])
1327
- this._readLocaleFile();
1328
- let str = quantity === 1 ? singular : plural;
1329
- if (this.cache[this.locale][singular]) {
1330
- const entry = this.cache[this.locale][singular];
1331
- str = entry[quantity === 1 ? 'one' : 'other'];
1332
- }
1333
- // we've observed a new string, update the language file.
1334
- if (!this.cache[this.locale][singular] && this.updateFiles) {
1335
- this.cache[this.locale][singular] = {
1336
- one: singular,
1337
- other: plural
1338
- };
1339
- // include the current directory and locale,
1340
- // since these values could change before the
1341
- // write is performed.
1342
- this._enqueueWrite({
1343
- directory: this.directory,
1344
- locale: this.locale,
1345
- cb
1346
- });
1347
- }
1348
- else {
1349
- cb();
1350
- }
1351
- // if a %d placeholder is provided, add quantity
1352
- // to the arguments expanded by util.format.
1353
- const values = [str];
1354
- if (~str.indexOf('%d'))
1355
- values.push(quantity);
1356
- return shim.format.apply(shim.format, values.concat(args));
1357
- }
1358
- setLocale(locale) {
1359
- this.locale = locale;
1360
- }
1361
- getLocale() {
1362
- return this.locale;
1363
- }
1364
- updateLocale(obj) {
1365
- if (!this.cache[this.locale])
1366
- this._readLocaleFile();
1367
- for (const key in obj) {
1368
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
1369
- this.cache[this.locale][key] = obj[key];
1370
- }
1371
- }
1372
- }
1373
- _taggedLiteral(parts, ...args) {
1374
- let str = '';
1375
- parts.forEach(function (part, i) {
1376
- const arg = args[i + 1];
1377
- str += part;
1378
- if (typeof arg !== 'undefined') {
1379
- str += '%s';
1380
- }
1381
- });
1382
- return this.__.apply(this, [str].concat([].slice.call(args, 1)));
1383
- }
1384
- _enqueueWrite(work) {
1385
- this.writeQueue.push(work);
1386
- if (this.writeQueue.length === 1)
1387
- this._processWriteQueue();
1388
- }
1389
- _processWriteQueue() {
1390
- const _this = this;
1391
- const work = this.writeQueue[0];
1392
- // destructure the enqueued work.
1393
- const directory = work.directory;
1394
- const locale = work.locale;
1395
- const cb = work.cb;
1396
- const languageFile = this._resolveLocaleFile(directory, locale);
1397
- const serializedLocale = JSON.stringify(this.cache[locale], null, 2);
1398
- shim.fs.writeFile(languageFile, serializedLocale, 'utf-8', function (err) {
1399
- _this.writeQueue.shift();
1400
- if (_this.writeQueue.length > 0)
1401
- _this._processWriteQueue();
1402
- cb(err);
1403
- });
1404
- }
1405
- _readLocaleFile() {
1406
- let localeLookup = {};
1407
- const languageFile = this._resolveLocaleFile(this.directory, this.locale);
1408
- try {
1409
- // When using a bundler such as webpack, readFileSync may not be defined:
1410
- if (shim.fs.readFileSync) {
1411
- localeLookup = JSON.parse(shim.fs.readFileSync(languageFile, 'utf-8'));
1412
- }
1413
- }
1414
- catch (err) {
1415
- if (err instanceof SyntaxError) {
1416
- err.message = 'syntax error in ' + languageFile;
1417
- }
1418
- if (err.code === 'ENOENT')
1419
- localeLookup = {};
1420
- else
1421
- throw err;
1422
- }
1423
- this.cache[this.locale] = localeLookup;
1424
- }
1425
- _resolveLocaleFile(directory, locale) {
1426
- let file = shim.resolve(directory, './', locale + '.json');
1427
- if (this.fallbackToLanguage && !this._fileExistsSync(file) && ~locale.lastIndexOf('_')) {
1428
- // attempt fallback to language only
1429
- const languageFile = shim.resolve(directory, './', locale.split('_')[0] + '.json');
1430
- if (this._fileExistsSync(languageFile))
1431
- file = languageFile;
1432
- }
1433
- return file;
1434
- }
1435
- _fileExistsSync(file) {
1436
- return shim.exists(file);
1437
- }
1438
- }
1439
- function y18n$1(opts, _shim) {
1440
- shim = _shim;
1441
- const y18n = new Y18N(opts);
1442
- return {
1443
- __: y18n.__.bind(y18n),
1444
- __n: y18n.__n.bind(y18n),
1445
- setLocale: y18n.setLocale.bind(y18n),
1446
- getLocale: y18n.getLocale.bind(y18n),
1447
- updateLocale: y18n.updateLocale.bind(y18n),
1448
- locale: y18n.locale
1449
- };
1450
- }
1451
-
1452
- const y18n = (opts) => {
1453
- return y18n$1(opts, shim$1)
1454
- };
1455
-
1456
- let __dirname;
1457
- try {
1458
- __dirname = fileURLToPath(import.meta.url);
1459
- } catch (e) {
1460
- __dirname = process.cwd();
1461
- }
1462
- const mainFilename = __dirname.substring(0, __dirname.lastIndexOf('node_modules'));
1463
-
1464
- ({
1465
- mainFilename: mainFilename || process.cwd(),
1466
- process: {
1467
- cwd: process.cwd,
1468
- exit: process.exit,
1469
- nextTick: process.nextTick,
1470
- stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
1471
- },
1472
- y18n: y18n({
1473
- directory: resolve(__dirname, '../../../locales'),
1474
- updateFiles: false
1475
- })
1476
- });
1477
-
1478
34
  var name = "@form8ion/utils-cli";
1479
35
  var description = "cli for various tools for the organization";
1480
36
  var license = "MIT";
1481
- var version = "13.1.17";
37
+ var version = "13.1.19";
1482
38
  var type = "module";
1483
39
  var engines = {
1484
40
  node: "^20.19.0 || >=22.14.0"
@@ -1528,7 +84,7 @@ var publishConfig = {
1528
84
  access: "public",
1529
85
  provenance: true
1530
86
  };
1531
- var packageManager = "npm@11.5.1+sha512.232e6f5d9e799bcb486920b3e9ba907fdf96e576cf7e8c9446c8162e33a416096a1d37a9e910d9a918f6b1f606791c99bc6bb61ee2569b496ec74af13d0dbd95";
87
+ var packageManager = "npm@11.5.2+sha512.aac1241cfc3f41dc38780d64295c6c6b917a41e24288b33519a7b11adfc5a54a5f881c642d7557215b6c70e01e55655ed7ba666300fd0238bc75fb17478afaf3";
1532
88
  var dependencies = {
1533
89
  "@form8ion/cli-core": "1.1.0",
1534
90
  "@form8ion/codecov": "6.2.0",
@@ -1546,7 +102,7 @@ var dependencies = {
1546
102
  "@form8ion/octoherd-script": "1.0.0",
1547
103
  "@form8ion/ossf-scorecard": "1.2.1",
1548
104
  "@form8ion/prettier": "3.1.0",
1549
- "@form8ion/project": "22.0.0-beta.7",
105
+ "@form8ion/project": "22.0.0-beta.8",
1550
106
  "@form8ion/remark-plugin-scaffolder": "4.0.0",
1551
107
  "@form8ion/remove-greenkeeper": "3.0.1",
1552
108
  "@form8ion/renovate-scaffolder": "3.0.0",
@@ -1556,7 +112,7 @@ var dependencies = {
1556
112
  "@form8ion/vite": "3.0.0",
1557
113
  "@form8ion/vitest": "5.2.0",
1558
114
  "update-notifier": "7.3.1",
1559
- yargs: "17.7.2"
115
+ yargs: "18.0.0"
1560
116
  };
1561
117
  var devDependencies = {
1562
118
  "@cucumber/cucumber": "11.3.0",
@@ -1572,9 +128,9 @@ var devDependencies = {
1572
128
  "@travi/any": "3.1.2",
1573
129
  "ban-sensitive-files": "1.10.9",
1574
130
  c8: "10.1.3",
1575
- chai: "5.2.1",
131
+ chai: "6.0.1",
1576
132
  "clear-module": "4.1.2",
1577
- "cross-env": "7.0.3",
133
+ "cross-env": "10.0.0",
1578
134
  "cz-conventional-changelog": "3.3.0",
1579
135
  "deep-equal": "2.2.3",
1580
136
  execa: "9.6.0",
@@ -1587,18 +143,18 @@ var devDependencies = {
1587
143
  "mdast-util-from-markdown": "2.0.2",
1588
144
  "mdast-zone": "6.1.0",
1589
145
  "mock-fs": "5.5.0",
1590
- msw: "2.10.4",
146
+ msw: "2.10.5",
1591
147
  "npm-run-all2": "8.0.4",
1592
148
  publint: "0.3.12",
1593
149
  "remark-cli": "12.0.1",
1594
150
  rimraf: "6.0.1",
1595
- rollup: "4.45.1",
151
+ rollup: "4.49.0",
1596
152
  "rollup-plugin-auto-external": "2.0.0",
1597
153
  "rollup-plugin-executable": "1.6.3",
1598
154
  testdouble: "3.20.2",
1599
155
  "unist-util-find": "3.0.0",
1600
156
  vitest: "3.2.4",
1601
- "vitest-when": "0.6.2"
157
+ "vitest-when": "0.7.0"
1602
158
  };
1603
159
  var pkg = {
1604
160
  name: name,
@@ -1768,10 +324,10 @@ const command$1 = 'scaffold';
1768
324
  const describe$1 = 'Scaffold a new project';
1769
325
 
1770
326
  var scaffoldCommand = /*#__PURE__*/Object.freeze({
1771
- __proto__: null,
1772
- command: command$1,
1773
- describe: describe$1,
1774
- handler: handler$1
327
+ __proto__: null,
328
+ command: command$1,
329
+ describe: describe$1,
330
+ handler: handler$1
1775
331
  });
1776
332
 
1777
333
  function unitTesting(options) {
@@ -1809,10 +365,10 @@ const command = 'lift';
1809
365
  const describe = 'Lift an existing project with additional functionality';
1810
366
 
1811
367
  var liftCommand = /*#__PURE__*/Object.freeze({
1812
- __proto__: null,
1813
- command: command,
1814
- describe: describe,
1815
- handler: handler
368
+ __proto__: null,
369
+ command: command,
370
+ describe: describe,
371
+ handler: handler
1816
372
  });
1817
373
 
1818
374
  function cli(yargs) {