@speedkit/cli 4.50.4 → 4.51.0-beta.1

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 (71) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/services/bundler/bundle-service-factory.d.ts +3 -0
  3. package/dist/services/bundler/bundle-service-factory.js +5 -1
  4. package/dist/services/bundler/bundle-service.d.ts +10 -1
  5. package/dist/services/bundler/bundle-service.js +16 -1
  6. package/dist/services/bundler/error/packjockel-error.d.ts +3 -0
  7. package/dist/services/bundler/error/packjockel-error.js +3 -0
  8. package/dist/services/bundler/index.d.ts +1 -0
  9. package/dist/services/bundler/index.js +1 -0
  10. package/dist/services/bundler/packjockel-service.d.ts +112 -0
  11. package/dist/services/bundler/packjockel-service.js +202 -0
  12. package/dist/services/bundler/spec/packjockel-service.spec.d.ts +1 -0
  13. package/dist/services/bundler/spec/packjockel-service.spec.js +186 -0
  14. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  15. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +2 -3
  16. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +2 -3
  17. package/dist/services/deploy/handler/customer-config-handler.d.ts +9 -0
  18. package/dist/services/deploy/handler/customer-config-handler.js +41 -6
  19. package/dist/services/deploy/interface/install.d.ts +7 -1
  20. package/dist/services/deploy/mr/live-state-check.js +21 -2
  21. package/dist/services/deploy/policy/auto-deploy-policy.js +2 -0
  22. package/dist/services/deploy/policy/deploy-policy-model.d.ts +4 -0
  23. package/dist/services/deploy/policy/deploy-policy-model.js +4 -0
  24. package/dist/services/deploy/policy/testing-deploy-policy.js +2 -0
  25. package/dist/services/deploy/spec/handler/customer-config-handler.spec.d.ts +1 -0
  26. package/dist/services/deploy/spec/handler/customer-config-handler.spec.js +98 -0
  27. package/dist/services/deploy/spec/mr/live-state-check.spec.js +45 -4
  28. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +2 -0
  29. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +3 -1
  30. package/dist/services/document-handler-runtime/document-handler-browser-mock.d.ts +13 -0
  31. package/dist/services/document-handler-runtime/document-handler-browser-mock.js +69 -0
  32. package/dist/services/document-handler-runtime/document-handler-server.d.ts +27 -0
  33. package/dist/services/document-handler-runtime/document-handler-server.js +112 -19
  34. package/dist/services/document-handler-runtime/spec/document-handler-browser-mock.spec.d.ts +1 -0
  35. package/dist/services/document-handler-runtime/spec/document-handler-browser-mock.spec.js +34 -0
  36. package/dist/services/integration-api/integration-api-model.d.ts +4 -1
  37. package/dist/services/integration-api/spec/customer-config-file.spec.d.ts +1 -0
  38. package/dist/services/integration-api/spec/customer-config-file.spec.js +56 -0
  39. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +68 -8
  40. package/dist/services/integration-api/struct/customer-config-file.d.ts +15 -0
  41. package/dist/services/integration-api/struct/customer-config-file.js +42 -0
  42. package/dist/services/integration-api/struct/customer-config.d.ts +55 -1
  43. package/dist/services/integration-api/struct/customer-config.js +70 -3
  44. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +11 -4
  45. package/dist/services/integration-api/struct/speed-kit-config-file.js +31 -10
  46. package/dist/services/onboarding/config-renderer/speed-kit-install-context.d.ts +2 -0
  47. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +29 -8
  48. package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +4 -25
  49. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +3 -1
  50. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +10 -2
  51. package/dist/services/onboarding/file-events/file-watcher.d.ts +3 -1
  52. package/dist/services/onboarding/file-events/file-watcher.js +9 -2
  53. package/dist/services/onboarding/html-charset.d.ts +28 -0
  54. package/dist/services/onboarding/html-charset.js +57 -0
  55. package/dist/services/onboarding/onboarding-model.d.ts +0 -1
  56. package/dist/services/onboarding/onboarding-model.js +0 -1
  57. package/dist/services/onboarding/onboarding-service-factory.js +12 -2
  58. package/dist/services/onboarding/spec/fetch-events/customer-domain-document-response.spec.d.ts +1 -0
  59. package/dist/services/onboarding/spec/fetch-events/customer-domain-document-response.spec.js +39 -0
  60. package/dist/services/onboarding/spec/file-events/file-watcher.spec.d.ts +1 -0
  61. package/dist/services/onboarding/spec/file-events/file-watcher.spec.js +67 -0
  62. package/dist/services/onboarding/spec/html-charset.spec.d.ts +1 -0
  63. package/dist/services/onboarding/spec/html-charset.spec.js +58 -0
  64. package/dist/services/onboarding/spec/virtual-orestes-app/index.spec.d.ts +1 -0
  65. package/dist/services/onboarding/spec/virtual-orestes-app/index.spec.js +19 -0
  66. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +5 -0
  67. package/dist/services/onboarding/virtual-orestes-app/index.js +3 -26
  68. package/dist/services/pull/pull-service.js +23 -5
  69. package/dist/services/query-builder/query-builder-factory.js +3 -3
  70. package/oclif.manifest.json +1 -1
  71. package/package.json +3 -2
