@speedkit/cli 4.36.1 → 4.36.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 (293) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/base/sk-command.d.ts +41 -0
  3. package/dist/base/sk-command.js +56 -0
  4. package/dist/commands/auto-prewarm.d.ts +6 -4
  5. package/dist/commands/auto-prewarm.js +13 -66
  6. package/dist/commands/autocomplete/fish.d.ts +2 -2
  7. package/dist/commands/autocomplete/fish.js +3 -2
  8. package/dist/commands/browser/clean.d.ts +2 -2
  9. package/dist/commands/browser/clean.js +6 -6
  10. package/dist/commands/browser/list.d.ts +2 -2
  11. package/dist/commands/browser/list.js +6 -7
  12. package/dist/commands/browser/update.d.ts +2 -2
  13. package/dist/commands/browser/update.js +9 -11
  14. package/dist/commands/bulk-deploy.d.ts +4 -2
  15. package/dist/commands/bulk-deploy.js +7 -37
  16. package/dist/commands/config/edit.d.ts +2 -2
  17. package/dist/commands/config/edit.js +2 -2
  18. package/dist/commands/config/setup.d.ts +5 -2
  19. package/dist/commands/config/setup.js +9 -19
  20. package/dist/commands/deploy.d.ts +12 -3
  21. package/dist/commands/deploy.js +14 -20
  22. package/dist/commands/diff-url-parameters.d.ts +3 -2
  23. package/dist/commands/diff-url-parameters.js +19 -16
  24. package/dist/commands/extension/add.d.ts +2 -2
  25. package/dist/commands/extension/add.js +6 -6
  26. package/dist/commands/extension/devtools.d.ts +2 -2
  27. package/dist/commands/extension/devtools.js +6 -7
  28. package/dist/commands/extension/list.d.ts +2 -2
  29. package/dist/commands/extension/list.js +5 -6
  30. package/dist/commands/extension/remove.d.ts +2 -2
  31. package/dist/commands/extension/remove.js +6 -6
  32. package/dist/commands/extension/update.d.ts +2 -2
  33. package/dist/commands/extension/update.js +5 -6
  34. package/dist/commands/find-pops.d.ts +2 -2
  35. package/dist/commands/find-pops.js +10 -11
  36. package/dist/commands/generate-customer-config.d.ts +5 -2
  37. package/dist/commands/generate-customer-config.js +9 -27
  38. package/dist/commands/generate-pop-config.d.ts +2 -2
  39. package/dist/commands/generate-pop-config.js +19 -15
  40. package/dist/commands/login.d.ts +2 -2
  41. package/dist/commands/login.js +6 -9
  42. package/dist/commands/onboarding.d.ts +18 -3
  43. package/dist/commands/onboarding.js +13 -11
  44. package/dist/commands/origin-request.d.ts +4 -2
  45. package/dist/commands/origin-request.js +10 -42
  46. package/dist/commands/prewarm.d.ts +4 -2
  47. package/dist/commands/prewarm.js +12 -56
  48. package/dist/commands/pull.d.ts +4 -2
  49. package/dist/commands/pull.js +9 -14
  50. package/dist/commands/query/parameter.d.ts +4 -2
  51. package/dist/commands/query/parameter.js +12 -19
  52. package/dist/commands/query/prewarm.d.ts +4 -2
  53. package/dist/commands/query/prewarm.js +16 -23
  54. package/dist/commands/revalidate.d.ts +4 -2
  55. package/dist/commands/revalidate.js +13 -56
  56. package/dist/commands/wpt-launcher.d.ts +2 -2
  57. package/dist/commands/wpt-launcher.js +16 -17
  58. package/dist/hooks/init/first-run.js +9 -10
  59. package/dist/models/context.d.ts +24 -0
  60. package/dist/models/context.js +31 -0
  61. package/dist/services/athena/athena-flags.d.ts +18 -0
  62. package/dist/services/athena/athena-flags.js +29 -0
  63. package/dist/services/athena/athena-service-build-context.d.ts +25 -0
  64. package/dist/services/athena/athena-service-build-context.js +4 -0
  65. package/dist/services/athena/athena-service-factory.d.ts +3 -16
  66. package/dist/services/athena/athena-service-factory.js +11 -27
  67. package/dist/services/athena/baqend-athena-service.d.ts +3 -14
  68. package/dist/services/athena/baqend-athena-service.js +8 -16
  69. package/dist/services/athena/index.d.ts +1 -0
  70. package/dist/services/athena/index.js +1 -0
  71. package/dist/services/athena/spec/baqend-athena-service.spec.js +2 -2
  72. package/dist/services/browser-fetch/browser-origin-fetch.d.ts +2 -2
  73. package/dist/services/browser-fetch/browser-origin-fetch.js +1 -1
  74. package/dist/services/browser-fetch/browser-origin-fetcher.d.ts +3 -3
  75. package/dist/services/browser-fetch/browser-origin-fetcher.js +5 -5
  76. package/dist/services/browser-fetch/spec/browser-origin-fetch.spec.js +10 -10
  77. package/dist/services/cli/cli-environment-factory.d.ts +25 -0
  78. package/dist/services/cli/cli-environment-factory.js +30 -0
  79. package/dist/services/cli/cli-environment.d.ts +73 -0
  80. package/dist/services/cli/cli-environment.js +216 -0
  81. package/dist/services/cli/cli-service-build-context.d.ts +10 -0
  82. package/dist/services/cli/cli-service-build-context.js +4 -0
  83. package/dist/services/cli/cli-service-factory.d.ts +7 -7
  84. package/dist/services/cli/cli-service-factory.js +7 -7
  85. package/dist/services/cli/cli-service-model.d.ts +0 -4
  86. package/dist/services/cli/cli-service-model.js +0 -6
  87. package/dist/services/cli/cli-service.d.ts +16 -2
  88. package/dist/services/cli/cli-service.js +17 -18
  89. package/dist/services/cli/cli-settings.d.ts +37 -0
  90. package/dist/services/cli/cli-settings.js +23 -0
  91. package/dist/services/cli/command-build-context.d.ts +23 -0
  92. package/dist/services/cli/index.d.ts +5 -1
  93. package/dist/services/cli/index.js +5 -1
  94. package/dist/services/cli/spec/cli-environment-detection.spec.js +52 -0
  95. package/dist/services/cli/spec/cli-environment.spec.js +125 -0
  96. package/dist/services/cli/spec/cli-service.spec.js +9 -19
  97. package/dist/services/config-api/client.d.ts +3 -3
  98. package/dist/services/config-api/client.js +4 -4
  99. package/dist/services/config-api/config-api-factory.js +3 -3
  100. package/dist/services/config-api/entity-manager-provider.d.ts +11 -0
  101. package/dist/services/config-api/{entity-manager-factory.js → entity-manager-provider.js} +7 -1
  102. package/dist/services/customer-config/customer-config-service-build-context.d.ts +33 -0
  103. package/dist/services/customer-config/customer-config-service-build-context.js +36 -0
  104. package/dist/services/customer-config/customer-config-service-factory.d.ts +3 -4
  105. package/dist/services/customer-config/customer-config-service-factory.js +5 -8
  106. package/dist/services/customer-config/customer-config-service.d.ts +2 -2
  107. package/dist/services/customer-config/index.d.ts +1 -1
  108. package/dist/services/customer-config/index.js +1 -1
  109. package/dist/services/customer-config/site-analyzer/index.d.ts +1 -0
  110. package/dist/services/customer-config/site-analyzer/index.js +1 -0
  111. package/dist/services/customer-config/site-analyzer/site-analyzer-service-build-context.d.ts +6 -0
  112. package/dist/services/customer-config/site-analyzer/site-analyzer-service-build-context.js +4 -0
  113. package/dist/services/customer-config/site-analyzer/site-analyzer-service-factory.d.ts +3 -3
  114. package/dist/services/customer-config/site-analyzer/site-analyzer-service-factory.js +4 -5
  115. package/dist/services/deploy/bulk/bulk-deploy-model.d.ts +0 -25
  116. package/dist/services/deploy/bulk/bulk-deploy-model.js +1 -27
  117. package/dist/services/deploy/bulk/bulk-deploy-service-build-context.d.ts +51 -0
  118. package/dist/services/deploy/bulk/bulk-deploy-service-build-context.js +50 -0
  119. package/dist/services/deploy/bulk/bulk-deploy-service-factory.d.ts +2 -4
  120. package/dist/services/deploy/bulk/bulk-deploy-service-factory.js +2 -5
  121. package/dist/services/deploy/bulk/bulk-deploy-service.d.ts +3 -2
  122. package/dist/services/deploy/bulk/config-deploy-factory.d.ts +3 -3
  123. package/dist/services/deploy/bulk/config-deploy-factory.js +16 -8
  124. package/dist/services/deploy/bulk/index.d.ts +1 -0
  125. package/dist/services/deploy/bulk/index.js +1 -0
  126. package/dist/services/deploy/checks/activation/customer-approval-check.d.ts +3 -1
  127. package/dist/services/deploy/checks/activation/customer-approval-check.js +4 -2
  128. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.d.ts +3 -1
  129. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +4 -2
  130. package/dist/services/deploy/checks/pre-deploy/split-change-check.d.ts +3 -1
  131. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +4 -2
  132. package/dist/services/deploy/deploy-service-build-context.d.ts +63 -0
  133. package/dist/services/deploy/deploy-service-build-context.js +64 -0
  134. package/dist/services/deploy/deploy-service-factory.d.ts +5 -8
  135. package/dist/services/deploy/deploy-service-factory.js +28 -19
  136. package/dist/services/deploy/mr/base-config-reader.d.ts +6 -4
  137. package/dist/services/deploy/mr/base-config-reader.js +6 -8
  138. package/dist/services/deploy/mr/index.d.ts +1 -0
  139. package/dist/services/deploy/mr/index.js +1 -0
  140. package/dist/services/deploy/mr/merge-request-deploy-model.d.ts +0 -35
  141. package/dist/services/deploy/mr/merge-request-deploy-model.js +0 -34
  142. package/dist/services/deploy/mr/merge-request-deploy-service-build-context.d.ts +32 -0
  143. package/dist/services/deploy/mr/merge-request-deploy-service-build-context.js +20 -0
  144. package/dist/services/deploy/mr/merge-request-deploy-service-factory.d.ts +2 -4
  145. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +31 -10
  146. package/dist/services/deploy/mr/merge-request-deploy-service.d.ts +3 -2
  147. package/dist/services/deploy/spec/bulk/bulk-deploy-service.spec.js +14 -3
  148. package/dist/services/deploy/spec/checks/activation/customer-approval-check.spec.js +7 -5
  149. package/dist/services/deploy/spec/checks/pre-deploy/split-change-check.spec.js +2 -1
  150. package/dist/services/diff/diff-service-build-context.d.ts +14 -0
  151. package/dist/services/diff/diff-service-build-context.js +4 -0
  152. package/dist/services/diff/diff-service-factory.d.ts +4 -5
  153. package/dist/services/diff/diff-service-factory.js +4 -7
  154. package/dist/services/diff/index.d.ts +1 -1
  155. package/dist/services/diff/index.js +1 -1
  156. package/dist/services/document-handler-runtime/{context/document-handler-runtime-context.d.ts → document-handler-runtime-model.d.ts} +0 -5
  157. package/dist/services/document-handler-runtime/document-handler-runtime-service-build-context.d.ts +11 -0
  158. package/dist/services/document-handler-runtime/document-handler-runtime-service-build-context.js +4 -0
  159. package/dist/services/document-handler-runtime/document-handler-server.js +2 -2
  160. package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.d.ts +3 -6
  161. package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +14 -14
  162. package/dist/services/document-handler-runtime/server/request.js +1 -1
  163. package/dist/services/document-handler-runtime/templates/database-mock.d.ts +1 -1
  164. package/dist/services/document-handler-runtime/templates/database-mock.js +1 -1
  165. package/dist/services/integration-api/customer-config-flags.d.ts +16 -0
  166. package/dist/services/integration-api/customer-config-flags.js +30 -0
  167. package/dist/services/integration-api/handler/install-resource-handler.d.ts +8 -0
  168. package/dist/services/integration-api/handler/install-resource-handler.js +10 -1
  169. package/dist/services/integration-api/index.d.ts +1 -0
  170. package/dist/services/integration-api/index.js +1 -0
  171. package/dist/services/integration-api/integration-api-factory.d.ts +4 -6
  172. package/dist/services/integration-api/integration-api-factory.js +11 -11
  173. package/dist/services/integration-api/integration-api-model.d.ts +0 -9
  174. package/dist/services/integration-api/integration-api-model.js +0 -16
  175. package/dist/services/integration-api/integration-api-service-build-context.d.ts +19 -0
  176. package/dist/services/integration-api/integration-api-service-build-context.js +4 -0
  177. package/dist/services/integration-api/spec/config-plugin.spec.js +1 -1
  178. package/dist/services/integration-api/spec/integration-api-service.spec.js +7 -3
  179. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +9 -2
  180. package/dist/services/integration-api/struct/config-plugin.d.ts +1 -1
  181. package/dist/services/integration-api/struct/config-plugin.js +12 -7
  182. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +18 -2
  183. package/dist/services/integration-api/struct/speed-kit-config-file.js +22 -12
  184. package/dist/services/integration-api/struct/speed-kit-config.d.ts +1 -1
  185. package/dist/services/onboarding/browser/config/browser-config.d.ts +3 -3
  186. package/dist/services/onboarding/browser/config/browser-config.js +5 -5
  187. package/dist/services/onboarding/browser/executable/executable-validator.d.ts +3 -3
  188. package/dist/services/onboarding/browser/executable/executable-validator.js +17 -15
  189. package/dist/services/onboarding/browser/extension/extension-downloader.d.ts +3 -3
  190. package/dist/services/onboarding/browser/extension/extension-downloader.js +6 -6
  191. package/dist/services/onboarding/browser/extension/extension-validator.d.ts +3 -3
  192. package/dist/services/onboarding/browser/extension/extension-validator.js +4 -4
  193. package/dist/services/onboarding/file-events/file-watcher.js +1 -0
  194. package/dist/services/onboarding/index.d.ts +1 -1
  195. package/dist/services/onboarding/index.js +1 -1
  196. package/dist/services/onboarding/onboarding-model.d.ts +8 -24
  197. package/dist/services/onboarding/onboarding-model.js +19 -87
  198. package/dist/services/onboarding/onboarding-service-build-context.d.ts +57 -0
  199. package/dist/services/onboarding/onboarding-service-build-context.js +67 -0
  200. package/dist/services/onboarding/onboarding-service-factory.d.ts +2 -5
  201. package/dist/services/onboarding/onboarding-service-factory.js +47 -34
  202. package/dist/services/onboarding/spec/onboarding-model.spec.js +11 -6
  203. package/dist/services/origin-request/index.d.ts +1 -1
  204. package/dist/services/origin-request/index.js +1 -1
  205. package/dist/services/origin-request/origin-request-service-build-context.d.ts +52 -0
  206. package/dist/services/origin-request/origin-request-service-build-context.js +54 -0
  207. package/dist/services/origin-request/origin-request-service-factory.d.ts +2 -5
  208. package/dist/services/origin-request/origin-request-service-factory.js +12 -12
  209. package/dist/services/origin-request/origin-request-service.d.ts +2 -2
  210. package/dist/services/pop-config/index.d.ts +1 -0
  211. package/dist/services/pop-config/index.js +1 -0
  212. package/dist/services/pop-config/pop-config-factory.d.ts +4 -1
  213. package/dist/services/pop-config/pop-config-factory.js +10 -3
  214. package/dist/services/pop-config/pop-config-service-build-context.d.ts +10 -0
  215. package/dist/services/pop-config/pop-config-service-build-context.js +4 -0
  216. package/dist/services/prewarm/auto-pre-warm-factory.d.ts +3 -31
  217. package/dist/services/prewarm/auto-pre-warm-factory.js +6 -11
  218. package/dist/services/prewarm/auto-pre-warm-service-build-context.d.ts +84 -0
  219. package/dist/services/prewarm/auto-pre-warm-service-build-context.js +68 -0
  220. package/dist/services/prewarm/index.d.ts +2 -0
  221. package/dist/services/prewarm/index.js +2 -0
  222. package/dist/services/prewarm/pre-warm-factory.d.ts +4 -5
  223. package/dist/services/prewarm/pre-warm-factory.js +6 -8
  224. package/dist/services/prewarm/pre-warm-model.d.ts +0 -10
  225. package/dist/services/prewarm/pre-warm-model.js +0 -18
  226. package/dist/services/prewarm/pre-warm-service-build-context.d.ts +47 -0
  227. package/dist/services/prewarm/pre-warm-service-build-context.js +64 -0
  228. package/dist/services/pull/index.d.ts +1 -0
  229. package/dist/services/pull/index.js +1 -0
  230. package/dist/services/pull/pull-service-build-context.d.ts +28 -0
  231. package/dist/services/pull/pull-service-build-context.js +17 -0
  232. package/dist/services/pull/pull-service-factory.d.ts +3 -5
  233. package/dist/services/pull/pull-service-factory.js +13 -14
  234. package/dist/services/pull/pull-service-model.d.ts +0 -5
  235. package/dist/services/pull/pull-service-model.js +0 -9
  236. package/dist/services/query-builder/query-builder-factory.d.ts +9 -7
  237. package/dist/services/query-builder/query-builder-factory.js +26 -15
  238. package/dist/{models/cli-parameters.d.ts → services/query-builder/query-builder-flags.d.ts} +1 -120
  239. package/dist/services/query-builder/query-builder-flags.js +150 -0
  240. package/dist/services/query-builder/query-builder-model.d.ts +1 -14
  241. package/dist/services/query-builder/query-builder-service-build-context.d.ts +113 -0
  242. package/dist/services/query-builder/query-builder-service-build-context.js +68 -0
  243. package/dist/services/query-builder/query-builder-service.d.ts +3 -3
  244. package/dist/services/query-builder/spec/query-builder-flags.spec.d.ts +1 -0
  245. package/dist/{models/spec/cli-parameters.spec.js → services/query-builder/spec/query-builder-flags.spec.js} +1 -1
  246. package/dist/services/revalidate/index.d.ts +1 -0
  247. package/dist/services/revalidate/index.js +1 -0
  248. package/dist/services/revalidate/revalidate-factory.d.ts +3 -5
  249. package/dist/services/revalidate/revalidate-factory.js +2 -6
  250. package/dist/services/revalidate/revalidate-model.d.ts +0 -9
  251. package/dist/services/revalidate/revalidate-model.js +0 -8
  252. package/dist/services/revalidate/revalidate-service-build-context.d.ts +38 -0
  253. package/dist/services/revalidate/revalidate-service-build-context.js +59 -0
  254. package/dist/services/setup/browser/browser-setup-service.d.ts +3 -4
  255. package/dist/services/setup/browser/browser-setup-service.js +16 -18
  256. package/dist/services/setup/difftool/difftool-setup-service.d.ts +3 -4
  257. package/dist/services/setup/difftool/difftool-setup-service.js +5 -7
  258. package/dist/services/setup/extension/extension-setup-service.d.ts +3 -4
  259. package/dist/services/setup/extension/extension-setup-service.js +8 -10
  260. package/dist/services/setup/index.d.ts +1 -1
  261. package/dist/services/setup/index.js +1 -1
  262. package/dist/services/setup/setup-service-build-context.d.ts +27 -0
  263. package/dist/services/setup/setup-service-build-context.js +26 -0
  264. package/dist/services/setup/setup-service-factory.d.ts +2 -6
  265. package/dist/services/setup/setup-service-factory.js +10 -18
  266. package/dist/services/setup/setup-service.d.ts +4 -5
  267. package/dist/services/setup/setup-service.js +6 -7
  268. package/oclif.manifest.json +1 -1
  269. package/package.json +4 -2
  270. package/dist/models/cli-parameters.js +0 -297
  271. package/dist/services/cli/cli-config.d.ts +0 -59
  272. package/dist/services/cli/cli-config.js +0 -180
  273. package/dist/services/cli/environment.d.ts +0 -15
  274. package/dist/services/cli/environment.js +0 -40
  275. package/dist/services/cli/spec/cli-config.spec.js +0 -117
  276. package/dist/services/cli/spec/environment.spec.js +0 -28
  277. package/dist/services/config-api/entity-manager-factory.d.ts +0 -5
  278. package/dist/services/customer-config/customer-config-service-context.d.ts +0 -13
  279. package/dist/services/customer-config/customer-config-service-context.js +0 -21
  280. package/dist/services/deploy/context/deploy-context.d.ts +0 -32
  281. package/dist/services/deploy/context/deploy-context.js +0 -72
  282. package/dist/services/diff/diff-model.d.ts +0 -9
  283. package/dist/services/diff/diff-model.js +0 -12
  284. package/dist/services/origin-request/origin-request-context.d.ts +0 -13
  285. package/dist/services/origin-request/origin-request-context.js +0 -23
  286. package/dist/services/query-builder/query-command.d.ts +0 -28
  287. package/dist/services/query-builder/query-command.js +0 -37
  288. package/dist/services/setup/setup-context.d.ts +0 -14
  289. package/dist/services/setup/setup-context.js +0 -15
  290. /package/dist/{models/spec/cli-parameters.spec.d.ts → services/cli/command-build-context.js} +0 -0
  291. /package/dist/services/cli/spec/{cli-config.spec.d.ts → cli-environment-detection.spec.d.ts} +0 -0
  292. /package/dist/services/cli/spec/{environment.spec.d.ts → cli-environment.spec.d.ts} +0 -0
  293. /package/dist/services/document-handler-runtime/{context/document-handler-runtime-context.js → document-handler-runtime-model.js} +0 -0
