@quilted/create 0.1.28 → 0.1.30

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,9 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var path = require('node:path');
3
+ var require$$0 = require('node:tty');
4
+ var index = require('./index.cjs');
4
5
  var fs = require('node:fs');
6
+ var path = require('node:path');
5
7
  var node_url = require('node:url');
6
- require('./index.cjs');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
10
 
8
11
  function _interopNamespace(e) {
9
12
  if (e && e.__esModule) return e;
@@ -23,8 +26,27 @@ function _interopNamespace(e) {
23
26
  return Object.freeze(n);
24
27
  }
25
28
 
26
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
29
+ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
27
30
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
31
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
32
+
33
+ const VALID_PACKAGE_MANAGERS = new Set(['npm', 'pnpm', 'yarn']);
34
+ async function getPackageManager$1(explicitPackageManager) {
35
+ if (explicitPackageManager) {
36
+ const normalizedPackageManager = explicitPackageManager.toLowerCase();
37
+ return VALID_PACKAGE_MANAGERS.has(normalizedPackageManager) ? normalizedPackageManager : undefined;
38
+ }
39
+
40
+ const npmUserAgent = process.env['npm_config_user_agent'];
41
+
42
+ if (npmUserAgent !== null && npmUserAgent !== void 0 && npmUserAgent.includes('pnpm') || fs.existsSync('pnpm-lock.yaml')) {
43
+ return 'pnpm';
44
+ } else if (npmUserAgent !== null && npmUserAgent !== void 0 && npmUserAgent.includes('yarn') || fs.existsSync('yarn.lock')) {
45
+ return 'yarn';
46
+ } else if (npmUserAgent !== null && npmUserAgent !== void 0 && npmUserAgent.includes('npm') || fs.existsSync('package-lock.json')) {
47
+ return 'npm';
48
+ }
49
+ }
28
50
 
29
51
  function loadTemplate(name) {
30
52
  let templateRootPromise;
@@ -179,6 +201,286 @@ function mergeDependencies(first = {}, second = {}) {
179
201
  return merged;
180
202
  }
181
203
 
204
+ var colorette = {};
205
+
206
+ Object.defineProperty(colorette, '__esModule', { value: true });
207
+
208
+ var tty = require$$0__default["default"];
209
+
210
+ function _interopNamespace$1(e) {
211
+ if (e && e.__esModule) return e;
212
+ var n = Object.create(null);
213
+ if (e) {
214
+ Object.keys(e).forEach(function (k) {
215
+ if (k !== 'default') {
216
+ var d = Object.getOwnPropertyDescriptor(e, k);
217
+ Object.defineProperty(n, k, d.get ? d : {
218
+ enumerable: true,
219
+ get: function () { return e[k]; }
220
+ });
221
+ }
222
+ });
223
+ }
224
+ n["default"] = e;
225
+ return Object.freeze(n);
226
+ }
227
+
228
+ var tty__namespace = /*#__PURE__*/_interopNamespace$1(tty);
229
+
230
+ const env = process.env || {};
231
+ const argv = process.argv || [];
232
+
233
+ const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
234
+ const isForced = "FORCE_COLOR" in env || argv.includes("--color");
235
+ const isWindows = process.platform === "win32";
236
+
237
+ const isCompatibleTerminal =
238
+ tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && env.TERM !== "dumb";
239
+
240
+ const isCI =
241
+ "CI" in env &&
242
+ ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
243
+
244
+ const isColorSupported =
245
+ !isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI);
246
+
247
+ const replaceClose = (
248
+ index,
249
+ string,
250
+ close,
251
+ replace,
252
+ head = string.substring(0, index) + replace,
253
+ tail = string.substring(index + close.length),
254
+ next = tail.indexOf(close)
255
+ ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
256
+
257
+ const clearBleed = (index, string, open, close, replace) =>
258
+ index < 0
259
+ ? open + string + close
260
+ : open + replaceClose(index, string, close, replace) + close;
261
+
262
+ const filterEmpty =
263
+ (open, close, replace = open, at = open.length + 1) =>
264
+ (string) =>
265
+ string || !(string === "" || string === undefined)
266
+ ? clearBleed(
267
+ ("" + string).indexOf(close, at),
268
+ string,
269
+ open,
270
+ close,
271
+ replace
272
+ )
273
+ : "";
274
+
275
+ const init = (open, close, replace) =>
276
+ filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
277
+
278
+ const colors = {
279
+ reset: init(0, 0),
280
+ bold: init(1, 22, "\x1b[22m\x1b[1m"),
281
+ dim: init(2, 22, "\x1b[22m\x1b[2m"),
282
+ italic: init(3, 23),
283
+ underline: init(4, 24),
284
+ inverse: init(7, 27),
285
+ hidden: init(8, 28),
286
+ strikethrough: init(9, 29),
287
+ black: init(30, 39),
288
+ red: init(31, 39),
289
+ green: init(32, 39),
290
+ yellow: init(33, 39),
291
+ blue: init(34, 39),
292
+ magenta: init(35, 39),
293
+ cyan: init(36, 39),
294
+ white: init(37, 39),
295
+ gray: init(90, 39),
296
+ bgBlack: init(40, 49),
297
+ bgRed: init(41, 49),
298
+ bgGreen: init(42, 49),
299
+ bgYellow: init(43, 49),
300
+ bgBlue: init(44, 49),
301
+ bgMagenta: init(45, 49),
302
+ bgCyan: init(46, 49),
303
+ bgWhite: init(47, 49),
304
+ blackBright: init(90, 39),
305
+ redBright: init(91, 39),
306
+ greenBright: init(92, 39),
307
+ yellowBright: init(93, 39),
308
+ blueBright: init(94, 39),
309
+ magentaBright: init(95, 39),
310
+ cyanBright: init(96, 39),
311
+ whiteBright: init(97, 39),
312
+ bgBlackBright: init(100, 49),
313
+ bgRedBright: init(101, 49),
314
+ bgGreenBright: init(102, 49),
315
+ bgYellowBright: init(103, 49),
316
+ bgBlueBright: init(104, 49),
317
+ bgMagentaBright: init(105, 49),
318
+ bgCyanBright: init(106, 49),
319
+ bgWhiteBright: init(107, 49),
320
+ };
321
+
322
+ const none = (any) => any;
323
+
324
+ const createColors = ({ useColor = isColorSupported } = {}) =>
325
+ useColor
326
+ ? colors
327
+ : Object.keys(colors).reduce(
328
+ (colors, key) => ({ ...colors, [key]: none }),
329
+ {}
330
+ );
331
+
332
+ const {
333
+ reset,
334
+ bold,
335
+ dim,
336
+ italic,
337
+ underline,
338
+ inverse,
339
+ hidden,
340
+ strikethrough,
341
+ black,
342
+ red,
343
+ green,
344
+ yellow,
345
+ blue,
346
+ magenta,
347
+ cyan,
348
+ white,
349
+ gray,
350
+ bgBlack,
351
+ bgRed,
352
+ bgGreen,
353
+ bgYellow,
354
+ bgBlue,
355
+ bgMagenta,
356
+ bgCyan,
357
+ bgWhite,
358
+ blackBright,
359
+ redBright,
360
+ greenBright,
361
+ yellowBright,
362
+ blueBright,
363
+ magentaBright,
364
+ cyanBright,
365
+ whiteBright,
366
+ bgBlackBright,
367
+ bgRedBright,
368
+ bgGreenBright,
369
+ bgYellowBright,
370
+ bgBlueBright,
371
+ bgMagentaBright,
372
+ bgCyanBright,
373
+ bgWhiteBright,
374
+ } = createColors();
375
+
376
+ colorette.bgBlack = bgBlack;
377
+ colorette.bgBlackBright = bgBlackBright;
378
+ colorette.bgBlue = bgBlue;
379
+ colorette.bgBlueBright = bgBlueBright;
380
+ colorette.bgCyan = bgCyan;
381
+ colorette.bgCyanBright = bgCyanBright;
382
+ colorette.bgGreen = bgGreen;
383
+ colorette.bgGreenBright = bgGreenBright;
384
+ colorette.bgMagenta = bgMagenta;
385
+ colorette.bgMagentaBright = bgMagentaBright;
386
+ colorette.bgRed = bgRed;
387
+ colorette.bgRedBright = bgRedBright;
388
+ colorette.bgWhite = bgWhite;
389
+ colorette.bgWhiteBright = bgWhiteBright;
390
+ colorette.bgYellow = bgYellow;
391
+ colorette.bgYellowBright = bgYellowBright;
392
+ colorette.black = black;
393
+ colorette.blackBright = blackBright;
394
+ colorette.blue = blue;
395
+ colorette.blueBright = blueBright;
396
+ var bold_1 = colorette.bold = bold;
397
+ colorette.createColors = createColors;
398
+ var cyan_1 = colorette.cyan = cyan;
399
+ colorette.cyanBright = cyanBright;
400
+ var dim_1 = colorette.dim = dim;
401
+ colorette.gray = gray;
402
+ colorette.green = green;
403
+ colorette.greenBright = greenBright;
404
+ colorette.hidden = hidden;
405
+ colorette.inverse = inverse;
406
+ colorette.isColorSupported = isColorSupported;
407
+ colorette.italic = italic;
408
+ var magenta_1 = colorette.magenta = magenta;
409
+ colorette.magentaBright = magentaBright;
410
+ colorette.red = red;
411
+ colorette.redBright = redBright;
412
+ colorette.reset = reset;
413
+ colorette.strikethrough = strikethrough;
414
+ var underline_1 = colorette.underline = underline;
415
+ colorette.white = white;
416
+ colorette.whiteBright = whiteBright;
417
+ colorette.yellow = yellow;
418
+ colorette.yellowBright = yellowBright;
419
+
420
+ async function getCreateAsMonorepo(argv) {
421
+ let createAsMonorepo;
422
+
423
+ if (argv['--monorepo' ]) {
424
+ createAsMonorepo = true;
425
+ } else if (argv['--no-monorepo']) {
426
+ createAsMonorepo = false;
427
+ } else {
428
+ createAsMonorepo = await index.prompt({
429
+ type: 'confirm',
430
+ message: 'Do you want to create this app as a monorepo, with room for more projects?',
431
+ initial: true
432
+ });
433
+ }
434
+
435
+ return createAsMonorepo;
436
+ }
437
+ async function getShouldInstall(argv) {
438
+ let shouldInstall;
439
+
440
+ if (argv['--install'] || argv['--yes']) {
441
+ shouldInstall = true;
442
+ } else if (argv['--no-install']) {
443
+ shouldInstall = false;
444
+ } else {
445
+ shouldInstall = await index.prompt({
446
+ type: 'confirm',
447
+ message: 'Do you want to install dependencies for this app after creating it?',
448
+ initial: true
449
+ });
450
+ }
451
+
452
+ return shouldInstall;
453
+ }
454
+ async function getPackageManager(argv) {
455
+ const packageManager = await getPackageManager$1(argv['--package-manager']);
456
+ return packageManager !== null && packageManager !== void 0 ? packageManager : 'npm';
457
+ }
458
+ const VALID_EXTRAS = new Set(['github', 'vscode']);
459
+ async function getExtrasToSetup(argv, {
460
+ inWorkspace
461
+ }) {
462
+ if (inWorkspace || argv['--no-extras']) return new Set();
463
+
464
+ if (argv['--extras']) {
465
+ return new Set(argv['--extras'].filter(extra => VALID_EXTRAS.has(extra)));
466
+ }
467
+
468
+ const setupExtras = await index.prompt({
469
+ type: 'multiselect',
470
+ message: 'Which additional tools would you like to configure?',
471
+ instructions: dim_1(`\n Use ${bold_1('space')} to select, ${bold_1('a')} to select all, ${bold_1('return')} to submit`),
472
+ choices: [{
473
+ title: 'VSCode',
474
+ value: 'vscode'
475
+ }, {
476
+ title: 'GitHub',
477
+ value: 'github'
478
+ }]
479
+ });
480
+ const extrasToSetup = new Set(setupExtras);
481
+ return extrasToSetup;
482
+ }
483
+
182
484
  const ENDS_WITH_TSCONFIG = /[/]?tsconfig[.a-z0-9]*[.]json/i;
183
485
  async function addToTsConfig(directory, output) {
184
486
  var _tsconfig$references;
@@ -320,11 +622,20 @@ async function addToWorkspaces(relative, workspaces) {
320
622
 
321
623
  exports.addToPackageManagerWorkspaces = addToPackageManagerWorkspaces;
322
624
  exports.addToTsConfig = addToTsConfig;
625
+ exports.bold_1 = bold_1;
323
626
  exports.createOutputTarget = createOutputTarget;
627
+ exports.cyan_1 = cyan_1;
628
+ exports.dim_1 = dim_1;
324
629
  exports.emptyDirectory = emptyDirectory;
325
630
  exports.format = format;
631
+ exports.getCreateAsMonorepo = getCreateAsMonorepo;
632
+ exports.getExtrasToSetup = getExtrasToSetup;
633
+ exports.getPackageManager = getPackageManager;
634
+ exports.getShouldInstall = getShouldInstall;
326
635
  exports.isEmpty = isEmpty;
327
636
  exports.loadTemplate = loadTemplate;
637
+ exports.magenta_1 = magenta_1;
328
638
  exports.mergeDependencies = mergeDependencies;
329
639
  exports.relativeDirectoryForDisplay = relativeDirectoryForDisplay;
330
640
  exports.toValidPackageName = toValidPackageName;
641
+ exports.underline_1 = underline_1;
@@ -37,10 +37,10 @@ let _ = t => t,
37
37
  _t3,
38
38
  _t4;
39
39
  async function createProject() {
40
- const argv = getArgv();
40
+ const args = getArguments();
41
41
 
42
- if (argv['--help']) {
43
- var _argv$PackageManag;
42
+ if (args['--help']) {
43
+ var _args$PackageManag;
44
44
 
45
45
  const additionalOptions = index.stripIndent(_t || (_t = _`
46
46
  ${0}, ${0}
@@ -58,23 +58,23 @@ async function createProject() {
58
58
  index.printHelp({
59
59
  kind: 'package',
60
60
  options: additionalOptions,
61
- packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
61
+ packageManager: (_args$PackageManag = args['--package-manager']) === null || _args$PackageManag === void 0 ? void 0 : _args$PackageManag.toLowerCase()
62
62
  });
63
63
  return;
64
64
  }
65
65
 
66
66
  const inWorkspace = fs__namespace.existsSync('quilt.workspace.ts');
67
- const name = await getName(argv);
68
- const directory = await getDirectory(argv, {
67
+ const name = await getName(args);
68
+ const directory = await getDirectory(args, {
69
69
  name,
70
70
  inWorkspace
71
71
  });
72
- const isPublic = await getPublic(argv);
73
- const useReact = await getReact(argv);
74
- const createAsMonorepo = !inWorkspace && (await index.getCreateAsMonorepo(argv));
75
- const shouldInstall = await index.getShouldInstall(argv);
76
- const packageManager$1 = await index.getPackageManager(argv);
77
- const setupExtras = await index.getExtrasToSetup(argv, {
72
+ const isPublic = await getPublic(args);
73
+ const useReact = await getReact(args);
74
+ const createAsMonorepo = !inWorkspace && (await packageManager.getCreateAsMonorepo(args));
75
+ const shouldInstall = await packageManager.getShouldInstall(args);
76
+ const packageManager$1 = await packageManager.getPackageManager(args);
77
+ const setupExtras = await packageManager.getExtrasToSetup(args, {
78
78
  inWorkspace
79
79
  });
80
80
  const partOfMonorepo = inWorkspace || createAsMonorepo;
@@ -151,7 +151,7 @@ async function createProject() {
151
151
  name: packageManager.toValidPackageName(name),
152
152
  react: useReact,
153
153
  isPublic,
154
- registry: argv['--registry']
154
+ registry: args['--registry']
155
155
  });
156
156
  quiltProject = quiltProject.replace('quiltPackage', 'quiltWorkspace, quiltPackage').replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
157
157
  await outputRoot.write('quilt.project.ts', await packageManager.format(quiltProject, {
@@ -192,7 +192,7 @@ async function createProject() {
192
192
  name: packageManager.toValidPackageName(name),
193
193
  react: useReact,
194
194
  isPublic,
195
- registry: argv['--registry']
195
+ registry: args['--registry']
196
196
  });
197
197
  await outputRoot.write(path__namespace.join(packageDirectory, 'package.json'), await packageManager.format(JSON.stringify(projectPackageJson), {
198
198
  as: 'json-stringify'
@@ -261,8 +261,8 @@ async function createProject() {
261
261
  console.log(followUp);
262
262
  } // Argument handling
263
263
 
264
- function getArgv() {
265
- const argv = index.arg_1({
264
+ function getArguments() {
265
+ const args = index.parseArguments({
266
266
  '--yes': Boolean,
267
267
  '-y': '--yes',
268
268
  '--name': String,
@@ -284,13 +284,13 @@ function getArgv() {
284
284
  }, {
285
285
  permissive: true
286
286
  });
287
- return argv;
287
+ return args;
288
288
  }
289
289
 
290
- async function getName(argv) {
290
+ async function getName(args) {
291
291
  let {
292
292
  '--name': name
293
- } = argv;
293
+ } = args;
294
294
 
295
295
  if (name == null) {
296
296
  name = await index.prompt({
@@ -303,11 +303,11 @@ async function getName(argv) {
303
303
  return name;
304
304
  }
305
305
 
306
- async function getDirectory(argv, {
306
+ async function getDirectory(args, {
307
307
  name,
308
308
  inWorkspace
309
309
  }) {
310
- let directory = argv['--directory'] ? path__namespace.resolve(argv['--directory']) : undefined;
310
+ let directory = args['--directory'] ? path__namespace.resolve(args['--directory']) : undefined;
311
311
 
312
312
  if (directory == null) {
313
313
  const basePackageName = packageManager.toValidPackageName(name.split('/').pop());
@@ -319,7 +319,7 @@ async function getDirectory(argv, {
319
319
  }));
320
320
  }
321
321
 
322
- while (!argv['--yes']) {
322
+ while (!args['--yes']) {
323
323
  if (fs__namespace.existsSync(directory) && !(await packageManager.isEmpty(directory))) {
324
324
  const relativeDirectory = path__namespace.relative(process.cwd(), directory);
325
325
  const empty = await index.prompt({
@@ -341,12 +341,12 @@ async function getDirectory(argv, {
341
341
  return directory;
342
342
  }
343
343
 
344
- async function getPublic(argv) {
344
+ async function getPublic(args) {
345
345
  let isPublic;
346
346
 
347
- if (argv['--public'] || argv['--yes']) {
347
+ if (args['--public'] || args['--yes']) {
348
348
  isPublic = true;
349
- } else if (argv['--private']) {
349
+ } else if (args['--private']) {
350
350
  isPublic = false;
351
351
  } else {
352
352
  isPublic = await index.prompt({
@@ -359,12 +359,12 @@ async function getPublic(argv) {
359
359
  return isPublic;
360
360
  }
361
361
 
362
- async function getReact(argv) {
362
+ async function getReact(args) {
363
363
  let useReact;
364
364
 
365
- if (argv['--react'] || argv['--yes']) {
365
+ if (args['--react'] || args['--yes']) {
366
366
  useReact = true;
367
- } else if (argv['--no-react']) {
367
+ } else if (args['--no-react']) {
368
368
  useReact = false;
369
369
  } else {
370
370
  useReact = await index.prompt({
package/build/esm/app.mjs CHANGED
@@ -1,13 +1,209 @@
1
1
  import * as fs from 'node:fs';
2
2
  import * as path from 'node:path';
3
3
  import { execSync } from 'node:child_process';
4
- import { s as stripIndent, c as cyan_1, b as bold_1, p as printHelp, g as getCreateAsMonorepo, a as getShouldInstall, d as getPackageManager, e as getExtrasToSetup, f as dim_1, u as underline_1, m as magenta_1, h as arg_1, i as prompt } from './index.mjs';
5
- import { e as emptyDirectory, t as toValidPackageName, f as format, m as mergeDependencies, l as loadTemplate, a as addToTsConfig, b as addToPackageManagerWorkspaces, r as relativeDirectoryForDisplay, i as isEmpty, c as createOutputTarget } from './package-manager.mjs';
4
+ import { c as cyan_1, b as bold_1, g as getCreateAsMonorepo, a as getShouldInstall, d as getPackageManager, e as getExtrasToSetup, f as emptyDirectory, t as toValidPackageName, h as format, m as mergeDependencies, l as loadTemplate, i as addToTsConfig, j as addToPackageManagerWorkspaces, r as relativeDirectoryForDisplay, k as dim_1, u as underline_1, n as magenta_1, o as isEmpty, p as createOutputTarget } from './package-manager.mjs';
5
+ import { s as stripIndent, p as printHelp, a as prompt } from './index.mjs';
6
6
  import 'node:tty';
7
7
  import 'node:url';
8
8
  import 'node:readline';
9
9
  import 'node:events';
10
10
 
11
+ const flagSymbol = Symbol('arg flag');
12
+
13
+ class ArgError extends Error {
14
+ constructor(msg, code) {
15
+ super(msg);
16
+ this.name = 'ArgError';
17
+ this.code = code;
18
+
19
+ Object.setPrototypeOf(this, ArgError.prototype);
20
+ }
21
+ }
22
+
23
+ function arg(
24
+ opts,
25
+ {
26
+ argv = process.argv.slice(2),
27
+ permissive = false,
28
+ stopAtPositional = false
29
+ } = {}
30
+ ) {
31
+ if (!opts) {
32
+ throw new ArgError(
33
+ 'argument specification object is required',
34
+ 'ARG_CONFIG_NO_SPEC'
35
+ );
36
+ }
37
+
38
+ const result = { _: [] };
39
+
40
+ const aliases = {};
41
+ const handlers = {};
42
+
43
+ for (const key of Object.keys(opts)) {
44
+ if (!key) {
45
+ throw new ArgError(
46
+ 'argument key cannot be an empty string',
47
+ 'ARG_CONFIG_EMPTY_KEY'
48
+ );
49
+ }
50
+
51
+ if (key[0] !== '-') {
52
+ throw new ArgError(
53
+ `argument key must start with '-' but found: '${key}'`,
54
+ 'ARG_CONFIG_NONOPT_KEY'
55
+ );
56
+ }
57
+
58
+ if (key.length === 1) {
59
+ throw new ArgError(
60
+ `argument key must have a name; singular '-' keys are not allowed: ${key}`,
61
+ 'ARG_CONFIG_NONAME_KEY'
62
+ );
63
+ }
64
+
65
+ if (typeof opts[key] === 'string') {
66
+ aliases[key] = opts[key];
67
+ continue;
68
+ }
69
+
70
+ let type = opts[key];
71
+ let isFlag = false;
72
+
73
+ if (
74
+ Array.isArray(type) &&
75
+ type.length === 1 &&
76
+ typeof type[0] === 'function'
77
+ ) {
78
+ const [fn] = type;
79
+ type = (value, name, prev = []) => {
80
+ prev.push(fn(value, name, prev[prev.length - 1]));
81
+ return prev;
82
+ };
83
+ isFlag = fn === Boolean || fn[flagSymbol] === true;
84
+ } else if (typeof type === 'function') {
85
+ isFlag = type === Boolean || type[flagSymbol] === true;
86
+ } else {
87
+ throw new ArgError(
88
+ `type missing or not a function or valid array type: ${key}`,
89
+ 'ARG_CONFIG_VAD_TYPE'
90
+ );
91
+ }
92
+
93
+ if (key[1] !== '-' && key.length > 2) {
94
+ throw new ArgError(
95
+ `short argument keys (with a single hyphen) must have only one character: ${key}`,
96
+ 'ARG_CONFIG_SHORTOPT_TOOLONG'
97
+ );
98
+ }
99
+
100
+ handlers[key] = [type, isFlag];
101
+ }
102
+
103
+ for (let i = 0, len = argv.length; i < len; i++) {
104
+ const wholeArg = argv[i];
105
+
106
+ if (stopAtPositional && result._.length > 0) {
107
+ result._ = result._.concat(argv.slice(i));
108
+ break;
109
+ }
110
+
111
+ if (wholeArg === '--') {
112
+ result._ = result._.concat(argv.slice(i + 1));
113
+ break;
114
+ }
115
+
116
+ if (wholeArg.length > 1 && wholeArg[0] === '-') {
117
+ /* eslint-disable operator-linebreak */
118
+ const separatedArguments =
119
+ wholeArg[1] === '-' || wholeArg.length === 2
120
+ ? [wholeArg]
121
+ : wholeArg
122
+ .slice(1)
123
+ .split('')
124
+ .map((a) => `-${a}`);
125
+ /* eslint-enable operator-linebreak */
126
+
127
+ for (let j = 0; j < separatedArguments.length; j++) {
128
+ const arg = separatedArguments[j];
129
+ const [originalArgName, argStr] =
130
+ arg[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];
131
+
132
+ let argName = originalArgName;
133
+ while (argName in aliases) {
134
+ argName = aliases[argName];
135
+ }
136
+
137
+ if (!(argName in handlers)) {
138
+ if (permissive) {
139
+ result._.push(arg);
140
+ continue;
141
+ } else {
142
+ throw new ArgError(
143
+ `unknown or unexpected option: ${originalArgName}`,
144
+ 'ARG_UNKNOWN_OPTION'
145
+ );
146
+ }
147
+ }
148
+
149
+ const [type, isFlag] = handlers[argName];
150
+
151
+ if (!isFlag && j + 1 < separatedArguments.length) {
152
+ throw new ArgError(
153
+ `option requires argument (but was followed by another short argument): ${originalArgName}`,
154
+ 'ARG_MISSING_REQUIRED_SHORTARG'
155
+ );
156
+ }
157
+
158
+ if (isFlag) {
159
+ result[argName] = type(true, argName, result[argName]);
160
+ } else if (argStr === undefined) {
161
+ if (
162
+ argv.length < i + 2 ||
163
+ (argv[i + 1].length > 1 &&
164
+ argv[i + 1][0] === '-' &&
165
+ !(
166
+ argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) &&
167
+ (type === Number ||
168
+ // eslint-disable-next-line no-undef
169
+ (typeof BigInt !== 'undefined' && type === BigInt))
170
+ ))
171
+ ) {
172
+ const extended =
173
+ originalArgName === argName ? '' : ` (alias for ${argName})`;
174
+ throw new ArgError(
175
+ `option requires argument: ${originalArgName}${extended}`,
176
+ 'ARG_MISSING_REQUIRED_LONGARG'
177
+ );
178
+ }
179
+
180
+ result[argName] = type(argv[i + 1], argName, result[argName]);
181
+ ++i;
182
+ } else {
183
+ result[argName] = type(argStr, argName, result[argName]);
184
+ }
185
+ }
186
+ } else {
187
+ result._.push(wholeArg);
188
+ }
189
+ }
190
+
191
+ return result;
192
+ }
193
+
194
+ arg.flag = (fn) => {
195
+ fn[flagSymbol] = true;
196
+ return fn;
197
+ };
198
+
199
+ // Utility types
200
+ arg.COUNT = arg.flag((v, name, existingCount) => (existingCount || 0) + 1);
201
+
202
+ // Expose error class
203
+ arg.ArgError = ArgError;
204
+
205
+ var arg_1 = arg;
206
+
11
207
  let _ = t => t,
12
208
  _t,
13
209
  _t2,