@speedkit/cli 4.44.0-beta.4 → 4.45.0

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 (196) hide show
  1. package/CHANGELOG.md +40 -11
  2. package/README.md +77 -47
  3. package/dist/base/sk-command.d.ts +7 -0
  4. package/dist/base/sk-command.js +19 -0
  5. package/dist/commands/deploy.d.ts +1 -0
  6. package/dist/commands/deploy.js +5 -1
  7. package/dist/commands/diff.d.ts +47 -0
  8. package/dist/commands/diff.js +67 -0
  9. package/dist/commands/generate-pop-config.js +3 -7
  10. package/dist/commands/origin-request.d.ts +2 -1
  11. package/dist/commands/origin-request.js +1 -0
  12. package/dist/helpers/race.js +4 -2
  13. package/dist/helpers/spec/race.spec.js +31 -0
  14. package/dist/models/files.d.ts +0 -1
  15. package/dist/models/files.js +0 -1
  16. package/dist/services/browser-fetch/browser-origin-fetch.js +1 -1
  17. package/dist/services/browser-fetch/browser-origin-fetcher.d.ts +1 -7
  18. package/dist/services/browser-fetch/browser-origin-fetcher.js +3 -26
  19. package/dist/services/bundler/bundle-service-factory.d.ts +0 -3
  20. package/dist/services/bundler/bundle-service-factory.js +1 -5
  21. package/dist/services/bundler/bundle-service.d.ts +1 -10
  22. package/dist/services/bundler/bundle-service.js +1 -16
  23. package/dist/services/bundler/index.d.ts +0 -1
  24. package/dist/services/bundler/index.js +0 -1
  25. package/dist/services/cli/cli-environment.d.ts +11 -0
  26. package/dist/services/cli/cli-environment.js +37 -0
  27. package/dist/services/cli/cli-service-model.d.ts +3 -1
  28. package/dist/services/cli/cli-service.d.ts +1 -1
  29. package/dist/services/cli/cli-service.js +4 -1
  30. package/dist/services/cli/spec/cli-environment.spec.js +30 -1
  31. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  32. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
  33. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
  34. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
  35. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
  36. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
  37. package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
  38. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
  39. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
  40. package/dist/services/deploy/deploy-service-build-context.d.ts +2 -0
  41. package/dist/services/deploy/deploy-service-build-context.js +13 -2
  42. package/dist/services/deploy/deploy-service-factory.js +2 -9
  43. package/dist/services/deploy/deploy-service-model.d.ts +11 -1
  44. package/dist/services/deploy/deploy-service.d.ts +2 -0
  45. package/dist/services/deploy/deploy-service.js +26 -1
  46. package/dist/services/deploy/handler/customer-config-handler.d.ts +2 -2
  47. package/dist/services/deploy/handler/install-resource-handler.d.ts +2 -2
  48. package/dist/services/deploy/handler/install-resource-handler.js +6 -3
  49. package/dist/services/deploy/handler/module-handler.d.ts +2 -2
  50. package/dist/services/deploy/handler/module-handler.js +2 -2
  51. package/dist/services/deploy/handler/server-config-handler.d.ts +2 -2
  52. package/dist/services/deploy/handler/server-config-handler.js +2 -2
  53. package/dist/services/deploy/mr/live-state-check.d.ts +2 -2
  54. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +2 -7
  55. package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
  56. package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
  57. package/dist/services/deploy/policy/index.d.ts +1 -0
  58. package/dist/services/deploy/policy/index.js +1 -0
  59. package/dist/services/deploy/policy/testing-deploy-policy.d.ts +16 -0
  60. package/dist/services/deploy/policy/testing-deploy-policy.js +42 -0
  61. package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
  62. package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
  63. package/dist/services/deploy/spec/handler/install-resource-handler.spec.js +58 -0
  64. package/dist/services/deploy/spec/mr/live-state-check.spec.js +2 -2
  65. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
  66. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.d.ts +1 -0
  67. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +46 -0
  68. package/dist/services/diff/create-diff-engine.d.ts +14 -0
  69. package/dist/services/diff/create-diff-engine.js +42 -0
  70. package/dist/services/diff/customer-origin.d.ts +9 -0
  71. package/dist/services/diff/customer-origin.js +19 -0
  72. package/dist/services/diff/diff-engine.d.ts +30 -0
  73. package/dist/services/diff/diff-engine.js +49 -0
  74. package/dist/services/diff/diff-log.d.ts +9 -0
  75. package/dist/services/diff/diff-log.js +18 -0
  76. package/dist/services/diff/diff-model.d.ts +68 -0
  77. package/dist/services/diff/diff-model.js +1 -0
  78. package/dist/services/diff/diff-service-build-context.d.ts +99 -9
  79. package/dist/services/diff/diff-service-build-context.js +299 -1
  80. package/dist/services/diff/diff-service-factory.d.ts +24 -2
  81. package/dist/services/diff/diff-service-factory.js +165 -3
  82. package/dist/services/diff/diff-service.d.ts +93 -33
  83. package/dist/services/diff/diff-service.js +274 -140
  84. package/dist/services/diff/index.d.ts +12 -1
  85. package/dist/services/diff/index.js +12 -1
  86. package/dist/services/diff/noise-baseline.d.ts +28 -0
  87. package/dist/services/diff/noise-baseline.js +105 -0
  88. package/dist/services/diff/page-source.d.ts +42 -0
  89. package/dist/services/diff/page-source.js +93 -0
  90. package/dist/services/diff/side-failure.d.ts +28 -0
  91. package/dist/services/diff/side-failure.js +100 -0
  92. package/dist/services/diff/sinks/json-diff-sink.d.ts +32 -0
  93. package/dist/services/diff/sinks/json-diff-sink.js +44 -0
  94. package/dist/services/diff/sinks/no-diff-sink.d.ts +5 -0
  95. package/dist/services/diff/sinks/no-diff-sink.js +6 -0
  96. package/dist/services/diff/sinks/patch-diff-sink.d.ts +19 -0
  97. package/dist/services/diff/sinks/patch-diff-sink.js +29 -0
  98. package/dist/services/diff/sinks/tool-diff-sink.d.ts +26 -0
  99. package/dist/services/diff/sinks/tool-diff-sink.js +88 -0
  100. package/dist/services/diff/sinks/unified-patch.d.ts +7 -0
  101. package/dist/services/diff/sinks/unified-patch.js +12 -0
  102. package/dist/services/diff/spec/customer-origin.spec.d.ts +1 -0
  103. package/dist/services/diff/spec/customer-origin.spec.js +27 -0
  104. package/dist/services/diff/spec/diff-engine.spec.d.ts +1 -0
  105. package/dist/services/diff/spec/diff-engine.spec.js +47 -0
  106. package/dist/services/diff/spec/diff-service-build-context.spec.d.ts +1 -0
  107. package/dist/services/diff/spec/diff-service-build-context.spec.js +185 -0
  108. package/dist/services/diff/spec/diff-service.spec.d.ts +1 -0
  109. package/dist/services/diff/spec/diff-service.spec.js +393 -0
  110. package/dist/services/diff/spec/noise-baseline.spec.d.ts +1 -0
  111. package/dist/services/diff/spec/noise-baseline.spec.js +95 -0
  112. package/dist/services/diff/spec/page-source.spec.d.ts +1 -0
  113. package/dist/services/diff/spec/page-source.spec.js +140 -0
  114. package/dist/services/diff/spec/sinks/json-diff-sink.spec.d.ts +1 -0
  115. package/dist/services/diff/spec/sinks/json-diff-sink.spec.js +72 -0
  116. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.d.ts +1 -0
  117. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.js +47 -0
  118. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.d.ts +1 -0
  119. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.js +61 -0
  120. package/dist/services/document-handler-runtime/document-handler-abort.d.ts +2 -0
  121. package/dist/services/document-handler-runtime/document-handler-abort.js +2 -0
  122. package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
  123. package/dist/services/document-handler-runtime/document-handler-server.js +19 -81
  124. package/dist/services/document-handler-runtime/runtime-files.d.ts +9 -0
  125. package/dist/services/document-handler-runtime/runtime-files.js +17 -0
  126. package/dist/services/integration-api/integration-api-model.d.ts +1 -2
  127. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -68
  128. package/dist/services/integration-api/struct/customer-config.d.ts +1 -32
  129. package/dist/services/integration-api/struct/customer-config.js +3 -33
  130. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
  131. package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -27
  132. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -25
  133. package/dist/services/onboarding/dashboard/diff-against-current-page.d.ts +29 -7
  134. package/dist/services/onboarding/dashboard/diff-against-current-page.js +24 -37
  135. package/dist/services/onboarding/dashboard/index.js +13 -6
  136. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +21 -8
  137. package/dist/services/onboarding/dashboard/request-diff-service.js +21 -49
  138. package/dist/services/onboarding/onboarding-model.d.ts +0 -1
  139. package/dist/services/onboarding/onboarding-model.js +0 -1
  140. package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
  141. package/dist/services/onboarding/onboarding-service-factory.js +24 -30
  142. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.d.ts +1 -0
  143. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.js +57 -0
  144. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
  145. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +3 -3
  146. package/dist/services/onboarding/virtual-orestes-app/index.js +5 -5
  147. package/dist/services/origin-request/index.d.ts +3 -0
  148. package/dist/services/origin-request/index.js +3 -0
  149. package/dist/services/origin-request/origin-fetcher.d.ts +52 -0
  150. package/dist/services/origin-request/origin-fetcher.js +93 -0
  151. package/dist/services/origin-request/origin-request-service-build-context.d.ts +6 -3
  152. package/dist/services/origin-request/origin-request-service-build-context.js +30 -4
  153. package/dist/services/origin-request/origin-request-service-factory.d.ts +5 -0
  154. package/dist/services/origin-request/origin-request-service-factory.js +40 -6
  155. package/dist/services/origin-request/origin-request-service.d.ts +6 -10
  156. package/dist/services/origin-request/origin-request-service.js +28 -70
  157. package/dist/services/origin-request/runtime-config-source.d.ts +36 -0
  158. package/dist/services/origin-request/runtime-config-source.js +59 -0
  159. package/dist/services/origin-request/spec/origin-error-cause.spec.d.ts +1 -0
  160. package/dist/services/{onboarding/spec/virtual-orestes-app → origin-request/spec}/origin-error-cause.spec.js +1 -1
  161. package/dist/services/origin-request/spec/origin-fetcher.spec.d.ts +1 -0
  162. package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.js → origin-request/spec/origin-fetcher.spec.js} +46 -15
  163. package/dist/services/origin-request/spec/origin-request-service-build-context.spec.d.ts +1 -0
  164. package/dist/services/origin-request/spec/origin-request-service-build-context.spec.js +32 -0
  165. package/dist/services/prewarm/assets/asset-api-client.d.ts +6 -0
  166. package/dist/services/prewarm/assets/asset-api-client.js +6 -1
  167. package/dist/services/prewarm/pre-warm-service.d.ts +10 -0
  168. package/dist/services/prewarm/pre-warm-service.js +17 -0
  169. package/dist/services/prewarm/spec/pre-warm-service.spec.d.ts +1 -0
  170. package/dist/services/prewarm/spec/pre-warm-service.spec.js +72 -0
  171. package/dist/services/query-builder/query-builder-factory.js +3 -3
  172. package/dist/services/setup/os/tool-registry.d.ts +1 -1
  173. package/oclif.manifest.json +162 -23
  174. package/package.json +1 -2
  175. package/dist/commands/diff-url-parameters.d.ts +0 -19
  176. package/dist/commands/diff-url-parameters.js +0 -121
  177. package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
  178. package/dist/services/bundler/error/packjockel-error.js +0 -3
  179. package/dist/services/bundler/packjockel-service.d.ts +0 -72
  180. package/dist/services/bundler/packjockel-service.js +0 -156
  181. package/dist/services/bundler/spec/packjockel-service.spec.js +0 -143
  182. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
  183. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
  184. package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
  185. package/dist/services/deploy/error/check-module-file-error.js +0 -4
  186. package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
  187. package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
  188. package/dist/services/onboarding/server-config/index.d.ts +0 -10
  189. package/dist/services/onboarding/server-config/index.js +0 -27
  190. package/dist/services/onboarding/virtual-orestes-app/crawler.d.ts +0 -31
  191. package/dist/services/onboarding/virtual-orestes-app/crawler.js +0 -98
  192. /package/dist/{services/bundler/spec/packjockel-service.spec.d.ts → helpers/spec/race.spec.d.ts} +0 -0
  193. /package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
  194. /package/dist/services/{onboarding/spec/virtual-orestes-app/origin-error-cause.spec.d.ts → deploy/spec/handler/install-resource-handler.spec.d.ts} +0 -0
  195. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.d.ts +0 -0
  196. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.js +0 -0