@@ -0,0 +1,216 @@
1
+ import * as dotenv from "dotenv";
2
+ import fs from "node:fs";
3
+ import path, { resolve } from "node:path";
4
+ import { parseChromeFlags } from "../../helpers/chrome-flags.js";
5
+ import { defaultSettings } from "./cli-settings.js";
6
+ import ApplicationError from "../error-handling/error/application-error.js";
7
+ dotenv.config({ quiet: true });
8
+ const environmentMapping = {
9
+ chromeExtensionPaths: "CHROME_EXTENSION_PATHS",
10
+ chromeFlags: "CHROME_FLAGS",
11
+ chromePath: "CHROME_PATH",
12
+ chromeUserProfilePath: "CHROME_USER_PROFILE_PATH",
13
+ diffExec: "DIFF_EXEC",
14
+ diffExecTemplate: "DIFF_EXEC_TEMPLATE",
15
+ ideaDirectory: "IDEA_INITIAL_DIRECTORY",
16
+ slackToken: "SLACK_TOKEN",
17
+ testApp: "TEST_APP",
18
+ };
19
+ const CONFIG_FILE_NAME = "config.json";
20
+ /** Variables CI providers set besides `CI`. */
21
+ const CI_MARKERS = [
22
+ "CONTINUOUS_INTEGRATION",
23
+ "BUILD_NUMBER",
24
+ "GITLAB_CI",
25
+ "GITHUB_ACTIONS",
26
+ "JENKINS_URL",
27
+ "TEAMCITY_VERSION",
28
+ "TF_BUILD",
29
+ "BITBUCKET_BUILD_NUMBER",
30
+ "CIRCLECI",
31
+ "TRAVIS",
32
+ ];
33
+ /**
34
+ * Where a command runs: the user's settings, oclif's config and the
35
+ * directories the CLI owns.
36
+ *
37
+ * One per invocation, built by {@link CliEnvironmentFactory} together with the
38
+ * invocation's one CLI ({@link cli}) and handed to every factory in its
39
+ * context. The settings merge three sources, later winning over earlier:
40
+ *
41
+ * ```
42
+ * ~/.config/speed-kit-cli/config.json < .env < process.env
43
+ * ```
44
+ */
45
+ export class CliEnvironment {
46
+ oclif;
47
+ env;
48
+ /** The user's settings; {@link save} writes changes back. */
49
+ settings = defaultSettings();
50
+ /** Where the extra node modules of a customer's documentHandler live. */
51
+ nodeModulesPath;
52
+ attachedCli;
53
+ /**
54
+ * Loads the settings for one invocation.
55
+ *
56
+ * @param oclif the oclif config of the running command
57
+ * @param customerPath the customer the command works on, if any, for its
58
+ * node modules
59
+ * @param env the process environment; a test passes its own
60
+ */
61
+ static load(oclif, customerPath, env = process.env) {
62
+ const environment = new CliEnvironment(oclif, env, customerPath);
63
+ environment.loadSettings();
64
+ return environment;
65
+ }
66
+ constructor(oclif, env, customerPath) {
67
+ this.oclif = oclif;
68
+ this.env = env;
69
+ this.nodeModulesPath = resolve(oclif.cacheDir, "additional_node_modules", customerPath || "");
70
+ }
71
+ /** The one CLI of this invocation: every output and every prompt. */
72
+ get cli() {
73
+ if (!this.attachedCli) {
74
+ throw new ApplicationError("This environment has no CLI: build it with CliEnvironmentFactory.");
75
+ }
76
+ return this.attachedCli;
77
+ }
78
+ /**
79
+ * Completes the environment with its CLI. Only {@link CliEnvironmentFactory}
80
+ * calls this, once: the CLI is built against the environment, so the two
81
+ * cannot be created in one step.
82
+ */
83
+ attachCli(cli) {
84
+ if (this.attachedCli) {
85
+ throw new ApplicationError("This environment already has a CLI.");
86
+ }
87
+ this.attachedCli = cli;
88
+ return this;
89
+ }
90
+ /** The directory the CLI keeps its caches and scratch files in. */
91
+ get cacheDir() {
92
+ return this.oclif.cacheDir;
93
+ }
94
+ /**
95
+ * Whether this runs in CI. Most CI providers set `CI=true`, and several set
96
+ * their own dedicated variable, so both are checked.
97
+ */
98
+ get isCI() {
99
+ const ci = this.env.CI;
100
+ if (ci !== undefined && ci !== "false" && ci !== "0") {
101
+ return true;
102
+ }
103
+ return CI_MARKERS.some((marker) => Boolean(this.env[marker]));
104
+ }
105
+ /**
106
+ * True when the user cannot safely be prompted: in CI, without an attached
107
+ * TTY (piped output, an npm background install), or when they opted out
108
+ * with SK_NON_INTERACTIVE.
109
+ */
110
+ get nonInteractive() {
111
+ const optOut = this.env.SK_NON_INTERACTIVE;
112
+ if (optOut !== undefined && optOut !== "") {
113
+ return true;
114
+ }
115
+ if (this.isCI) {
116
+ return true;
117
+ }
118
+ return !process.stdin.isTTY || !process.stdout.isTTY;
119
+ }
120
+ /**
121
+ * Persists the given settings into the user config.json, merging with what
122
+ * is already there. Also reflects the change in {@link settings} so the
123
+ * running command sees it immediately.
124
+ */
125
+ save(partial) {
126
+ const existing = this.readRawConfigFile() ?? {};
127
+ const merged = { ...existing, ...partial };
128
+ fs.mkdirSync(path.resolve(this.oclif.configDir), { recursive: true });
129
+ fs.writeFileSync(this.getConfigFilePath(), JSON.stringify(merged, null, `\t`));
130
+ Object.assign(this.settings, partial);
131
+ }
132
+ loadSettings() {
133
+ // load config from configFile
134
+ this.loadConfigFromConfigFile();
135
+ // override config from environment
136
+ this.loadConfigFromEnvironment();
137
+ // The environment holds a string, config.json an array.
138
+ this.settings.chromeFlags = parseChromeFlags(this.settings.chromeFlags);
139
+ this.resolveExtensionConfigPaths();
140
+ }
141
+ createEmptyConfigFile() {
142
+ fs.mkdirSync(path.resolve(this.oclif.configDir), { recursive: true });
143
+ fs.writeFileSync(this.getConfigFilePath(), JSON.stringify(defaultSettings(), null, `\t`));
144
+ }
145
+ getConfigFilePath() {
146
+ return path.resolve(this.oclif.configDir, CONFIG_FILE_NAME);
147
+ }
148
+ loadConfigFromConfigFile() {
149
+ const configJson = this.readCliConfigFromFile();
150
+ if (!configJson) {
151
+ return;
152
+ }
153
+ for (const configKey in this.settings) {
154
+ if (!(configKey in configJson)) {
155
+ continue;
156
+ }
157
+ const value = configJson[configKey];
158
+ // skip null/undefined and empty strings so file values only override
159
+ // defaults when they carry an actual setting (keeps booleans/numbers,
160
+ // unlike the previous `.length`-only check which dropped them)
161
+ if (value === undefined || value === null) {
162
+ continue;
163
+ }
164
+ if (typeof value === "string" && value.length === 0) {
165
+ continue;
166
+ }
167
+ this.settings[configKey] = value;
168
+ }
169
+ }
170
+ loadConfigFromEnvironment() {
171
+ for (const configKey in this.settings) {
172
+ if (!(configKey in environmentMapping)) {
173
+ continue;
174
+ }
175
+ const environmentVariable = environmentMapping[configKey];
176
+ if (environmentVariable in this.env &&
177
+ this.env[environmentVariable].length > 0) {
178
+ this.settings[configKey] = this.env[environmentVariable];
179
+ }
180
+ }
181
+ }
182
+ resolveExtensionConfigPaths() {
183
+ const pathKeys = [
184
+ "chromeExtensionPaths",
185
+ "chromeUserProfilePath",
186
+ "chromePath",
187
+ "ideaDirectory",
188
+ ];
189
+ for (const key of pathKeys) {
190
+ this.settings[key] = this.settings[key].replaceAll(new RegExp("~", "g"), this.oclif.home);
191
+ }
192
+ }
193
+ readCliConfigFromFile() {
194
+ if (!fs.existsSync(this.getConfigFilePath())) {
195
+ this.createEmptyConfigFile();
196
+ return;
197
+ }
198
+ return this.readRawConfigFile();
199
+ }
200
+ /**
201
+ * Reads and parses config.json without any side effects. Returns null when
202
+ * the file is missing or cannot be parsed.
203
+ */
204
+ readRawConfigFile() {
205
+ if (!fs.existsSync(this.getConfigFilePath())) {
206
+ return null;
207
+ }
208
+ try {
209
+ const configFileContent = fs.readFileSync(this.getConfigFilePath(), "utf8");
210
+ return JSON.parse(configFileContent);
211
+ }
212
+ catch {
213
+ return null;
214
+ }
215
+ }
216
+ }
@@ -0,0 +1,10 @@
1
+ import type { CommandContextValues } from "./command-build-context.js";
2
+ export interface CliServiceBuildContextValues extends CommandContextValues {
3
+ /** Keep to what `--quiet` allows: no spinners, default answers. */
4
+ readonly quiet: boolean;
5
+ }
6
+ declare const CliServiceBuildContext_base: new (values: CliServiceBuildContextValues) => Readonly<CliServiceBuildContextValues>;
7
+ /** What the invocation's one CLI is built from. */
8
+ export declare class CliServiceBuildContext extends CliServiceBuildContext_base {
9
+ }
10
+ export {};
@@ -0,0 +1,4 @@
1
+ import { Context } from "../../models/context.js";
2
+ /** What the invocation's one CLI is built from. */
3
+ export class CliServiceBuildContext extends Context() {
4
+ }
@@ -1,16 +1,16 @@
1
1
  import { CliService } from "./cli-service.js";
