systeminformation 6.0.0-beta.7 → 6.0.0-beta.8

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 CHANGED
@@ -49,6 +49,8 @@ in a browser.
49
49
  - `npu()` - detected NPUs / AI accelerators (experimental)
50
50
  - `software()` - installed software / applications
51
51
  - `npm()` - globally installed npm packages
52
+ - `fans()` - detected fans with rpm and pwm
53
+ - `serialPorts()` - detected serial / COM ports
52
54
 
53
55
  ### Extended Windows support
54
56
 
@@ -163,7 +165,7 @@ implementations can be tree-shaken away.
163
165
 
164
166
  - complete rewrite in TypeScript with typed declarations for every function
165
167
  - modular imports: load the whole library, a single operating system, or a single function
166
- - new functions: `camera()`, `keyboard()`, `mouse()`, `thunderbolt()`, `pci()`, `npu()`, `software()`, `npm()`
168
+ - new functions: `camera()`, `keyboard()`, `mouse()`, `thunderbolt()`, `pci()`, `npu()`, `software()`, `npm()`, `fans()`, `serialPorts()`
167
169
  - extended Windows support: `disksIO()`, `fsStats()`, `fsOpenFiles()`, `thunderbolt()`
168
170
  - `time()` and `version()` are now asynchronous - all functions are async (async/await preferred, promises as alternative)
169
171
  - callbacks are no longer supported
@@ -616,6 +618,15 @@ On Windows, `si.displays()` reports physical monitors: in duplicate/mirror mode
616
618
  | | [0].maxPower | X | | | | | max power |
617
619
  | | [0].default | X | | X | X | | is default printer |
618
620
  | | [0].serialNumber | | | X | | | serial number |
621
+ | si.serialPorts() | [{...}] | X | | X | X | | detected serial / COM ports |
622
+ | | [0].device | X | | X | X | | device path (COMx on Windows) |
623
+ | | [0].name | X | | X | X | | product / friendly name |
624
+ | | [0].manufacturer | X | | X | X | | manufacturer |
625
+ | | [0].serialNumber | X | | X | X | | serial number (USB only) |
626
+ | | [0].vendorId | X | | X | X | | vendor id (hex) |
627
+ | | [0].productId | X | | X | X | | product id (hex) |
628
+ | | [0].pnpId | X | | | X | | stable id (by-id / DeviceID) |
629
+ | | [0].type | X | | X | X | | usb, onboard, pci, bluetooth |
619
630
 
620
631
  #### 11. Devices
621
632
 
@@ -1017,6 +1028,10 @@ and - as soon as the package exposes them - the fan speeds in `fans()`.
1017
1028
 
