@speedkit/cli 4.30.0 → 4.32.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 (52) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -1
  3. package/dist/services/deploy/checks/activation/customer-approval-check.js +5 -2
  4. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +9 -7
  5. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +7 -6
  6. package/dist/services/integration-api/file-list.d.ts +2 -1
  7. package/dist/services/integration-api/file-list.js +7 -1
  8. package/dist/services/integration-api/handler/install-resource-handler.js +10 -2
  9. package/dist/services/integration-api/integration-api-model.d.ts +8 -0
  10. package/dist/services/integration-api/integration-api-model.js +3 -0
  11. package/dist/services/integration-api/spec/config-plugin.spec.js +188 -0
  12. package/dist/services/integration-api/spec/speed-kit-config-file.spec.d.ts +1 -0
  13. package/dist/{helpers/evaluate-speed-kit-config.spec.js → services/integration-api/spec/speed-kit-config-file.spec.js} +43 -12
  14. package/dist/services/integration-api/spec/speed-kit-config.spec.d.ts +1 -0
  15. package/dist/services/integration-api/spec/speed-kit-config.spec.js +108 -0
  16. package/dist/services/integration-api/struct/config-plugin.d.ts +41 -0
  17. package/dist/services/integration-api/struct/config-plugin.js +241 -0
  18. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +46 -0
  19. package/dist/services/integration-api/struct/speed-kit-config-file.js +223 -0
  20. package/dist/services/integration-api/struct/speed-kit-config.d.ts +84 -0
  21. package/dist/services/integration-api/struct/speed-kit-config.js +114 -0
  22. package/dist/services/integration-api/virtual/static-recipe.d.ts +1 -1
  23. package/dist/services/onboarding/empty-service-worker.d.ts +8 -0
  24. package/dist/services/onboarding/empty-service-worker.js +17 -0
  25. package/dist/services/onboarding/empty-service-worker.spec.d.ts +1 -0
  26. package/dist/services/onboarding/empty-service-worker.spec.js +22 -0
  27. package/dist/services/onboarding/fetch-events/customer-service-worker-js.js +3 -2
  28. package/dist/services/onboarding/onboarding-service.js +2 -1
  29. package/dist/services/query-builder/queries/spec/golden-configs.d.ts +2 -0
  30. package/dist/services/query-builder/queries/spec/golden-configs.js +37 -0
  31. package/dist/services/query-builder/queries/spec/golden.spec.js +5 -4
  32. package/dist/services/query-builder/queries/spec/queries.spec.js +2 -1
  33. package/dist/services/query-builder/queries/spec/reported-bugs.spec.js +2 -1
  34. package/dist/services/query-builder/query-builder-factory.js +4 -8
  35. package/dist/services/query-builder/query-builder-service.js +4 -0
  36. package/dist/services/query-builder/query-builder-service.spec.js +2 -1
  37. package/dist/services/query-builder/rules/rule-model.d.ts +6 -2
  38. package/dist/services/query-builder/rules/rule-model.js +0 -2
  39. package/dist/services/query-builder/rules/rule-parser.d.ts +7 -8
  40. package/dist/services/query-builder/rules/rule-parser.js +41 -47
  41. package/dist/services/query-builder/rules/spec/rule-parser.spec.js +30 -32
  42. package/dist/services/query-builder/rules/spec/rule-reducer.spec.js +2 -1
  43. package/dist/services/query-builder/rules/spec/rule-relevance.spec.js +7 -3
  44. package/dist/services/query-builder/rules/spec/rule-to-sql.spec.js +3 -2
  45. package/dist/services/query-builder/rules/spec/strip-parameters.spec.js +5 -2
  46. package/oclif.manifest.json +112 -112
  47. package/package.json +1 -1
  48. package/dist/helpers/evaluate-speed-kit-config.d.ts +0 -16
  49. package/dist/helpers/evaluate-speed-kit-config.js +0 -157
  50. /package/dist/services/{deploy → integration-api}/error/evaluate-sk-config-error.d.ts +0 -0
  51. /package/dist/services/{deploy → integration-api}/error/evaluate-sk-config-error.js +0 -0
  52. /package/dist/{helpers/evaluate-speed-kit-config.spec.d.ts → services/integration-api/spec/config-plugin.spec.d.ts} +0 -0