2
- import { CliContext } from "./cli-service-model.js";
2
+ import { CliServiceBuildContext } from "./cli-service-build-context.js";
3
3
  /**
4
4
  * Builds the CLI service. Deliberately neither a singleton nor cached.
5
5
  *
6
- * One instance is created per invocation — at the command — and threaded into
7
- * every factory that needs it, each of which takes an optional `cli`. Sharing
8
- * by construction rather than by global state is what keeps `--quiet` honest:
9
- * with a cached instance the flag would be decided by whichever factory
6
+ * {@link CliEnvironmentFactory} builds the one instance of an invocation and
7
+ * hands it out as `environment.cli`; nothing else calls this. Sharing by
8
+ * construction rather than by global state is what keeps `--quiet` honest:
9
+ * with a CLI per factory the flag would be decided by whichever factory
10
10
  * happened to build first, which is not something a caller can reason about.
11
11
  */
12
12
  export declare class CliServiceFactory {
13
- private context;
14
- constructor(context?: CliContext);
13
+ private readonly context;
14
+ constructor(context: CliServiceBuildContext);
15
15
  getService(): CliService;
16
16
  }
@@ -1,20 +1,20 @@
1
1
  import { CliService } from "./cli-service.js";
2
- import { CliContext } from "./cli-service-model.js";
2
+ import { ClipboardService } from "./clipboard/index.js";
3
3
  /**
4
4
  * Builds the CLI service. Deliberately neither a singleton nor cached.
5
5
  *
6
- * One instance is created per invocation — at the command — and threaded into
7
- * every factory that needs it, each of which takes an optional `cli`. Sharing
8
- * by construction rather than by global state is what keeps `--quiet` honest:
9
- * with a cached instance the flag would be decided by whichever factory
6
+ * {@link CliEnvironmentFactory} builds the one instance of an invocation and
7
+ * hands it out as `environment.cli`; nothing else calls this. Sharing by
8
+ * construction rather than by global state is what keeps `--quiet` honest:
9
+ * with a CLI per factory the flag would be decided by whichever factory
10
10
  * happened to build first, which is not something a caller can reason about.
11
11
  */
