config-flags.d.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_ARGS: readonly ["build", "cache", "checkVersion", "ci", "compare", "debug", "dev", "devtools", "docs", "e2e", "es5", "esm", "headless", "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_ARGS: readonly ["port", "maxConcurrency", "testTimeout"];
  10. /**
  11. * All the String options supported by the Stencil CLI
  12. */
  13. export declare const STRING_CLI_ARGS: 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", "collectCoverageOnlyFrom", "coveragePathIgnorePatterns", "coverageReporters", "moduleDirectories", "moduleFileExtensions", "modulePathIgnorePatterns", "modulePaths", "projects", "reporters", "roots", "selectProjects", "setupFiles", "setupFilesAfterEnv", "snapshotSerializers", "testMatch", "testPathIgnorePatterns", "testPathPattern", "testRegex", "transformIgnorePatterns", "unmockedModulePathPatterns", "watchPathIgnorePatterns"];
  14. /**
  15. * All the CLI arguments which may have string or number values
  16. *
  17. * `maxWorkers` is an argument which is used both by Stencil _and_ by Jest,
  18. * which means that we need to support parsing both string and number values.
  19. */
  20. export declare const STRING_NUMBER_CLI_ARGS: readonly ["maxWorkers"];
  21. /**
  22. * All the LogLevel-type options supported by the Stencil CLI
  23. *
  24. * This is a bit silly since there's only one such argument atm,
  25. * but this approach lets us make sure that we're handling all
  26. * our arguments in a type-safe way.
  27. */
  28. export declare const LOG_LEVEL_CLI_ARGS: readonly ["logLevel"];
  29. /**
  30. * A type which gives the members of a `ReadonlyArray<string>` as
  31. * an enum-like type which can be used for e.g. keys in a `Record`
  32. * (as in the `AliasMap` type below)
  33. */
  34. declare type ArrayValuesAsUnion<T extends ReadonlyArray<string>> = T[number];
  35. export declare type BooleanCLIArg = ArrayValuesAsUnion<typeof BOOLEAN_CLI_ARGS>;
  36. export declare type StringCLIArg = ArrayValuesAsUnion<typeof STRING_CLI_ARGS>;
  37. export declare type NumberCLIArg = ArrayValuesAsUnion<typeof NUMBER_CLI_ARGS>;
  38. export declare type StringNumberCLIArg = ArrayValuesAsUnion<typeof STRING_NUMBER_CLI_ARGS>;
  39. export declare type LogCLIArg = ArrayValuesAsUnion<typeof LOG_LEVEL_CLI_ARGS>;
  40. declare type KnownCLIArg = BooleanCLIArg | StringCLIArg | NumberCLIArg | StringNumberCLIArg | LogCLIArg;
  41. declare type AliasMap = Partial<Record<KnownCLIArg, string>>;
  42. /**
  43. * For a small subset of CLI options we support a short alias e.g. `'h'` for `'help'`
  44. */
  45. export declare const CLI_ARG_ALIASES: AliasMap;
  46. /**
  47. * Given two types `K` and `T` where `K` extends `ReadonlyArray<string>`,
  48. * construct a type which maps the strings in `K` as keys to values of type `T`.
  49. *
  50. * Because we use types derived this way to construct an interface (`ConfigFlags`)
  51. * for which we want optional keys, we make all the properties optional (w/ `'?'`)
  52. * and possibly null.
  53. */
  54. declare type ObjectFromKeys<K extends ReadonlyArray<string>, T> = {
  55. [key in K[number]]?: T | null;
  56. };
  57. /**
  58. * Type containing the possible Boolean configuration flags, to be included
  59. * in ConfigFlags, below
  60. */
  61. declare type BooleanConfigFlags = ObjectFromKeys<typeof BOOLEAN_CLI_ARGS, boolean>;
  62. /**
  63. * Type containing the possible String configuration flags, to be included
  64. * in ConfigFlags, below
  65. */
  66. declare type StringConfigFlags = ObjectFromKeys<typeof STRING_CLI_ARGS, string>;
  67. /**
  68. * Type containing the possible numeric configuration flags, to be included
  69. * in ConfigFlags, below
  70. */
  71. declare type NumberConfigFlags = ObjectFromKeys<typeof NUMBER_CLI_ARGS, number>;
  72. /**
  73. * Type containing the configuration flags which may be set to either string
  74. * or number values.
  75. */
  76. declare type StringNumberConfigFlags = ObjectFromKeys<typeof STRING_NUMBER_CLI_ARGS, string | number>;
  77. /**
  78. * Type containing the possible LogLevel configuration flags, to be included
  79. * in ConfigFlags, below
  80. */
  81. declare type LogLevelFlags = ObjectFromKeys<typeof LOG_LEVEL_CLI_ARGS, LogLevel>;
  82. /**
  83. * The configuration flags which can be set by the user on the command line.
  84. * This interface captures both known arguments (which are enumerated and then
  85. * parsed according to their types) and unknown arguments which the user may
  86. * pass at the CLI.
  87. *
  88. * Note that this interface is constructed by extending `BooleanConfigFlags`,
  89. * `StringConfigFlags`, etc. These types are in turn constructed from types
  90. * extending `ReadonlyArray<string>` which we declare in another module. This
  91. * allows us to record our known CLI arguments in one place, using a
  92. * `ReadonlyArray<string>` to get both a type-level representation of what CLI
  93. * options we support and a runtime list of strings which can be used to match
  94. * on actual flags passed by the user.
  95. */
  96. export interface ConfigFlags extends BooleanConfigFlags, StringConfigFlags, NumberConfigFlags, StringNumberConfigFlags, LogLevelFlags {
  97. task: TaskCommand | null;
  98. args: string[];
  99. knownArgs: string[];
  100. unknownArgs: string[];
  101. }
  102. /**
  103. * Helper function for initializing a `ConfigFlags` object. Provide any overrides
  104. * for default values and off you go!
  105. *
  106. * @param init an object with any overrides for default values
  107. * @returns a complete CLI flag object
  108. */
  109. export declare const createConfigFlags: (init?: Partial<ConfigFlags>) => ConfigFlags;
  110. export {};