config-flags.d.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import type { LogLevel, TaskCommand } from '../internal/index';
  2. /**
  3. * All the Boolean options supported by the Stencil CLI
  4. */
  5. export declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "checkVersion", "ci", "compare", "debug", "dev", "devtools", "docs", "e2e", "es5", "esm", "help", "log", "open", "prerender", "prerenderExternal", "prod", "profile", "serviceWorker", "screenshot", "serve", "skipNodeCheck", "spec", "ssr", "stats", "updateScreenshot", "verbose", "version", "watch", "all", "automock", "bail", "changedFilesWithAncestor", "clearCache", "clearMocks", "collectCoverage", "color", "colors", "coverage", "detectLeaks", "detectOpenHandles", "errorOnDeprecated", "expand", "findRelatedTests", "forceExit", "init", "injectGlobals", "json", "lastCommit", "listTests", "logHeapUsage", "noStackTrace", "notify", "onlyChanged", "onlyFailures", "passWithNoTests", "resetMocks", "resetModules", "restoreMocks", "runInBand", "runTestsByPath", "showConfig", "silent", "skipFilter", "testLocationInResults", "updateSnapshot", "useStderr", "watchAll", "watchman"];
  6. /**
  7. * All the Number options supported by the Stencil CLI
  8. */
  9. export declare const NUMBER_CLI_FLAGS: readonly ["port", "maxConcurrency", "testTimeout"];
  10. /**
  11. * All the String options supported by the Stencil CLI
  12. */
  13. export declare const STRING_CLI_FLAGS: readonly ["address", "config", "docsApi", "docsJson", "emulate", "root", "screenshotConnector", "cacheDirectory", "changedSince", "collectCoverageFrom", "coverageDirectory", "coverageThreshold", "env", "filter", "globalSetup", "globalTeardown", "globals", "haste", "moduleNameMapper", "notifyMode", "outputFile", "preset", "prettierPath", "resolver", "rootDir", "runner", "testEnvironment", "testEnvironmentOptions", "testFailureExitCode", "testNamePattern", "testResultsProcessor", "testRunner", "testSequencer", "testURL", "timers", "transform"];
  14. export declare const STRING_ARRAY_CLI_FLAGS: readonly ["collectCoverageOnlyFrom", "coveragePathIgnorePatterns", "coverageReporters", "moduleDirectories", "moduleFileExtensions", "modulePathIgnorePatterns", "modulePaths", "projects", "reporters", "roots", "selectProjects", "setupFiles", "setupFilesAfterEnv", "snapshotSerializers", "testMatch", "testPathIgnorePatterns", "testPathPattern", "testRegex", "transformIgnorePatterns", "unmockedModulePathPatterns", "watchPathIgnorePatterns"];
  15. /**
  16. * All the CLI arguments which may have string or number values
  17. *
  18. * `maxWorkers` is an argument which is used both by Stencil _and_ by Jest,
  19. * which means that we need to support parsing both string and number values.
  20. */
  21. export declare const STRING_NUMBER_CLI_FLAGS: readonly ["maxWorkers"];
  22. /**
  23. * All the CLI arguments which may have boolean or string values.
  24. */
  25. export declare const BOOLEAN_STRING_CLI_FLAGS: readonly ["headless"];
  26. /**
  27. * All the LogLevel-type options supported by the Stencil CLI
  28. *
  29. * This is a bit silly since there's only one such argument atm,
  30. * but this approach lets us make sure that we're handling all
  31. * our arguments in a type-safe way.
  32. */
  33. export declare const LOG_LEVEL_CLI_FLAGS: readonly ["logLevel"];
  34. /**
  35. * A type which gives the members of a `ReadonlyArray<string>` as
  36. * an enum-like type which can be used for e.g. keys in a `Record`
  37. * (as in the `AliasMap` type below)
  38. */
  39. type ArrayValuesAsUnion<T extends ReadonlyArray<string>> = T[number];
  40. export type BooleanCLIFlag = ArrayValuesAsUnion<typeof BOOLEAN_CLI_FLAGS>;
  41. export type StringCLIFlag = ArrayValuesAsUnion<typeof STRING_CLI_FLAGS>;
  42. export type StringArrayCLIFlag = ArrayValuesAsUnion<typeof STRING_ARRAY_CLI_FLAGS>;
  43. export type NumberCLIFlag = ArrayValuesAsUnion<typeof NUMBER_CLI_FLAGS>;
  44. export type StringNumberCLIFlag = ArrayValuesAsUnion<typeof STRING_NUMBER_CLI_FLAGS>;
  45. export type BooleanStringCLIFlag = ArrayValuesAsUnion<typeof BOOLEAN_STRING_CLI_FLAGS>;
  46. export type LogCLIFlag = ArrayValuesAsUnion<typeof LOG_LEVEL_CLI_FLAGS>;
  47. export type KnownCLIFlag = BooleanCLIFlag | StringCLIFlag | StringArrayCLIFlag | NumberCLIFlag | StringNumberCLIFlag | BooleanStringCLIFlag | LogCLIFlag;
  48. type AliasMap = Partial<Record<string, KnownCLIFlag>>;
  49. /**
  50. * For a small subset of CLI options we support a short alias e.g. `'h'` for `'help'`
  51. */
  52. export declare const CLI_FLAG_ALIASES: AliasMap;
  53. /**
  54. * A regular expression which can be used to match a CLI flag for one of our
  55. * short aliases.
  56. */
  57. export declare const CLI_FLAG_REGEX: RegExp;
  58. /**
  59. * Given two types `K` and `T` where `K` extends `ReadonlyArray<string>`,
  60. * construct a type which maps the strings in `K` as keys to values of type `T`.
  61. *
  62. * Because we use types derived this way to construct an interface (`ConfigFlags`)
  63. * for which we want optional keys, we make all the properties optional (w/ `'?'`)
  64. * and possibly null.
  65. */
  66. type ObjectFromKeys<K extends ReadonlyArray<string>, T> = {
  67. [key in K[number]]?: T | null;
  68. };
  69. /**
  70. * Type containing the possible Boolean configuration flags, to be included
  71. * in ConfigFlags, below
  72. */
  73. type BooleanConfigFlags = ObjectFromKeys<typeof BOOLEAN_CLI_FLAGS, boolean>;
  74. /**
  75. * Type containing the possible String configuration flags, to be included
  76. * in ConfigFlags, below
  77. */
  78. type StringConfigFlags = ObjectFromKeys<typeof STRING_CLI_FLAGS, string>;
  79. /**
  80. * Type containing the possible String Array configuration flags. This is
  81. * one of the 'constituent types' for `ConfigFlags`.
  82. */
  83. type StringArrayConfigFlags = ObjectFromKeys<typeof STRING_ARRAY_CLI_FLAGS, string[]>;
  84. /**
  85. * Type containing the possible numeric configuration flags, to be included
  86. * in ConfigFlags, below
  87. */
  88. type NumberConfigFlags = ObjectFromKeys<typeof NUMBER_CLI_FLAGS, number>;
  89. /**
  90. * Type containing the configuration flags which may be set to either string
  91. * or number values.
  92. */
  93. type StringNumberConfigFlags = ObjectFromKeys<typeof STRING_NUMBER_CLI_FLAGS, string | number>;
  94. /**
  95. * Type containing the configuration flags which may be set to either string
  96. * or boolean values.
  97. */
  98. type BooleanStringConfigFlags = ObjectFromKeys<typeof BOOLEAN_STRING_CLI_FLAGS, boolean | string>;
  99. /**
  100. * Type containing the possible LogLevel configuration flags, to be included
  101. * in ConfigFlags, below
  102. */
  103. type LogLevelFlags = ObjectFromKeys<typeof LOG_LEVEL_CLI_FLAGS, LogLevel>;
  104. /**
  105. * The configuration flags which can be set by the user on the command line.
  106. * This interface captures both known arguments (which are enumerated and then
  107. * parsed according to their types) and unknown arguments which the user may
  108. * pass at the CLI.
  109. *
  110. * Note that this interface is constructed by extending `BooleanConfigFlags`,
  111. * `StringConfigFlags`, etc. These types are in turn constructed from types
  112. * extending `ReadonlyArray<string>` which we declare in another module. This
  113. * allows us to record our known CLI arguments in one place, using a
  114. * `ReadonlyArray<string>` to get both a type-level representation of what CLI
  115. * options we support and a runtime list of strings which can be used to match
  116. * on actual flags passed by the user.
  117. */
  118. export interface ConfigFlags extends BooleanConfigFlags, StringConfigFlags, StringArrayConfigFlags, NumberConfigFlags, StringNumberConfigFlags, BooleanStringConfigFlags, LogLevelFlags {
  119. task: TaskCommand | null;
  120. args: string[];
  121. knownArgs: string[];
  122. unknownArgs: string[];
  123. }
  124. /**
  125. * Helper function for initializing a `ConfigFlags` object. Provide any overrides
  126. * for default values and off you go!
  127. *
  128. * @param init an object with any overrides for default values
  129. * @returns a complete CLI flag object
  130. */
  131. export declare const createConfigFlags: (init?: Partial<ConfigFlags>) => ConfigFlags;
  132. export {};