vitest 4.1.0-beta.1 → 4.1.0-beta.2

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.
Files changed (65) hide show
  1. package/LICENSE.md +36 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
  5. package/dist/chunks/{base.CBRNZa3k.js → base.DiopZV8F.js} +48 -14
  6. package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.BoqSLF53.js} +1 -1
  7. package/dist/chunks/{browser.d.8hOapKZr.d.ts → browser.d.BE4kbYok.d.ts} +2 -1
  8. package/dist/chunks/{cac.B1v3xxoC.js → cac.C4jjt2RX.js} +797 -13
  9. package/dist/chunks/{cli-api.B4CqEpI6.js → cli-api.ChbI1JU9.js} +322 -124
  10. package/dist/chunks/{config.d.idH22YSr.d.ts → config.d.Cr1Ep39N.d.ts} +6 -1
  11. package/dist/chunks/{console.uGgdMhyZ.js → console.CNlG1KsP.js} +2 -2
  12. package/dist/chunks/{constants.D_Q9UYh-.js → constants.B63TT-Bl.js} +1 -1
  13. package/dist/chunks/coverage.tyqbzn4W.js +1001 -0
  14. package/dist/chunks/{creator.C7WwjkuR.js → creator.yyCHuw5R.js} +1 -1
  15. package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.JeWMqlOm.d.ts} +1 -1
  16. package/dist/chunks/{globals.DjuGMoMc.js → globals.C6Ecf1TO.js} +6 -6
  17. package/dist/chunks/{index.Dm4xqZ0s.js → index.B-iBE_Gx.js} +20 -4
  18. package/dist/chunks/{coverage.BMlOMIWl.js → index.BCY_7LL2.js} +5 -969
  19. package/dist/chunks/{index.BiOAd_ki.js → index.CAN630q3.js} +7 -7
  20. package/dist/chunks/{index.DyBZXrH3.js → index.CFulQRmC.js} +1 -1
  21. package/dist/chunks/{index.BEFi2-_3.js → index.CouFDptX.js} +2 -2
  22. package/dist/chunks/{init-forks.CHeQ9Moq.js → init-forks.BnCXPazU.js} +1 -1
  23. package/dist/chunks/{init-threads.uZiNAuPk.js → init-threads.Cyh2PqXi.js} +1 -1
  24. package/dist/chunks/{init.DVtKdFty.js → init.B95Mm0Iz.js} +47 -9
  25. package/dist/chunks/native.mV0-490A.js +148 -0
  26. package/dist/chunks/nativeModuleMocker.D_q5sFv6.js +206 -0
  27. package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
  28. package/dist/chunks/{node.Ce0vMQM7.js → node.CrSEwhm4.js} +1 -1
  29. package/dist/chunks/{plugin.d.D8KU2PY_.d.ts → plugin.d.C9o5bttz.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.Db3MiIWX.d.ts → reporters.d.7faYdkxy.d.ts} +120 -51
  31. package/dist/chunks/{rpc.HLmECnw_.js → rpc.DcRWTy5G.js} +1 -1
  32. package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.CM7x9-sm.d.ts} +1 -0
  33. package/dist/chunks/{setup-common.BcqLPsn5.js → setup-common.cvFp-ao9.js} +2 -2
  34. package/dist/chunks/{startModuleRunner.C5CcWyXW.js → startVitestModuleRunner.BK-u7y4N.js} +163 -372
  35. package/dist/chunks/{test.prxIahgM.js → test.G82XYNFk.js} +9 -4
  36. package/dist/chunks/{utils.DvEY5TfP.js → utils.DT4VyRyl.js} +5 -1
  37. package/dist/chunks/{vm.CrifS09m.js → vm.BdLtzhnj.js} +13 -6
  38. package/dist/chunks/{worker.d.Bji1eq5g.d.ts → worker.d.CPzI2ZzJ.d.ts} +2 -2
  39. package/dist/cli.js +4 -3
  40. package/dist/config.d.ts +8 -8
  41. package/dist/config.js +1 -1
  42. package/dist/coverage.d.ts +7 -5
  43. package/dist/coverage.js +5 -4
  44. package/dist/index.d.ts +18 -23
  45. package/dist/index.js +5 -5
  46. package/dist/module-evaluator.d.ts +10 -1
  47. package/dist/node.d.ts +9 -9
  48. package/dist/node.js +18 -16
  49. package/dist/nodejs-worker-loader.js +41 -0
  50. package/dist/reporters.d.ts +5 -5
  51. package/dist/reporters.js +2 -2
  52. package/dist/runners.d.ts +2 -1
  53. package/dist/runners.js +4 -4
  54. package/dist/runtime.js +4 -5
  55. package/dist/snapshot.js +2 -2
  56. package/dist/suite.js +2 -2
  57. package/dist/worker.d.ts +6 -6
  58. package/dist/worker.js +25 -18
  59. package/dist/workers/forks.js +21 -14
  60. package/dist/workers/runVmTests.js +7 -7
  61. package/dist/workers/threads.js +21 -14
  62. package/dist/workers/vmForks.js +14 -10
  63. package/dist/workers/vmThreads.js +14 -10
  64. package/package.json +17 -14
  65. package/suppress-warnings.cjs +1 -0
@@ -1,9 +1,10 @@
1
1
  import { toArray } from '@vitest/utils/helpers';
2
2
  import { EventEmitter } from 'events';
3
3
  import { normalize } from 'pathe';
4
- import c from 'tinyrainbow';
5
- import { a as defaultPort, d as defaultBrowserPort } from './constants.D_Q9UYh-.js';
6
- import { R as ReportersMap } from './index.Dm4xqZ0s.js';
4
+ import c$2 from 'tinyrainbow';
5
+ import { b as defaultPort, d as defaultBrowserPort } from './constants.B63TT-Bl.js';
6
+ import { R as ReportersMap } from './index.B-iBE_Gx.js';
7
+ import assert from 'node:assert';
7
8
 
