@nordicsemiconductor/nrf-jlink-js 0.0.11 → 0.9.1

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.
Files changed (2) hide show
  1. package/dist/jlink.js +25 -39
  2. package/package.json +1 -1
package/dist/jlink.js CHANGED
@@ -55,6 +55,7 @@ var path_1 = __importDefault(require("path"));
55
55
  var semver_1 = __importDefault(require("semver"));
56
56
  var fs_1 = require("fs");
57
57
  var common_1 = require("./common");
58
+ var util_1 = require("util");
58
59
  function winRegQuery(key) {
59
60
  var _a;
60
61
  if (process.platform !== 'win32') {
@@ -67,16 +68,18 @@ function winRegQuery(key) {
67
68
  return (0, child_process_1.execSync)("".concat(reg, " query ").concat(key)).toString().trim();
68
69
  }
69
70
  var getJLinkExePath = function () {
71
+ var _a;
70
72
  switch (os_1.default.platform()) {
71
73
  case 'win32':
72
- var jlinkDir = winRegQuery('HKEY_CURRENT_USER\\Software\\SEGGER\\J-Link /v InstallPath');
73
- if (!jlinkDir) {
74
- jlinkDir = winRegQuery('HKEY_LOCAL_MACHINE\\Software\\SEGGER\\J-Link /v InstallPath');
74
+ var cwd = winRegQuery('HKEY_CURRENT_USER\\Software\\SEGGER\\J-Link /v InstallPath');
75
+ if (!cwd) {
76
+ cwd = winRegQuery('HKEY_LOCAL_MACHINE\\Software\\SEGGER\\J-Link /v InstallPath');
75
77
  }
76
- if (!jlinkDir) {
78
+ cwd = ((_a = /InstallPath\s+\w+\s+(.*)/.exec(cwd)) !== null && _a !== void 0 ? _a : [])[1];
79
+ if (!cwd) {
77
80
  throw new Error('JLink not installed');
78
81
  }
79
- return path_1.default.resolve(jlinkDir, 'JLink.exe');
82
+ return "\"".concat(path_1.default.join(cwd, 'JLink.exe'), "\"");
80
83
  case 'linux':
81
84
  case 'darwin':
82
85
  return 'JLinkExe';
@@ -84,40 +87,23 @@ var getJLinkExePath = function () {
84
87
  throw new Error('Invalid platform');
85
88
  }
86
89
  };
87
- function killProcess(childProcess, signal) {
88
- var pid = typeof childProcess === 'number' ? childProcess : childProcess === null || childProcess === void 0 ? void 0 : childProcess.pid;
89
- if (!pid) {
90
- return;
91
- }
92
- if (process.platform === 'win32') {
93
- (0, child_process_1.spawn)('taskkill', ['/pid', "".concat(pid), '/f', '/t']);
94
- }
95
- else {
96
- process.kill(pid, signal);
97
- }
98
- }
99
- var getInstalledJLinkVersion = function () {
100
- return new Promise(function (resolve, reject) {
101
- var jlinkExeCmd = (0, child_process_1.spawn)(getJLinkExePath(), ['-NoGUI', '1', '-USB', '0'], {
102
- shell: true,
103
- });
104
- var output = '';
105
- var timeout = setTimeout(function () {
106
- killProcess(jlinkExeCmd.pid);
107
- reject(new Error("Timeout while waiting for J-Link version. Output: ".concat(output)));
108
- }, 5000);
109
- var versionRegExp = /^SEGGER J-Link Commander V([0-9a-z.]+) .*$/m;
110
- jlinkExeCmd.stdout.on('data', function (data) {
111
- output += data.toString();
112
- var match = output.match(versionRegExp);
113
- if (match === null || match === void 0 ? void 0 : match[1]) {
114
- clearTimeout(timeout);
115
- killProcess(jlinkExeCmd.pid);
116
- resolve(match[1]);
117
- }
118
- });
90
+ var getInstalledJLinkVersion = function () { return __awaiter(void 0, void 0, void 0, function () {
91
+ var output, versionRegExp, match;
92
+ var _a;
93
+ return __generator(this, function (_b) {
94
+ switch (_b.label) {
95
+ case 0: return [4 /*yield*/, (0, util_1.promisify)(child_process_1.exec)("".concat(getJLinkExePath(), " -CommandFile foo")).catch(function (e) { return e; })];
96
+ case 1:
97
+ output = _b.sent();
98
+ versionRegExp = /^SEGGER J-Link Commander V([0-9a-z.]+) .*$/m;
99
+ match = (_a = output.stdout.match(versionRegExp)) === null || _a === void 0 ? void 0 : _a[1];
100
+ if (!match) {
101
+ throw new Error("Couldn't get jlink version.");
102
+ }
103
+ return [2 /*return*/, "v".concat(match)];
104
+ }
119
105
  });
120
- };
106
+ }); };
121
107
  var downloadJLink = function (_a, onUpdate_1) {
122
108
  var args_1 = [];
123
109
  for (var _i = 2; _i < arguments.length; _i++) {
@@ -202,7 +188,7 @@ var installJLink = function (installerPath, onUpdate) {
202
188
  args = ['sh', '-c', "dpkg -i \"".concat(installerPath, "\"")];
203
189
  break;
204
190
  case 'win32':
205
- command = "\"".concat(installerPath, "\"");
191
+ command = installerPath;
206
192
  break;
207
193
  default:
208
194
  throw new Error('Invalid platform');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nordicsemiconductor/nrf-jlink-js",
3
- "version": "0.0.11",
3
+ "version": "0.9.1",
4
4
  "main": "dist",
5
5
  "types": "dist",
6
6
  "files": [