@webiny/cli 5.43.0-beta.1 → 5.43.0-beta.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/cli",
3
- "version": "5.43.0-beta.1",
3
+ "version": "5.43.0-beta.3",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "webiny": "./bin.js"
@@ -13,9 +13,9 @@
13
13
  "author": "Pavel Denisjuk <pavel@webiny.com>",
14
14
  "description": "A tool to bootstrap a Webiny project.",
15
15
  "dependencies": {
16
- "@webiny/system-requirements": "5.43.0-beta.1",
17
- "@webiny/telemetry": "5.43.0-beta.1",
18
- "@webiny/wcp": "5.43.0-beta.1",
16
+ "@webiny/system-requirements": "5.43.0-beta.3",
17
+ "@webiny/telemetry": "5.43.0-beta.3",
18
+ "@webiny/wcp": "5.43.0-beta.3",
19
19
  "boolean": "3.2.0",
20
20
  "camelcase": "6.3.0",
21
21
  "chalk": "4.1.2",
@@ -66,5 +66,5 @@
66
66
  ]
67
67
  }
68
68
  },
69
- "gitHead": "d47a234b09383cb7ab2d9907300b8eaa89aa64d6"
69
+ "gitHead": "bb3de95f65a48bc7264719fcd2d78bf78749fc69"
70
70
  }
@@ -0,0 +1,99 @@
1
+ const execa = require("execa");
2
+ const logger = require("./log");
3
+
4
+ const DEBUG_FLAG = "--debug";
5
+ const usingDebugFlag = process.argv.includes(DEBUG_FLAG);
6
+
7
+ const SKIP_WEBINY_VERSIONS_CHECK_FLAG = "--no-package-versions-check";
8
+ const skippingWebinyVersionsCheck = process.argv.includes(SKIP_WEBINY_VERSIONS_CHECK_FLAG);
9
+
10
+ function listWebinyPackageVersions() {
11
+ const { stdout } = execa.sync("yarn", ["info", "@webiny/*", "--name-only", "--all", "--json"], {
12
+ encoding: "utf-8"
13
+ });
14
+
15
+ // Each line is a JSON string, so parse them individually
16
+ const lines = stdout
17
+ .trim()
18
+ .split("\n")
19
+ .map(line => JSON.parse(line));
20
+
21
+ const versionMap = new Map();
22
+
23
+ for (const entry of lines) {
24
+ // An example entry: "@webiny/cli@npm:5.42.3"
25
+ const match = entry.match(/^(@webiny\/[^@]+)@npm:(.+)$/);
26
+ if (!match) {
27
+ continue;
28
+ }
29
+
30
+ const [, pkg, version] = match;
31
+ if (!versionMap.has(pkg)) {
32
+ versionMap.set(pkg, new Set());
33
+ }
34
+
35
+ versionMap.get(pkg).add(version);
36
+ }
37
+
38
+ return versionMap;
39
+ }
40
+
41
+ function ensureSameWebinyPackageVersions() {
42
+ // Just in case, we want to allow users to skip the check.
43
+ if (skippingWebinyVersionsCheck) {
44
+ return;
45
+ }
46
+
47
+ let webinyVersions;
48
+ try {
49
+ webinyVersions = listWebinyPackageVersions();
50
+ } catch (e) {
51
+ const message = ["Failed to inspect Webiny package versions."];
52
+
53
+ if (!usingDebugFlag) {
54
+ message.push(
55
+ `For more information, try running with ${logger.warning.hl(DEBUG_FLAG)}.`
56
+ );
57
+ }
58
+
59
+ message.push("Learn more: https://webiny.link/webiny-package-versions-check");
60
+
61
+ logger.warning(message.join(" "));
62
+ if (usingDebugFlag) {
63
+ logger.debug(e);
64
+ }
65
+
66
+ console.log();
67
+ return;
68
+ }
69
+
70
+ let hasMismatch = false;
71
+ const mismatchedPackages = [];
72
+ for (const [pkg, versions] of webinyVersions.entries()) {
73
+ if (versions.size > 1) {
74
+ hasMismatch = true;
75
+ mismatchedPackages.push([pkg, versions]);
76
+ }
77
+ }
78
+
79
+ if (hasMismatch) {
80
+ const message = [
81
+ "The following Webiny packages have mismatched versions:",
82
+ "",
83
+ ...mismatchedPackages.map(([pkg, versions]) => {
84
+ return `‣ ${pkg}: ${Array.from(versions).join(", ")}`;
85
+ }),
86
+ "",
87
+ `Please ensure all Webiny packages are using the same version. If you think this is a mistake, you can also skip this check by appending the ${logger.error.hl(
88
+ SKIP_WEBINY_VERSIONS_CHECK_FLAG
89
+ )} flag. Learn more: https://webiny.link/webiny-package-versions-check`
90
+ ];
91
+
92
+ logger.error(message.join("\n"));
93
+ process.exit(1);
94
+ }
95
+ }
96
+
97
+ module.exports = {
98
+ ensureSameWebinyPackageVersions
99
+ };