1018
1029
  Windows itself does not expose actual fan speeds: `Win32_Fan` only reports that a fan exists, its `DesiredSpeed` is the *requested* speed and is left empty by virtually every mainboard. Real values are read from a running [LibreHardwareMonitor](https://github.com/LibreHardwareMonitor/LibreHardwareMonitor) or OpenHardwareMonitor, which publish their sensors in an own WMI namespace. Without one of these tools running, `fans()` returns an empty array or entries without `rpm`.
1019
1030
 
1031
+ #### Serial Ports
1032
+
1033
+ `serialPorts()` only *enumerates* ports - opening one (baud rate, termios, RTS toggling) needs a native binding and is out of scope for this zero-dependency library. Two things worth knowing: on Linux a port shows up in the list even when your user is not in the `dialout` / `uucp` group, so listing can succeed while opening fails; on Windows the `COMx` number is reassigned per USB port, so `pnpId` is the only stable key. RS-232 and RS-485 cannot be told apart by enumeration - an RS-485 transceiver looks like an ordinary UART to the operating system - so no such information is reported.
1034
+
1020
1035
  #### Windows Temperature, Battery, ...
1021
1036
 
1022
1037
  `get-WmiObject` - which is used to determine temperature and battery sometimes needs to be run with admin
@@ -1,6 +1,7 @@
1
- import type { AudioData, BaseboardData, BatteryObject, BiosData, ChassisData, CpuCacheData, CpuObject, CpuTemperatureObject, DisksIoData, DisplayData, FsBlockDevicesData, FsOpenFilesData, FsStatsData, InetChecksiteData, MemData, NetworkInterfacesData, NetworkStatsData, NpuData, OsData, PciData, ProcessesData, SystemData, UsbData, UuidData } from './types';
1
+ import type { AudioData, BaseboardData, BatteryObject, BiosData, ChassisData, CpuCacheData, CpuObject, CpuTemperatureObject, DisksIoData, DisplayData, FsBlockDevicesData, FsOpenFilesData, FsStatsData, InetChecksiteData, MemData, NetworkInterfacesData, NetworkStatsData, NpuData, OsData, PciData, ProcessesData, SerialPortData, SystemData, UsbData, UuidData } from './types';
2
2
  export declare const initBatteryResult: BatteryObject;
3
3
  export declare const initAudioResult: AudioData;
4
+ export declare const initSerialPortResult: SerialPortData;
4
5
  export declare const initUsbResult: UsbData;
5
6
  export declare const initCpuResult: CpuObject;
6
7
  export declare const initCpuCacheResult: CpuCacheData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initNetworkSpeed = exports.initPciData = exports.initNpuData = exports.initNetworkInterface = exports.initProcesses = exports.initDisplay = exports.initDiskIo = exports.initFsStats = exports.initFsBlockDevice = exports.initFsOpenFiles = exports.initSystem = exports.initBios = exports.initBaseboard = exports.initChassis = exports.initUUID = exports.initOsInfo = exports.initMemData = exports.initCheckSite = exports.initCpuTemperature = exports.initCpuCacheResult = exports.initCpuResult = exports.initUsbResult = exports.initAudioResult = exports.initBatteryResult = void 0;
3
+ exports.initNetworkSpeed = exports.initPciData = exports.initNpuData = exports.initNetworkInterface = exports.initProcesses = exports.initDisplay = exports.initDiskIo = exports.initFsStats = exports.initFsBlockDevice = exports.initFsOpenFiles = exports.initSystem = exports.initBios = exports.initBaseboard = exports.initChassis = exports.initUUID = exports.initOsInfo = exports.initMemData = exports.initCheckSite = exports.initCpuTemperature = exports.initCpuCacheResult = exports.initCpuResult = exports.initUsbResult = exports.initSerialPortResult = exports.initAudioResult = exports.initBatteryResult = void 0;
4
4
  const node_os_1 = require("node:os");
5
5
  const acceleration_1 = require("./acceleration");
6
6
  const const_1 = require("./const");
@@ -34,6 +34,16 @@ exports.initAudioResult = {
34
34
  out: null,
35
35
  status: ''
36
36
  };
37
+ exports.initSerialPortResult = {
38
+ device: '',
39
+ name: null,
40
+ manufacturer: null,
41
+ serialNumber: null,
42
+ vendorId: null,
43
+ productId: null,
44
+ pnpId: null,
45
+ type: 'unknown'
46
+ };
37
47
  exports.initUsbResult = {
38
48
  id: null,
39
49
  bus: null,
@@ -328,6 +328,17 @@ export type FanData = {
328
328
  pwm: number | null;
329
329
  source: string;
330
330
  };
331
+ export type SerialPortType = 'usb' | 'onboard' | 'pci' | 'bluetooth' | 'virtual' | 'unknown';
332
+ export type SerialPortData = {
333
+ device: string;
334
+ name: string | null;
335
+ manufacturer: string | null;
336
+ serialNumber: string | null;
337
+ vendorId: string | null;
338
+ productId: string | null;
339
+ pnpId: string | null;
340
+ type: SerialPortType;
341
+ };
331
342
  export type CurrentLoadData = {
332
343
  avgLoad: number;
333
344
  currentLoad: number;
@@ -46,6 +46,7 @@ export { software } from './software';
46
46
  export { system } from './system';
47
47
  export { thunderbolt } from './thunderbolt';
48
48
  export { time } from '../time';
49
+ export { serialPorts } from './serial-ports';
49
50
  export { usb } from './usb';
50
51
  export { users } from './users';
51
52
  export { uuid } from './uuid';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
5
5
  var audio_1 = require("./audio");
6
6
  Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
7
7
  var baseboard_1 = require("./baseboard");
@@ -104,6 +104,8 @@ var thunderbolt_1 = require("./thunderbolt");
104
104
  Object.defineProperty(exports, "thunderbolt", { enumerable: true, get: function () { return thunderbolt_1.thunderbolt; } });
105
105
  var time_1 = require("../time");
106
106
  Object.defineProperty(exports, "time", { enumerable: true, get: function () { return time_1.time; } });
107
+ var serial_ports_1 = require("./serial-ports");
108
+ Object.defineProperty(exports, "serialPorts", { enumerable: true, get: function () { return serial_ports_1.serialPorts; } });
107
109
  var usb_1 = require("./usb");
108
110
  Object.defineProperty(exports, "usb", { enumerable: true, get: function () { return usb_1.usb; } });
109
111
  var users_1 = require("./users");
@@ -0,0 +1,2 @@
1
+ import type { SerialPortData } from '../common/types';
2
+ export declare const serialPorts: () => Promise<SerialPortData[]>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialPorts = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const common_1 = require("../common");
6
+ const defaults_1 = require("../common/defaults");
7
+ const exec_1 = require("../common/exec");
8
+ const toHex4 = (value) => {
9
+ const num = Number.parseInt(value, 10);
10
+ return Number.isNaN(num) ? null : num.toString(16).padStart(4, '0');
11
+ };
12
+ const parseUsbPorts = (stdout) => {
13
+ const ports = new Map();
14
+ let usb = {};
15
+ for (const raw of stdout.split('\n')) {
16
+ const line = raw.replace(/\|/g, '').trim();
17
+ if (line.startsWith('+-o')) {
18
+ if (line.includes('class IOUSBHostDevice')) {
19
+ usb = {};
20
+ }
21
+ continue;
22
+ }
23
+ const entry = /^"([^"]+)" = (.+)$/.exec(line);
24
+ if (!entry) {
25
+ continue;
26
+ }
27
+ const key = entry[1];
28
+ const value = (entry[2] || '').replace(/^"|"$/g, '').trim();
29
+ switch (key) {
30
+ case 'idVendor':
31
+ usb.vendorId = toHex4(value);
32
+ break;
33
+ case 'idProduct':
34
+ usb.productId = toHex4(value);
35
+ break;
36
+ case 'USB Vendor Name':
37
+ usb.manufacturer = value || null;
38
+ break;
39
+ case 'USB Product Name':
40
+ usb.name = value || null;
41
+ break;
42
+ case 'USB Serial Number':
43
+ usb.serialNumber = value || null;
44
+ break;
45
+ case 'IOCalloutDevice':
46
+ ports.set(value, { ...usb });
47
+ break;
48
+ default:
49
+ break;
50
+ }
51
+ }
52
+ return ports;
53
+ };
54
+ const calloutDevices = (stdout) => {
55
+ const devices = new Set();
56
+ const regex = /"IOCalloutDevice" = "([^"]+)"/g;
57
+ let match = regex.exec(stdout);
58
+ while (match) {
59
+ if (match[1]) {
60
+ devices.add(match[1]);
61
+ }
62
+ match = regex.exec(stdout);
63
+ }
64
+ return devices;
65
+ };
66
+ const serialPorts = async () => {
67
+ await (0, common_1.nextTick)();
68
+ const result = [];
69
+ let devices = [];
70
+ try {
71
+ devices = (await (0, promises_1.readdir)('/dev')).filter((device) => device.startsWith('cu.'));
72
+ }
73
+ catch {
74
+ return result;
75
+ }
76
+ const [usbTree, bluetoothTree] = await Promise.all([(0, exec_1.execSave)('ioreg -r -c IOUSBHostDevice -l -w0'), (0, exec_1.execSave)('ioreg -r -c IOBluetoothDevice -l -w0')]);
77
+ const usbPorts = parseUsbPorts(usbTree.stdout);
78
+ const bluetoothPorts = calloutDevices(bluetoothTree.stdout);
79
+ for (const device of devices.sort()) {
80
+ const path = `/dev/${device}`;
81
+ const usb = usbPorts.get(path);
82
+ const name = device.substring(3);
83
+ result.push({
84
+ ...(0, common_1.cloneObj)(defaults_1.initSerialPortResult),
85
+ ...usb,
86
+ device: path,
87
+ name: usb?.name || name,
88
+ type: usb ? 'usb' : bluetoothPorts.has(path) ? 'bluetooth' : 'unknown'
89
+ });
90
+ }
91
+ return result;
92
+ };
93
+ exports.serialPorts = serialPorts;
@@ -16,6 +16,7 @@ export declare const getStaticData: () => Promise<{
16
16
  audio: import("./common/types").AudioData[] | null;
17
17
  bluetooth: import("./common/types").BluetoothObject[] | null;
18
18
  usb: import("./common/types").UsbData[] | null;
19
+ serialPorts: import("./common/types").SerialPortData[] | null;
19
20
  printer: import("./common/types").PrinterData[] | null;
20
21
  camera: import("./common/types").Camera[] | null;
21
22
  keyboard: import("./common/types").Keyboard[] | null;
@@ -100,6 +101,7 @@ export declare const getAllData: (srv?: string, iface?: string) => Promise<{
100
101
  audio: import("./common/types").AudioData[] | null;
101
102
  bluetooth: import("./common/types").BluetoothObject[] | null;
102
103
  usb: import("./common/types").UsbData[] | null;
104
+ serialPorts: import("./common/types").SerialPortData[] | null;
103
105
  printer: import("./common/types").PrinterData[] | null;
104
106
  camera: import("./common/types").Camera[] | null;
105
107
  keyboard: import("./common/types").Keyboard[] | null;
package/dist/get-data.js CHANGED
@@ -38,7 +38,7 @@ const common_1 = require("./common");
38
38
  const si = __importStar(require("./index"));
39
39
  const getStaticData = async () => {
40
40
  await (0, common_1.nextTick)();
41
- const [version, system, bios, baseboard, chassis, os, uuid, versions, cpu, cpuFlags, gpu, displays, net, memLayout, diskLayout, audio, bluetooth, usb, printer, camera, keyboard, mouse, pci, thunderbolt, npu, wifiInterfaces, software] = await Promise.all([
41
+ const [version, system, bios, baseboard, chassis, os, uuid, versions, cpu, cpuFlags, gpu, displays, net, memLayout, diskLayout, audio, bluetooth, usb, serialPorts, printer, camera, keyboard, mouse, pci, thunderbolt, npu, wifiInterfaces, software] = await Promise.all([
42
42
  si.version(),
43
43
  si.system(),
44
44
  si.bios(),
@@ -57,6 +57,7 @@ const getStaticData = async () => {
57
57
  si.audio(),
58
58
  si.bluetoothDevices(),
59
59
  si.usb(),
60
+ si.serialPorts(),
60
61
  si.printer(),
61
62
  si.camera(),
62
63
  si.keyboard(),
@@ -85,6 +86,7 @@ const getStaticData = async () => {
85
86
  audio,
86
87
  bluetooth,
87
88
  usb,
89
+ serialPorts,
88
90
  printer,
89
91
  camera,
90
92
  keyboard,
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export { pci } from './pci';
44
44
  export { printer } from './printer';
45
45
  export { processes } from './processes';
46
46
  export { processLoad } from './process-load';
47
+ export { serialPorts } from './serial-ports';
47
48
  export { services } from './services';
48
49
  export { shell } from './shell';
49
50
  export { software } from './software';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.osInfo = exports.observe = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetPublicIp = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.getAllData = exports.getDynamicData = exports.getStaticData = exports.get = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.serialPorts = exports.processLoad = exports.processes = exports.printer = exports.pci = void 0;
5
5
  var audio_1 = require("./audio");
6
6
  Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
7
7
  var baseboard_1 = require("./baseboard");
@@ -102,6 +102,8 @@ var processes_1 = require("./processes");
102
102
  Object.defineProperty(exports, "processes", { enumerable: true, get: function () { return processes_1.processes; } });
103
103
  var process_load_1 = require("./process-load");
104
104
  Object.defineProperty(exports, "processLoad", { enumerable: true, get: function () { return process_load_1.processLoad; } });
105
+ var serial_ports_1 = require("./serial-ports");
106
+ Object.defineProperty(exports, "serialPorts", { enumerable: true, get: function () { return serial_ports_1.serialPorts; } });
105
107
  var services_1 = require("./services");
106
108
  Object.defineProperty(exports, "services", { enumerable: true, get: function () { return services_1.services; } });
107
109
  var shell_1 = require("./shell");
@@ -46,6 +46,7 @@ export { software } from './software';
46
46
  export { system } from './system';
47
47
  export { thunderbolt } from './thunderbolt';
48
48
  export { time } from '../time';
49
+ export { serialPorts } from './serial-ports';
49
50
  export { usb } from './usb';
50
51
  export { users } from './users';
51
52
  export { uuid } from './uuid';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.shell = exports.services = exports.processLoad = exports.processes = exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.inetChecksite = exports.gpu = exports.fullLoad = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.dockerAll = exports.dockerVolumes = exports.dockerContainerProcesses = exports.dockerContainerStats = exports.dockerContainers = exports.dockerImages = exports.dockerInfo = exports.displays = exports.disksIO = exports.diskLayout = exports.currentLoad = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCurrentSpeed = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.versions = exports.version = exports.vboxInfo = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.time = exports.thunderbolt = exports.system = exports.software = void 0;
5
5
  var audio_1 = require("./audio");
6
6
  Object.defineProperty(exports, "audio", { enumerable: true, get: function () { return audio_1.audio; } });
7
7
  var baseboard_1 = require("./baseboard");
@@ -104,6 +104,8 @@ var thunderbolt_1 = require("./thunderbolt");
104
104
  Object.defineProperty(exports, "thunderbolt", { enumerable: true, get: function () { return thunderbolt_1.thunderbolt; } });
105
105
  var time_1 = require("../time");
106
106
  Object.defineProperty(exports, "time", { enumerable: true, get: function () { return time_1.time; } });
107
+ var serial_ports_1 = require("./serial-ports");
108
+ Object.defineProperty(exports, "serialPorts", { enumerable: true, get: function () { return serial_ports_1.serialPorts; } });
107
109
  var usb_1 = require("./usb");
108
110
  Object.defineProperty(exports, "usb", { enumerable: true, get: function () { return usb_1.usb; } });
109
111
  var users_1 = require("./users");
@@ -0,0 +1,2 @@
1
+ import type { SerialPortData } from '../common/types';
2
+ export declare const serialPorts: (sysPath?: string, byIdPath?: string) => Promise<SerialPortData[]>;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialPorts = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const path_1 = require("path");
6
+ const common_1 = require("../common");
7
+ const defaults_1 = require("../common/defaults");
8
+ const files_1 = require("../common/files");
9
+ const busType = (subsystem, name) => {
10
+ switch (subsystem) {
11
+ case 'usb':
12
+ case 'usb-serial':
13
+ return 'usb';
14
+ case 'pnp':
15
+ case 'amba':
16
+ case 'platform':
17
+ case 'of_serial':
18
+ return 'onboard';
19
+ case 'pci':
20
+ return 'pci';
21
+ case 'bluetooth':
22
+ return 'bluetooth';
23
+ default:
24
+ return name.startsWith('rfcomm') ? 'bluetooth' : 'unknown';
25
+ }
26
+ };
27
+ const usbDevicePath = async (devicePath) => {
28
+ let current = devicePath;
29
+ for (let depth = 0; depth < 6; depth++) {
30
+ if (await (0, files_1.fileExists)(`${current}/idVendor`)) {
31
+ return current;
32
+ }
33
+ const parent = (0, path_1.dirname)(current);
34
+ if (parent === current) {
35
+ return '';
36
+ }
37
+ current = parent;
38
+ }
39
+ return '';
40
+ };
41
+ const stableIds = async (path) => {
42
+ const map = {};
43
+ try {
44
+ for (const entry of await (0, promises_1.readdir)(path)) {
45
+ try {
46
+ map[(0, path_1.basename)(await (0, promises_1.readlink)(`${path}/${entry}`))] = entry;
47
+ }
48
+ catch { }
49
+ }
50
+ }
51
+ catch { }
52
+ return map;
53
+ };
54
+ const serialPorts = async (sysPath = '/sys/class/tty', byIdPath = '/dev/serial/by-id') => {
55
+ await (0, common_1.nextTick)();
56
+ const result = [];
57
+ let names = [];
58
+ try {
59
+ names = await (0, promises_1.readdir)(sysPath);
60
+ }
61
+ catch {
62
+ return result;
63
+ }
64
+ const byId = await stableIds(byIdPath);
65
+ for (const name of names.sort()) {
66
+ let devicePath = '';
67
+ try {
68
+ devicePath = await (0, promises_1.realpath)(`${sysPath}/${name}/device`);
69
+ }
70
+ catch {
71
+ continue;
72
+ }
73
+ if ((await (0, files_1.readSysfs)(`${sysPath}/${name}/type`)) === '0') {
74
+ continue;
75
+ }
76
+ let subsystem = '';
77
+ try {
78
+ subsystem = (0, path_1.basename)(await (0, promises_1.realpath)(`${devicePath}/subsystem`));
79
+ }
80
+ catch { }
81
+ const port = {
82
+ ...(0, common_1.cloneObj)(defaults_1.initSerialPortResult),
83
+ device: `/dev/${name}`,
84
+ name,
85
+ type: busType(subsystem, name),
86
+ pnpId: byId[name] || null
87
+ };
88
+ const usbPath = await usbDevicePath(devicePath);
89
+ if (usbPath) {
90
+ port.type = 'usb';
91
+ port.vendorId = (await (0, files_1.readSysfs)(`${usbPath}/idVendor`)).toLowerCase() || null;
92
+ port.productId = (await (0, files_1.readSysfs)(`${usbPath}/idProduct`)).toLowerCase() || null;
93
+ port.manufacturer = (await (0, files_1.readSysfs)(`${usbPath}/manufacturer`)) || null;
94
+ port.serialNumber = (await (0, files_1.readSysfs)(`${usbPath}/serial`)) || null;
95
+ port.name = (await (0, files_1.readSysfs)(`${usbPath}/product`)) || name;
96
+ }
97
+ result.push(port);
98
+ }
99
+ return result;
100
+ };
101
+ exports.serialPorts = serialPorts;
@@ -0,0 +1 @@
1
+ export declare const serialPorts: () => Promise<import("./common/types").SerialPortData[] | null>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialPorts = void 0;
4
+ const const_1 = require("./common/const");
5
+ const serialPorts = async () => {
6
+ switch (true) {
7
+ case const_1.LINUX || const_1.ANDROID:
8
+ return (await import('./linux/serial-ports.js')).serialPorts();
9
+ case const_1.DARWIN:
10
+ return (await import('./darwin/serial-ports.js')).serialPorts();
11
+ case const_1.WINDOWS:
12
+ return (await import('./windows/serial-ports.js')).serialPorts();
13
+ default:
14
+ return null;
15
+ }
16
+ };
17
+ exports.serialPorts = serialPorts;
@@ -49,6 +49,7 @@ export { shell } from './shell';
49
49
  export { software } from './software';
50
50
  export { system } from './system';
51
51
  export { thunderbolt } from './thunderbolt';
52
+ export { serialPorts } from './serial-ports';
52
53
  export { usb } from './usb';
53
54
  export { users } from './users';
54
55
  export { uuid } from './uuid';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printer = exports.pci = exports.osInfo = exports.npu = exports.npm = exports.networkStats = exports.networkInterfaces = exports.networkInterfaceDefault = exports.networkGatewayDefault = exports.networkConnections = exports.mouse = exports.memLayout = exports.mem = exports.keyboard = exports.inetLatency = exports.gpu = exports.fsStats = exports.fsSize = exports.fsOpenFiles = exports.displays = exports.disksIO = exports.diskLayout = exports.fans = exports.cpuTemperature = exports.cpuFlags = exports.cpuCache = exports.cpu = exports.chassis = exports.camera = exports.bluetoothDevices = exports.blockDevices = exports.bios = exports.battery = exports.baseboard = exports.audio = exports.vboxInfo = exports.versions = exports.version = exports.time = exports.inetChecksite = exports.dockerVolumes = exports.dockerInfo = exports.dockerImages = exports.dockerContainerStats = exports.dockerContainers = exports.dockerContainerProcesses = exports.dockerAll = exports.fullLoad = exports.cpuCurrentSpeed = exports.currentLoad = void 0;
4
- exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.uuid = exports.users = exports.usb = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processes = exports.processLoad = void 0;
4
+ exports.wifiNetworks = exports.wifiInterfaces = exports.wifiConnections = exports.uuid = exports.users = exports.usb = exports.serialPorts = exports.thunderbolt = exports.system = exports.software = exports.shell = exports.services = exports.processes = exports.processLoad = void 0;
5
5
  var cpu_current_load_1 = require("../cpu-current-load");
6
6
  Object.defineProperty(exports, "currentLoad", { enumerable: true, get: function () { return cpu_current_load_1.currentLoad; } });
7
7
  var cpu_current_speed_1 = require("../cpu-current-speed");
@@ -110,6 +110,8 @@ var system_1 = require("./system");
110
110
  Object.defineProperty(exports, "system", { enumerable: true, get: function () { return system_1.system; } });
111
111
  var thunderbolt_1 = require("./thunderbolt");
112
112
  Object.defineProperty(exports, "thunderbolt", { enumerable: true, get: function () { return thunderbolt_1.thunderbolt; } });
113
+ var serial_ports_1 = require("./serial-ports");
114
+ Object.defineProperty(exports, "serialPorts", { enumerable: true, get: function () { return serial_ports_1.serialPorts; } });
113
115
  var usb_1 = require("./usb");
114
116
  Object.defineProperty(exports, "usb", { enumerable: true, get: function () { return usb_1.usb; } });
115
117
  var users_1 = require("./users");
@@ -0,0 +1,3 @@
1
+ import type { SerialPortData } from '../common/types';
2
+ export declare const parseSerialPorts: (devices: any[]) => SerialPortData[];
3
+ export declare const serialPorts: () => Promise<SerialPortData[]>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialPorts = exports.parseSerialPorts = void 0;
4
+ const common_1 = require("../common");
5
+ const defaults_1 = require("../common/defaults");
6
+ const windows_1 = require("../common/windows");
7
+ const matchId = (deviceId, key) => {
8
+ const match = new RegExp(`${key}_([0-9A-Fa-f]{4})`).exec(deviceId);
9
+ return match?.[1] ? match[1].toLowerCase() : null;
10
+ };
11
+ const parseSerial = (deviceId) => {
12
+ const ftdi = /PID_[0-9A-Fa-f]{4}\+([^+\\]+)/.exec(deviceId);
13
+ if (ftdi?.[1]) {
14
+ return ftdi[1];
15
+ }
16
+ const last = deviceId.split('\\').pop() || '';
17
+ return last && !last.includes('&') ? last : null;
18
+ };
19
+ const parseType = (deviceId) => {
20
+ const id = deviceId.toUpperCase();
21
+ if (id.startsWith('USB\\') || id.startsWith('FTDIBUS\\')) {
22
+ return 'usb';
23
+ }
24
+ if (id.startsWith('BTHENUM') || id.startsWith('BTHLE')) {
25
+ return 'bluetooth';
26
+ }
27
+ if (id.startsWith('PCI\\')) {
28
+ return 'pci';
29
+ }
30
+ if (id.startsWith('ACPI\\')) {
31
+ return 'onboard';
32
+ }
33
+ if (id.startsWith('ROOT\\') || id.startsWith('SW\\') || id.startsWith('UMB\\')) {
34
+ return 'virtual';
35
+ }
36
+ return 'unknown';
37
+ };
38
+ const parseSerialPorts = (devices) => {
39
+ const result = [];
40
+ for (const device of devices) {
41
+ const name = (device.Name || '').trim();
42
+ const port = /\((COM\d+)\)/.exec(name);
43
+ if (!port?.[1]) {
44
+ continue;
45
+ }
46
+ const deviceId = device.DeviceID || device.PNPDeviceID || '';
47
+ const type = parseType(deviceId);
48
+ result.push({
49
+ ...(0, common_1.cloneObj)(defaults_1.initSerialPortResult),
50
+ device: port[1],
51
+ name: name.replace(/\s*\(COM\d+\)\s*$/, '') || port[1],
52
+ manufacturer: (device.Manufacturer || '').trim() || null,
53
+ serialNumber: type === 'usb' ? parseSerial(deviceId) : null,
54
+ vendorId: matchId(deviceId, 'VID'),
55
+ productId: matchId(deviceId, 'PID'),
56
+ pnpId: deviceId || null,
57
+ type
58
+ });
59
+ }
60
+ return result;
61
+ };
62
+ exports.parseSerialPorts = parseSerialPorts;
63
+ const serialPorts = async () => {
64
+ await (0, common_1.nextTick)();
65
+ try {
66
+ const result = await windows_1.ps.exec(`@(Get-CimInstance Win32_PnPEntity -Filter "Name LIKE '%(COM%'" | Select-Object Name,DeviceID,Manufacturer) | ConvertTo-Json -Depth 3`);
67
+ return (0, exports.parseSerialPorts)((0, windows_1.psArray)(result));
68
+ }
69
+ catch {
70
+ return [];
71
+ }
72
+ };
73
+ exports.serialPorts = serialPorts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "6.0.0-beta.7",
3
+ "version": "6.0.0-beta.8",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",