12
12
  export class CliServiceFactory {
13
13
  context;
14
- constructor(context = new CliContext()) {
14
+ constructor(context) {
15
15
  this.context = context;
16
16
  }
17
17
  getService() {
18
- return new CliService(this.context.quiet);
18
+ return new CliService(new ClipboardService(), this.context.environment, this.context.quiet);
19
19
  }
20
20
  }
@@ -1,10 +1,6 @@
1
1
  import { Options } from "cli-progress";
2
2
  import { ExecSyncOptions } from "node:child_process";
3
3
  import { ChalkInstance } from "chalk";
4
- export declare class CliContext {
5
- readonly quiet: boolean;
6
- constructor(quiet?: boolean);
7
- }
8
4
  export declare enum CliActionStatus {
9
5
  COMPLETED = "completed",
10
6
  FAILED = "failed",
@@ -1,9 +1,3 @@
1
- export class CliContext {
2
- quiet;
3
- constructor(quiet = false) {
4
- this.quiet = quiet;
5
- }
6
- }
7
1
  export var CliActionStatus;
8
2
  (function (CliActionStatus) {
9
3
  CliActionStatus["COMPLETED"] = "completed";
@@ -1,14 +1,28 @@
1
1
  import { ChalkInstance } from "chalk";
2
2
  import { Options } from "cli-progress";
3
3
  import { CliServiceInterface, CliTableColumns } from "./cli-service-model.js";
4
+ import { ClipboardService } from "./clipboard/index.js";
5
+ import type { CliEnvironment } from "./cli-environment.js";
4
6
  import { ExecSyncOptions } from "node:child_process";
7
+ /** What the CLI needs to know about where it runs. */
8
+ export type CliTerminal = Pick<CliEnvironment, "isCI" | "nonInteractive">;
5
9
  export declare class CliService implements CliServiceInterface {
10
+ private readonly clipboard;
11
+ private readonly terminal;
6
12
  readonly quiet: boolean;
7
13
  style: ChalkInstance;
8
14
  private buffer;
9
15
  private progressBar?;
10
16
  private spinners;
11
- private readonly clipboard;
17
+ /**
18
+ * Whether a spinner can actually spin here.
19
+ *
20
+ * The same condition spinnies itself uses to decide, so the two never
21
+ * disagree: without it spinnies falls back to re-rendering *every* spinner it
22
+ * knows on every update, which in a CI log means the first action's line is
23
+ * printed again under each later one — a page of "build prewarm-query" for a
24
+ * job that only ever built one.
25
+ */
12
26
  private readonly animates;
13
27
  /** The text of each running action, for the log line that replaces it. */
14
28
  private readonly actions;
@@ -19,7 +33,7 @@ export declare class CliService implements CliServiceInterface {
19
33
  * than being re-derived wherever a prompt happens to be.
20
34
  */
21
35
  get nonInteractive(): boolean;
22
- constructor(quiet?: boolean);
36
+ constructor(clipboard: ClipboardService, terminal: CliTerminal, quiet?: boolean);
23
37
  code(code: string, buffered?: boolean): void;
24
38
  codeStyle(code: string): string;
25
39
  comment(message: string, buffered?: boolean): void;
@@ -3,23 +3,9 @@ import { Chalk } from "chalk";
3
3
  import Table from "tty-table";
4
4
  import { Presets, SingleBar } from "cli-progress";
5
5
  import Spinnies from "spinnies";
6
- import { ClipboardService } from "./clipboard/index.js";
7
- import { isCI, isNonInteractive } from "./environment.js";
8
6
  import { safe } from "../../helpers/safe.js";
9
7
  import { execSync } from "node:child_process";
10
8
  import ApplicationError from "../error-handling/error/application-error.js";
11
- /**
12
- * Whether a spinner can actually spin here.
13
- *
14
- * The same condition spinnies itself uses to decide, so the two never
15
- * disagree: without it spinnies falls back to re-rendering *every* spinner it
16
- * knows on every update, which in a CI log means the first action's line is
17
- * printed again under each later one — a page of "build prewarm-query" for a
18
- * job that only ever built one.
19
- */
20
- function canAnimate() {
21
- return Boolean(!isCI() && process.stderr && process.stderr.isTTY);
22
- }
23
9
  /** The padding and the gutter that a table draws inside every column. */
24
10
  const CELL_OVERHEAD = 3;
25
11
  /** The left margin and the outer borders of a table. */
@@ -58,13 +44,23 @@ function columnWidths(entries, rows) {
58
44
  return widths;
59
45
  }
60
46
  export class CliService {
47
+ clipboard;
48
+ terminal;
61
49
  quiet;
62
50
  style;
63
51
  buffer = [];
64
52
  progressBar;
65
53
  spinners;
66
- clipboard = new ClipboardService();
67
- animates = canAnimate();
54
+ /**
55
+ * Whether a spinner can actually spin here.
56
+ *
57
+ * The same condition spinnies itself uses to decide, so the two never
58
+ * disagree: without it spinnies falls back to re-rendering *every* spinner it
59
+ * knows on every update, which in a CI log means the first action's line is
60
+ * printed again under each later one — a page of "build prewarm-query" for a
61
+ * job that only ever built one.
62
+ */
63
+ animates;
68
64
  /** The text of each running action, for the log line that replaces it. */
69
65
  actions = new Map();
70
66
  /**
@@ -74,10 +70,13 @@ export class CliService {
74
70
  * than being re-derived wherever a prompt happens to be.
75
71
  */
76
72
  get nonInteractive() {
77
- return isNonInteractive();
73
+ return this.terminal.nonInteractive;
78
74
  }
79
- constructor(quiet = false) {
75
+ constructor(clipboard, terminal, quiet = false) {
76
+ this.clipboard = clipboard;
77
+ this.terminal = terminal;
80
78
  this.quiet = quiet;
79
+ this.animates = Boolean(!terminal.isCI && process.stderr && process.stderr.isTTY);
81
80
  this.spinners = new Spinnies();
82
81
  this.style = new Chalk();
83
82
  }
@@ -0,0 +1,37 @@
1
+ /** A Chrome extension installed via the setup wizard and tracked for updates. */
2
+ export interface ManagedExtension {
3
+ /** Chrome Web Store extension id */
4
+ id: string;
5
+ name: string;
6
+ version: string;
7
+ /** absolute path to the unpacked extension directory */
8
+ path: string;
9
+ }
10
+ /**
11
+ * The user's settings: what `config.json` holds, overridden by `.env` and the
12
+ * process environment. Nothing in here is derived at run time — that lives on
13
+ * {@link CliEnvironment}.
14
+ */
15
+ export interface CliSettings {
16
+ chromeExtensionPaths: string;
17
+ /** system-specific flags, appended to the onboarding browser's launch args */
18
+ chromeFlags: string[];
19
+ chromePath: string;
20
+ chromeUserProfilePath: string;
21
+ diffExec: string;
22
+ diffExecTemplate: string;
23
+ diffTool: string;
24
+ ideaDirectory: string;
25
+ slackToken: string;
26
+ testApp: string;
27
+ browserChannel: string;
28
+ browserBuildId: string;
29
+ browserAutoUpdate: boolean;
30
+ updateReminderDays: number;
31
+ lastBrowserUpdateCheck: string;
32
+ managedChromeExtensions: ManagedExtension[];
33
+ lastExtensionUpdateCheck: string;
34
+ firstRunCompleted: boolean;
35
+ }
36
+ /** The settings of a user who has configured nothing yet. */
37
+ export declare function defaultSettings(): CliSettings;
@@ -0,0 +1,23 @@
1
+ /** The settings of a user who has configured nothing yet. */
2
+ export function defaultSettings() {
3
+ return {
4
+ chromeExtensionPaths: "",
5
+ chromeFlags: [],
6
+ chromePath: "",
7
+ chromeUserProfilePath: "",
8
+ diffExec: "",
9
+ diffExecTemplate: "$exec $file1 $file2",
10
+ diffTool: "",
11
+ ideaDirectory: "",
12
+ slackToken: "",
13
+ testApp: "",
14
+ browserChannel: "",
15
+ browserBuildId: "",
16
+ browserAutoUpdate: false,
17
+ updateReminderDays: 3,
18
+ lastBrowserUpdateCheck: "",
19
+ managedChromeExtensions: [],
20
+ lastExtensionUpdateCheck: "",
21
+ firstRunCompleted: false,
22
+ };
23
+ }
@@ -0,0 +1,23 @@
1
+ import type { Interfaces } from "@oclif/core";
2
+ import type { CliEnvironment } from "./cli-environment.js";
3
+ /**
4
+ * What every build context carries: the environment of the invocation, with
5
+ * its one CLI. A parent factory passes its own on to the build contexts it
6
+ * creates for child factories.
7
+ */
8
+ export interface CommandContextValues {
9
+ readonly environment: CliEnvironment;
10
+ }
11
+ /**
12
+ * The static side of a build context that a command builds: its argument and
13
+ * flag definitions, and `create`, typed from exactly those definitions.
14
+ *
15
+ * Because `create` reads parsed values whose type oclif infers from `args` and
16
+ * `flags`, a context cannot read a flag nobody defined, and a command that
17
+ * takes its definitions from the context cannot leave one out.
18
+ */
19
+ export interface CommandBuildContext<Built, Args extends Interfaces.ArgInput = Interfaces.ArgInput, Flags extends Interfaces.FlagInput = Interfaces.FlagInput> {
20
+ readonly args: Args;
21
+ readonly flags: Flags;
22
+ create(args: Interfaces.InferredArgs<Args>, flags: Interfaces.InferredFlags<Flags>, environment: CliEnvironment): Built;
23
+ }
@@ -1,4 +1,8 @@
1
1
  export * from "./cli-service.js";
2
2
  export * from "./cli-service-model.js";
3
3
  export * from "./cli-service-factory.js";
4
- export * from "./cli-config.js";
4
+ export * from "./cli-service-build-context.js";
5
+ export * from "./cli-environment.js";
6
+ export * from "./cli-environment-factory.js";
7
+ export * from "./cli-settings.js";
8
+ export * from "./command-build-context.js";
@@ -1,4 +1,8 @@
1
1
  export * from "./cli-service.js";
2
2
  export * from "./cli-service-model.js";
3
3
  export * from "./cli-service-factory.js";
4
- export * from "./cli-config.js";
4
+ export * from "./cli-service-build-context.js";
5
+ export * from "./cli-environment.js";
6
+ export * from "./cli-environment-factory.js";
7
+ export * from "./cli-settings.js";
8
+ export * from "./command-build-context.js";
@@ -0,0 +1,52 @@
1
+ import { expect } from "chai";
2
+ import { afterEach, beforeEach, describe, it } from "mocha";
3
+ import { mkdtempSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import path from "node:path";
6
+ import { CliEnvironment } from "../cli-environment.js";
7
+ describe("CliEnvironment detection", () => {
8
+ let dir;
9
+ beforeEach(() => {
10
+ dir = mkdtempSync(path.join(tmpdir(), "sk-cli-detection-"));
11
+ });
12
+ afterEach(() => {
13
+ rmSync(dir, { recursive: true, force: true });
14
+ });
15
+ /** An environment that sees exactly the given variables. */
16
+ function environment(env) {
17
+ const oclif = { configDir: dir, cacheDir: dir, home: dir };
18
+ return CliEnvironment.load(oclif, undefined, env);
19
+ }
20
+ describe("isCI", () => {
21
+ it("is false for an empty environment", () => {
22
+ expect(environment({}).isCI).to.equal(false);
23
+ });
24
+ it("is true when CI is set to a truthy value", () => {
25
+ expect(environment({ CI: "true" }).isCI).to.equal(true);
26
+ expect(environment({ CI: "1" }).isCI).to.equal(true);
27
+ });
28
+ it("treats CI=false / CI=0 as not CI", () => {
29
+ expect(environment({ CI: "false" }).isCI).to.equal(false);
30
+ expect(environment({ CI: "0" }).isCI).to.equal(false);
31
+ });
32
+ it("detects provider-specific markers", () => {
33
+ expect(environment({ GITLAB_CI: "true" }).isCI).to.equal(true);
34
+ expect(environment({ GITHUB_ACTIONS: "true" }).isCI).to.equal(true);
35
+ });
36
+ });
37
+ describe("nonInteractive", () => {
38
+ it("is true when SK_NON_INTERACTIVE is set", () => {
39
+ expect(environment({ SK_NON_INTERACTIVE: "1" }).nonInteractive).to.equal(true);
40
+ });
41
+ it("is true when running in CI", () => {
42
+ expect(environment({ CI: "true" }).nonInteractive).to.equal(true);
43
+ });
44
+ });
45
+ it("reads the settings from the environment it was given", () => {
46
+ const loaded = environment({ DIFF_EXEC: "/usr/bin/meld" });
47
+ expect(loaded.settings.diffExec).to.equal("/usr/bin/meld");
48
+ });
49
+ it("has no CLI until the factory attaches one", () => {
50
+ expect(() => environment({}).cli).to.throw(/no CLI/);
51
+ });
52
+ });