@adecore/shell 0.49.0 → 0.49.2

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.
@@ -2,10 +2,30 @@
2
2
  * The order the shell sorts the release list in has to be the order the page reads it in, or the
3
3
  * notes of a version land under the wrong heading. One comparison, so the two cannot disagree.
4
4
  */
5
- const SEMVER = /^(\d+)\.(\d+)\.(\d+)$/;
6
- /* A plain `1.2.3`. A git tag carries a `v` in front of it, which is the tag's and not the version's. */
5
+ const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
6
+ const NUMERIC = /^\d+$/;
7
+ /* A `1.2.3` or `1.2.3-beta.1`. A git tag carries a `v` in front of it, which is the tag's and not the version's. */
7
8
  export const isVersion = (version) => SEMVER.test(version);
8
- /* Negative when `a` is older than `b`. A version that is not semver sorts below every one that is. */
9
+ /* Semver's order: part by part, numbers by value and below words, and a shorter list below a longer one it starts. */
10
+ const comparePrereleases = (a, b) => {
11
+ const left = a.split('.');
12
+ const right = b.split('.');
13
+ for (let i = 0; i < Math.min(left.length, right.length); i++) {
14
+ const leftPart = left[i];
15
+ const rightPart = right[i];
16
+ const leftNumeric = NUMERIC.test(leftPart);
17
+ const rightNumeric = NUMERIC.test(rightPart);
18
+ if (leftNumeric !== rightNumeric) {
19
+ return leftNumeric ? -1 : 1;
20
+ }
21
+ const difference = leftNumeric ? Number(leftPart) - Number(rightPart) : leftPart < rightPart ? -1 : leftPart > rightPart ? 1 : 0;
22
+ if (difference !== 0) {
23
+ return difference;
24
+ }
25
+ }
26
+ return left.length - right.length;
27
+ };
28
+ /* Negative when `a` is older than `b`, a prerelease coming before its own release. A version that is not semver sorts below every one that is. */
9
29
  export const compareVersions = (a, b) => {
10
30
  const left = SEMVER.exec(a);
11
31
  const right = SEMVER.exec(b);
@@ -18,5 +38,10 @@ export const compareVersions = (a, b) => {
18
38
  return difference;
19
39
  }
20
40
  }
21
- return 0;
41
+ const leftPrerelease = left[4];
42
+ const rightPrerelease = right[4];
43
+ if (leftPrerelease === undefined || rightPrerelease === undefined) {
44
+ return (leftPrerelease === undefined ? 1 : 0) - (rightPrerelease === undefined ? 1 : 0);
45
+ }
46
+ return comparePrereleases(leftPrerelease, rightPrerelease);
22
47
  };
package/dist/updater.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface UpdaterOptions {
12
12
  publish: (state: UpdateState) => void;
13
13
  beforeCheck?: () => void;
14
14
  onQuit?: (quitting: boolean) => void;
15
+ silentInstall?: boolean;
15
16
  log?: (message: string, error: unknown) => void;
16
17
  setInterval?: (run: () => void, ms: number) => unknown;
17
18
  }
package/dist/updater.js CHANGED
@@ -106,7 +106,12 @@ export const createUpdater = (options) => {
106
106
  installing = true;
107
107
  options.onQuit?.(true);
108
108
  try {
109
- updater.quitAndInstall();
109
+ if (options.silentInstall) {
110
+ updater.quitAndInstall(true, true);
111
+ }
112
+ else {
113
+ updater.quitAndInstall();
114
+ }
110
115
  return true;
111
116
  }
112
117
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/shell",
3
- "version": "0.49.0",
3
+ "version": "0.49.2",
4
4
  "description": "The main process of an Electron app: its menu, its updater and the guards around its page.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "Bas Milius",
@@ -3,12 +3,38 @@
3
3
  * notes of a version land under the wrong heading. One comparison, so the two cannot disagree.
4
4
  */
5
5
 
6
- const SEMVER = /^(\d+)\.(\d+)\.(\d+)$/;
6
+ const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
7
+ const NUMERIC = /^\d+$/;
7
8
 
8
- /* A plain `1.2.3`. A git tag carries a `v` in front of it, which is the tag's and not the version's. */
9
+ /* A `1.2.3` or `1.2.3-beta.1`. A git tag carries a `v` in front of it, which is the tag's and not the version's. */
9
10
  export const isVersion = (version: string): boolean => SEMVER.test(version);
10
11
 
11
- /* Negative when `a` is older than `b`. A version that is not semver sorts below every one that is. */
12
+ /* Semver's order: part by part, numbers by value and below words, and a shorter list below a longer one it starts. */
13
+ const comparePrereleases = (a: string, b: string): number => {
14
+ const left = a.split('.');
15
+ const right = b.split('.');
16
+
17
+ for (let i = 0; i < Math.min(left.length, right.length); i++) {
18
+ const leftPart = left[i]!;
19
+ const rightPart = right[i]!;
20
+ const leftNumeric = NUMERIC.test(leftPart);
21
+ const rightNumeric = NUMERIC.test(rightPart);
22
+
23
+ if (leftNumeric !== rightNumeric) {
24
+ return leftNumeric ? -1 : 1;
25
+ }
26
+
27
+ const difference = leftNumeric ? Number(leftPart) - Number(rightPart) : leftPart < rightPart ? -1 : leftPart > rightPart ? 1 : 0;
28
+
29
+ if (difference !== 0) {
30
+ return difference;
31
+ }
32
+ }
33
+
34
+ return left.length - right.length;
35
+ };
36
+
37
+ /* Negative when `a` is older than `b`, a prerelease coming before its own release. A version that is not semver sorts below every one that is. */
12
38
  export const compareVersions = (a: string, b: string): number => {
13
39
  const left = SEMVER.exec(a);
14
40
  const right = SEMVER.exec(b);
@@ -25,5 +51,12 @@ export const compareVersions = (a: string, b: string): number => {
25
51
  }
26
52
  }
27
53
 
28
- return 0;
54
+ const leftPrerelease = left[4];
55
+ const rightPrerelease = right[4];
56
+
57
+ if (leftPrerelease === undefined || rightPrerelease === undefined) {
58
+ return (leftPrerelease === undefined ? 1 : 0) - (rightPrerelease === undefined ? 1 : 0);
59
+ }
60
+
61
+ return comparePrereleases(leftPrerelease, rightPrerelease);
29
62
  };
package/src/updater.ts CHANGED
@@ -38,6 +38,8 @@ export interface UpdaterOptions {
38
38
  * windows learns the quit is coming: pass `windows.quitForUpdate`.
39
39
  */
40
40
  onQuit?: (quitting: boolean) => void;
41
+ /* Installs without the installer's windows and starts the app again after. Only Windows reads it. */
42
+ silentInstall?: boolean;
41
43
  log?: (message: string, error: unknown) => void;
42
44
  setInterval?: (run: () => void, ms: number) => unknown;
43
45
  }
@@ -148,7 +150,11 @@ export const createUpdater = (options: UpdaterOptions) => {
148
150
  options.onQuit?.(true);
149
151
 
150
152
  try {
151
- updater.quitAndInstall();
153
+ if (options.silentInstall) {
154
+ updater.quitAndInstall(true, true);
155
+ } else {
156
+ updater.quitAndInstall();
157
+ }
152
158
 
153
159
  return true;
154
160
  } catch (e) {