-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch.js
More file actions
26 lines (22 loc) · 731 Bytes
/
patch.js
File metadata and controls
26 lines (22 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const fs = require('fs');
const path = 'node_modules/@serialport/bindings-cpp/dist/linux-list.js';
const data = fs.readFileSync(path, {
encoding: 'utf8',
});
if(data.includes('checkPathOfDevicePatched')) {
// Already patched
process.exit(0);
}
// Replace the checkPathOfDevice() call
const data2 = data.replace('if (checkPathOfDevice(', 'if (checkPathOfDevicePatched(');
if(data == data2) {
throw new Error("Failed to patch call");
}
// Append the patched version of checkPathOfDevice()
const data3 = data2 + `
function checkPathOfDevicePatched(path) { // Added by patch.js
return (path && /bus\\/usb/.test(path)) || checkPathOfDevice(path);
}
`;
fs.copyFileSync(path, path + '.unpatched');
fs.writeFileSync(path, data3);