@@ -1,15 +1,177 @@
1
+ import { applyOriginProxy } from "../../helpers/origin-proxy.js";
2
+ import { installBrowserOriginFetch } from "../browser-fetch/index.js";
3
+ import { ConfigApiContext, ConfigApiServiceFactory, } from "../config-api/index.js";
4
+ import { DocumentHandlerRuntimeServiceBuildContext } from "../document-handler-runtime/document-handler-runtime-service-build-context.js";
5
+ import DocumentHandlerRuntimeServiceFactory from "../document-handler-runtime/factory/document-handler-runtime-service-factory.js";
6
+ import { documentHandlerRuntimeFiles } from "../document-handler-runtime/runtime-files.js";
7
+ import ApplicationError from "../error-handling/error/application-error.js";
8
+ import { IntegrationApiFactory, IntegrationApiServiceBuildContext, } from "../integration-api/index.js";
9
+ import { DEFAULT_TYPE, OriginFetcher, RuntimeConfigSource, } from "../origin-request/index.js";
10
+ import { createDiffEngine } from "./create-diff-engine.js";
11
+ import { assertCustomerOrigin } from "./customer-origin.js";
12
+ import { stderrLog } from "./diff-log.js";
13
+ import { variationPair, } from "./diff-service-build-context.js";
1
14
  import { DiffService } from "./diff-service.js";
