@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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [4.50.5](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.50.4...v4.50.5) (2026-11-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **onboarding:** detect the HTML charset like the Baqend server ([78ce6d7](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/78ce6d7ac5794c385212d16ee33bc137a278208f))
7
+
1
8
  ## [4.50.4](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.50.3...v4.50.4) (2026-11-02)
2
9
 
3
10
 
@@ -1,6 +1,9 @@
1
1
  import { BundleService } from "./bundle-service.js";
2
2
  export declare class BundleServiceFactory {
3
3
  private customerFolder?;
4
+ /**
5
+ * @param customerFolder the directory bundled code resolves its own imports from
6
+ */
4
7
  constructor(customerFolder?: string);
5
8
  buildService(): BundleService;
6
9
  }
@@ -1,10 +1,14 @@
1
1
  import { BundleService } from "./bundle-service.js";
2
+ import { PackjockelService } from "./packjockel-service.js";
2
3
  export class BundleServiceFactory {
3
4
  customerFolder;
5
+ /**
6
+ * @param customerFolder the directory bundled code resolves its own imports from
7
+ */
4
8
  constructor(customerFolder) {
5
9
  this.customerFolder = customerFolder;
6
10
  }
7
11
  buildService() {
8
- return new BundleService(this.customerFolder);
12
+ return new BundleService(this.customerFolder, new PackjockelService());
9
13
  }
10
14
  }
@@ -1,4 +1,5 @@
1
1
  import { PluginBuild, LogLevel } from "esbuild";
2
+ import type { PackjockelService } from "./packjockel-service.js";
2
3
  export type BundleEntryPoints = Record<string, string>;
3
4
  export type BundleBasePaths = Record<string, string>;
4
5
  /**
@@ -8,10 +9,18 @@ export type BundleBasePaths = Record<string, string>;
8
9
  export type BundleResolveFallback = (specifier: string) => Promise<string | null>;
9
10
  export declare class BundleService {
10
11
  private moduleDiscoveryDir;
12
+ private readonly packjockelService?;
11
13
  /**
12
14
  * @param moduleDiscoveryDir the directory bundled code resolves its own imports from
15
+ * @param packjockelService bundles instead of esbuild for customers with the `enableSpeedKitConfigPlugins` feature
13
16
  */
14
- constructor(moduleDiscoveryDir: string);
17
+ constructor(moduleDiscoveryDir: string, packjockelService?: PackjockelService);
18
+ /**
19
+ * The packjockel bundler for customers with the `enableSpeedKitConfigPlugins` feature.
20
+ *
21
+ * @throws ApplicationError when the service was built without one
22
+ */
23
+ get packjockel(): PackjockelService;
15
24
  bundle({ entryPoints, basePaths, define, target, minify, logLevel, alias, platform, resolveFallback, packages, }: {
16
25
  entryPoints: BundleEntryPoints;
17
26
  basePaths?: BundleBasePaths;
@@ -4,16 +4,31 @@ import { URL } from "node:url";
4
4
  import { BundleResolveError } from "./error/bundle-resolve-error.js";
5
5
  import { BundleFetchError } from "./error/bundle-fetch-error.js";
6
6
  import { resolve } from "node:path";
7
+ import ApplicationError from "../error-handling/error/application-error.js";
7
8
  const FALLBACK_NAMESPACE = "bundle-resolve-fallback";
8
9
  const RELATIVE_SPECIFIER = /^\.{1,2}\//;
9
10
  const importCache = {};
10
11
  export class BundleService {
11
12
  moduleDiscoveryDir;
13
+ packjockelService;
12
14
  /**
13
15
  * @param moduleDiscoveryDir the directory bundled code resolves its own imports from
16
+ * @param packjockelService bundles instead of esbuild for customers with the `enableSpeedKitConfigPlugins` feature
14
17
  */
15
- constructor(moduleDiscoveryDir) {
18
+ constructor(moduleDiscoveryDir, packjockelService) {
16
19
  this.moduleDiscoveryDir = moduleDiscoveryDir;
20
+ this.packjockelService = packjockelService;
21
+ }
22
+ /**
23
+ * The packjockel bundler for customers with the `enableSpeedKitConfigPlugins` feature.
24
+ *
25
+ * @throws ApplicationError when the service was built without one
26
+ */
27
+ get packjockel() {
28
+ if (!this.packjockelService) {
29
+ throw new ApplicationError("This bundler has no packjockel");
30
+ }
31
+ return this.packjockelService;
17
32
  }
18
33
  async bundle({ entryPoints, basePaths, define, target = "es5", minify = true, logLevel = "silent", alias = {}, platform, resolveFallback, packages = "bundle", }) {
19
34
  const plugins = [];
@@ -0,0 +1,3 @@
1
+ import ApplicationError from "../../error-handling/error/application-error.js";
2
+ export declare class PackjockelError extends ApplicationError {
3
+ }
@@ -0,0 +1,3 @@
1
+ import ApplicationError from "../../error-handling/error/application-error.js";
2
+ export class PackjockelError extends ApplicationError {
3
+ }
@@ -1,2 +1,3 @@
1
1
  export * from "./bundle-service-factory.js";
2
2
  export * from "./bundle-service.js";
3
+ export * from "./packjockel-service.js";
@@ -1,2 +1,3 @@
1
1
  export * from "./bundle-service-factory.js";
2
2
  export * from "./bundle-service.js";
3
+ export * from "./packjockel-service.js";
@@ -0,0 +1,112 @@
1
+ /**
2
+ * The tags of the Speed Kit assets that packjockel bundles, each a version such as `1.8.0` or a channel
3
+ * such as `@release`. packjockel takes `latest` for a tag that is not set. The names are the client
4
+ * config keys of packjockel.
5
+ */
6
+ export interface AssetVersions {
7
+ /** Speed Kit: snippet, service worker and dynamic fetcher */
8
+ speedKitVersion?: string;
9
+ rumPluginsVersion?: string;
10
+ /** predictive preloading */
11
+ ppVersion?: string;
12
+ configPluginsVersion?: string;
13
+ documentHandlerVersion?: string;
14
+ }
15
+ export interface PackjockelBundleRequest {
16
+ /** The entry points by file name, in output order. */
17
+ entryPoints: Record<string, string>;
18
+ versions?: AssetVersions;
19
+ define?: Record<string, string>;
20
+ platform?: "browser" | "node";
21
+ target?: "es5" | "es6";
22
+ minify?: boolean;
23
+ }
24
+ export interface PackjockelInstallScriptRequest {
25
+ /** The config plugins, such as the `rum.js` load handler. */
26
+ plugins: string;
27
+ /** The Speed Kit config, which writes `SpeedKit.config`. */
28
+ config: string;
29
+ loader: string;
30
+ /** Set as `SpeedKit.config.installationId`. */
31
+ installationId: string;
32
+ /**
33
+ * The feature flags of the app. packjockel reads the flags it knows, such as `executeInIframe`, and
34
+ * ignores the others.
35
+ */
36
+ features?: Record<string, boolean>;
37
+ versions?: AssetVersions;
38
+ define?: Record<string, string>;
39
+ minify?: boolean;
40
+ }
41
+ export interface PackjockelDocumentHandlerRequest {
42
+ /** The document handler library; without it packjockel bundles the published one of `documentHandlerVersion`. */
43
+ documentHandler?: string;
44
+ documentHandlerConfig: string;
45
+ speedKitConfig: string;
46
+ appName: string;
47
+ dynamicFetcher?: string;
48
+ dynamicFetcherConfig?: string;
49
+ customStyle?: string;
50
+ versions?: AssetVersions;
51
+ }
52
+ export interface PackjockelServiceWorkerRequest {
53
+ /** The Speed Kit service worker, with the `INSERT_CONFIG_HERE` placeholder of its config. */
54
+ serviceWorker: string;
55
+ /** The Speed Kit config, which writes `SpeedKit.config`. */
56
+ speedKitConfig: string;
57
+ appName: string;
58
+ versions?: AssetVersions;
59
+ }
60
+ /**
61
+ * Bundles with the packjockel binary in embedded mode, so no packjockel server is needed.
62
+ *
63
+ * Every input goes to the binary as a file, because a document handler is too large for one
64
+ * command line argument.
65
+ */
66
+ export declare class PackjockelService {
67
+ private readonly resolveBinary;
68
+ /**
69
+ * @param resolveBinary returns the packjockel binary; it runs only when a bundle is needed, so
70
+ * a platform without a packjockel package fails only for the `enableSpeedKitConfigPlugins` feature
71
+ */
72
+ constructor(resolveBinary?: () => string);
73
+ /**
74
+ * Bundles the entry points in their order into one script. packjockel puts a script before them
75
+ * which exposes the `SpeedKit` global.
76
+ *
77
+ * @returns the bundled code
78
+ */
79
+ bundle(request: PackjockelBundleRequest): Promise<string>;
80
+ /**
81
+ * Bundles the Speed Kit install script: the `SpeedKit` global, the plugins, the config, the
82
+ * installation (app, installation id) and the loader, in this order.
83
+ *
84
+ * @returns the install script
85
+ */
86
+ bundleInstallScript(request: PackjockelInstallScriptRequest): Promise<string>;
87
+ /**
88
+ * Bundles a document handler with its config, the embedded Speed Kit config and the default `post`.
89
+ *
90
+ * @returns the code of one CommonJS module, which exports `post`
91
+ */
92
+ bundleDocumentHandler(request: PackjockelDocumentHandlerRequest): Promise<string>;
93
+ /**
94
+ * Bundles the service worker with the embedded Speed Kit config. The config module runs before
95
+ * the service worker, so its plugin imports resolve to their service worker builds, and the
96
+ * placeholder reads the `SpeedKit.config` it wrote.
97
+ *
98
+ * @returns the bundled service worker
99
+ */
100
+ bundleServiceWorker(request: PackjockelServiceWorkerRequest): Promise<string>;
101
+ /**
102
+ * Runs packjockel in a scratch directory, which is removed afterwards.
103
+ *
104
+ * @param buildArgs writes the inputs into the directory and returns the arguments that read them
105
+ */
106
+ private run;
107
+ /**
108
+ * Runs the binary without stdin: packjockel reads a piped stdin as the document handler, and only
109
+ * without input it bundles the published one.
110
+ */
111
+ private execute;
112
+ }
@@ -0,0 +1,202 @@
1
+ import { spawn } from "node:child_process";
2
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { binaryPath } from "@speedkit/packjockel";
6
+ import { PackjockelError } from "./error/packjockel-error.js";
7
+ const VERSION_FLAGS = {
8
+ speedKitVersion: "--speed-kit-version",
9
+ rumPluginsVersion: "--rum-plugin-version",
10
+ ppVersion: "--pp-version",
11
+ configPluginsVersion: "--config-plugins-version",
12
+ documentHandlerVersion: "--document-handler-version",
13
+ };
14
+ /**
15
+ * Bundles with the packjockel binary in embedded mode, so no packjockel server is needed.
16
+ *
17
+ * Every input goes to the binary as a file, because a document handler is too large for one
18
+ * command line argument.
19
+ */
20
+ export class PackjockelService {
21
+ resolveBinary;
22
+ /**
23
+ * @param resolveBinary returns the packjockel binary; it runs only when a bundle is needed, so
24
+ * a platform without a packjockel package fails only for the `enableSpeedKitConfigPlugins` feature
25
+ */
26
+ constructor(resolveBinary = binaryPath) {
27
+ this.resolveBinary = resolveBinary;
28
+ }
29
+ /**
30
+ * Bundles the entry points in their order into one script. packjockel puts a script before them
31
+ * which exposes the `SpeedKit` global.
32
+ *
33
+ * @returns the bundled code
34
+ */
35
+ async bundle(request) {
36
+ return this.run(async (directory) => {
37
+ const args = [
38
+ "bundle",
39
+ "--bundle",
40
+ `--platform=${request.platform ?? "browser"}`,
41
+ `--target=${request.target ?? "es5"}`,
42
+ ];
43
+ if (request.minify) {
44
+ args.push("--minify");
45
+ }
46
+ args.push(...keyValueFlags("--define", request.define));
47
+ for (const [name, code] of Object.entries(request.entryPoints)) {
48
+ args.push(await writeInput(directory, name, code));
49
+ }
50
+ return args;
51
+ }, request.versions);
52
+ }
53
+ /**
54
+ * Bundles the Speed Kit install script: the `SpeedKit` global, the plugins, the config, the
55
+ * installation (app, installation id) and the loader, in this order.
56
+ *
57
+ * @returns the install script
58
+ */
59
+ async bundleInstallScript(request) {
60
+ return this.run(async (directory) => {
61
+ const args = [
62
+ "bundle",
63
+ "install-script",
64
+ await writeInput(directory, "loader.js", request.loader),
65
+ `--plugins=${await writeInput(directory, "plugins.js", request.plugins)}`,
66
+ `--config=${await writeInput(directory, "config.js", request.config)}`,
67
+ `--installation-id=${request.installationId}`,
68
+ ];
69
+ if (request.features) {
70
+ args.push(`--features=${await writeInput(directory, "features.json", JSON.stringify(request.features))}`);
71
+ }
72
+ if (request.minify) {
73
+ args.push("--minify");
74
+ }
75
+ args.push(...keyValueFlags("--define", request.define));
76
+ return args;
77
+ }, request.versions);
78
+ }
79
+ /**
80
+ * Bundles a document handler with its config, the embedded Speed Kit config and the default `post`.
81
+ *
82
+ * @returns the code of one CommonJS module, which exports `post`
83
+ */
84
+ async bundleDocumentHandler(request) {
85
+ return this.run(async (directory) => {
86
+ const args = ["bundle", "document-handler"];
87
+ if (request.documentHandler !== undefined) {
88
+ args.push(await writeInput(directory, "DocumentHandler.js", request.documentHandler));
89
+ }
90
+ args.push(`--document-handler-config=${await writeInput(directory, "documentHandlerConfig.js", request.documentHandlerConfig)}`, `--speed-kit-config=${await writeInput(directory, "speedKitConfig.js", request.speedKitConfig)}`, `--app-name=${request.appName}`);
91
+ const optional = {
92
+ "dynamic-fetcher": ["dynamicFetcher.js", request.dynamicFetcher],
93
+ "dynamic-fetcher-config": [
94
+ "dynamicFetcherConfig.js",
95
+ request.dynamicFetcherConfig,
96
+ ],
97
+ "custom-style": ["customStyle.css", request.customStyle],
98
+ };
99
+ for (const [flag, [name, value]] of Object.entries(optional)) {
100
+ if (value) {
101
+ args.push(`--${flag}=${await writeInput(directory, name, value)}`);
102
+ }
103
+ }
104
+ return args;
105
+ }, request.versions);
106
+ }
107
+ /**
108
+ * Bundles the service worker with the embedded Speed Kit config. The config module runs before
109
+ * the service worker, so its plugin imports resolve to their service worker builds, and the
110
+ * placeholder reads the `SpeedKit.config` it wrote.
111
+ *
112
+ * @returns the bundled service worker
113
+ */
114
+ async bundleServiceWorker(request) {
115
+ return this.run(async (directory) => [
116
+ "bundle",
117
+ "service-worker",
118
+ await writeInput(directory, "sw.js", `${request.speedKitConfig}\n${request.serviceWorker}`),
119
+ "--sk-config=SpeedKit.config",
120
+ // The Speed Kit service worker is ES6 and cannot be lowered to the es5 default.
121
+ "--target=es6",
122
+ ...keyValueFlags("--define", {
123
+ APP: JSON.stringify(request.appName),
124
+ }),
125
+ ], request.versions);
126
+ }
127
+ /**
128
+ * Runs packjockel in a scratch directory, which is removed afterwards.
129
+ *
130
+ * @param buildArgs writes the inputs into the directory and returns the arguments that read them
131
+ */
132
+ async run(buildArgs, versions = {}) {
133
+ const directory = await mkdtemp(join(tmpdir(), "sk-packjockel-"));
134
+ try {
135
+ const output = join(directory, "out.js");
136
+ const args = [
137
+ ...(await buildArgs(directory)),
138
+ ...versionFlags(versions),
139
+ "--embedded",
140
+ `--output=${output}`,
141
+ ];
142
+ await this.execute(args);
143
+ return await readFile(output, "utf8");
144
+ }
145
+ finally {
146
+ await rm(directory, { recursive: true, force: true });
147
+ }
148
+ }
149
+ /**
150
+ * Runs the binary without stdin: packjockel reads a piped stdin as the document handler, and only
151
+ * without input it bundles the published one.
152
+ */
153
+ execute(args) {
154
+ let binary;
155
+ try {
156
+ binary = this.resolveBinary();
157
+ }
158
+ catch (error) {
159
+ return Promise.reject(new PackjockelError(error.message));
160
+ }
161
+ return new Promise((resolve, reject) => {
162
+ const child = spawn(binary, args, {
163
+ stdio: ["ignore", "ignore", "pipe"],
164
+ });
165
+ let stderr = "";
166
+ child.stderr.on("data", (chunk) => (stderr += chunk));
167
+ child.on("error", (error) => reject(new PackjockelError(`packjockel failed: ${error.message}`)));
168
+ child.on("close", (code) => {
169
+ if (code === 0) {
170
+ resolve();
171
+ }
172
+ else {
173
+ reject(new PackjockelError(`packjockel failed: ${withoutLogLines(stderr) || `exit code ${code}`}`));
174
+ }
175
+ });
176
+ });
177
+ }
178
+ }
179
+ /** Writes one input into the scratch directory and returns the `file://` value that reads it. */
180
+ async function writeInput(directory, name, content) {
181
+ const path = join(directory, name);
182
+ await writeFile(path, content);
183
+ return `file://${path}`;
184
+ }
185
+ /** The flags of the tags that are set. */
186
+ function versionFlags(versions) {
187
+ return Object.entries(VERSION_FLAGS)
188
+ .filter(([key]) => versions[key])
189
+ .map(([key, flag]) => `${flag}=${versions[key]}`);
190
+ }
191
+ function keyValueFlags(flag, values = {}) {
192
+ return Object.entries(values).map(([key, value]) => `${flag}=${key}=${value}`);
193
+ }
194
+ /** packjockel and its cache log to stderr as well; the error is in the remaining lines. */
195
+ function withoutLogLines(stderr = "") {
196
+ return stderr
197
+ .split("\n")
198
+ .filter((line) => line.trim() &&
199
+ !line.startsWith("time=") &&
200
+ !/^\d{4}\/\d{2}\/\d{2} /.test(line))
201
+ .join("\n");
202
+ }
@@ -0,0 +1,186 @@
1
+ import { expect } from "chai";
2
+ import { afterEach, beforeEach, describe, it } from "mocha";
3
+ import { chmod, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { existsSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { PackjockelService } from "../packjockel-service.js";
8
+ import { PackjockelError } from "../error/packjockel-error.js";
9
+ /**
10
+ * A packjockel stand-in: it records its arguments, the content of every `file://` input and a
11
+ * piped stdin, and writes a fixed bundle to `--output`.
12
+ */
13
+ const FAKE_PACKJOCKEL = `#!/bin/sh
14
+ if [ -p /dev/stdin ] || [ -f /dev/stdin ]; then
15
+ echo "piped" > "$RECORD_DIR/stdin"
16
+ fi
17
+ out=""
18
+ for arg in "$@"; do
19
+ echo "$arg" >> "$RECORD_DIR/args"
20
+ case "$arg" in
21
+ --output=*) out="\${arg#--output=}" ;;
22
+ esac
23
+ path=$(echo "$arg" | sed -n 's|.*file://||p')
24
+ if [ -n "$path" ]; then
25
+ echo "$(basename "$path"): $(cat "$path")" >> "$RECORD_DIR/inputs"
26
+ fi
27
+ done
28
+ if [ -n "$FAIL" ]; then
29
+ echo "time=\\"2026\\" level=info msg=starting" >&2
30
+ echo "invalid bundle: could not resolve x" >&2
31
+ exit 1
32
+ fi
33
+ echo "bundled" > "$out"
34
+ `;
35
+ describe("PackjockelService", () => {
36
+ let directory;
37
+ let service;
38
+ beforeEach(async () => {
39
+ directory = await mkdtemp(join(tmpdir(), "packjockel-spec-"));
40
+ const binary = join(directory, "packjockel");
41
+ await writeFile(binary, FAKE_PACKJOCKEL);
42
+ await chmod(binary, 0o755);
43
+ process.env.RECORD_DIR = directory;
44
+ service = new PackjockelService(() => binary);
45
+ });
46
+ afterEach(async () => {
47
+ delete process.env.RECORD_DIR;
48
+ delete process.env.FAIL;
49
+ await rm(directory, { recursive: true, force: true });
50
+ });
51
+ async function recorded() {
52
+ const args = (await readFile(join(directory, "args"), "utf8"))
53
+ .trim()
54
+ .split("\n");
55
+ const inputs = (await readFile(join(directory, "inputs"), "utf8"))
56
+ .trim()
57
+ .split("\n");
58
+ return { args, inputs };
59
+ }
60
+ it("should bundle the entry points in their order", async () => {
61
+ const bundle = await service.bundle({
62
+ entryPoints: { "rum.js": "rum()", "config.js": "SpeedKit.config = {}" },
63
+ versions: { configPluginsVersion: "@release", rumPluginsVersion: "" },
64
+ define: { APP: '"shop"' },
65
+ platform: "browser",
66
+ });
67
+ const { args, inputs } = await recorded();
68
+ expect(bundle.trim()).to.equal("bundled");
69
+ expect(args.slice(0, 5)).to.deep.equal([
70
+ "bundle",
71
+ "--bundle",
72
+ "--platform=browser",
73
+ "--target=es5",
74
+ '--define=APP="shop"',
75
+ ]);
76
+ expect(args).to.include("--config-plugins-version=@release");
77
+ expect(args.filter((arg) => arg.endsWith("-version=")), "a tag that is not set is left to packjockel").to.deep.equal([]);
78
+ expect(args).to.include("--embedded");
79
+ expect(inputs).to.deep.equal([
80
+ "rum.js: rum()",
81
+ "config.js: SpeedKit.config = {}",
82
+ ]);
83
+ });
84
+ it("should bundle the install script with its loader, plugins and config", async () => {
85
+ const bundle = await service.bundleInstallScript({
86
+ plugins: "rum()",
87
+ config: "SpeedKit.config = {}",
88
+ loader: "load()",
89
+ installationId: "onboarding",
90
+ features: { executeInIframe: true },
91
+ versions: { speedKitVersion: "2.22.4" },
92
+ define: { APP: '"shop"' },
93
+ });
94
+ const { args, inputs } = await recorded();
95
+ expect(bundle.trim()).to.equal("bundled");
96
+ expect(args.slice(0, 2)).to.deep.equal(["bundle", "install-script"]);
97
+ expect(args).to.include("--installation-id=onboarding");
98
+ expect(args.some((arg) => arg.startsWith("--target")), "packjockel builds the install script for one browser gate").to.equal(false);
99
+ expect(args).to.include('--define=APP="shop"');
100
+ expect(args).to.include("--speed-kit-version=2.22.4");
101
+ expect(args).to.include("--embedded");
102
+ expect(inputs).to.deep.equal([
103
+ "loader.js: load()",
104
+ "plugins.js: rum()",
105
+ "config.js: SpeedKit.config = {}",
106
+ 'features.json: {"executeInIframe":true}',
107
+ ]);
108
+ });
109
+ it("should bundle a document handler with every input it got", async () => {
110
+ await service.bundleDocumentHandler({
111
+ documentHandler: "var DocumentHandler = 1",
112
+ documentHandlerConfig: "export default new DocumentHandler()",
113
+ speedKitConfig: "SpeedKit.config = {}",
114
+ appName: "shop",
115
+ dynamicFetcherConfig: "window.dynamicBlockConfig = {}",
116
+ });
117
+ const { args, inputs } = await recorded();
118
+ expect(args.slice(0, 2)).to.deep.equal(["bundle", "document-handler"]);
119
+ expect(args).to.include("--app-name=shop");
120
+ expect(args.some((arg) => arg.startsWith("--dynamic-fetcher="))).to.equal(false);
121
+ expect(inputs).to.deep.equal([
122
+ "DocumentHandler.js: var DocumentHandler = 1",
123
+ "documentHandlerConfig.js: export default new DocumentHandler()",
124
+ "speedKitConfig.js: SpeedKit.config = {}",
125
+ "dynamicFetcherConfig.js: window.dynamicBlockConfig = {}",
126
+ ]);
127
+ });
128
+ it("should bundle the service worker after the Speed Kit config", async () => {
129
+ await service.bundleServiceWorker({
130
+ serviceWorker: "const config = INSERT_CONFIG_HERE;",
131
+ speedKitConfig: "SpeedKit.config = {}",
132
+ appName: "shop",
133
+ versions: { configPluginsVersion: "@release" },
134
+ });
135
+ const { args, inputs } = await recorded();
136
+ expect(args.slice(0, 2)).to.deep.equal(["bundle", "service-worker"]);
137
+ expect(args).to.include("--sk-config=SpeedKit.config");
138
+ expect(args).to.include("--target=es6");
139
+ expect(args).to.include('--define=APP="shop"');
140
+ expect(args).to.include("--config-plugins-version=@release");
141
+ expect(inputs).to.deep.equal([
142
+ "sw.js: SpeedKit.config = {}",
143
+ "const config = INSERT_CONFIG_HERE;",
144
+ ]);
145
+ });
146
+ it("should leave the document handler to packjockel without one", async () => {
147
+ await service.bundleDocumentHandler({
148
+ documentHandlerConfig: "export default new DomDocumentHandler()",
149
+ speedKitConfig: "SpeedKit.config = {}",
150
+ appName: "shop",
151
+ versions: {
152
+ documentHandlerVersion: "1.8.0",
153
+ speedKitVersion: "2.22.4",
154
+ rumPluginsVersion: "@release",
155
+ },
156
+ });
157
+ const { args, inputs } = await recorded();
158
+ expect(args.slice(0, 2)).to.deep.equal(["bundle", "document-handler"]);
159
+ expect(args[2], "no handler argument").to.match(/^--document-handler-config=/);
160
+ expect(args).to.include("--document-handler-version=1.8.0");
161
+ expect(args).to.include("--speed-kit-version=2.22.4");
162
+ expect(args).to.include("--rum-plugin-version=@release");
163
+ expect(existsSync(join(directory, "stdin")), "packjockel reads a piped stdin as the handler").to.equal(false);
164
+ expect(inputs).to.deep.equal([
165
+ "documentHandlerConfig.js: export default new DomDocumentHandler()",
166
+ "speedKitConfig.js: SpeedKit.config = {}",
167
+ ]);
168
+ });
169
+ it("should report the error of packjockel without its log lines", async () => {
170
+ process.env.FAIL = "1";
171
+ const failure = await service
172
+ .bundle({ entryPoints: { "config.js": "x" } })
173
+ .catch((error) => error);
174
+ expect(failure).to.be.instanceOf(PackjockelError);
175
+ expect(failure.message).to.equal("packjockel failed: invalid bundle: could not resolve x");
176
+ });
177
+ it("should report a platform without a packjockel package", async () => {
178
+ const failure = await new PackjockelService(() => {
179
+ throw new Error("packjockel: @speedkit/packjockel-aix-ppc64 is not installed.");
180
+ })
181
+ .bundle({ entryPoints: { "config.js": "x" } })
182
+ .catch((error) => error);
183
+ expect(failure).to.be.instanceOf(PackjockelError);
184
+ expect(failure.message).to.contain("is not installed");
185
+ });
186
+ });
@@ -50,7 +50,7 @@ export class CustomerApprovalCheck {
50
50
  const configFile = await VirtualSpeedKitConfigFile.createRemote(speedKitConfig, this.bundler);
51
51
  const splits = [];
52
52
  for (const origin of this.customer.origins) {
53
- const result = await safe(configFile.evaluate(this.customer.app, origin));
53
+ const result = await safe(configFile.evaluate(this.customer, origin));
54
54
  if (result.success === false) {
55
55
  // An unreadable config is not proof that the split is 0, so keep the
56
56
  // approval question rather than skipping it.
@@ -70,11 +70,10 @@ export class DeviceDetectionChangedCheck {
70
70
  }
71
71
  async checkForChangedDeviceDetection(speedKitConfigFile, activeSpeedKitConfig) {
72
72
  const remoteConfigFile = await VirtualSpeedKitConfigFile.createRemote(activeSpeedKitConfig, this.bundler);
73
- const app = this.customerConfig.app;
74
73
  const origin = this.customerConfig.origins[0];
75
74
  const changes = [];
76
- const localSpeedKit = await speedKitConfigFile.evaluate(app, origin);
77
- const remoteSpeedKit = await remoteConfigFile.evaluate(app, origin);
75
+ const localSpeedKit = await speedKitConfigFile.evaluate(this.customerConfig, origin);
76
+ const remoteSpeedKit = await remoteConfigFile.evaluate(this.customerConfig, origin);
78
77
  if ((localSpeedKit.detectDevice && !remoteSpeedKit.detectDevice) ||
79
78
  (!localSpeedKit.detectDevice && remoteSpeedKit.detectDevice)) {
80
79
  changes.push("detectDevice");
@@ -63,11 +63,10 @@ export class SplitChangeCheck {
63
63
  }
64
64
  async checkSplitsForEachOrigin(speedKitConfigFile, activeSpeedKitConfig) {
65
65
  const remoteConfigFile = await VirtualSpeedKitConfigFile.createRemote(activeSpeedKitConfig, this.bundler);
66
- const app = this.customerConfig.app;
67
66
  const changes = [];
68
67
  for (const origin of this.customerConfig.origins) {
69
- const localSpeedKit = await speedKitConfigFile.evaluate(app, origin);
70
- const remoteSpeedKit = await remoteConfigFile.evaluate(app, origin);
68
+ const localSpeedKit = await speedKitConfigFile.evaluate(this.customerConfig, origin);
69
+ const remoteSpeedKit = await remoteConfigFile.evaluate(this.customerConfig, origin);
71
70
  // check for split change
72
71
  if (localSpeedKit.split !== remoteSpeedKit.split) {
73
72
  changes.push({