@darthcav/ts-utils 0.8.8 → 0.9.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.
- package/README.md +23 -1
- package/dist/__tests__/os-utils-nofile.test.js +3 -3
- package/dist/__tests__/os-utils-nofile.test.js.map +1 -1
- package/dist/__tests__/os-utils-windows.test.js +13 -18
- package/dist/__tests__/os-utils-windows.test.js.map +1 -1
- package/dist/__tests__/os-utils.test.js +27 -32
- package/dist/__tests__/os-utils.test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/os-utils.d.ts +20 -29
- package/dist/os-utils.d.ts.map +1 -1
- package/dist/os-utils.js +75 -74
- package/dist/os-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -10
- package/src/os-utils.ts +82 -86
package/README.md
CHANGED
|
@@ -107,6 +107,27 @@ const payload: RuntimeObject = {
|
|
|
107
107
|
}
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
### `osRelease`
|
|
111
|
+
|
|
112
|
+
Returns OS release information for the current platform as an `OsRelease` object, or `null` on
|
|
113
|
+
unsupported platforms or when `/etc/os-release` is absent on Linux.
|
|
114
|
+
|
|
115
|
+
The `OsRelease` type exposes three normalized fields — `name`, `version`, and `arch` — present on
|
|
116
|
+
all platforms. On Linux, all raw key-value pairs from `/etc/os-release` (e.g. `PRETTY_NAME`, `ID`,
|
|
117
|
+
`ID_LIKE`) are also accessible by string index.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { osRelease } from "@darthcav/ts-utils"
|
|
121
|
+
|
|
122
|
+
const info = osRelease()
|
|
123
|
+
if (info) {
|
|
124
|
+
console.log(info.name) // e.g. "Ubuntu" or "Windows 11"
|
|
125
|
+
console.log(info.version) // e.g. "24.04" or "10.0.22000"
|
|
126
|
+
console.log(info.arch) // e.g. "x64"
|
|
127
|
+
console.log(info.PRETTY_NAME) // e.g. "Ubuntu 24.04 LTS" (Linux only)
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
110
131
|
### `getDummyLogger`
|
|
111
132
|
|
|
112
133
|
Returns a no-op `Logger` useful as a placeholder in tests. All logging methods are no-ops and
|
|
@@ -179,6 +200,7 @@ src/
|
|
|
179
200
|
index.ts # Public API entry point
|
|
180
201
|
main.ts # Main module
|
|
181
202
|
noop.ts # No-op function
|
|
203
|
+
os-utils.ts # OS release utilities
|
|
182
204
|
loggers/ # Logger utilities
|
|
183
205
|
__tests__/ # Test files
|
|
184
206
|
dist/ # Compiled output (generated)
|
|
@@ -191,7 +213,7 @@ public/ # Documentation output (generated)
|
|
|
191
213
|
|
|
192
214
|
[node-version]: https://img.shields.io/badge/node-%3E%3D25-orange.svg?style=flat-square
|
|
193
215
|
[node-url]: https://nodejs.org
|
|
194
|
-
[version-image]: https://img.shields.io/badge/version-0.
|
|
216
|
+
[version-image]: https://img.shields.io/badge/version-0.9.0-blue.svg?style=flat-square
|
|
195
217
|
[ci-badge]: https://github.com/darthcav/ts-utils/actions/workflows/tests.yml/badge.svg
|
|
196
218
|
[coverage-badge]:
|
|
197
219
|
https://codecov.io/github/darthcav/ts-utils/branch/dev/graph/badge.svg?token=RNEPER4KEI
|
|
@@ -7,10 +7,10 @@ mock.module("node:fs", {
|
|
|
7
7
|
readFileSync,
|
|
8
8
|
},
|
|
9
9
|
});
|
|
10
|
-
const {
|
|
11
|
-
await suite("
|
|
10
|
+
const { osRelease } = await import("../os-utils.js");
|
|
11
|
+
await suite("osRelease (file missing)", async () => {
|
|
12
12
|
test("returns null when /etc/os-release does not exist", () => {
|
|
13
|
-
assert.equal(
|
|
13
|
+
assert.equal(osRelease(), null);
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=os-utils-nofile.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"os-utils-nofile.test.js","sourceRoot":"","sources":["../../src/__tests__/os-utils-nofile.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAE7C,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;IACnB,YAAY,EAAE;QACV,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK;QACvB,YAAY;KACf;CACJ,CAAC,CAAA;AAEF,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"os-utils-nofile.test.js","sourceRoot":"","sources":["../../src/__tests__/os-utils-nofile.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAE7C,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;IACnB,YAAY,EAAE;QACV,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK;QACvB,YAAY;KACf;CACJ,CAAC,CAAA;AAEF,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAEpD,MAAM,KAAK,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;IAC/C,IAAI,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -8,16 +8,11 @@ mock.module("node:os", {
|
|
|
8
8
|
arch: () => "x64",
|
|
9
9
|
},
|
|
10
10
|
});
|
|
11
|
-
const {
|
|
12
|
-
await suite("
|
|
13
|
-
test("returns null on non-Linux platforms", () => {
|
|
14
|
-
assert.equal(linuxRelease(), null);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
await suite("windowsRelease (win32 platform)", async () => {
|
|
11
|
+
const { osRelease } = await import("../os-utils.js");
|
|
12
|
+
await suite("osRelease (win32 platform)", async () => {
|
|
18
13
|
test("Windows 11 (build >= 22000)", () => {
|
|
19
14
|
mockRelease = "10.0.22000";
|
|
20
|
-
const result =
|
|
15
|
+
const result = osRelease();
|
|
21
16
|
assert.ok(result !== null);
|
|
22
17
|
assert.equal(result.name, "Windows 11");
|
|
23
18
|
assert.equal(result.version, "10.0.22000");
|
|
@@ -25,43 +20,43 @@ await suite("windowsRelease (win32 platform)", async () => {
|
|
|
25
20
|
});
|
|
26
21
|
test("Windows 10 (build < 22000)", () => {
|
|
27
22
|
mockRelease = "10.0.19041";
|
|
28
|
-
assert.equal(
|
|
23
|
+
assert.equal(osRelease()?.name, "Windows 10");
|
|
29
24
|
});
|
|
30
25
|
test("Windows 8.1", () => {
|
|
31
26
|
mockRelease = "6.3.9600";
|
|
32
|
-
assert.equal(
|
|
27
|
+
assert.equal(osRelease()?.name, "Windows 8.1");
|
|
33
28
|
});
|
|
34
29
|
test("Windows 8", () => {
|
|
35
30
|
mockRelease = "6.2.9200";
|
|
36
|
-
assert.equal(
|
|
31
|
+
assert.equal(osRelease()?.name, "Windows 8");
|
|
37
32
|
});
|
|
38
33
|
test("Windows 7", () => {
|
|
39
34
|
mockRelease = "6.1.7601";
|
|
40
|
-
assert.equal(
|
|
35
|
+
assert.equal(osRelease()?.name, "Windows 7");
|
|
41
36
|
});
|
|
42
37
|
test("Windows Vista", () => {
|
|
43
38
|
mockRelease = "6.0.6002";
|
|
44
|
-
assert.equal(
|
|
39
|
+
assert.equal(osRelease()?.name, "Windows Vista");
|
|
45
40
|
});
|
|
46
41
|
test("Windows XP 64-Bit Edition", () => {
|
|
47
42
|
mockRelease = "5.2.3790";
|
|
48
|
-
assert.equal(
|
|
43
|
+
assert.equal(osRelease()?.name, "Windows XP 64-Bit Edition");
|
|
49
44
|
});
|
|
50
45
|
test("Windows XP", () => {
|
|
51
46
|
mockRelease = "5.1.2600";
|
|
52
|
-
assert.equal(
|
|
47
|
+
assert.equal(osRelease()?.name, "Windows XP");
|
|
53
48
|
});
|
|
54
49
|
test("Windows 2000", () => {
|
|
55
50
|
mockRelease = "5.0.2195";
|
|
56
|
-
assert.equal(
|
|
51
|
+
assert.equal(osRelease()?.name, "Windows 2000");
|
|
57
52
|
});
|
|
58
53
|
test("unknown version", () => {
|
|
59
54
|
mockRelease = "4.0.1381";
|
|
60
|
-
assert.equal(
|
|
55
|
+
assert.equal(osRelease()?.name, "Windows unknown version");
|
|
61
56
|
});
|
|
62
57
|
test("Windows 10 when build number is absent", () => {
|
|
63
58
|
mockRelease = "10.0";
|
|
64
|
-
assert.equal(
|
|
59
|
+
assert.equal(osRelease()?.name, "Windows 10");
|
|
65
60
|
});
|
|
66
61
|
});
|
|
67
62
|
//# sourceMappingURL=os-utils-windows.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"os-utils-windows.test.js","sourceRoot":"","sources":["../../src/__tests__/os-utils-windows.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAI7C,IAAI,WAAW,GAAG,YAAY,CAAA;AAE9B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;IACnB,YAAY,EAAE;QACV,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO;QACvB,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW;QAC1B,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK;KACpB;CACJ,CAAC,CAAA;AAEF,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"os-utils-windows.test.js","sourceRoot":"","sources":["../../src/__tests__/os-utils-windows.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBA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C,CAAA;IAEF,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,WAAW,GAAG,MAAM,CAAA;QACpB,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -1,73 +1,68 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { platform } from "node:os";
|
|
3
3
|
import { suite, test } from "node:test";
|
|
4
|
-
import {
|
|
5
|
-
await suite("
|
|
4
|
+
import { osRelease } from "../os-utils.js";
|
|
5
|
+
await suite("osRelease", () => {
|
|
6
6
|
test("returns an object on Linux", () => {
|
|
7
7
|
if (platform() !== "linux") {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
|
-
const result =
|
|
10
|
+
const result = osRelease();
|
|
11
11
|
assert.notEqual(result, null);
|
|
12
12
|
assert.equal(typeof result, "object");
|
|
13
13
|
});
|
|
14
|
-
test("returns
|
|
15
|
-
if (platform()
|
|
14
|
+
test("returns an object on Windows", () => {
|
|
15
|
+
if (platform() !== "win32") {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const result = osRelease();
|
|
19
|
+
assert.notEqual(result, null);
|
|
20
|
+
assert.equal(typeof result, "object");
|
|
21
|
+
});
|
|
22
|
+
test("returns null on unsupported platforms", () => {
|
|
23
|
+
if (platform() === "linux" || platform() === "win32") {
|
|
16
24
|
return;
|
|
17
25
|
}
|
|
18
|
-
assert.equal(
|
|
26
|
+
assert.equal(osRelease(), null);
|
|
19
27
|
});
|
|
20
|
-
test("
|
|
28
|
+
test("all values are strings on Linux", () => {
|
|
21
29
|
if (platform() !== "linux") {
|
|
22
30
|
return;
|
|
23
31
|
}
|
|
24
|
-
const result =
|
|
32
|
+
const result = osRelease();
|
|
25
33
|
assert.ok(result !== null);
|
|
26
34
|
for (const value of Object.values(result)) {
|
|
27
35
|
assert.equal(typeof value, "string");
|
|
28
36
|
}
|
|
29
37
|
});
|
|
30
|
-
test("
|
|
38
|
+
test("contains expected raw keys on Linux", () => {
|
|
31
39
|
if (platform() !== "linux") {
|
|
32
40
|
return;
|
|
33
41
|
}
|
|
34
|
-
const result =
|
|
42
|
+
const result = osRelease();
|
|
35
43
|
assert.ok(result !== null);
|
|
36
44
|
assert.ok("ID" in result);
|
|
37
45
|
assert.ok("NAME" in result);
|
|
38
46
|
});
|
|
39
|
-
test("values do not contain surrounding quotes", () => {
|
|
47
|
+
test("values do not contain surrounding quotes on Linux", () => {
|
|
40
48
|
if (platform() !== "linux") {
|
|
41
49
|
return;
|
|
42
50
|
}
|
|
43
|
-
const result =
|
|
51
|
+
const result = osRelease();
|
|
44
52
|
assert.ok(result !== null);
|
|
45
53
|
for (const value of Object.values(result)) {
|
|
54
|
+
if (typeof value !== "string") {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
46
57
|
assert.ok(!value.startsWith('"'));
|
|
47
58
|
assert.ok(!value.endsWith('"'));
|
|
48
59
|
}
|
|
49
60
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
test("returns an object on Windows", () => {
|
|
53
|
-
if (platform() !== "win32") {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const result = windowsRelease();
|
|
57
|
-
assert.notEqual(result, null);
|
|
58
|
-
assert.equal(typeof result, "object");
|
|
59
|
-
});
|
|
60
|
-
test("returns null on non-Windows platforms", () => {
|
|
61
|
-
if (platform() === "win32") {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
assert.equal(windowsRelease(), null);
|
|
65
|
-
});
|
|
66
|
-
test("returned object has name, version, and arch on Windows", () => {
|
|
67
|
-
if (platform() !== "win32") {
|
|
61
|
+
test("name, version, and arch are strings", () => {
|
|
62
|
+
if (platform() !== "linux" && platform() !== "win32") {
|
|
68
63
|
return;
|
|
69
64
|
}
|
|
70
|
-
const result =
|
|
65
|
+
const result = osRelease();
|
|
71
66
|
assert.ok(result !== null);
|
|
72
67
|
assert.equal(typeof result.name, "string");
|
|
73
68
|
assert.equal(typeof result.version, "string");
|
|
@@ -77,7 +72,7 @@ await suite("windowsRelease", () => {
|
|
|
77
72
|
if (platform() !== "win32") {
|
|
78
73
|
return;
|
|
79
74
|
}
|
|
80
|
-
const result =
|
|
75
|
+
const result = osRelease();
|
|
81
76
|
assert.ok(result !== null);
|
|
82
77
|
assert.ok(result.name.startsWith("Windows "));
|
|
83
78
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"os-utils.test.js","sourceRoot":"","sources":["../../src/__tests__/os-utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,
|
|
1
|
+
{"version":3,"file":"os-utils.test.js","sourceRoot":"","sources":["../../src/__tests__/os-utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAM1D,MAAM,KAAK,CAAC,WAAW,EAAE,GAAG,EAAE;IAC1B,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,IAAI,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;YACzB,OAAM;QACV,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;QAC1B,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAC7B,MAAM,CAAC,KAAK,CAAC,OAAO,MAAM,EAAE,QAAQ,CAAC,CAAA;IACzC,CAAC,CAAC,CAAA;IAEF,IAAI,C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AQ,EAAE,KAAK,OAAO,EAAE,CAAC;YACzB,OAAM;QACV,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;QAC1B,MAAM,CAAC,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,CAAA;QAC1B,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { type LauncherFunction, main } from "./main.ts";
|
|
|
9
9
|
import millisecondsToString from "./millisecondsToString.ts";
|
|
10
10
|
import monitorMemory from "./monitorMemory.ts";
|
|
11
11
|
import noop from "./noop.ts";
|
|
12
|
-
import { type
|
|
12
|
+
import { type OsRelease, osRelease } from "./os-utils.ts";
|
|
13
13
|
import type { RuntimeObject } from "./types.ts";
|
|
14
|
-
export { getConsoleLogger, getDummyLogger, type LauncherFunction,
|
|
14
|
+
export { getConsoleLogger, getDummyLogger, type LauncherFunction, main, millisecondsToString, monitorMemory, noop, type OsRelease, osRelease, type RuntimeObject, };
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,gBAAgB,MAAM,+BAA+B,CAAA;AAC5D,OAAO,cAAc,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,KAAK,gBAAgB,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,oBAAoB,MAAM,2BAA2B,CAAA;AAC5D,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,gBAAgB,MAAM,+BAA+B,CAAA;AAC5D,OAAO,cAAc,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,KAAK,gBAAgB,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,oBAAoB,MAAM,2BAA2B,CAAA;AAC5D,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,EACH,gBAAgB,EAChB,cAAc,EACd,KAAK,gBAAgB,EACrB,IAAI,EACJ,oBAAoB,EACpB,aAAa,EACb,IAAI,EACJ,KAAK,SAAS,EACd,SAAS,EACT,KAAK,aAAa,GACrB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,6 @@ import { main } from "./main.js";
|
|
|
9
9
|
import millisecondsToString from "./millisecondsToString.js";
|
|
10
10
|
import monitorMemory from "./monitorMemory.js";
|
|
11
11
|
import noop from "./noop.js";
|
|
12
|
-
import {
|
|
13
|
-
export { getConsoleLogger, getDummyLogger,
|
|
12
|
+
import { osRelease } from "./os-utils.js";
|
|
13
|
+
export { getConsoleLogger, getDummyLogger, main, millisecondsToString, monitorMemory, noop, osRelease, };
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,gBAAgB,MAAM,+BAA+B,CAAA;AAC5D,OAAO,cAAc,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAyB,IAAI,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,oBAAoB,MAAM,2BAA2B,CAAA;AAC5D,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,gBAAgB,MAAM,+BAA+B,CAAA;AAC5D,OAAO,cAAc,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAyB,IAAI,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,oBAAoB,MAAM,2BAA2B,CAAA;AAC5D,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAkB,SAAS,EAAE,MAAM,eAAe,CAAA;AAGzD,OAAO,EACH,gBAAgB,EAChB,cAAc,EAEd,IAAI,EACJ,oBAAoB,EACpB,aAAa,EACb,IAAI,EAEJ,SAAS,GAEZ,CAAA"}
|
package/dist/os-utils.d.ts
CHANGED
|
@@ -1,46 +1,37 @@
|
|
|
1
|
+
import type { RuntimeObject } from "./types.ts";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* OS release information with normalized fields and optional platform-specific extras.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* `name`, `version`, and `arch` are always present. On Linux, all keys from
|
|
6
|
+
* `/etc/os-release` (e.g. `ID`, `PRETTY_NAME`, `ID_LIKE`) are also accessible by string index.
|
|
6
7
|
*/
|
|
7
|
-
export type
|
|
8
|
-
/**
|
|
9
|
-
* Basic information about the current Windows environment.
|
|
10
|
-
*/
|
|
11
|
-
export type WindowsRelease = {
|
|
12
|
-
/** Human-readable Windows version name, e.g. `"Windows 11"`. */
|
|
8
|
+
export type OsRelease = {
|
|
9
|
+
/** Human-readable OS name, e.g. `"Ubuntu"` or `"Windows 11"`. */
|
|
13
10
|
name: string;
|
|
14
|
-
/**
|
|
11
|
+
/** OS version string, e.g. `"24.04"` or `"10.0.22000"`. */
|
|
15
12
|
version: string;
|
|
16
13
|
/** Processor architecture as returned by `os.arch()`, e.g. `"x64"`. */
|
|
17
14
|
arch: string;
|
|
18
|
-
};
|
|
15
|
+
} & RuntimeObject;
|
|
19
16
|
/**
|
|
20
|
-
* Returns
|
|
21
|
-
* or when
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* import { linuxRelease } from "@darthcav/ts-utils"
|
|
17
|
+
* Returns OS release information for the current platform, or `null` on unsupported
|
|
18
|
+
* platforms or when `/etc/os-release` is absent on Linux.
|
|
26
19
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
export declare function linuxRelease(): LinuxRelease | null;
|
|
32
|
-
/**
|
|
33
|
-
* Returns basic Windows version information, or `null` on non-Windows platforms.
|
|
20
|
+
* On Linux, `name`, `version`, and `arch` are normalized from `NAME`/`PRETTY_NAME`,
|
|
21
|
+
* `VERSION_ID`/`VERSION`, and `os.arch()` respectively. All raw keys from
|
|
22
|
+
* `/etc/os-release` are also present on the returned object.
|
|
34
23
|
*
|
|
35
|
-
*
|
|
24
|
+
* On Windows, distinguishes Windows 11 from Windows 10 by NT build number
|
|
25
|
+
* (>= 22000 → Windows 11).
|
|
36
26
|
*
|
|
37
27
|
* @example
|
|
38
28
|
* ```ts
|
|
39
|
-
* import {
|
|
29
|
+
* import { osRelease } from "@darthcav/ts-utils"
|
|
40
30
|
*
|
|
41
|
-
* const info =
|
|
42
|
-
* if (info) console.log(info.name)
|
|
31
|
+
* const info = osRelease()
|
|
32
|
+
* if (info) console.log(info.name) // e.g. "Ubuntu" or "Windows 11"
|
|
33
|
+
* if (info) console.log(info.PRETTY_NAME) // e.g. "Ubuntu 24.04 LTS" (Linux only)
|
|
43
34
|
* ```
|
|
44
35
|
*/
|
|
45
|
-
export declare function
|
|
36
|
+
export declare function osRelease(): OsRelease | null;
|
|
46
37
|
//# sourceMappingURL=os-utils.d.ts.map
|
package/dist/os-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"os-utils.d.ts","sourceRoot":"","sources":["../src/os-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"os-utils.d.ts","sourceRoot":"","sources":["../src/os-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;CACf,GAAG,aAAa,CAAA;AAIjB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,IAAI,SAAS,GAAG,IAAI,CAiE5C"}
|
package/dist/os-utils.js
CHANGED
|
@@ -1,90 +1,91 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { arch, release as
|
|
2
|
+
import { arch, release as kernelRelease, platform } from "node:os";
|
|
3
3
|
const OS_RELEASE = "/etc/os-release";
|
|
4
4
|
/**
|
|
5
|
-
* Returns
|
|
6
|
-
* or when
|
|
5
|
+
* Returns OS release information for the current platform, or `null` on unsupported
|
|
6
|
+
* platforms or when `/etc/os-release` is absent on Linux.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* const info = linuxRelease()
|
|
13
|
-
* if (info) console.log(info.PRETTY_NAME) // e.g. "Ubuntu 24.04 LTS"
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export function linuxRelease() {
|
|
17
|
-
if (platform() !== "linux" || !existsSync(OS_RELEASE)) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const result = {};
|
|
21
|
-
for (const line of readFileSync(OS_RELEASE, "utf-8").split("\n")) {
|
|
22
|
-
const eq = line.indexOf("=");
|
|
23
|
-
if (eq === -1) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
const key = line.substring(0, eq).trim();
|
|
27
|
-
result[key] = line
|
|
28
|
-
.substring(eq + 1)
|
|
29
|
-
.trim()
|
|
30
|
-
.replace(/^"|"$/g, "");
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns basic Windows version information, or `null` on non-Windows platforms.
|
|
8
|
+
* On Linux, `name`, `version`, and `arch` are normalized from `NAME`/`PRETTY_NAME`,
|
|
9
|
+
* `VERSION_ID`/`VERSION`, and `os.arch()` respectively. All raw keys from
|
|
10
|
+
* `/etc/os-release` are also present on the returned object.
|
|
36
11
|
*
|
|
37
|
-
*
|
|
12
|
+
* On Windows, distinguishes Windows 11 from Windows 10 by NT build number
|
|
13
|
+
* (>= 22000 → Windows 11).
|
|
38
14
|
*
|
|
39
15
|
* @example
|
|
40
16
|
* ```ts
|
|
41
|
-
* import {
|
|
17
|
+
* import { osRelease } from "@darthcav/ts-utils"
|
|
42
18
|
*
|
|
43
|
-
* const info =
|
|
44
|
-
* if (info) console.log(info.name)
|
|
19
|
+
* const info = osRelease()
|
|
20
|
+
* if (info) console.log(info.name) // e.g. "Ubuntu" or "Windows 11"
|
|
21
|
+
* if (info) console.log(info.PRETTY_NAME) // e.g. "Ubuntu 24.04 LTS" (Linux only)
|
|
45
22
|
* ```
|
|
46
23
|
*/
|
|
47
|
-
export function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
24
|
+
export function osRelease() {
|
|
25
|
+
const p = platform();
|
|
26
|
+
if (p === "linux") {
|
|
27
|
+
if (!existsSync(OS_RELEASE)) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const raw = {};
|
|
31
|
+
for (const line of readFileSync(OS_RELEASE, "utf-8").split("\n")) {
|
|
32
|
+
const eq = line.indexOf("=");
|
|
33
|
+
if (eq === -1) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const key = line.substring(0, eq).trim();
|
|
37
|
+
raw[key] = line
|
|
38
|
+
.substring(eq + 1)
|
|
39
|
+
.trim()
|
|
40
|
+
.replace(/^"|"$/g, "");
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...raw,
|
|
44
|
+
name: raw["NAME"] ?? raw["PRETTY_NAME"] ?? "",
|
|
45
|
+
version: raw["VERSION_ID"] ?? raw["VERSION"] ?? "",
|
|
46
|
+
arch: arch(),
|
|
47
|
+
};
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
49
|
+
if (p === "win32") {
|
|
50
|
+
const version = kernelRelease();
|
|
51
|
+
const [major, , build] = version.split(".").map(Number);
|
|
52
|
+
let name = "Windows ";
|
|
53
|
+
if (major === 10 && (build ?? 0) >= 22000) {
|
|
54
|
+
name += "11";
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
switch (version.substring(0, 3)) {
|
|
58
|
+
case "10.":
|
|
59
|
+
name += "10";
|
|
60
|
+
break;
|
|
61
|
+
case "6.3":
|
|
62
|
+
name += "8.1";
|
|
63
|
+
break;
|
|
64
|
+
case "6.2":
|
|
65
|
+
name += "8";
|
|
66
|
+
break;
|
|
67
|
+
case "6.1":
|
|
68
|
+
name += "7";
|
|
69
|
+
break;
|
|
70
|
+
case "6.0":
|
|
71
|
+
name += "Vista";
|
|
72
|
+
break;
|
|
73
|
+
case "5.2":
|
|
74
|
+
name += "XP 64-Bit Edition";
|
|
75
|
+
break;
|
|
76
|
+
case "5.1":
|
|
77
|
+
name += "XP";
|
|
78
|
+
break;
|
|
79
|
+
case "5.0":
|
|
80
|
+
name += "2000";
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
name += "unknown version";
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
86
|
}
|
|
87
|
+
return { name, version, arch: arch() };
|
|
87
88
|
}
|
|
88
|
-
return
|
|
89
|
+
return null;
|
|
89
90
|
}
|
|
90
91
|
//# sourceMappingURL=os-utils.js.map
|
package/dist/os-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"os-utils.js","sourceRoot":"","sources":["../src/os-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"os-utils.js","sourceRoot":"","sources":["../src/os-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAkBlE,MAAM,UAAU,GAAG,iBAAiB,CAAA;AAEpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS;IACrB,MAAM,CAAC,GAAG,QAAQ,EAAE,CAAA;IACpB,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAA;QACf,CAAC;QACD,MAAM,GAAG,GAA2B,EAAE,CAAA;Q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AC9B,KAAK,KAAK;oBACN,IAAI,IAAI,IAAI,CAAA;oBACZ,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,KAAK,CAAA;oBACb,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,GAAG,CAAA;oBACX,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,GAAG,CAAA;oBACX,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,OAAO,CAAA;oBACf,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,mBAAmB,CAAA;oBAC3B,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,IAAI,CAAA;oBACZ,MAAK;gBACT,KAAK,KAAK;oBACN,IAAI,IAAI,MAAM,CAAA;oBACd,MAAK;gBACT;oBACI,IAAI,IAAI,iBAAiB,CAAA;oBACzB,MAAK;YACb,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAA;IAC1C,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -10,25 +10,18 @@ import { type LauncherFunction, main } from "./main.ts"
|
|
|
10
10
|
import millisecondsToString from "./millisecondsToString.ts"
|
|
11
11
|
import monitorMemory from "./monitorMemory.ts"
|
|
12
12
|
import noop from "./noop.ts"
|
|
13
|
-
import {
|
|
14
|
-
type LinuxRelease,
|
|
15
|
-
linuxRelease,
|
|
16
|
-
type WindowsRelease,
|
|
17
|
-
windowsRelease,
|
|
18
|
-
} from "./os-utils.ts"
|
|
13
|
+
import { type OsRelease, osRelease } from "./os-utils.ts"
|
|
19
14
|
import type { RuntimeObject } from "./types.ts"
|
|
20
15
|
|
|
21
16
|
export {
|
|
22
17
|
getConsoleLogger,
|
|
23
18
|
getDummyLogger,
|
|
24
19
|
type LauncherFunction,
|
|
25
|
-
type LinuxRelease,
|
|
26
|
-
linuxRelease,
|
|
27
20
|
main,
|
|
28
21
|
millisecondsToString,
|
|
29
22
|
monitorMemory,
|
|
30
23
|
noop,
|
|
24
|
+
type OsRelease,
|
|
25
|
+
osRelease,
|
|
31
26
|
type RuntimeObject,
|
|
32
|
-
type WindowsRelease,
|
|
33
|
-
windowsRelease,
|
|
34
27
|
}
|
package/src/os-utils.ts
CHANGED
|
@@ -1,111 +1,107 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs"
|
|
2
|
-
import { arch, release as
|
|
2
|
+
import { arch, release as kernelRelease, platform } from "node:os"
|
|
3
|
+
import type { RuntimeObject } from "./types.ts"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* OS release information with normalized fields and optional platform-specific extras.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* `name`, `version`, and `arch` are always present. On Linux, all keys from
|
|
9
|
+
* `/etc/os-release` (e.g. `ID`, `PRETTY_NAME`, `ID_LIKE`) are also accessible by string index.
|
|
9
10
|
*/
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Basic information about the current Windows environment.
|
|
14
|
-
*/
|
|
15
|
-
export type WindowsRelease = {
|
|
16
|
-
/** Human-readable Windows version name, e.g. `"Windows 11"`. */
|
|
11
|
+
export type OsRelease = {
|
|
12
|
+
/** Human-readable OS name, e.g. `"Ubuntu"` or `"Windows 11"`. */
|
|
17
13
|
name: string
|
|
18
|
-
/**
|
|
14
|
+
/** OS version string, e.g. `"24.04"` or `"10.0.22000"`. */
|
|
19
15
|
version: string
|
|
20
16
|
/** Processor architecture as returned by `os.arch()`, e.g. `"x64"`. */
|
|
21
17
|
arch: string
|
|
22
|
-
}
|
|
18
|
+
} & RuntimeObject
|
|
23
19
|
|
|
24
20
|
const OS_RELEASE = "/etc/os-release"
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
|
-
* Returns
|
|
28
|
-
* or when
|
|
23
|
+
* Returns OS release information for the current platform, or `null` on unsupported
|
|
24
|
+
* platforms or when `/etc/os-release` is absent on Linux.
|
|
29
25
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* const info = linuxRelease()
|
|
35
|
-
* if (info) console.log(info.PRETTY_NAME) // e.g. "Ubuntu 24.04 LTS"
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export function linuxRelease(): LinuxRelease | null {
|
|
39
|
-
if (platform() !== "linux" || !existsSync(OS_RELEASE)) {
|
|
40
|
-
return null
|
|
41
|
-
}
|
|
42
|
-
const result: LinuxRelease = {}
|
|
43
|
-
for (const line of readFileSync(OS_RELEASE, "utf-8").split("\n")) {
|
|
44
|
-
const eq = line.indexOf("=")
|
|
45
|
-
if (eq === -1) {
|
|
46
|
-
continue
|
|
47
|
-
}
|
|
48
|
-
const key = line.substring(0, eq).trim()
|
|
49
|
-
result[key] = line
|
|
50
|
-
.substring(eq + 1)
|
|
51
|
-
.trim()
|
|
52
|
-
.replace(/^"|"$/g, "")
|
|
53
|
-
}
|
|
54
|
-
return result
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns basic Windows version information, or `null` on non-Windows platforms.
|
|
26
|
+
* On Linux, `name`, `version`, and `arch` are normalized from `NAME`/`PRETTY_NAME`,
|
|
27
|
+
* `VERSION_ID`/`VERSION`, and `os.arch()` respectively. All raw keys from
|
|
28
|
+
* `/etc/os-release` are also present on the returned object.
|
|
59
29
|
*
|
|
60
|
-
*
|
|
30
|
+
* On Windows, distinguishes Windows 11 from Windows 10 by NT build number
|
|
31
|
+
* (>= 22000 → Windows 11).
|
|
61
32
|
*
|
|
62
33
|
* @example
|
|
63
34
|
* ```ts
|
|
64
|
-
* import {
|
|
35
|
+
* import { osRelease } from "@darthcav/ts-utils"
|
|
65
36
|
*
|
|
66
|
-
* const info =
|
|
67
|
-
* if (info) console.log(info.name)
|
|
37
|
+
* const info = osRelease()
|
|
38
|
+
* if (info) console.log(info.name) // e.g. "Ubuntu" or "Windows 11"
|
|
39
|
+
* if (info) console.log(info.PRETTY_NAME) // e.g. "Ubuntu 24.04 LTS" (Linux only)
|
|
68
40
|
* ```
|
|
69
41
|
*/
|
|
70
|
-
export function
|
|
71
|
-
|
|
72
|
-
|
|
42
|
+
export function osRelease(): OsRelease | null {
|
|
43
|
+
const p = platform()
|
|
44
|
+
if (p === "linux") {
|
|
45
|
+
if (!existsSync(OS_RELEASE)) {
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
const raw: Record<string, string> = {}
|
|
49
|
+
for (const line of readFileSync(OS_RELEASE, "utf-8").split("\n")) {
|
|
50
|
+
const eq = line.indexOf("=")
|
|
51
|
+
if (eq === -1) {
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
const key = line.substring(0, eq).trim()
|
|
55
|
+
raw[key] = line
|
|
56
|
+
.substring(eq + 1)
|
|
57
|
+
.trim()
|
|
58
|
+
.replace(/^"|"$/g, "")
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
...raw,
|
|
62
|
+
name: raw["NAME"] ?? raw["PRETTY_NAME"] ?? "",
|
|
63
|
+
version: raw["VERSION_ID"] ?? raw["VERSION"] ?? "",
|
|
64
|
+
arch: arch(),
|
|
65
|
+
}
|
|
73
66
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
67
|
+
if (p === "win32") {
|
|
68
|
+
const version = kernelRelease()
|
|
69
|
+
const [major, , build] = version.split(".").map(Number)
|
|
70
|
+
let name = "Windows "
|
|
71
|
+
if (major === 10 && (build ?? 0) >= 22000) {
|
|
72
|
+
name += "11"
|
|
73
|
+
} else {
|
|
74
|
+
switch (version.substring(0, 3)) {
|
|
75
|
+
case "10.":
|
|
76
|
+
name += "10"
|
|
77
|
+
break
|
|
78
|
+
case "6.3":
|
|
79
|
+
name += "8.1"
|
|
80
|
+
break
|
|
81
|
+
case "6.2":
|
|
82
|
+
name += "8"
|
|
83
|
+
break
|
|
84
|
+
case "6.1":
|
|
85
|
+
name += "7"
|
|
86
|
+
break
|
|
87
|
+
case "6.0":
|
|
88
|
+
name += "Vista"
|
|
89
|
+
break
|
|
90
|
+
case "5.2":
|
|
91
|
+
name += "XP 64-Bit Edition"
|
|
92
|
+
break
|
|
93
|
+
case "5.1":
|
|
94
|
+
name += "XP"
|
|
95
|
+
break
|
|
96
|
+
case "5.0":
|
|
97
|
+
name += "2000"
|
|
98
|
+
break
|
|
99
|
+
default:
|
|
100
|
+
name += "unknown version"
|
|
101
|
+
break
|
|
102
|
+
}
|
|
108
103
|
}
|
|
104
|
+
return { name, version, arch: arch() }
|
|
109
105
|
}
|
|
110
|
-
return
|
|
106
|
+
return null
|
|
111
107
|
}
|