15
+ import { PageSource } from "./page-source.js";
16
+ /**
17
+ * The variations a person can choose from: the device variations and the
18
+ * runtime config's named ones. A template, which needs a value filled in,
19
+ * has to be named.
20
+ */
21
+ function variationChoices(variations) {
22
+ const names = [
23
+ ...new Set([
24
+ DEFAULT_TYPE,
25
+ "mobile",
26
+ "tablet",
27
+ ...Object.keys(variations).filter((name) => /^[\w-]+$/.test(name)),
28
+ ]),
29
+ ];
30
+ return names.map((name) => ({
31
+ name: name === DEFAULT_TYPE ? "desktop" : name,
32
+ value: name,
33
+ }));
34
+ }
2
35
  export class DiffServiceFactory {
3
36
  context;
4
37
  service = undefined;
5
38
  constructor(context) {
6
39
  this.context = context;
7
40
  }
8
- getService() {
41
+ async buildService() {
9
42
  if (!(this.service instanceof DiffService)) {
10
- const cliService = this.context.environment.cli;
11
- this.service = new DiffService(cliService, this.context.executablePath, this.context.executableTemplate, this.context.opensDiffTool ?? true);
43
+ this.service = await this.build();
12
44
  }
13
45
  return this.service;
14
46
  }
47
+ async build() {
48
+ const { environment } = this.context;
49
+ const chosenParameters = await this.withChosenParameters();
50
+ const json = this.context.output === "json";
51
+ const log = json ? stderrLog(environment.cli) : environment.cli;
52
+ const files = this.context.customerPath
53
+ ? await this.getIntegrationFiles()
54
+ : undefined;
55
+ const customer = files?.getCustomerConfig().config;
56
+ // JSON owns stdout, so the proxy line stays out of a machine-readable run.
57
+ if (customer) {
58
+ const { pageUrl, against } = this.context;
59
+ for (const url of [pageUrl, against].filter(Boolean)) {
60
+ assertCustomerOrigin(url, customer.origins, this.context.customerPath);
61
+ }
62
+ applyOriginProxy(customer.chromeFlags, json ? undefined : environment.cli);
63
+ }
64
+ const config = await this.loadRuntimeConfig(log, customer?.app);
65
+ if (!config) {
66
+ throw new ApplicationError("no runtime config to build the requests from");
67
+ }
68
+ const options = await this.withChosenVariations(chosenParameters, config.variations);
69
+ // Installed last, after everything that can fail: the service closes it.
70
+ const browserFetch = this.context.browserFetch
71
+ ? installBrowserOriginFetch({ environment, logger: log, mode: "always" })
72
+ : undefined;
73
+ if (browserFetch) {
74
+ log.writeWarning("Fetching every page through a headless Chrome.");
75
+ }
76
+ return new DiffService({
77
+ options,
78
+ log,
79
+ browserFetch,
80
+ engine: createDiffEngine(environment, this.context.output),
81
+ pages: new PageSource({
82
+ fetcher: new OriginFetcher({
83
+ cli: log,
84
+ config,
85
+ host: this.context.host,
86
+ strict: true,
87
+ }),
88
+ documentHandler: this.context.raw || !files
89
+ ? undefined
90
+ : await this.buildDocumentHandler(files),
91
+ ignore: this.context.ignore.map((pattern) => new RegExp(pattern, "g")),
92
+ }),
93
+ });
94
+ }
95
+ /**
96
+ * The options, with the parameters an empty `--param` asked for added to
97
+ * the ones removed. Asked first, before anything is loaded or fetched.
98
+ */
99
+ async withChosenParameters() {
100
+ if (!this.context.chooseParameters)
101
+ return this.context;
102
+ const { environment, pageUrl, parameters = [] } = this.context;
103
+ const names = [...new Set(new URL(pageUrl).searchParams.keys())];
104
+ const chosen = await environment.cli.multiSelect("Which parameters should be removed?", names.map((name) => ({ name, value: name })));
105
+ if (chosen.length === 0 && parameters.length === 0) {
106
+ throw new ApplicationError("No parameter chosen, so nothing to check.");
107
+ }
108
+ return {
109
+ ...this.context,
110
+ parameters: [...new Set([...parameters, ...chosen])],
111
+ };
112
+ }
113
+ /**
114
+ * The options, with the variations an empty `--variations` or
115
+ * `--variation` asked for.
116
+ */
117
+ async withChosenVariations(options, variations) {
118
+ if (options.chooseVariation) {
119
+ return { ...options, variation: await this.chooseVariation(variations) };
120
+ }
121
+ if (!options.chooseVariations)
122
+ return options;
123
+ const chosen = await this.context.environment.cli.multiSelect("Which variations should be compared? One is compared against desktop", variationChoices(variations), (picked) => (picked.length === 1 && picked[0] !== DEFAULT_TYPE) ||
124
+ picked.length === 2 ||
125
+ "Choose one variation to compare against desktop, or two to compare with each other.");
126
+ // A quiet CLI (--output json) does not ask, and answers with no choice.
127
+ if (chosen.length === 0) {
128
+ throw new ApplicationError("No variation chosen, so nothing to compare.", ["Name them: --variations mobile, or --variations tablet,mobile"]);
129
+ }
130
+ return { ...options, variations: variationPair(chosen) };
131
+ }
132
+ /** The one variation an empty `--variation` asks for. */
133
+ async chooseVariation(variations) {
134
+ // JSON owns stdout, where the prompt would land.
135
+ if (this.context.output === "json") {
136
+ throw new ApplicationError("An empty --variation asks which variation to take, and --output json cannot ask.", ["Name it: --variation mobile"]);
137
+ }
138
+ return this.context.environment.cli.select("Which variation should the pages be requested in?", variationChoices(variations), DEFAULT_TYPE);
139
+ }
140
+ /**
141
+ * The runtime config: a local file when one is named, else the app's. Without
142
+ * a customer there is no app, and the requests carry Speed Kit's device
143
+ * defaults only.
144
+ */
145
+ async loadRuntimeConfig(log, app) {
146
+ if (!app && !this.context.variationsFile) {
147
+ log.writeWarning("no customer: the requests carry Speed Kit's device defaults only, no variations of an app");
148
+ return { variations: {}, authentications: [] };
149
+ }
150
+ return new RuntimeConfigSource({
151
+ cli: log,
152
+ configApi: app
153
+ ? new ConfigApiServiceFactory(new ConfigApiContext(app)).getService()
154
+ : undefined,
155
+ fileFlag: "--variationsFile",
156
+ }).load(this.context.variationsFile);
157
+ }
158
+ /** The customer's files, with the released document handler unless it brings its own. */
159
+ async getIntegrationFiles() {
160
+ return new IntegrationApiFactory(new IntegrationApiServiceBuildContext({
161
+ environment: this.context.environment,
162
+ basePath: this.context.customerPath,
163
+ configName: this.context.configName,
164
+ whitelist: [],
165
+ }))
166
+ .buildService()
167
+ .run(this.context.raw ? [] : documentHandlerRuntimeFiles());
168
+ }
169
+ async buildDocumentHandler(files) {
170
+ return new DocumentHandlerRuntimeServiceFactory(new DocumentHandlerRuntimeServiceBuildContext({
171
+ environment: this.context.environment,
172
+ customerPath: this.context.customerPath,
173
+ configName: this.context.configName,
174
+ verboseLevel: false,
175
+ }), files).buildDocumentHandlerServer();
176
+ }
15
177
  }
@@ -1,43 +1,103 @@
1
- import { CliServiceInterface } from "../cli/index.js";
1
+ import { DiffEngine } from "./diff-engine.js";
2
+ import { DiffLog } from "./diff-log.js";
3
+ import { ComparisonOutcome } from "./diff-model.js";
4
+ import { DiffOptions } from "./diff-service-build-context.js";
5
+ import { BrowserOriginFetchHandle } from "../browser-fetch/index.js";
6
+ import { PageSource } from "./page-source.js";
7
+ export interface DiffServiceDeps {
8
+ readonly options: DiffOptions;
9
+ readonly log: DiffLog;
10
+ readonly engine: DiffEngine;
11
+ readonly pages: PageSource;
12
+ /** The headless Chrome pages are fetched through; closed when the run ends. */
13
+ readonly browserFetch?: BrowserOriginFetchHandle;
14
+ }
15
+ /**
16
+ * `sk diff`: compares one page, as Speed Kit's server would request and the
17
+ * customer's documentHandler would render it, along two axes, or against
18
+ * another page.
19
+ *
20
+ * - **Parameters:** the page against itself with its query parameters
21
+ * removed. A parameter that changes nothing can be dropped from the cache
22
+ * key; one that changes the page must stay. When removing all of them makes
23
+ * a difference, each is checked on its own, so the report names the ones
24
+ * that matter.
25
+ * - **Variations:** the page in one variation against another
26
+ * variation, which shows whether the origin serves a device or a custom
27
+ * variation different markup.
28
+ *
29
+ * With both, the parameter check runs once per variation, each against that
30
+ * variation's own page. Without variations, the parameter check runs in the
31
+ * one `variation` names, desktop by default.
32
+ *
33
+ * - **Against:** the page against another page in one variation, such as
34
+ * `?color=red` against `?color=blue`. With and without a parameter cannot
35
+ * tell a filter apart from a shop that answers a missing or unknown value
36
+ * with the unfiltered page; two values can.
37
+ *
38
+ * Parameters selected by name are checked once, all removed together while
39
+ * the others stay in the url, without the check of removing all of them.
40
+ *
41
+ * With `baseline`, every side is fetched twice, and what differs between the
42
+ * two is noise no comparison counts. Each side is fetched once per run, so a
43
+ * page that takes part in several comparisons costs its requests once.
44
+ *
45
+ * A side that fails ends its comparison, not the run. When the
46
+ * documentHandler aborts a side, Speed Kit never caches it, so that
47
+ * comparison is `uncacheable`; any other failure leaves it `failed`.
48
+ */
2
49
  export declare class DiffService {
3
- private cli;
4
- private diffExecutablePath?;
5
- private diffExecutableTemplate?;
6
- private opensDiffTool;
7
- private tempPath;
8
- constructor(cli: CliServiceInterface, diffExecutablePath?: string, diffExecutableTemplate?: string, opensDiffTool?: boolean);
9
- diff(localPath: string, fileName: string, temporaryContent: string): Promise<boolean>;
10
- diffContent(fileName: string, firstContent: string, secondContent: string, diffSuffix?: string[]): Promise<{
11
- updatedFile: string;
12
- diff: boolean;
13
- }>;
50
+ private readonly deps;
51
+ private readonly outcomes;
52
+ private readonly sides;
53
+ /** The hints written, so a failure seen in several comparisons writes them once. */
54
+ private readonly hinted;
55
+ constructor(deps: DiffServiceDeps);
56
+ /**
57
+ * Runs every comparison. Resolves to the worst outcome among them: a
58
+ * comparison that failed before one that differed, before one that is not
59
+ * cacheable.
60
+ */
61
+ run(): Promise<ComparisonOutcome>;
62
+ private check;
63
+ /** The page against another page, both in one variation. */
64
+ private checkAgainst;
65
+ private checkVariations;
66
+ /**
67
+ * Without variations the parameters are all there is to compare. A url
68
+ * without any is a mistake, not a page without a diff, so it does not end
69
+ * as one.
70
+ */
71
+ private assertParameters;
72
+ private checkParameters;
14
73
  /**
15
- * Returns a temporal directory path.
74
+ * The page against itself without each group of parameters. With
75
+ * `stripped`, each comparison also says whether its difference is the one
76
+ * removing every parameter makes.
16
77
  */
17
- getTemporalDirectoryPath(): Promise<string>;
78
+ private checkEachParameter;
18
79
  /**
19
- * The temporary directory remote installation files are written to.
20
- *
21
- * Returns null instead of throwing, because the one caller turns that into a
22
- * readable CLI error — an mkdtemp stack trace says less than "unable to
23
- * create a temporary directory" does.
80
+ * Compares two sides and reports the verdict. With `stripped`, the
81
+ * verdict also says whether the difference is the one removing every
82
+ * parameter makes: when it is not, the parameter matters together with
83
+ * the others too. The right side carries the answer as
84
+ * `sameAsWithoutAnyParam`, for a sink that reports it.
24
85
  */
25
- private createTemporalDirectory;
26
- writeContentToTemporalFile(temporaryFileName: string, content: string): Promise<string>;
86
+ private compare;
27
87
  /**
28
- * @param localContent local file content.
29
- * @param remoteContent remote content.
30
- * @description removes whitespaces, newlines and compares both params content for equality.
31
- * @return returns true if both localContent and remoteContent are equal otherwise returns false.
88
+ * Reports a comparison a side of failed. It is `uncacheable` when every
89
+ * failed side is a documentHandler abort: Speed Kit never caches such a
90
+ * page, which is a verdict in itself. Any other failure leaves the
91
+ * comparison `failed`.
32
92
  */
33
- isContentEqual(localContent?: string, remoteContent?: string): boolean;
93
+ private reportFailure;
94
+ private settle;
95
+ private diffVerdict;
34
96
  /**
35
- *
36
- * check if content of two files are equal
37
- *
38
- * @param firstPath
39
- * @param secondPath
40
- * @param skipDiffExecution
97
+ * The side of a url in a variation, fetched once per run. A side Speed
98
+ * Kit's server would fail on resolves to that failure; any other error
99
+ * ends the run.
41
100
  */
42
- executeDiff(firstPath: string, secondPath: string, skipDiffExecution?: boolean): Promise<boolean>;
101
+ private side;
102
+ private announce;
43
103
  }