8
9
  function toArr(any) {
9
10
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -619,7 +620,7 @@ class CAC extends EventEmitter {
619
620
 
620
621
  const cac = (name = "") => new CAC(name);
621
622
 
622
- var version = "4.1.0-beta.1";
623
+ var version = "4.1.0-beta.2";
623
624
 
624
625
  const apiConfig = (port) => ({
625
626
  port: {
@@ -1154,7 +1155,17 @@ const cliOptionsConfig = {
1154
1155
  return value;
1155
1156
  }
1156
1157
  },
1158
+ listTags: {
1159
+ description: "List all available tags instead of running tests. `--list-tags=json` will output tags in JSON format, unless there are no tags.",
1160
+ argument: "[type]"
1161
+ },
1157
1162
  clearCache: { description: "Delete all Vitest caches, including `experimental.fsModuleCache`, without running any tests. This will reduce the performance in the subsequent test run." },
1163
+ tagsFilter: {
1164
+ description: "Run only tests with the specified tags. You can use logical operators `&&` (and), `||` (or) and `!` (not) to create complex expressions, see [Test Tags](https://vitest.dev/guide/test-tags#syntax) for more information.",
1165
+ argument: "<expression>",
1166
+ array: true
1167
+ },
1168
+ strictTags: { description: "Should Vitest throw an error if test has a tag that is not defined in the config. (default: `true`)" },
1158
1169
  experimental: {
1159
1170
  description: "Experimental features.",
1160
1171
  argument: "<features>",
@@ -1162,7 +1173,9 @@ const cliOptionsConfig = {
1162
1173
  fsModuleCache: { description: "Enable caching of modules on the file system between reruns." },
1163
1174
  fsModuleCachePath: null,
1164
1175
  openTelemetry: null,
1165
- printImportBreakdown: { description: "Print import breakdown after the summary. If the reporter doesn't support summary, this will have no effect. Note that UI's \"Module Graph\" tab always has an import breakdown." }
1176
+ printImportBreakdown: { description: "Print import breakdown after the summary. If the reporter doesn't support summary, this will have no effect. Note that UI's \"Module Graph\" tab always has an import breakdown." },
1177
+ viteModuleRunner: { description: "Control whether Vitest uses Vite's module runner to run the code or fallback to the native `import`. (default: `true`)" },
1178
+ nodeLoader: { description: "Controls whether Vitest will use Node.js Loader API to process in-source or mocked files. This has no effect if `viteModuleRunner` is enabled. Disabling this can increase performance. (default: `true`)" }
1166
1179
  }
1167
1180
  },
1168
1181
  cliExclude: null,
@@ -1198,7 +1211,8 @@ const cliOptionsConfig = {
1198
1211
  provide: null,
1199
1212
  filesOnly: null,
1200
1213
  projects: null,
1201
- watchTriggerPatterns: null
1214
+ watchTriggerPatterns: null,
1215
+ tags: null
1202
1216
  };
1203
1217
  const benchCliOptionsConfig = {
1204
1218
  compare: {
@@ -1223,6 +1237,775 @@ const collectCliOptionsConfig = {
1223
1237
  }
1224
1238
  };
1225
1239
 
1240
+ function t(e,t){return `#compdef ${e}
1241
+ compdef _${e} ${e}
1242
+
1243
+ # zsh completion for ${e} -*- shell-script -*-
1244
+
1245
+ __${e}_debug() {
1246
+ local file="$BASH_COMP_DEBUG_FILE"
1247
+ if [[ -n \${file} ]]; then
1248
+ echo "$*" >> "\${file}"
1249
+ fi
1250
+ }
1251
+
1252
+ _${e}() {
1253
+ local shellCompDirectiveError=${a.ShellCompDirectiveError}
1254
+ local shellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
1255
+ local shellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
1256
+ local shellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
1257
+ local shellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
1258
+ local shellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
1259
+
1260
+ local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
1261
+ local -a completions
1262
+
1263
+ __${e}_debug "\\n========= starting completion logic =========="
1264
+ __${e}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
1265
+
1266
+ # The user could have moved the cursor backwards on the command-line.
1267
+ # We need to trigger completion from the $CURRENT location, so we need
1268
+ # to truncate the command-line ($words) up to the $CURRENT location.
1269
+ # (We cannot use $CURSOR as its value does not work when a command is an alias.)
1270
+ words=( "\${=words[1,CURRENT]}" )
1271
+ __${e}_debug "Truncated words[*]: \${words[*]},"
1272
+
1273
+ lastParam=\${words[-1]}
1274
+ lastChar=\${lastParam[-1]}
1275
+ __${e}_debug "lastParam: \${lastParam}, lastChar: \${lastChar}"
1276
+
1277
+ # For zsh, when completing a flag with an = (e.g., ${e} -n=<TAB>)
1278
+ # completions must be prefixed with the flag
1279
+ setopt local_options BASH_REMATCH
1280
+ if [[ "\${lastParam}" =~ '-.*=' ]]; then
1281
+ # We are dealing with a flag with an =
1282
+ flagPrefix="-P \${BASH_REMATCH}"
1283
+ fi
1284
+
1285
+ # Prepare the command to obtain completions, ensuring arguments are quoted for eval
1286
+ local -a args_to_quote=("\${(@)words[2,-1]}")
1287
+ if [ "\${lastChar}" = "" ]; then
1288
+ # If the last parameter is complete (there is a space following it)
1289
+ # We add an extra empty parameter so we can indicate this to the go completion code.
1290
+ __${e}_debug "Adding extra empty parameter"
1291
+ args_to_quote+=("")
1292
+ fi
1293
+
1294
+ # Use Zsh's (q) flag to quote each argument safely for eval
1295
+ local quoted_args=("\${(@q)args_to_quote}")
1296
+
1297
+ # Join the main command and the quoted arguments into a single string for eval
1298
+ requestComp="${t} complete -- \${quoted_args[*]}"
1299
+
1300
+ __${e}_debug "About to call: eval \${requestComp}"
1301
+
1302
+ # Use eval to handle any environment variables and such
1303
+ out=$(eval \${requestComp} 2>/dev/null)
1304
+ __${e}_debug "completion output: \${out}"
1305
+
1306
+ # Extract the directive integer following a : from the last line
1307
+ local lastLine
1308
+ while IFS='\n' read -r line; do
1309
+ lastLine=\${line}
1310
+ done < <(printf "%s\n" "\${out[@]}")
1311
+ __${e}_debug "last line: \${lastLine}"
1312
+
1313
+ if [ "\${lastLine[1]}" = : ]; then
1314
+ directive=\${lastLine[2,-1]}
1315
+ # Remove the directive including the : and the newline
1316
+ local suffix
1317
+ (( suffix=\${#lastLine}+2))
1318
+ out=\${out[1,-$suffix]}
1319
+ else
1320
+ # There is no directive specified. Leave $out as is.
1321
+ __${e}_debug "No directive found. Setting to default"
1322
+ directive=0
1323
+ fi
1324
+
1325
+ __${e}_debug "directive: \${directive}"
1326
+ __${e}_debug "completions: \${out}"
1327
+ __${e}_debug "flagPrefix: \${flagPrefix}"
1328
+
1329
+ if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
1330
+ __${e}_debug "Completion received error. Ignoring completions."
1331
+ return
1332
+ fi
1333
+
1334
+ local activeHelpMarker="%"
1335
+ local endIndex=\${#activeHelpMarker}
1336
+ local startIndex=$((\${#activeHelpMarker}+1))
1337
+ local hasActiveHelp=0
1338
+ while IFS='\n' read -r comp; do
1339
+ # Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
1340
+ if [ "\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
1341
+ __${e}_debug "ActiveHelp found: $comp"
1342
+ comp="\${comp[$startIndex,-1]}"
1343
+ if [ -n "$comp" ]; then
1344
+ compadd -x "\${comp}"
1345
+ __${e}_debug "ActiveHelp will need delimiter"
1346
+ hasActiveHelp=1
1347
+ fi
1348
+ continue
1349
+ fi
1350
+
1351
+ if [ -n "$comp" ]; then
1352
+ # If requested, completions are returned with a description.
1353
+ # The description is preceded by a TAB character.
1354
+ # For zsh's _describe, we need to use a : instead of a TAB.
1355
+ # We first need to escape any : as part of the completion itself.
1356
+ comp=\${comp//:/\\:}
1357
+
1358
+ local tab="$(printf '\\t')"
1359
+ comp=\${comp//$tab/:}
1360
+
1361
+ __${e}_debug "Adding completion: \${comp}"
1362
+ completions+=\${comp}
1363
+ lastComp=$comp
1364
+ fi
1365
+ done < <(printf "%s\n" "\${out[@]}")
1366
+
1367
+ # Add a delimiter after the activeHelp statements, but only if:
1368
+ # - there are completions following the activeHelp statements, or
1369
+ # - file completion will be performed (so there will be choices after the activeHelp)
1370
+ if [ $hasActiveHelp -eq 1 ]; then
1371
+ if [ \${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
1372
+ __${e}_debug "Adding activeHelp delimiter"
1373
+ compadd -x "--"
1374
+ hasActiveHelp=0
1375
+ fi
1376
+ fi
1377
+
1378
+ if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
1379
+ __${e}_debug "Activating nospace."
1380
+ noSpace="-S ''"
1381
+ fi
1382
+
1383
+ if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
1384
+ __${e}_debug "Activating keep order."
1385
+ keepOrder="-V"
1386
+ fi
1387
+
1388
+ if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
1389
+ # File extension filtering
1390
+ local filteringCmd
1391
+ filteringCmd='_files'
1392
+ for filter in \${completions[@]}; do
1393
+ if [ \${filter[1]} != '*' ]; then
1394
+ # zsh requires a glob pattern to do file filtering
1395
+ filter="\\*.$filter"
1396
+ fi
1397
+ filteringCmd+=" -g $filter"
1398
+ done
1399
+ filteringCmd+=" \${flagPrefix}"
1400
+
1401
+ __${e}_debug "File filtering command: $filteringCmd"
1402
+ _arguments '*:filename:'"$filteringCmd"
1403
+ elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
1404
+ # File completion for directories only
1405
+ local subdir
1406
+ subdir="\${completions[1]}"
1407
+ if [ -n "$subdir" ]; then
1408
+ __${e}_debug "Listing directories in $subdir"
1409
+ pushd "\${subdir}" >/dev/null 2>&1
1410
+ else
1411
+ __${e}_debug "Listing directories in ."
1412
+ fi
1413
+
1414
+ local result
1415
+ _arguments '*:dirname:_files -/'" \${flagPrefix}"
1416
+ result=$?
1417
+ if [ -n "$subdir" ]; then
1418
+ popd >/dev/null 2>&1
1419
+ fi
1420
+ return $result
1421
+ else
1422
+ __${e}_debug "Calling _describe"
1423
+ if eval _describe $keepOrder "completions" completions -Q \${flagPrefix} \${noSpace}; then
1424
+ __${e}_debug "_describe found some completions"
1425
+
1426
+ # Return the success of having called _describe
1427
+ return 0
1428
+ else
1429
+ __${e}_debug "_describe did not find completions."
1430
+ __${e}_debug "Checking if we should do file completion."
1431
+ if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
1432
+ __${e}_debug "deactivating file completion"
1433
+
1434
+ # Return 0 to indicate completion is finished and prevent zsh from
1435
+ # trying other completion algorithms (which could cause hanging).
1436
+ # We use NoFileComp directive to explicitly disable file completion.
1437
+ return 0
1438
+ else
1439
+ # Perform file completion
1440
+ __${e}_debug "Activating file completion"
1441
+
1442
+ # We must return the result of this command, so it must be the
1443
+ # last command, or else we must store its result to return it.
1444
+ _arguments '*:filename:_files'" \${flagPrefix}"
1445
+ fi
1446
+ fi
1447
+ fi
1448
+ }
1449
+
1450
+ # don't run the completion function when being sourced or eval-ed
1451
+ if [ "\${funcstack[1]}" = "_${e}" ]; then
1452
+ _${e}
1453
+ fi
1454
+ `}function n(e,t){let n=e.replace(/[-:]/g,`_`);return `# bash completion for ${e}
1455
+
1456
+ # Define shell completion directives
1457
+ readonly ShellCompDirectiveError=${a.ShellCompDirectiveError}
1458
+ readonly ShellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
1459
+ readonly ShellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
1460
+ readonly ShellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
1461
+ readonly ShellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
1462
+ readonly ShellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
1463
+
1464
+ # Function to debug completion
1465
+ __${n}_debug() {
1466
+ if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
1467
+ echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
1468
+ fi
1469
+ }
1470
+
1471
+ # Function to handle completions
1472
+ __${n}_complete() {
1473
+ local cur prev words cword
1474
+ _get_comp_words_by_ref -n "=:" cur prev words cword
1475
+
1476
+ local requestComp out directive
1477
+
1478
+ # Build the command to get completions
1479
+ requestComp="${t} complete -- \${words[@]:1}"
1480
+
1481
+ # Add an empty parameter if the last parameter is complete
1482
+ if [[ -z "$cur" ]]; then
1483
+ requestComp="$requestComp ''"
1484
+ fi
1485
+
1486
+ # Get completions from the program
1487
+ out=$(eval "$requestComp" 2>/dev/null)
1488
+
1489
+ # Extract directive if present
1490
+ directive=0
1491
+ if [[ "$out" == *:* ]]; then
1492
+ directive=\${out##*:}
1493
+ out=\${out%:*}
1494
+ fi
1495
+
1496
+ # Process completions based on directive
1497
+ if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then
1498
+ # Error, no completion
1499
+ return
1500
+ fi
1501
+
1502
+ # Apply directives
1503
+ if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then
1504
+ compopt -o nospace
1505
+ fi
1506
+ if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then
1507
+ compopt -o nosort
1508
+ fi
1509
+ if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then
1510
+ compopt +o default
1511
+ fi
1512
+
1513
+ # Handle file extension filtering
1514
+ if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then
1515
+ local filter=""
1516
+ for ext in $out; do
1517
+ filter="$filter|$ext"
1518
+ done
1519
+ filter="\\.($filter)"
1520
+ compopt -o filenames
1521
+ COMPREPLY=( $(compgen -f -X "!$filter" -- "$cur") )
1522
+ return
1523
+ fi
1524
+
1525
+ # Handle directory filtering
1526
+ if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then
1527
+ compopt -o dirnames
1528
+ COMPREPLY=( $(compgen -d -- "$cur") )
1529
+ return
1530
+ fi
1531
+
1532
+ # Process completions
1533
+ local IFS=$'\\n'
1534
+ local tab=$(printf '\\t')
1535
+
1536
+ # Parse completions with descriptions
1537
+ local completions=()
1538
+ while read -r comp; do
1539
+ if [[ "$comp" == *$tab* ]]; then
1540
+ # Split completion and description
1541
+ local value=\${comp%%$tab*}
1542
+ local desc=\${comp#*$tab}
1543
+ completions+=("$value")
1544
+ else
1545
+ completions+=("$comp")
1546
+ fi
1547
+ done <<< "$out"
1548
+
1549
+ # Return completions
1550
+ COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
1551
+ }
1552
+
1553
+ # Register completion function
1554
+ complete -F __${n}_complete ${e}
1555
+ `}function r(e,t){let n=e.replace(/[-:]/g,`_`);return `# fish completion for ${e} -*- shell-script -*-
1556
+
1557
+ # Define shell completion directives
1558
+ set -l ShellCompDirectiveError ${a.ShellCompDirectiveError}
1559
+ set -l ShellCompDirectiveNoSpace ${a.ShellCompDirectiveNoSpace}
1560
+ set -l ShellCompDirectiveNoFileComp ${a.ShellCompDirectiveNoFileComp}
1561
+ set -l ShellCompDirectiveFilterFileExt ${a.ShellCompDirectiveFilterFileExt}
1562
+ set -l ShellCompDirectiveFilterDirs ${a.ShellCompDirectiveFilterDirs}
1563
+ set -l ShellCompDirectiveKeepOrder ${a.ShellCompDirectiveKeepOrder}
1564
+
1565
+ function __${n}_debug
1566
+ set -l file "$BASH_COMP_DEBUG_FILE"
1567
+ if test -n "$file"
1568
+ echo "$argv" >> $file
1569
+ end
1570
+ end
1571
+
1572
+ function __${n}_perform_completion
1573
+ __${n}_debug "Starting __${n}_perform_completion"
1574
+
1575
+ # Extract all args except the completion flag
1576
+ set -l args (string match -v -- "--completion=" (commandline -opc))
1577
+
1578
+ # Extract the current token being completed
1579
+ set -l current_token (commandline -ct)
1580
+
1581
+ # Check if current token starts with a dash
1582
+ set -l flag_prefix ""
1583
+ if string match -q -- "-*" $current_token
1584
+ set flag_prefix "--flag="
1585
+ end
1586
+
1587
+ __${n}_debug "Current token: $current_token"
1588
+ __${n}_debug "All args: $args"
1589
+
1590
+ # Call the completion program and get the results
1591
+ set -l requestComp "${t} complete -- $args"
1592
+ __${n}_debug "Calling $requestComp"
1593
+ set -l results (eval $requestComp 2> /dev/null)
1594
+
1595
+ # Some programs may output extra empty lines after the directive.
1596
+ # Let's ignore them or else it will break completion.
1597
+ # Ref: https://github.com/spf13/cobra/issues/1279
1598
+ for line in $results[-1..1]
1599
+ if test (string sub -s 1 -l 1 -- $line) = ":"
1600
+ # The directive
1601
+ set -l directive (string sub -s 2 -- $line)
1602
+ set -l directive_num (math $directive)
1603
+ break
1604
+ end
1605
+ end
1606
+
1607
+ # No directive specified, use default
1608
+ if not set -q directive_num
1609
+ set directive_num 0
1610
+ end
1611
+
1612
+ __${n}_debug "Directive: $directive_num"
1613
+
1614
+ # Process completions based on directive
1615
+ if test $directive_num -eq $ShellCompDirectiveError
1616
+ # Error code. No completion.
1617
+ __${n}_debug "Received error directive: aborting."
1618
+ return 1
1619
+ end
1620
+
1621
+ # Filter out the directive (last line)
1622
+ if test (count $results) -gt 0 -a (string sub -s 1 -l 1 -- $results[-1]) = ":"
1623
+ set results $results[1..-2]
1624
+ end
1625
+
1626
+ # No completions, let fish handle file completions unless forbidden
1627
+ if test (count $results) -eq 0
1628
+ if test $directive_num -ne $ShellCompDirectiveNoFileComp
1629
+ __${n}_debug "No completions, performing file completion"
1630
+ return 1
1631
+ end
1632
+ __${n}_debug "No completions, but file completion forbidden"
1633
+ return 0
1634
+ end
1635
+
1636
+ # Filter file extensions
1637
+ if test $directive_num -eq $ShellCompDirectiveFilterFileExt
1638
+ __${n}_debug "File extension filtering"
1639
+ set -l file_extensions
1640
+ for item in $results
1641
+ if test -n "$item" -a (string sub -s 1 -l 1 -- $item) != "-"
1642
+ set -a file_extensions "*$item"
1643
+ end
1644
+ end
1645
+ __${n}_debug "File extensions: $file_extensions"
1646
+
1647
+ # Use the file extensions as completions
1648
+ set -l completions
1649
+ for ext in $file_extensions
1650
+ # Get all files matching the extension
1651
+ set -a completions (string replace -r '^.*/' '' -- $ext)
1652
+ end
1653
+
1654
+ for item in $completions
1655
+ echo -e "$item\t"
1656
+ end
1657
+ return 0
1658
+ end
1659
+
1660
+ # Filter directories
1661
+ if test $directive_num -eq $ShellCompDirectiveFilterDirs
1662
+ __${n}_debug "Directory filtering"
1663
+ set -l dirs
1664
+ for item in $results
1665
+ if test -d "$item"
1666
+ set -a dirs "$item/"
1667
+ end
1668
+ end
1669
+
1670
+ for item in $dirs
1671
+ echo -e "$item\t"
1672
+ end
1673
+ return 0
1674
+ end
1675
+
1676
+ # Process remaining completions
1677
+ for item in $results
1678
+ if test -n "$item"
1679
+ # Check if the item has a description
1680
+ if string match -q "*\t*" -- "$item"
1681
+ set -l completion_parts (string split \t -- "$item")
1682
+ set -l comp $completion_parts[1]
1683
+ set -l desc $completion_parts[2]
1684
+
1685
+ # Add the completion and description
1686
+ echo -e "$comp\t$desc"
1687
+ else
1688
+ # Add just the completion
1689
+ echo -e "$item\t"
1690
+ end
1691
+ end
1692
+ end
1693
+
1694
+ # If directive contains NoSpace, tell fish not to add a space after completion
1695
+ if test (math "$directive_num & $ShellCompDirectiveNoSpace") -ne 0
1696
+ return 2
1697
+ end
1698
+
1699
+ return 0
1700
+ end
1701
+
1702
+ # Set up the completion for the ${e} command
1703
+ complete -c ${e} -f -a "(eval __${n}_perform_completion)"
1704
+ `}function i(e,t,n=false){let r=e.replace(/[-:]/g,`_`);return `# powershell completion for ${e} -*- shell-script -*-
1705
+
1706
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
1707
+ function __${e}_debug {
1708
+ if ($env:BASH_COMP_DEBUG_FILE) {
1709
+ "$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
1710
+ }
1711
+ }
1712
+
1713
+ filter __${e}_escapeStringWithSpecialChars {
1714
+ $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\`$&'
1715
+ }
1716
+
1717
+ [scriptblock]$__${r}CompleterBlock = {
1718
+ param(
1719
+ $WordToComplete,
1720
+ $CommandAst,
1721
+ $CursorPosition
1722
+ )
1723
+
1724
+ # Get the current command line and convert into a string
1725
+ $Command = $CommandAst.CommandElements
1726
+ $Command = "$Command"
1727
+
1728
+ __${e}_debug ""
1729
+ __${e}_debug "========= starting completion logic =========="
1730
+ __${e}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
1731
+
1732
+ # The user could have moved the cursor backwards on the command-line.
1733
+ # We need to trigger completion from the $CursorPosition location, so we need
1734
+ # to truncate the command-line ($Command) up to the $CursorPosition location.
1735
+ # Make sure the $Command is longer then the $CursorPosition before we truncate.
1736
+ # This happens because the $Command does not include the last space.
1737
+ if ($Command.Length -gt $CursorPosition) {
1738
+ $Command = $Command.Substring(0, $CursorPosition)
1739
+ }
1740
+ __${e}_debug "Truncated command: $Command"
1741
+
1742
+ $ShellCompDirectiveError=${a.ShellCompDirectiveError}
1743
+ $ShellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
1744
+ $ShellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
1745
+ $ShellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
1746
+ $ShellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
1747
+ $ShellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
1748
+
1749
+ # Prepare the command to request completions for the program.
1750
+ # Split the command at the first space to separate the program and arguments.
1751
+ $Program, $Arguments = $Command.Split(" ", 2)
1752
+
1753
+ $RequestComp = "& ${t} complete -- $Arguments"
1754
+ __${e}_debug "RequestComp: $RequestComp"
1755
+
1756
+ # we cannot use $WordToComplete because it
1757
+ # has the wrong values if the cursor was moved
1758
+ # so use the last argument
1759
+ if ($WordToComplete -ne "" ) {
1760
+ $WordToComplete = $Arguments.Split(" ")[-1]
1761
+ }
1762
+ __${e}_debug "New WordToComplete: $WordToComplete"
1763
+
1764
+
1765
+ # Check for flag with equal sign
1766
+ $IsEqualFlag = ($WordToComplete -Like "--*=*" )
1767
+ if ( $IsEqualFlag ) {
1768
+ __${e}_debug "Completing equal sign flag"
1769
+ # Remove the flag part
1770
+ $Flag, $WordToComplete = $WordToComplete.Split("=", 2)
1771
+ }
1772
+
1773
+ if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
1774
+ # If the last parameter is complete (there is a space following it)
1775
+ # We add an extra empty parameter so we can indicate this to the go method.
1776
+ __${e}_debug "Adding extra empty parameter"
1777
+ # PowerShell 7.2+ changed the way how the arguments are passed to executables,
1778
+ # so for pre-7.2 or when Legacy argument passing is enabled we need to use
1779
+ if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
1780
+ ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
1781
+ (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
1782
+ $PSNativeCommandArgumentPassing -eq 'Legacy')) {
1783
+ $RequestComp="$RequestComp" + ' \`"\`"'
1784
+ } else {
1785
+ $RequestComp = "$RequestComp" + ' ""'
1786
+ }
1787
+ }
1788
+
1789
+ __${e}_debug "Calling $RequestComp"
1790
+ # First disable ActiveHelp which is not supported for Powershell
1791
+ $env:ActiveHelp = 0
1792
+
1793
+ # call the command store the output in $out and redirect stderr and stdout to null
1794
+ # $Out is an array contains each line per element
1795
+ Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
1796
+
1797
+ # get directive from last line
1798
+ [int]$Directive = $Out[-1].TrimStart(':')
1799
+ if ($Directive -eq "") {
1800
+ # There is no directive specified
1801
+ $Directive = 0
1802
+ }
1803
+ __${e}_debug "The completion directive is: $Directive"
1804
+
1805
+ # remove directive (last element) from out
1806
+ $Out = $Out | Where-Object { $_ -ne $Out[-1] }
1807
+ __${e}_debug "The completions are: $Out"
1808
+
1809
+ if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
1810
+ # Error code. No completion.
1811
+ __${e}_debug "Received error from custom completion go code"
1812
+ return
1813
+ }
1814
+
1815
+ $Longest = 0
1816
+ [Array]$Values = $Out | ForEach-Object {
1817
+ # Split the output in name and description
1818
+ $Name, $Description = $_.Split("\`t", 2)
1819
+ __${e}_debug "Name: $Name Description: $Description"
1820
+
1821
+ # Look for the longest completion so that we can format things nicely
1822
+ if ($Longest -lt $Name.Length) {
1823
+ $Longest = $Name.Length
1824
+ }
1825
+
1826
+ # Set the description to a one space string if there is none set.
1827
+ # This is needed because the CompletionResult does not accept an empty string as argument
1828
+ if (-Not $Description) {
1829
+ $Description = " "
1830
+ }
1831
+ @{ Name = "$Name"; Description = "$Description" }
1832
+ }
1833
+
1834
+
1835
+ $Space = " "
1836
+ if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
1837
+ # remove the space here
1838
+ __${e}_debug "ShellCompDirectiveNoSpace is called"
1839
+ $Space = ""
1840
+ }
1841
+
1842
+ if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
1843
+ (($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
1844
+ __${e}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
1845
+
1846
+ # return here to prevent the completion of the extensions
1847
+ return
1848
+ }
1849
+
1850
+ $Values = $Values | Where-Object {
1851
+ # filter the result
1852
+ $_.Name -like "$WordToComplete*"
1853
+
1854
+ # Join the flag back if we have an equal sign flag
1855
+ if ( $IsEqualFlag ) {
1856
+ __${e}_debug "Join the equal sign flag back to the completion value"
1857
+ $_.Name = $Flag + "=" + $_.Name
1858
+ }
1859
+ }
1860
+
1861
+ # we sort the values in ascending order by name if keep order isn't passed
1862
+ if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) {
1863
+ $Values = $Values | Sort-Object -Property Name
1864
+ }
1865
+
1866
+ if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
1867
+ __${e}_debug "ShellCompDirectiveNoFileComp is called"
1868
+
1869
+ if ($Values.Length -eq 0) {
1870
+ # Just print an empty string here so the
1871
+ # shell does not start to complete paths.
1872
+ # We cannot use CompletionResult here because
1873
+ # it does not accept an empty string as argument.
1874
+ ""
1875
+ return
1876
+ }
1877
+ }
1878
+
1879
+ # Get the current mode
1880
+ $Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
1881
+ __${e}_debug "Mode: $Mode"
1882
+
1883
+ $Values | ForEach-Object {
1884
+
1885
+ # store temporary because switch will overwrite $_
1886
+ $comp = $_
1887
+
1888
+ # PowerShell supports three different completion modes
1889
+ # - TabCompleteNext (default windows style - on each key press the next option is displayed)
1890
+ # - Complete (works like bash)
1891
+ # - MenuComplete (works like zsh)
1892
+ # You set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>
1893
+
1894
+ # CompletionResult Arguments:
1895
+ # 1) CompletionText text to be used as the auto completion result
1896
+ # 2) ListItemText text to be displayed in the suggestion list
1897
+ # 3) ResultType type of completion result
1898
+ # 4) ToolTip text for the tooltip with details about the object
1899
+
1900
+ switch ($Mode) {
1901
+
1902
+ # bash like
1903
+ "Complete" {
1904
+
1905
+ if ($Values.Length -eq 1) {
1906
+ __${e}_debug "Only one completion left"
1907
+
1908
+ # insert space after value
1909
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${e}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
1910
+
1911
+ } else {
1912
+ # Add the proper number of spaces to align the descriptions
1913
+ while($comp.Name.Length -lt $Longest) {
1914
+ $comp.Name = $comp.Name + " "
1915
+ }
1916
+
1917
+ # Check for empty description and only add parentheses if needed
1918
+ if ($($comp.Description) -eq " " ) {
1919
+ $Description = ""
1920
+ } else {
1921
+ $Description = " ($($comp.Description))"
1922
+ }
1923
+
1924
+ [System.Management.Automation.CompletionResult]::new("$($comp.Name)$Description", "$($comp.Name)$Description", 'ParameterValue', "$($comp.Description)")
1925
+ }
1926
+ }
1927
+
1928
+ # zsh like
1929
+ "MenuComplete" {
1930
+ # insert space after value
1931
+ # MenuComplete will automatically show the ToolTip of
1932
+ # the highlighted value at the bottom of the suggestions.
1933
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${e}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
1934
+ }
1935
+
1936
+ # TabCompleteNext and in case we get something unknown
1937
+ Default {
1938
+ # Like MenuComplete but we don't want to add a space here because
1939
+ # the user need to press space anyway to get the completion.
1940
+ # Description will not be shown because that's not possible with TabCompleteNext
1941
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${e}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
1942
+ }
1943
+ }
1944
+
1945
+ }
1946
+ }
1947
+
1948
+ Register-ArgumentCompleter -CommandName '${e}' -ScriptBlock $__${r}CompleterBlock
1949
+ `}const a={ShellCompDirectiveError:1,ShellCompDirectiveNoSpace:2,ShellCompDirectiveNoFileComp:4,ShellCompDirectiveFilterFileExt:8,ShellCompDirectiveFilterDirs:16,ShellCompDirectiveKeepOrder:32,ShellCompDirectiveDefault:0};var o$1=class o{name;variadic;command;handler;constructor(e,t,n,r=false){this.command=e,this.name=t,this.handler=n,this.variadic=r;}},s$1=class s{value;description;command;handler;alias;isBoolean;constructor(e,t,n,r,i,a){this.command=e,this.value=t,this.description=n,this.handler=r,this.alias=i,this.isBoolean=a;}},c$1=class c{value;description;options=new Map;arguments=new Map;parent;constructor(e,t){this.value=e,this.description=t;}option(e,t,n,r){let i,a,o;typeof n==`function`?(i=n,a=r,o=false):typeof n==`string`?(i=void 0,a=n,o=true):(i=void 0,a=void 0,o=true);let c=new s$1(this,e,t,i,a,o);return this.options.set(e,c),this}argument(e,t,n=false){let r=new o$1(this,e,t,n);return this.arguments.set(e,r),this}},l$1=class l extends c$1{commands=new Map;completions=[];directive=a.ShellCompDirectiveDefault;constructor(){super(``,``);}command(e,t){let n=new c$1(e,t);return this.commands.set(e,n),n}stripOptions(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.startsWith(`-`)){n++;let t=false,i=this.findOption(this,r);if(i)t=i.isBoolean??false;else for(let[,e]of this.commands){let n=this.findOption(e,r);if(n){t=n.isBoolean??false;break}}!t&&n<e.length&&!e[n].startsWith(`-`)&&n++;}else t.push(r),n++;}return t}matchCommand(e){e=this.stripOptions(e);let t=[],n=[],r=null;for(let i=0;i<e.length;i++){let a=e[i];t.push(a);let o=this.commands.get(t.join(` `));if(o)r=o;else {n=e.slice(i,e.length);break}}return [r||this,n]}shouldCompleteFlags(e,t,n){if(t.startsWith(`-`))return true;if(e?.startsWith(`-`)){let t=this.findOption(this,e);if(!t){for(let[,n]of this.commands)if(t=this.findOption(n,e),t)break}return !(t&&t.isBoolean)}return false}shouldCompleteCommands(e,t){return !e.startsWith(`-`)}handleFlagCompletion(e,t,n,r,i){let a;if(n.includes(`=`)){let[e]=n.split(`=`);a=e;}else i?.startsWith(`-`)&&(a=i);if(a){let t=this.findOption(e,a);if(t?.handler){let n=[];t.handler.call(t,(e,t)=>n.push({value:e,description:t}),e.options),this.completions=n;}return}if(n.startsWith(`-`)){let t=n.startsWith(`-`)&&!n.startsWith(`--`),r=n.replace(/^-+/,``);for(let[i,a]of e.options)t&&a.alias&&`-${a.alias}`.startsWith(n)?this.completions.push({value:`-${a.alias}`,description:a.description}):!t&&i.startsWith(r)&&this.completions.push({value:`--${i}`,description:a.description});}}findOption(e,t){let n=e.options.get(t);if(n||(n=e.options.get(t.replace(/^-+/,``)),n))return n;for(let[n,r]of e.options)if(r.alias&&`-${r.alias}`===t)return r}handleCommandCompletion(e,t){let n=this.stripOptions(e);for(let[e,r]of this.commands){if(e===``)continue;let i=e.split(` `);i.slice(0,n.length).every((e,t)=>e===n[t])&&i[n.length]?.startsWith(t)&&this.completions.push({value:i[n.length],description:r.description});}}handlePositionalCompletion(e,t,n,r){let i=e.value.split(` `).length,a=Math.max(0,t.length-i),o=Array.from(e.arguments.entries());if(o.length>0){let t;if(a<o.length){let[e,n]=o[a];t=n;}else {let e=o[o.length-1][1];e.variadic&&(t=e);}if(t&&t.handler&&typeof t.handler==`function`){let n=[];t.handler.call(t,(e,t)=>n.push({value:e,description:t}),e.options),this.completions.push(...n);}}}complete(e){this.directive=a.ShellCompDirectiveNoFileComp;let t=new Set;this.completions.filter(e=>t.has(e.value)?false:(t.add(e.value),true)).filter(t=>{if(e.includes(`=`)){let[,n]=e.split(`=`);return t.value.startsWith(n)}return t.value.startsWith(e)}).forEach(e=>console.log(`${e.value}\t${e.description??``}`)),console.log(`:${this.directive}`);}parse(e){this.completions=[];let t=e[e.length-1]===``;t&&e.pop();let n=e[e.length-1]||``,r=e.slice(0,-1);t&&(n!==``&&r.push(n),n=``);let[i]=this.matchCommand(r),a=r[r.length-1];if(this.shouldCompleteFlags(a,n,t))this.handleFlagCompletion(i,r,n,t,a);else {if(a?.startsWith(`-`)&&n===``&&t){let e=this.findOption(this,a);if(!e){for(let[,t]of this.commands)if(e=this.findOption(t,a),e)break}if(e&&e.isBoolean){this.complete(n);return}}this.shouldCompleteCommands(n,t)&&this.handleCommandCompletion(r,n),i&&i.arguments.size>0&&this.handlePositionalCompletion(i,r,n,t);}this.complete(n);}setup(a,o,s){switch(assert(s===`zsh`||s===`bash`||s===`fish`||s===`powershell`,`Unsupported shell`),s){case `zsh`:{let e=t(a,o);console.log(e);break}case `bash`:{let e=n(a,o);console.log(e);break}case `fish`:{let e=r(a,o);console.log(e);break}case `powershell`:{let e=i(a,o);console.log(e);break}}}};const u$1=new l$1;var f$1=u$1;
1950
+
1951
+ function e(e=`cli`){if(process.argv.indexOf(`--`)===-1){let t=`Error: You need to use -- to separate completion arguments.\nExample: ${e} complete -- <args>`;console.error(t),process.exit(1);}}
1952
+
1953
+ const o=process.execPath,s=process.argv.slice(1),c=f(o),l=s.map(f),u=`${c} ${process.execArgv.map(f).join(` `)} ${l[0]}`,d=/<[^>]+>|\[[^\]]+\]/;function f(e){return e.includes(` `)?`'${e}'`:e}async function p(c,l){for(let e of [c.globalCommand,...c.commands]){if(e.name===`complete`)continue;let t=(e.rawName.match(/\[.*?\]|<.*?>/g)||[]).map(e=>e.startsWith(`[`)),n=e.name===`@@global@@`,i=n?l:l?.subCommands?.[e.name],a=n?``:e.name,o=n?f$1:f$1.command(a,e.description||``);if(o){let n=(e.rawName.match(/<([^>]+)>|\[\.\.\.([^\]]+)\]/g)||[]).map(e=>e.startsWith(`<`)&&e.endsWith(`>`)?e.slice(1,-1):e.startsWith(`[...`)&&e.endsWith(`]`)?e.slice(4,-1):e);t.forEach((e,t)=>{let r=n[t]||`arg${t}`,a=i?.args?.[r];a?o.argument(r,a,e):o.argument(r,void 0,e);});}for(let t of [...c.globalCommand.options,...e.options]){let e=t.rawName.match(/^-([a-zA-Z]), --/)?.[1],a=t.name,s=n?f$1:o;if(s){let n=i?.options?.[a],r=t.required||d.test(t.rawName);n?e?s.option(a,t.description||``,n,e):s.option(a,t.description||``,n):r?e?s.option(a,t.description||``,async()=>[],e):s.option(a,t.description||``,async()=>[]):e?s.option(a,t.description||``,e):s.option(a,t.description||``);}}}return c.command(`complete [shell]`).action(async(l,d)=>{switch(l){case `zsh`:{let e=t(c.name,u);console.log(e);break}case `bash`:{let e=n(c.name,u);console.log(e);break}case `fish`:{let e=r(c.name,u);console.log(e);break}case `powershell`:{let t=i(c.name,u);console.log(t);break}default:{e(c.name);let e$1=d[`--`]||[];return c.showHelpOnExit=false,c.unsetMatchedCommand(),c.parse([o,s[0],...e$1],{run:false}),f$1.parse(e$1)}}}),f$1}
1954
+
1955
+ async function setupTabCompletions(cli) {
1956
+ await p(cli, {
1957
+ subCommands: {},
1958
+ options: {
1959
+ environment(complete) {
1960
+ complete("node", "Node.js environment");
1961
+ complete("jsdom", "JSDOM environment");
1962
+ complete("happy-dom", "Happy DOM environment");
1963
+ complete("edge-runtime", "Edge runtime environment");
1964
+ },
1965
+ pool(complete) {
1966
+ complete("threads", "Threads pool");
1967
+ complete("forks", "Forks pool");
1968
+ complete("vmThreads", "VM threads pool");
1969
+ complete("vmForks", "VM forks pool");
1970
+ },
1971
+ reporter(complete) {
1972
+ complete("default", "Default reporter");
1973
+ complete("verbose", "Verbose reporter");
1974
+ complete("dot", "Dot reporter");
1975
+ complete("json", "JSON reporter");
1976
+ complete("junit", "JUnit reporter");
1977
+ complete("html", "HTML reporter");
1978
+ complete("tap", "TAP reporter");
1979
+ complete("tap-flat", "TAP flat reporter");
1980
+ complete("hanging-process", "Hanging process reporter");
1981
+ },
1982
+ "coverage.reporter": function(complete) {
1983
+ complete("text", "Text coverage reporter");
1984
+ complete("html", "HTML coverage reporter");
1985
+ complete("clover", "Clover coverage reporter");
1986
+ complete("json", "JSON coverage reporter");
1987
+ complete("json-summary", "JSON summary coverage reporter");
1988
+ complete("lcov", "LCOV coverage reporter");
1989
+ complete("lcovonly", "LCOV only coverage reporter");
1990
+ complete("teamcity", "TeamCity coverage reporter");
1991
+ complete("cobertura", "Cobertura coverage reporter");
1992
+ },
1993
+ "browser.name": function(complete) {
1994
+ complete("chromium", "Chromium");
1995
+ complete("firefox", "Mozilla Firefox");
1996
+ complete("safari", "Safari");
1997
+ complete("chrome", "Google Chrome");
1998
+ complete("edge", "Microsoft Edge");
1999
+ },
2000
+ silent(complete) {
2001
+ complete("true", "Enable silent mode");
2002
+ complete("false", "Disable silent mode");
2003
+ complete("passed-only", "Show logs from failing tests only");
2004
+ }
2005
+ }
2006
+ });
2007
+ }
2008
+
1226
2009
  function addCommand(cli, name, option) {
1227
2010
  const commandName = option.alias || name;
1228
2011
  let command = option.shorthand ? `-${option.shorthand}, --${commandName}` : `--${commandName}`;
@@ -1305,6 +2088,7 @@ function createCLI(options = {}) {
1305
2088
  cli.command("init <project>", void 0, options).action(init);
1306
2089
  addCliOptions(cli.command("list [...filters]", void 0, options).action((filters, options) => collect("test", filters, options)), collectCliOptionsConfig);
1307
2090
  cli.command("[...filters]", void 0, options).action((filters, options) => start("test", filters, options));
2091
+ setupTabCompletions(cli);
1308
2092
  return cli;
1309
2093
  }
1310
2094
  function removeQuotes(str) {
@@ -1356,7 +2140,7 @@ async function run(cliFilters, options) {
1356
2140
  await start("test", cliFilters, options);
1357
2141
  }
1358
2142
  async function benchmark(cliFilters, options) {
1359
- console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
2143
+ console.warn(c$2.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
1360
2144
  await start("benchmark", cliFilters, options);
1361
2145
  }
1362
2146
  function normalizeCliOptions(cliFilters, argv) {
@@ -1366,7 +2150,7 @@ function normalizeCliOptions(cliFilters, argv) {
1366
2150
  }
1367
2151
  if (cliFilters.some((filter) => filter.includes(":"))) argv.includeTaskLocation ??= true;
1368
2152
  if (typeof argv.typecheck?.only === "boolean") argv.typecheck.enabled ??= true;
1369
- if (argv.clearCache) {
2153
+ if (argv.clearCache || argv.listTags) {
1370
2154
  argv.watch = false;
1371
2155
  argv.run = true;
1372
2156
  }
@@ -1374,11 +2158,11 @@ function normalizeCliOptions(cliFilters, argv) {
1374
2158
  }
1375
2159
  async function start(mode, cliFilters, options) {
1376
2160
  try {
1377
- const { startVitest } = await import('./cli-api.B4CqEpI6.js').then(function (n) { return n.q; });
2161
+ const { startVitest } = await import('./cli-api.ChbI1JU9.js').then(function (n) { return n.q; });
1378
2162
  const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1379
2163
  if (!ctx.shouldKeepServer()) await ctx.exit();
1380
2164
  } catch (e) {
1381
- const { errorBanner } = await import('./index.Dm4xqZ0s.js').then(function (n) { return n.A; });
2165
+ const { errorBanner } = await import('./index.B-iBE_Gx.js').then(function (n) { return n.A; });
1382
2166
  console.error(`\n${errorBanner("Startup Error")}`);
1383
2167
  console.error(e);
1384
2168
  console.error("\n\n");
@@ -1391,12 +2175,12 @@ async function init(project) {
1391
2175
  console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
1392
2176
  process.exit(1);
1393
2177
  }
1394
- const { create } = await import('./creator.C7WwjkuR.js');
2178
+ const { create } = await import('./creator.yyCHuw5R.js');
1395
2179
  await create();
1396
2180
  }
1397
2181
  async function collect(mode, cliFilters, options) {
1398
2182
  try {
1399
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.B4CqEpI6.js').then(function (n) { return n.q; });
2183
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.ChbI1JU9.js').then(function (n) { return n.q; });
1400
2184
  const ctx = await prepareVitest(mode, {
1401
2185
  ...normalizeCliOptions(cliFilters, options),
1402
2186
  watch: false,
@@ -1415,7 +2199,7 @@ async function collect(mode, cliFilters, options) {
1415
2199
  } else outputFileList(await ctx.getRelevantTestSpecifications(cliFilters.map(normalize)), options);
1416
2200
  await ctx.close();
1417
2201
  } catch (e) {
1418
- const { errorBanner } = await import('./index.Dm4xqZ0s.js').then(function (n) { return n.A; });
2202
+ const { errorBanner } = await import('./index.B-iBE_Gx.js').then(function (n) { return n.A; });
1419
2203
  console.error(`\n${errorBanner("Collect Error")}`);
1420
2204
  console.error(e);
1421
2205
  console.error("\n\n");