@@ -1,21 +1,12 @@
1
1
  import * as vm from "node:vm";
2
2
  import { expect } from "chai";
3
3
  import { describe, it } from "mocha";
4
- import { parseCondition, parseRuleSets, parseRuleSetVersion, parseStripQueryParams, } from "../rule-parser.js";
5
- describe("parseRuleSetVersion", () => {
6
- it("should default to version 1", () => {
7
- expect(parseRuleSetVersion({})).to.equal(1);
8
- });
9
- it("should read the declared version", () => {
10
- expect(parseRuleSetVersion({ ruleSetConfig: { version: 2 } })).to.equal(2);
11
- });
12
- it("should read a version given as a string", () => {
13
- expect(parseRuleSetVersion({ ruleSetConfig: { version: "2" } })).to.equal(2);
14
- });
15
- it("should fall back for an unusable version", () => {
16
- expect(parseRuleSetVersion({ ruleSetConfig: { version: "x" } })).to.equal(1);
17
- });
18
- });
4
+ import { parseCondition, parseRuleSets, parseStripQueryParams, } from "../rule-parser.js";
5
+ import { SpeedKitConfig, } from "../../../integration-api/struct/speed-kit-config.js";
6
+ /** The rule sets of a config, the way the query builder reads one. */
7
+ function ruleSetsOf(config) {
8
+ return parseRuleSets(SpeedKitConfig.createFrom(config));
9
+ }
19
10
  describe("parseCondition", () => {
20
11
  it("should wrap a single string", () => {
21
12
  expect(parseCondition("/shop")).to.deep.equal([
@@ -51,30 +42,30 @@ describe("parseCondition", () => {
51
42
  });
52
43
  describe("parseRuleSets", () => {
53
44
  it("should read every whitelist rule, not just the first", () => {
54
- const { whitelist } = parseRuleSets({
45
+ const { whitelist } = ruleSetsOf({
55
46
  whitelist: [{ host: ["www.shop.de"] }, { host: ["m.shop.de"] }],
56
47
  });
57
48
  expect(whitelist).to.have.lengthOf(2);
58
49
  expect(whitelist[1].source).to.equal("whitelist[1]");
59
50
  });
60
51
  it("should keep the conditions of a rule together", () => {
61
- const { enabledSites } = parseRuleSets({
52
+ const { enabledSites } = ruleSetsOf({
62
53
  enabledSites: [{ host: ["www.shop.de"], pathname: [/^\/p\//i] }],
63
54
  });
64
55
  expect(enabledSites[0].conditions.map(({ subject }) => subject)).to.deep.eq(["host", "pathname"]);
65
56
  });
66
57
  it("should normalize the content types", () => {
67
- const { blacklist } = parseRuleSets({
58
+ const { blacklist } = ruleSetsOf({
68
59
  blacklist: [{ contentType: "Image" }],
69
60
  });
70
61
  expect(blacklist[0].contentTypes).to.deep.equal(["image"]);
71
62
  });
72
63
  it("should leave the content types undefined when there are none", () => {
73
- const { blacklist } = parseRuleSets({ blacklist: [{ pathname: "/a" }] });
64
+ const { blacklist } = ruleSetsOf({ blacklist: [{ pathname: "/a" }] });
74
65
  expect(blacklist[0].contentTypes).to.equal(undefined);
75
66
  });
76
67
  it("should record criteria that are not part of the url", () => {
77
- const { disabledSites } = parseRuleSets({
68
+ const { disabledSites } = ruleSetsOf({
78
69
  disabledSites: [{ cookie: /loggedIn/, mobile: true, pathname: "/a" }],
79
70
  });
80
71
  expect(disabledSites[0].criteriaOutsideTheUrl).to.deep.equal([
@@ -83,44 +74,41 @@ describe("parseRuleSets", () => {
83
74
  ]);
84
75
  });
85
76
  it("should apply the config version to every rule", () => {
86
- const { enabledSites } = parseRuleSets({
77
+ const { enabledSites } = ruleSetsOf({
87
78
  enabledSites: [{ pathname: "/a" }],
88
79
  ruleSetConfig: { version: 2 },
89
80
  });
90
81
  expect(enabledSites[0].ruleSetVersion).to.equal(2);
91
82
  });
92
83
  it("should let a rule override the version", () => {
93
- const { enabledSites } = parseRuleSets({
84
+ const { enabledSites } = ruleSetsOf({
94
85
  enabledSites: [{ pathname: "/a", ruleSetVersion: 1 }],
95
86
  ruleSetConfig: { version: 2 },
96
87
  });
97
88
  expect(enabledSites[0].ruleSetVersion).to.equal(1);
98
89
  });
99
90
  it("should survive a config without any rule set", () => {
100
- const parsed = parseRuleSets({});
91
+ const parsed = ruleSetsOf({});
101
92
  expect(parsed.whitelist).to.deep.equal([]);
102
93
  expect(parsed.enabledSites).to.deep.equal([]);
103
94
  expect(parsed.stripQueryParams).to.deep.equal([]);
104
95
  });
105
- it("should ignore a rule set that is not an array", () => {
106
- expect(parseRuleSets({ blacklist: "everything" }).blacklist).to.deep.equal([]);
107
- });
108
96
  it("should keep a rule without conditions", () => {
109
- const { whitelist } = parseRuleSets({ whitelist: [{}] });
97
+ const { whitelist } = ruleSetsOf({ whitelist: [{}] });
110
98
  expect(whitelist).to.have.lengthOf(1);
111
99
  expect(whitelist[0].conditions).to.deep.equal([]);
112
100
  expect(whitelist[0].matchesNothing).to.equal(true);
113
101
  });
114
102
  it("should mark a rule with an empty condition as matching nothing", () => {
115
- const { blacklist } = parseRuleSets({ blacklist: [{ host: [] }] });
103
+ const { blacklist } = ruleSetsOf({ blacklist: [{ host: [] }] });
116
104
  expect(blacklist[0].matchesNothing).to.equal(true);
117
105
  });
118
106
  it("should mark an empty content type as matching nothing", () => {
119
- const { blacklist } = parseRuleSets({ blacklist: [{ contentType: [] }] });
107
+ const { blacklist } = ruleSetsOf({ blacklist: [{ contentType: [] }] });
120
108
  expect(blacklist[0].matchesNothing).to.equal(true);
121
109
  });
122
110
  it("should not mark a rule with a usable condition", () => {
123
- const { blacklist } = parseRuleSets({ blacklist: [{ host: ["a.de"] }] });
111
+ const { blacklist } = ruleSetsOf({ blacklist: [{ host: ["a.de"] }] });
124
112
  expect(blacklist[0].matchesNothing).to.equal(false);
125
113
  });
126
114
  });
@@ -132,10 +120,20 @@ describe("parseStripQueryParams", () => {
132
120
  expect(rules[0].enabledSites).to.equal(undefined);
133
121
  });
134
122
  it("should read a single parameter", () => {
135
- expect(parseStripQueryParams("gclid", 2)[0].params).to.deep.equal([
123
+ expect(parseStripQueryParams(["gclid"], 2)[0].params).to.deep.equal([
136
124
  { kind: "string", value: "gclid" },
137
125
  ]);
138
126
  });
127
+ it("should read a bare pattern from another realm", () => {
128
+ // A bare list is told apart from a list of rules by what is in it, and a
129
+ // config's own regular expressions are not `instanceof RegExp` here. Read
130
+ // as a rule, such an entry carries no `params` and is dropped — the whole
131
+ // list with it, so nothing would ever be stripped.
132
+ const foreign = vm.runInNewContext("/^utm[_-]/");
133
+ const rules = parseStripQueryParams(["gclid", foreign], 2);
134
+ expect(rules).to.have.lengthOf(1);
135
+ expect(rules[0].params).to.have.lengthOf(2);
136
+ });
139
137
  it("should keep the pages a rule is scoped to", () => {
140
138
  const rules = parseStripQueryParams([{ enabledSites: [{ pathname: [/^\/p\//i] }], params: ["size"] }], 2);
141
139
  expect(rules[0].enabledSites).to.have.lengthOf(1);
@@ -145,6 +143,6 @@ describe("parseStripQueryParams", () => {
145
143
  expect(parseStripQueryParams([{ enabledSites: [] }], 2)).to.deep.equal([]);
146
144
  });
147
145
  it("should return nothing when the property is missing", () => {
148
- expect(parseStripQueryParams(undefined, 2)).to.deep.equal([]);
146
+ expect(parseStripQueryParams([], 2)).to.deep.equal([]);
149
147
  });
150
148
  });
@@ -1,9 +1,10 @@
1
1
  import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
3
  import { parseRuleSets } from "../rule-parser.js";
4
+ import { SpeedKitConfig } from "../../../integration-api/struct/speed-kit-config.js";
4
5
  import { absorbRules, dropUnreachableRules, findShadowedRules, reductionBudget, } from "../rule-reducer.js";
5
6
  function rulesOf(config, version = 2) {
6
- return parseRuleSets({ ruleSetConfig: { version }, ...config });
7
+ return parseRuleSets(SpeedKitConfig.createFrom({ ruleSetConfig: { version }, ...config }));
7
8
  }
8
9
  function blacklist(rules, version = 2) {
9
10
  return rulesOf({ blacklist: rules }, version).blacklist;
@@ -1,13 +1,17 @@
1
1
  import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
3
  import { parseRuleSets } from "../rule-parser.js";
4
+ import { SpeedKitConfig } from "../../../integration-api/struct/speed-kit-config.js";
4
5
  import { keepRelevantRules } from "../rule-relevance.js";
5
6
  function blacklist(...rules) {
6
- return parseRuleSets({ blacklist: rules }).blacklist;
7
+ return parseRuleSets(SpeedKitConfig.createFrom({ blacklist: rules }))
8
+ .blacklist;
7
9
  }
8
10
  function blacklistV2(...rules) {
9
- return parseRuleSets({ blacklist: rules, ruleSetConfig: { version: 2 } })
10
- .blacklist;
11
+ return parseRuleSets(SpeedKitConfig.createFrom({
12
+ blacklist: rules,
13
+ ruleSetConfig: { version: 2 },
14
+ })).blacklist;
11
15
  }
12
16
  describe("keepRelevantRules content types", () => {
13
17
  it("should drop a rule that only applies to other content types", () => {
@@ -2,13 +2,14 @@ import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
3
  import { column, formatPredicate, isFalse, isTrue, leaf, } from "../../sql/index.js";
4
4
  import { parseRuleSets } from "../rule-parser.js";
5
+ import { SpeedKitConfig } from "../../../integration-api/struct/speed-kit-config.js";
5
6
  import { translateRules, urlSubjects } from "../rule-to-sql.js";
6
7
  const subjects = urlSubjects(column("url"));
7
8
  function enabledSites(rules, version) {
8
- return parseRuleSets({
9
+ return parseRuleSets(SpeedKitConfig.createFrom({
9
10
  enabledSites: rules,
10
11
  ...(version ? { ruleSetConfig: { version } } : {}),
11
- }).enabledSites;
12
+ })).enabledSites;
12
13
  }
13
14
  function sql(rules, version) {
14
15
  return formatPredicate(translateRules(enabledSites(rules, version), subjects).predicate);
@@ -2,12 +2,15 @@ import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
3
  import { column, formatPredicate } from "../../sql/index.js";
4
4
  import { parseRuleSets } from "../rule-parser.js";
5
+ import { SpeedKitConfig } from "../../../integration-api/struct/speed-kit-config.js";
5
6
  import { urlSubjects } from "../rule-to-sql.js";
6
7
  import { notStrippedParameter, prepareStripParameters, strippedUrlExpression, } from "../strip-parameters.js";
7
8
  const subjects = urlSubjects(column("url"));
8
9
  function prepare(stripQueryParams, version = 2) {
9
- return prepareStripParameters(parseRuleSets({ ruleSetConfig: { version }, stripQueryParams })
10
- .stripQueryParams, subjects);
10
+ return prepareStripParameters(parseRuleSets(SpeedKitConfig.createFrom({
11
+ ruleSetConfig: { version },
12
+ stripQueryParams,
13
+ })).stripQueryParams, subjects);
11
14
  }
12
15
  function strippedUrl(stripQueryParams, version = 2) {
13
16
  return strippedUrlExpression(prepare(stripQueryParams, version), "url");
@@ -1228,6 +1228,117 @@
1228
1228
  "setup.js"
1229
1229
  ]
1230
1230
  },
1231
+ "extension:add": {
1232
+ "aliases": [],
1233
+ "args": {
1234
+ "ref": {
1235
+ "description": "Chrome Web Store link or extension id",
1236
+ "name": "ref",
1237
+ "required": false
1238
+ }
1239
+ },
1240
+ "description": "Install a Chrome extension into the onboarding browser by Web Store link or id",
1241
+ "examples": [
1242
+ "$ sk extension add fmkadmapgofadopljbjfkapdkoienihi",
1243
+ "$ sk extension add https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi",
1244
+ "$ sk extension add"
1245
+ ],
1246
+ "flags": {},
1247
+ "hasDynamicHelp": false,
1248
+ "hiddenAliases": [],
1249
+ "id": "extension:add",
1250
+ "pluginAlias": "@speedkit/cli",
1251
+ "pluginName": "@speedkit/cli",
1252
+ "pluginType": "core",
1253
+ "strict": true,
1254
+ "enableJsonFlag": false,
1255
+ "isESM": true,
1256
+ "relativePath": [
1257
+ "dist",
1258
+ "commands",
1259
+ "extension",
1260
+ "add.js"
1261
+ ]
1262
+ },
1263
+ "extension:list": {
1264
+ "aliases": [],
1265
+ "args": {},
1266
+ "description": "List Chrome extensions managed by the setup wizard",
1267
+ "examples": [
1268
+ "$ sk extension list"
1269
+ ],
1270
+ "flags": {},
1271
+ "hasDynamicHelp": false,
1272
+ "hiddenAliases": [],
1273
+ "id": "extension:list",
1274
+ "pluginAlias": "@speedkit/cli",
1275
+ "pluginName": "@speedkit/cli",
1276
+ "pluginType": "core",
1277
+ "strict": true,
1278
+ "enableJsonFlag": false,
1279
+ "isESM": true,
1280
+ "relativePath": [
1281
+ "dist",
1282
+ "commands",
1283
+ "extension",
1284
+ "list.js"
1285
+ ]
1286
+ },
1287
+ "extension:remove": {
1288
+ "aliases": [],
1289
+ "args": {
1290
+ "ref": {
1291
+ "description": "Chrome Web Store link or extension id",
1292
+ "name": "ref",
1293
+ "required": false
1294
+ }
1295
+ },
1296
+ "description": "Remove a managed Chrome extension",
1297
+ "examples": [
1298
+ "$ sk extension remove",
1299
+ "$ sk extension remove <id>"
1300
+ ],
1301
+ "flags": {},
1302
+ "hasDynamicHelp": false,
1303
+ "hiddenAliases": [],
1304
+ "id": "extension:remove",
1305
+ "pluginAlias": "@speedkit/cli",
1306
+ "pluginName": "@speedkit/cli",
1307
+ "pluginType": "core",
1308
+ "strict": true,
1309
+ "enableJsonFlag": false,
1310
+ "isESM": true,
1311
+ "relativePath": [
1312
+ "dist",
1313
+ "commands",
1314
+ "extension",
1315
+ "remove.js"
1316
+ ]
1317
+ },
1318
+ "extension:update": {
1319
+ "aliases": [],
1320
+ "args": {},
1321
+ "description": "Check managed Chrome extensions for updates and install them",
1322
+ "examples": [
1323
+ "$ sk extension update"
1324
+ ],
1325
+ "flags": {},
1326
+ "hasDynamicHelp": false,
1327
+ "hiddenAliases": [],
1328
+ "id": "extension:update",
1329
+ "pluginAlias": "@speedkit/cli",
1330
+ "pluginName": "@speedkit/cli",
1331
+ "pluginType": "core",
1332
+ "strict": true,
1333
+ "enableJsonFlag": false,
1334
+ "isESM": true,
1335
+ "relativePath": [
1336
+ "dist",
1337
+ "commands",
1338
+ "extension",
1339
+ "update.js"
1340
+ ]
1341
+ },
1231
1342
  "query:parameter": {
1232
1343
  "aliases": [
1233
1344
  "build-parameter-query"
@@ -1538,118 +1649,7 @@
1538
1649
  "query",
1539
1650
  "prewarm.js"
1540
1651
  ]
1541
- },
1542
- "extension:add": {
1543
- "aliases": [],
1544
- "args": {
1545
- "ref": {
1546
- "description": "Chrome Web Store link or extension id",
1547
- "name": "ref",
1548
- "required": false
1549
- }
1550
- },
1551
- "description": "Install a Chrome extension into the onboarding browser by Web Store link or id",
1552
- "examples": [
1553
- "$ sk extension add fmkadmapgofadopljbjfkapdkoienihi",
1554
- "$ sk extension add https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi",
1555
- "$ sk extension add"
1556
- ],
1557
- "flags": {},
1558
- "hasDynamicHelp": false,
1559
- "hiddenAliases": [],
1560
- "id": "extension:add",
1561
- "pluginAlias": "@speedkit/cli",
1562
- "pluginName": "@speedkit/cli",
1563
- "pluginType": "core",
1564
- "strict": true,
1565
- "enableJsonFlag": false,
1566
- "isESM": true,
1567
- "relativePath": [
1568
- "dist",
1569
- "commands",
1570
- "extension",
1571
- "add.js"
1572
- ]
1573
- },
1574
- "extension:list": {
1575
- "aliases": [],
1576
- "args": {},
1577
- "description": "List Chrome extensions managed by the setup wizard",
1578
- "examples": [
1579
- "$ sk extension list"
1580
- ],
1581
- "flags": {},
1582
- "hasDynamicHelp": false,
1583
- "hiddenAliases": [],
1584
- "id": "extension:list",
1585
- "pluginAlias": "@speedkit/cli",
1586
- "pluginName": "@speedkit/cli",
1587
- "pluginType": "core",
1588
- "strict": true,
1589
- "enableJsonFlag": false,
1590
- "isESM": true,
1591
- "relativePath": [
1592
- "dist",
1593
- "commands",
1594
- "extension",
1595
- "list.js"
1596
- ]
1597
- },
1598
- "extension:remove": {
1599
- "aliases": [],
1600
- "args": {
1601
- "ref": {
1602
- "description": "Chrome Web Store link or extension id",
1603
- "name": "ref",
1604
- "required": false
1605
- }
1606
- },
1607
- "description": "Remove a managed Chrome extension",
1608
- "examples": [
1609
- "$ sk extension remove",
1610
- "$ sk extension remove <id>"
1611
- ],
1612
- "flags": {},
1613
- "hasDynamicHelp": false,
1614
- "hiddenAliases": [],
1615
- "id": "extension:remove",
1616
- "pluginAlias": "@speedkit/cli",
1617
- "pluginName": "@speedkit/cli",
1618
- "pluginType": "core",
1619
- "strict": true,
1620
- "enableJsonFlag": false,
1621
- "isESM": true,
1622
- "relativePath": [
1623
- "dist",
1624
- "commands",
1625
- "extension",
1626
- "remove.js"
1627
- ]
1628
- },
1629
- "extension:update": {
1630
- "aliases": [],
1631
- "args": {},
1632
- "description": "Check managed Chrome extensions for updates and install them",
1633
- "examples": [
1634
- "$ sk extension update"
1635
- ],
1636
- "flags": {},
1637
- "hasDynamicHelp": false,
1638
- "hiddenAliases": [],
1639
- "id": "extension:update",
1640
- "pluginAlias": "@speedkit/cli",
1641
- "pluginName": "@speedkit/cli",
1642
- "pluginType": "core",
1643
- "strict": true,
1644
- "enableJsonFlag": false,
1645
- "isESM": true,
1646
- "relativePath": [
1647
- "dist",
1648
- "commands",
1649
- "extension",
1650
- "update.js"
1651
- ]
1652
1652
  }
1653
1653
  },
1654
- "version": "4.30.0"
1654
+ "version": "4.32.0"
1655
1655
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.30.0",
4
+ "version": "4.32.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"
@@ -1,16 +0,0 @@
1
- import { InstallResourceFile } from "../services/integration-api/index.js";
2
- /**
3
- * The `window.speedKit` a config assigned — whatever shape the config wrote,
4
- * not the seed object the browser mock starts from.
5
- */
6
- export type EvaluatedSpeedKitConfig = Record<string, any>;
7
- export declare function evaluateLocalSpeedKitConfig(app: string, origin: string, speedKitConfigFile: InstallResourceFile): Promise<EvaluatedSpeedKitConfig>;
8
- /**
9
- * The same evaluation for a config that is not on disk — the one an install
10
- * resource carries, for instance.
11
- */
12
- export declare function evaluateSpeedKitConfig(app: string, origin: string, content: string, filename?: string): Promise<EvaluatedSpeedKitConfig>;
13
- export declare function evaluateLocalAndRemoteSpeedKit(app: string, origin: string, speedKitConfigFile: InstallResourceFile, activeSpeedKitConfig: string): Promise<{
14
- localSpeedKit: EvaluatedSpeedKitConfig;
15
- remoteSpeedKit: EvaluatedSpeedKitConfig;
16
- }>;
@@ -1,157 +0,0 @@
1
- import { EvaluateSkConfigError } from "../services/deploy/error/evaluate-sk-config-error.js";
2
- import * as vm from "node:vm";
3
- import { BundleServiceFactory } from "../services/bundler/index.js";
4
- import ApplicationError from "../services/error-handling/error/application-error.js";
5
- export async function evaluateLocalSpeedKitConfig(app, origin, speedKitConfigFile) {
6
- return evaluateSpeedKitConfig(app, origin, speedKitConfigFile.getContent(), speedKitConfigFile.path);
7
- }
8
- /**
9
- * The same evaluation for a config that is not on disk — the one an install
10
- * resource carries, for instance.
11
- */
12
- export async function evaluateSpeedKitConfig(app, origin, content, filename) {
13
- const browserContext = buildBrowserMock(origin, app);
14
- const fileContent = safeFileContentWrapper(await bundle(content, app));
15
- vm.runInNewContext(fileContent, browserContext, {
16
- filename,
17
- displayErrors: false,
18
- breakOnSigint: true,
19
- });
20
- if (browserContext.vmError !== null) {
21
- throw new EvaluateSkConfigError(`[config_Speedkit.js] ${browserContext.vmError?.message}`);
22
- }
23
- return browserContext.window.speedKit;
24
- }
25
- export async function evaluateLocalAndRemoteSpeedKit(app, origin, speedKitConfigFile, activeSpeedKitConfig) {
26
- const localBrowserContext = buildBrowserMock(origin, app);
27
- const localFileContent = safeFileContentWrapper(await bundle(speedKitConfigFile.getContent(), app));
28
- vm.runInNewContext(localFileContent, localBrowserContext, {
29
- filename: speedKitConfigFile.path,
30
- displayErrors: false,
31
- breakOnSigint: true,
32
- });
33
- const remoteBrowserContext = buildBrowserMock(origin, app);
34
- const remoteFileContent = safeFileContentWrapper(await bundle(activeSpeedKitConfig, app));
35
- vm.runInNewContext(remoteFileContent, remoteBrowserContext, {
36
- displayErrors: false,
37
- breakOnSigint: true,
38
- });
39
- if (localBrowserContext.vmError !== null) {
40
- throw new EvaluateSkConfigError(`[config_Speedkit.js] ${localBrowserContext.vmError?.message}`);
41
- }
42
- if (remoteBrowserContext.vmError !== null) {
43
- throw new EvaluateSkConfigError(`[remote_config] ${JSON.stringify(remoteBrowserContext.vmError?.message)}`);
44
- }
45
- const localSpeedKit = localBrowserContext.window.speedKit;
46
- const remoteSpeedKit = remoteBrowserContext.window.speedKit;
47
- return { localSpeedKit, remoteSpeedKit };
48
- }
49
- function buildBrowserMock(origin, app) {
50
- const originUrl = new URL(origin);
51
- const window = {
52
- location: originUrl,
53
- APP: app,
54
- speedKit: {
55
- split: undefined,
56
- splitTestId: undefined,
57
- detectDevice: () => {
58
- /* empty */
59
- },
60
- customVariation: [],
61
- },
62
- SpeedKit: {},
63
- serviceWorkerUrl: "",
64
- screen: { width: 0, height: 0 },
65
- devicePixelRatio: 1,
66
- setTimeout: () => {
67
- /* empty */
68
- },
69
- clearTimeout: () => {
70
- /* empty */
71
- },
72
- addEventListener: () => {
73
- /* empty */
74
- },
75
- removeEventListener: () => {
76
- /* empty */
77
- },
78
- navigator: {
79
- userAgent: "",
80
- connection: {},
81
- cookieEnabled: false,
82
- languages: [],
83
- online: true,
84
- },
85
- top: {},
86
- };
87
- window.top = window;
88
- // A config may read the DOM while it builds itself — `precache` is
89
- // frequently a list of script and link hrefs. There is no document here, so
90
- // these answer the way the DOM answers for a page without matches: an empty
91
- // list, not `undefined`, which `Array.from` and `forEach` would choke on.
92
- const document = {
93
- cookie: "",
94
- referrer: "",
95
- getElementById: () => null,
96
- querySelector: () => null,
97
- querySelectorAll: () => [],
98
- createElement: () => {
99
- /* empty */
100
- },
101
- addEventListener: () => {
102
- /* empty */
103
- },
104
- removeEventListener: () => {
105
- /* empty */
106
- },
107
- head: {},
108
- body: {},
109
- };
110
- document.head = document;
111
- document.body = document;
112
- return {
113
- vmError: null,
114
- ...window,
115
- window,
116
- document,
117
- navigator: { userAgent: "" },
118
- localStorage: {
119
- getItem: () => {
120
- /* empty */
121
- },
122
- setItem: () => {
123
- /* empty */
124
- },
125
- },
126
- JSON: JSON,
127
- decodeURIComponent: decodeURIComponent,
128
- URL: URL,
129
- };
130
- }
131
- function safeFileContentWrapper(fileContent) {
132
- return `
133
- try{
134
- ${fileContent}
135
- } catch (error){
136
- vmError = error
137
- }
138
- `;
139
- }
140
- async function bundle(content, app) {
141
- if (!content) {
142
- throw new ApplicationError("Content is empty");
143
- }
144
- const bundler = new BundleServiceFactory("./").buildService();
145
- return bundler.bundle({
146
- basePaths: {
147
- "speed-kit-config": "https://www.baqend.com/speed-kit-config/latest/",
148
- },
149
- entryPoints: { "config.js": content },
150
- logLevel: "error",
151
- minify: false,
152
- define: {
153
- APP: JSON.stringify(app),
154
- },
155
- platform: "browser",
156
- });
157
- }