@@ -0,0 +1,67 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { FileWatcher } from "../../file-events/file-watcher.js";
4
+ import { INTEGRATION_FILES } from "../../../../models/files.js";
5
+ /**
6
+ * Builds a FileWatcher with fakes and returns what it did on a change of `config_SpeedKit`.
7
+ *
8
+ * @param features the features of the customer config
9
+ */
10
+ async function changeSpeedKitConfig(features) {
11
+ const calls = [];
12
+ const callbacks = new Map();
13
+ const file = (name) => ({
14
+ name,
15
+ type: "file",
16
+ onChange: (callback) => callbacks.set(name, callback),
17
+ });
18
+ const files = {
19
+ hasFile: (name) => name === INTEGRATION_FILES.CONFIG.SPEED_KIT,
20
+ getByName: (name) => name === INTEGRATION_FILES.BUILD.INSTALL
21
+ ? {
22
+ buildContent: async () => calls.push("buildInstallResource"),
23
+ }
24
+ : file(name),
25
+ };
26
+ const page = {
27
+ url: () => "https://www.example.com/products/1",
28
+ target: () => ({
29
+ createCDPSession: async () => ({
30
+ send: async (method) => method === "CacheStorage.requestCacheNames" ? { caches: [] } : {},
31
+ }),
32
+ }),
33
+ };
34
+ const watcher = new FileWatcher({
35
+ writeWarning: () => undefined,
36
+ writeError: () => undefined,
37
+ }, { app: "example", features }, files, {
38
+ buildDocumentHandler: async () => calls.push("buildDocumentHandler"),
39
+ }, { domain: "https://www.example.com" }, { clear: () => calls.push("clearCache") });
40
+ watcher.addCallbackOnFileChange(page, async () => {
41
+ calls.push("reinstallServiceWorker");
42
+ }, new AbortController().signal);
43
+ await callbacks.get(INTEGRATION_FILES.CONFIG.SPEED_KIT)(file(INTEGRATION_FILES.CONFIG.SPEED_KIT));
44
+ return calls;
45
+ }
46
+ describe("FileWatcher", () => {
47
+ describe("on a change of config_SpeedKit", () => {
48
+ it("rebuilds the document handler when it embeds the config", async () => {
49
+ const calls = await changeSpeedKitConfig({
50
+ enableSpeedKitConfigPlugins: true,
51
+ });
52
+ expect(calls).to.deep.equal([
53
+ "buildDocumentHandler",
54
+ "clearCache",
55
+ "buildInstallResource",
56
+ "reinstallServiceWorker",
57
+ ]);
58
+ });
59
+ it("only reinstalls the service worker without config plugins", async () => {
60
+ const calls = await changeSpeedKitConfig(undefined);
61
+ expect(calls).to.deep.equal([
62
+ "buildInstallResource",
63
+ "reinstallServiceWorker",
64
+ ]);
65
+ });
66
+ });
67
+ });
@@ -0,0 +1,58 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import iconv from "iconv-lite";
4
+ import { decodeHtml, detectHtmlCharset } from "../html-charset.js";
5
+ import { UnsupportedEncodingError } from "../error/unsupported-encoding-error.js";
6
+ const TITLE = "掃除機";
7
+ function page(head, charset) {
8
+ return iconv.encode(`<!doctype html><html><head>${head}<title>${TITLE}</title></head></html>`, charset);
9
+ }
10
+ describe("html-charset", () => {
11
+ it("takes <meta charset> when the header has no charset", () => {
12
+ const body = page('<meta charset="shift_jis">', "shift_jis");
13
+ expect(decodeHtml("text/html", body)).to.deep.equal({
14
+ text: iconv.decode(body, "shift_jis"),
15
+ charset: "shift_jis",
16
+ });
17
+ expect(decodeHtml("text/html", body).text).to.contain(TITLE);
18
+ });
19
+ it("lets the body charset replace a non-UTF-8 header charset", () => {
20
+ const body = page('<meta charset="shift_jis">', "shift_jis");
21
+ const { text, charset } = decodeHtml("text/html; charset=MS932", body);
22
+ expect(charset).to.equal("shift_jis");
23
+ expect(text).to.contain(TITLE);
24
+ });
25
+ it("trusts a UTF-8 header and ignores a conflicting meta tag", () => {
26
+ const body = page('<meta charset="shift_jis">', "utf-8");
27
+ const { text, charset } = decodeHtml("text/html; charset=UTF-8", body);
28
+ expect(charset).to.equal("utf-8");
29
+ expect(text).to.contain(TITLE);
30
+ });
31
+ it("falls back to UTF-8 without any hint", () => {
32
+ expect(detectHtmlCharset("text/html", page("", "utf-8"))).to.equal("utf-8");
33
+ expect(detectHtmlCharset("", page("", "utf-8"))).to.equal("utf-8");
34
+ });
35
+ it("keeps a non-UTF-8 header charset when the body has no hint", () => {
36
+ expect(detectHtmlCharset("text/html; charset=EUC-JP", page("", "euc-jp"))).to.equal("euc-jp");
37
+ });
38
+ it("reads the http-equiv form of the meta tag", () => {
39
+ const body = page('<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">', "shift_jis");
40
+ const { text, charset } = decodeHtml("text/html", body);
41
+ expect(charset).to.equal("shift_jis");
42
+ expect(text).to.contain(TITLE);
43
+ });
44
+ it("reads a BOM", () => {
45
+ const body = Buffer.concat([
46
+ Buffer.from([0xef, 0xbb, 0xbf]),
47
+ page("", "utf-8"),
48
+ ]);
49
+ expect(detectHtmlCharset("text/html; charset=iso-8859-1", body)).to.equal("utf-8");
50
+ });
51
+ it("does not sniff a non-HTML content type", () => {
52
+ const body = page('<meta charset="shift_jis">', "shift_jis");
53
+ expect(detectHtmlCharset("application/xhtml+xml", body)).to.equal("utf-8");
54
+ });
55
+ it("throws UnsupportedEncodingError for a charset iconv-lite does not know", () => {
56
+ expect(() => decodeHtml("text/html; charset=x-unknown", page("", "utf-8"))).to.throw(UnsupportedEncodingError, "x-unknown");
57
+ });
58
+ });
@@ -0,0 +1,19 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import iconv from "iconv-lite";
4
+ import { VirtualOrestesApp } from "../../virtual-orestes-app/index.js";
5
+ describe("VirtualOrestesApp", () => {
6
+ it("decodes the Speed Kit document by its <meta charset>", async () => {
7
+ const html = '<html><head><meta charset="shift_jis"><title>掃除機</title></head></html>';
8
+ const body = iconv.encode(html, "shift_jis");
9
+ // getResponseText needs no collaborator, so the constructor is skipped.
10
+ const app = Object.create(VirtualOrestesApp.prototype);
11
+ const result = await app["getResponseText"](new Response(new Uint8Array(body), {
12
+ headers: { "content-type": "text/html" },
13
+ }));
14
+ expect(result).to.deep.equal({
15
+ responseContent: html,
16
+ textEncoding: "shift_jis",
17
+ });
18
+ });
19
+ });
@@ -5,6 +5,11 @@ export class InstallSpeedKitJsTemplate extends AbstractTemplate {
5
5
  // Config
6
6
  {{{config}}}
7
7
 
8
+ {{#if configPlugins}}
9
+ // The config writes SpeedKit.config, which packjockel exposes; the overrides below change it.
10
+ var speedKit = SpeedKit.config;
11
+ {{/if}}
12
+
8
13
  // Reset potential split test parameters
9
14
  speedKit.split = 1.0;
10
15
  speedKit.splitTestId = 'debug';
@@ -2,9 +2,8 @@ import { BaqendResponse } from "../browser/baqend-response.js";
2
2
  import { ABORT_SERVER_TIMING, ABORT_STATUS_CODE, isDocumentHandlerAbort, isLocalPrerendererUnreachable, LOCAL_PRERENDERER_PORT, prerenderFailure, } from "../../document-handler-runtime/document-handler-abort.js";
3
3
  import { isBlockedOriginStatus, ORIGIN_ERROR_STATUS_CODE, originErrorCauseName, originErrorCode, originErrorServerTiming, } from "../../origin-request/index.js";
4
4
  import { safe } from "../../../helpers/safe.js";
5
- import { META_CONTENT_TYPE_REGEX, } from "../onboarding-model.js";
6
5
  import iconv from "iconv-lite";
7
- import { UnsupportedEncodingError } from "../error/unsupported-encoding-error.js";
6
+ import { decodeHtml } from "../html-charset.js";
8
7
  import { removeContentSecurityMetaTag, rewriteInstallResource, } from "../html-rewrites.js";
9
8
  // for none encodable chars use a space, so the broken char is invisible.
10
9
  // We are using the same trick in our node.js server
@@ -191,30 +190,8 @@ export class VirtualOrestesApp {
191
190
  return baqendResponse;
192
191
  }
193
192
  async getResponseText(response) {
194
- const buffer = Buffer.from(await response.arrayBuffer());
195
- const contentType = response?.headers.get("content-type") || "";
196
- const charsetRegex = /charset=([^\s"(),./:;<=>?@[\]]*)/i;
197
- const encodingFromHeader = (contentType && charsetRegex.test(contentType)
198
- ? charsetRegex.exec(contentType)[1]
199
- : null) ?? "utf-8";
200
- if (!iconv.encodingExists(encodingFromHeader)) {
201
- throw new UnsupportedEncodingError(`encoding is not supported by cli: "${encodingFromHeader}"`);
202
- }
203
- let encodedBody = iconv.decode(buffer, encodingFromHeader);
204
- const metaSelector = META_CONTENT_TYPE_REGEX;
205
- const encodingFromBodyMeta = metaSelector.test(encodedBody)
206
- ? metaSelector.exec(encodedBody)[1]
207
- : null;
208
- if (encodingFromBodyMeta && encodingFromBodyMeta !== encodingFromHeader) {
209
- if (!iconv.encodingExists(encodingFromBodyMeta)) {
210
- throw new UnsupportedEncodingError(`encoding is not supported by cli: "${encodingFromBodyMeta}"`);
211
- }
212
- encodedBody = iconv.decode(buffer, encodingFromBodyMeta);
213
- }
214
- return {
215
- responseContent: encodedBody,
216
- textEncoding: encodingFromBodyMeta ?? encodingFromHeader,
217
- };
193
+ const { text, charset } = decodeHtml(response?.headers.get("content-type") || "", Buffer.from(await response.arrayBuffer()));
194
+ return { responseContent: text, textEncoding: charset };
218
195
  }
219
196
  localCacheErrorKey(url, variation) {
220
197
  return `${url}|${variation}`;
@@ -1,4 +1,4 @@
1
- import { InstallResourceFile, } from "../integration-api/index.js";
1
+ import { InstallResourceFile, versionsOfInstall, } from "../integration-api/index.js";
2
2
  import { InstallResourceToFileMapping } from "./index.js";
3
3
  import { safe } from "../../helpers/safe.js";
4
4
  import { execSync } from "node:child_process";
@@ -107,13 +107,31 @@ export class PullService {
107
107
  async handleConfigCustomer(installResource) {
108
108
  const customerConfigFile = this.fileList.getCustomerConfig();
109
109
  const config = customerConfigFile.config;
110
- if (JSON.stringify(installResource.origins.sort()) !==
111
- JSON.stringify(config.origins.sort())) {
110
+ const updatesOrigins = JSON.stringify(installResource.origins.sort()) !==
111
+ JSON.stringify(config.origins.sort());
112
+ if (updatesOrigins) {
112
113
  this.cli.writeWarning(`update: config_customer(origins)`);
113
114
  customerConfigFile.updateOrigins(installResource.origins);
115
+ }
116
+ else {
117
+ this.cli.writeSuccess("equal, skip: config_customer(origins)");
118
+ }
119
+ const updatesFeatures = customerConfigFile.updateFeatures(installResource.features);
120
+ if (updatesFeatures) {
121
+ this.cli.writeWarning(`update: config_customer(features)`);
122
+ }
123
+ else {
124
+ this.cli.writeSuccess("equal, skip: config_customer(features)");
125
+ }
126
+ const updatesVersions = customerConfigFile.updateVersions(versionsOfInstall(installResource));
127
+ if (updatesVersions) {
128
+ this.cli.writeWarning(`update: config_customer(versions)`);
129
+ }
130
+ else {
131
+ this.cli.writeSuccess("equal, skip: config_customer(versions)");
132
+ }
133
+ if (updatesOrigins || updatesFeatures || updatesVersions) {
114
134
  await customerConfigFile.updateFile();
115
- return;
116
135
  }
117
- this.cli.writeSuccess("equal, skip: config_customer(origins)");
118
136
  }
119
137
  }
@@ -22,7 +22,7 @@ export class QueryBuilderFactory {
22
22
  const customerConfig = files.getCustomerConfig().config;
23
23
  const app = customerConfig.app;
24
24
  const origins = customerConfig.origins ?? [];
25
- const speedKitConfig = await this.getSpeedKitConfig(app, origins[0], files.getSpeedKitConfig());
25
+ const speedKitConfig = await this.getSpeedKitConfig(customerConfig, origins[0], files.getSpeedKitConfig());
26
26
  const serviceContext = {
27
27
  app,
28
28
  bySet: this.context.bySet,
@@ -72,8 +72,8 @@ export class QueryBuilderFactory {
72
72
  const integrationApi = new IntegrationApiFactory(integrationApiContext).buildService();
73
73
  return await integrationApi.run();
74
74
  }
75
- async getSpeedKitConfig(app, origin, speedKitConfigFile) {
76
- const result = await safe(speedKitConfigFile.evaluate(app, origin));
75
+ async getSpeedKitConfig(customer, origin, speedKitConfigFile) {
76
+ const result = await safe(speedKitConfigFile.evaluate(customer, origin));
77
77
  if (result.success !== true) {
78
78
  throw new ParseConfigSpeedKitError(result.error);
79
79
  }
@@ -2113,5 +2113,5 @@
2113
2113
  ]
2114
2114
  }
2115
2115
  },
2116
- "version": "4.50.4"
2116
+ "version": "4.51.0-beta.1"
2117
2117
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.50.4",
4
+ "version": "4.51.0-beta.1",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"
@@ -110,6 +110,7 @@
110
110
  "@oclif/plugin-help": "^6.2.45",
111
111
  "@oclif/plugin-not-found": "^3.2.81",
112
112
  "@oclif/plugin-warn-if-update-available": "^3.1.61",
113
+ "@speedkit/packjockel": "4.1.0",
113
114
  "@speedkit/rules": "^1.3.0-0",
114
115
  "baqend": "^4.2.5",
115
116
  "chalk": "^5.6.2",
@@ -124,7 +125,7 @@
124
125
  "domhandler": "^5.0.3",
125
126
  "domutils": "^3.1.0",
126
127
  "dotenv": "^17.4.2",
127
- "encoding-japanese": "^2.2.0",
128
+ "encoding-sniffer": "^0.2.1",
128
129
  "esbuild": "^0.27.3",
129
130
  "extract-zip": "^2.0.1",
130
131
  "fetch-socks": "^1.3.3",