Skip to content

Commit b26514b

Browse files
authored
node: replace native-reg with call to reg query (#250)
Co-authored-by: Sebastian Alex <[email protected]>
1 parent da813bc commit b26514b

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

package-lock.json

+1-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/node/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
},
5151
"dependencies": {
5252
"@backtrace/sdk-core": "^0.3.2",
53-
"form-data": "^4.0.0",
54-
"native-reg": "^1.1.1"
53+
"form-data": "^4.0.0"
5554
}
5655
}

packages/node/src/attributes/MachineIdentitfierAttributeProvider.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { BacktraceAttributeProvider, IdGenerator } from '@backtrace/sdk-core';
22
import { execSync } from 'child_process';
3-
import { getValue, HKEY } from 'native-reg';
43

54
export class MachineIdentitfierAttributeProvider implements BacktraceAttributeProvider {
65
public static readonly SUPPORTED_PLATFORMS = ['win32', 'darwin', 'linux', 'freebsd'];
76
private readonly MACHINE_ID_ATTRIBUTE = 'guid';
87

98
private readonly COMMANDS = {
9+
win32: 'reg query "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Cryptography" /v MachineGuid',
1010
darwin: 'ioreg -rd1 -c IOPlatformExpertDevice',
1111
linux: '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :',
1212
freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid',
@@ -26,8 +26,9 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr
2626
public generateGuid() {
2727
switch (process.platform) {
2828
case 'win32': {
29-
return this.getWindowsMachineId()
30-
?.replace(/\r+|\n+|\s+/gi, '')
29+
return execSync(this.COMMANDS['win32'])
30+
.toString()
31+
.match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i)?.[0]
3132
.toLowerCase();
3233
}
3334
case 'darwin': {
@@ -50,9 +51,4 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr
5051
}
5152
}
5253
}
53-
54-
private getWindowsMachineId() {
55-
const regVal = getValue(HKEY.LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Cryptography', 'MachineGuid');
56-
return regVal?.toString();
57-
}
5854
}

0 commit comments

Comments
 (0)