@nordicsemiconductor/nrf-jlink-js 0.0.9 → 0.0.10

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/dist/jlink.d.ts CHANGED
@@ -10,6 +10,6 @@ interface JLinkState {
10
10
  installedVersion?: string;
11
11
  }
12
12
  export declare const getVersionToInstall: (fallbackVersion?: string) => Promise<JLinkState>;
13
- export declare const downloadAndSaveJLink: (destination: string, onUpdate?: (update: Update) => void) => Promise<string>;
13
+ export declare const downloadAndSaveJLink: (destinationDir: string, destinationFileName?: string, onUpdate?: (update: Update) => void) => Promise<string>;
14
14
  export declare const downloadAndInstallJLink: (onUpdate?: (update: Update) => void) => Promise<void>;
15
15
  export {};
package/dist/jlink.js CHANGED
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
38
47
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
49
  };
@@ -102,70 +111,77 @@ var getInstalledJLinkVersion = function () {
102
111
  });
103
112
  });
104
113
  };
105
- var downloadJLink = function (_a, onUpdate_1, destinationFilePath_1) { return __awaiter(void 0, [_a, onUpdate_1, destinationFilePath_1], void 0, function (_b, onUpdate, destinationFilePath) {
106
- var platform, arch, url, response, hasContentLength, contentLength, reader, chunks, receivedLength, _c, done, value, chunksAll, position;
107
- var _d, _e;
108
- var jlinkUrls = _b.jlinkUrls;
109
- return __generator(this, function (_f) {
110
- switch (_f.label) {
111
- case 0:
112
- platform = os_1.default.platform();
113
- arch = os_1.default.arch();
114
- // @ts-expect-error It is quite literally checked right before
115
- if (!(platform in jlinkUrls) || !(arch in jlinkUrls[platform])) {
116
- throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
117
- }
118
- url = (_d = jlinkUrls[platform]) === null || _d === void 0 ? void 0 : _d[arch];
119
- if (!url) {
120
- throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
121
- }
122
- return [4 /*yield*/, fetch(url, {
123
- headers: {
124
- Range: 'bytes=0-',
125
- },
126
- })];
127
- case 1:
128
- response = _f.sent();
129
- if (!response.ok) {
130
- throw new Error("Unable to download ".concat(url, ". Got status code ").concat(status, "."));
131
- }
132
- hasContentLength = response.headers.has('content-length');
133
- contentLength = hasContentLength
134
- ? Number(response.headers.get('content-length'))
135
- : 1;
136
- reader = (_e = response.body) === null || _e === void 0 ? void 0 : _e.getReader();
137
- chunks = [];
138
- receivedLength = 0;
139
- _f.label = 2;
140
- case 2:
141
- if (!reader) return [3 /*break*/, 4];
142
- return [4 /*yield*/, reader.read()];
143
- case 3:
144
- _c = _f.sent(), done = _c.done, value = _c.value;
145
- if (done) {
146
- return [3 /*break*/, 4];
147
- }
148
- chunks.push(value);
149
- receivedLength += value.length;
150
- onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
151
- step: 'download',
152
- percentage: hasContentLength
153
- ? Number(((receivedLength / contentLength) * 100).toFixed(2))
154
- : 0,
155
- });
156
- return [3 /*break*/, 2];
157
- case 4:
158
- chunksAll = new Uint8Array(receivedLength);
159
- position = 0;
160
- chunks.forEach(function (chunk) {
161
- chunksAll.set(chunk, position);
162
- position += chunk.length;
163
- });
164
- return [4 /*yield*/, (0, common_1.saveToFile)(destinationFilePath || path_1.default.join(os_1.default.tmpdir(), path_1.default.basename(url)), Buffer.from(chunksAll))];
165
- case 5: return [2 /*return*/, _f.sent()];
166
- }
114
+ var downloadJLink = function (_a, onUpdate_1) {
115
+ var args_1 = [];
116
+ for (var _i = 2; _i < arguments.length; _i++) {
117
+ args_1[_i - 2] = arguments[_i];
118
+ }
119
+ return __awaiter(void 0, __spreadArray([_a, onUpdate_1], args_1, true), void 0, function (_b, onUpdate, destinationDir, destinationFileName) {
120
+ var platform, arch, url, response, hasContentLength, contentLength, reader, chunks, receivedLength, _c, done, value, chunksAll, position;
121
+ var _d, _e;
122
+ var jlinkUrls = _b.jlinkUrls;
123
+ if (destinationDir === void 0) { destinationDir = os_1.default.tmpdir(); }
124
+ return __generator(this, function (_f) {
125
+ switch (_f.label) {
126
+ case 0:
127
+ platform = os_1.default.platform();
128
+ arch = os_1.default.arch();
129
+ // @ts-expect-error It is quite literally checked right before
130
+ if (!(platform in jlinkUrls) || !(arch in jlinkUrls[platform])) {
131
+ throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
132
+ }
133
+ url = (_d = jlinkUrls[platform]) === null || _d === void 0 ? void 0 : _d[arch];
134
+ if (!url) {
135
+ throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
136
+ }
137
+ return [4 /*yield*/, fetch(url, {
138
+ headers: {
139
+ Range: 'bytes=0-',
140
+ },
141
+ })];
142
+ case 1:
143
+ response = _f.sent();
144
+ if (!response.ok) {
145
+ throw new Error("Unable to download ".concat(url, ". Got status code ").concat(status, "."));
146
+ }
147
+ hasContentLength = response.headers.has('content-length');
148
+ contentLength = hasContentLength
149
+ ? Number(response.headers.get('content-length'))
150
+ : 1;
151
+ reader = (_e = response.body) === null || _e === void 0 ? void 0 : _e.getReader();
152
+ chunks = [];
153
+ receivedLength = 0;
154
+ _f.label = 2;
155
+ case 2:
156
+ if (!reader) return [3 /*break*/, 4];
157
+ return [4 /*yield*/, reader.read()];
158
+ case 3:
159
+ _c = _f.sent(), done = _c.done, value = _c.value;
160
+ if (done) {
161
+ return [3 /*break*/, 4];
162
+ }
163
+ chunks.push(value);
164
+ receivedLength += value.length;
165
+ onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
166
+ step: 'download',
167
+ percentage: hasContentLength
168
+ ? Number(((receivedLength / contentLength) * 100).toFixed(2))
169
+ : 0,
170
+ });
171
+ return [3 /*break*/, 2];
172
+ case 4:
173
+ chunksAll = new Uint8Array(receivedLength);
174
+ position = 0;
175
+ chunks.forEach(function (chunk) {
176
+ chunksAll.set(chunk, position);
177
+ position += chunk.length;
178
+ });
179
+ return [4 /*yield*/, (0, common_1.saveToFile)(path_1.default.join(destinationDir, destinationFileName || path_1.default.basename(url)), Buffer.from(chunksAll))];
180
+ case 5: return [2 /*return*/, _f.sent()];
181
+ }
182
+ });
167
183
  });
168
- }); };
184
+ };
169
185
  var installJLink = function (installerPath, onUpdate) {
170
186
  var command;
171
187
  var args;
@@ -235,7 +251,7 @@ var getVersionToInstall = function (fallbackVersion) { return __awaiter(void 0,
235
251
  });
236
252
  }); };
237
253
  exports.getVersionToInstall = getVersionToInstall;
238
- var downloadAndSaveJLink = function (destination, onUpdate) { return (0, common_1.fetchIndex)().then(function (v) { return downloadJLink(v, onUpdate, destination); }); };
254
+ var downloadAndSaveJLink = function (destinationDir, destinationFileName, onUpdate) { return (0, common_1.fetchIndex)().then(function (v) { return downloadJLink(v, onUpdate, destinationDir, destinationFileName); }); };
239
255
  exports.downloadAndSaveJLink = downloadAndSaveJLink;
240
256
  var downloadAndInstallJLink = function (onUpdate) {
241
257
  return (0, common_1.fetchIndex)()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nordicsemiconductor/nrf-jlink-js",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "main": "dist",
5
5
  "types": "dist",
6
6
  "files": [