@nordicsemiconductor/pc-nrfconnect-shared 213.0.0 → 215.0.0

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 (105) hide show
  1. package/Changelog.md +32 -0
  2. package/nrfutil/collectingResultParser.ts +82 -0
  3. package/nrfutil/common.ts +41 -0
  4. package/nrfutil/device/batch.ts +25 -62
  5. package/nrfutil/device/batchTypes.ts +8 -46
  6. package/nrfutil/device/boardController.ts +2 -2
  7. package/nrfutil/device/common.ts +6 -10
  8. package/nrfutil/device/deviceInfo.ts +4 -3
  9. package/nrfutil/device/erase.ts +4 -3
  10. package/nrfutil/device/getBoardControllerConfig.ts +2 -2
  11. package/nrfutil/device/getBoardControllerVersion.ts +2 -2
  12. package/nrfutil/device/getCoreInfo.ts +4 -3
  13. package/nrfutil/device/getFwInfo.ts +4 -3
  14. package/nrfutil/device/getProtectionStatus.ts +4 -3
  15. package/nrfutil/device/list.ts +5 -10
  16. package/nrfutil/device/logLibVersions.ts +8 -69
  17. package/nrfutil/device/program.ts +60 -66
  18. package/nrfutil/device/recover.ts +4 -3
  19. package/nrfutil/device/reset.ts +7 -13
  20. package/nrfutil/device/setMcuState.ts +2 -2
  21. package/nrfutil/device/setProtectionStatus.ts +4 -3
  22. package/nrfutil/device/xRead.ts +26 -28
  23. package/nrfutil/index.ts +2 -3
  24. package/nrfutil/modules.ts +10 -15
  25. package/nrfutil/sandbox.ts +162 -327
  26. package/nrfutil/sandboxTypes.ts +4 -43
  27. package/nrfutil/{jlinkVersion.test.ts → version/jlinkVersion.test.ts} +1 -1
  28. package/nrfutil/{jlinkVersion.ts → version/jlinkVersion.ts} +2 -2
  29. package/nrfutil/{moduleVersion.ts → version/moduleVersion.ts} +44 -7
  30. package/package.json +1 -1
  31. package/scripts/nordic-publish.js +4 -2
  32. package/scripts/nordic-publish.ts +44 -7
  33. package/src/StateSelector/StateSelector.tsx +45 -8
  34. package/src/logging/index.ts +0 -1
  35. package/src/utils/systemReport.ts +17 -1
  36. package/typings/generated/nrfutil/collectingResultParser.d.ts +19 -0
  37. package/typings/generated/nrfutil/collectingResultParser.d.ts.map +1 -0
  38. package/typings/generated/nrfutil/common.d.ts +6 -0
  39. package/typings/generated/nrfutil/common.d.ts.map +1 -0
  40. package/typings/generated/nrfutil/device/__mocks__/device.d.ts +1 -1
  41. package/typings/generated/nrfutil/device/batch.d.ts +6 -4
  42. package/typings/generated/nrfutil/device/batch.d.ts.map +1 -1
  43. package/typings/generated/nrfutil/device/batchTypes.d.ts +8 -30
  44. package/typings/generated/nrfutil/device/batchTypes.d.ts.map +1 -1
  45. package/typings/generated/nrfutil/device/boardController.d.ts +2 -2
  46. package/typings/generated/nrfutil/device/boardController.d.ts.map +1 -1
  47. package/typings/generated/nrfutil/device/common.d.ts +4 -3
  48. package/typings/generated/nrfutil/device/common.d.ts.map +1 -1
  49. package/typings/generated/nrfutil/device/device.d.ts +14 -14
  50. package/typings/generated/nrfutil/device/deviceInfo.d.ts +2 -2
  51. package/typings/generated/nrfutil/device/deviceInfo.d.ts.map +1 -1
  52. package/typings/generated/nrfutil/device/erase.d.ts +2 -2
  53. package/typings/generated/nrfutil/device/erase.d.ts.map +1 -1
  54. package/typings/generated/nrfutil/device/getBoardControllerConfig.d.ts +2 -2
  55. package/typings/generated/nrfutil/device/getBoardControllerConfig.d.ts.map +1 -1
  56. package/typings/generated/nrfutil/device/getBoardControllerVersion.d.ts +2 -2
  57. package/typings/generated/nrfutil/device/getBoardControllerVersion.d.ts.map +1 -1
  58. package/typings/generated/nrfutil/device/getCoreInfo.d.ts +2 -2
  59. package/typings/generated/nrfutil/device/getCoreInfo.d.ts.map +1 -1
  60. package/typings/generated/nrfutil/device/getFwInfo.d.ts +2 -2
  61. package/typings/generated/nrfutil/device/getFwInfo.d.ts.map +1 -1
  62. package/typings/generated/nrfutil/device/getProtectionStatus.d.ts +2 -2
  63. package/typings/generated/nrfutil/device/getProtectionStatus.d.ts.map +1 -1
  64. package/typings/generated/nrfutil/device/list.d.ts.map +1 -1
  65. package/typings/generated/nrfutil/device/logLibVersions.d.ts +2 -2
  66. package/typings/generated/nrfutil/device/logLibVersions.d.ts.map +1 -1
  67. package/typings/generated/nrfutil/device/program.d.ts +13 -13
  68. package/typings/generated/nrfutil/device/program.d.ts.map +1 -1
  69. package/typings/generated/nrfutil/device/recover.d.ts +2 -2
  70. package/typings/generated/nrfutil/device/recover.d.ts.map +1 -1
  71. package/typings/generated/nrfutil/device/reset.d.ts +2 -2
  72. package/typings/generated/nrfutil/device/reset.d.ts.map +1 -1
  73. package/typings/generated/nrfutil/device/setMcuState.d.ts +2 -2
  74. package/typings/generated/nrfutil/device/setMcuState.d.ts.map +1 -1
  75. package/typings/generated/nrfutil/device/setProtectionStatus.d.ts +2 -2
  76. package/typings/generated/nrfutil/device/setProtectionStatus.d.ts.map +1 -1
  77. package/typings/generated/nrfutil/device/xRead.d.ts +9 -2
  78. package/typings/generated/nrfutil/device/xRead.d.ts.map +1 -1
  79. package/typings/generated/nrfutil/index.d.ts +2 -3
  80. package/typings/generated/nrfutil/index.d.ts.map +1 -1
  81. package/typings/generated/nrfutil/modules.d.ts +1 -1
  82. package/typings/generated/nrfutil/modules.d.ts.map +1 -1
  83. package/typings/generated/nrfutil/sandbox.d.ts +27 -35
  84. package/typings/generated/nrfutil/sandbox.d.ts.map +1 -1
  85. package/typings/generated/nrfutil/sandboxTypes.d.ts +4 -29
  86. package/typings/generated/nrfutil/sandboxTypes.d.ts.map +1 -1
  87. package/typings/generated/nrfutil/{jlinkVersion.d.ts → version/jlinkVersion.d.ts} +1 -1
  88. package/typings/generated/nrfutil/version/jlinkVersion.d.ts.map +1 -0
  89. package/typings/generated/nrfutil/version/jlinkVersion.test.d.ts.map +1 -0
  90. package/typings/generated/nrfutil/version/moduleVersion.d.ts +40 -0
  91. package/typings/generated/nrfutil/version/moduleVersion.d.ts.map +1 -0
  92. package/typings/generated/nrfutil/version/version.d.ts.map +1 -0
  93. package/typings/generated/src/StateSelector/StateSelector.d.ts +3 -2
  94. package/typings/generated/src/StateSelector/StateSelector.d.ts.map +1 -1
  95. package/typings/generated/src/logging/index.d.ts.map +1 -1
  96. package/typings/generated/src/utils/systemReport.d.ts.map +1 -1
  97. package/src/StateSelector/state-selector.scss +0 -40
  98. package/typings/generated/nrfutil/jlinkVersion.d.ts.map +0 -1
  99. package/typings/generated/nrfutil/jlinkVersion.test.d.ts.map +0 -1
  100. package/typings/generated/nrfutil/moduleVersion.d.ts +0 -12
  101. package/typings/generated/nrfutil/moduleVersion.d.ts.map +0 -1
  102. package/typings/generated/nrfutil/version.d.ts.map +0 -1
  103. /package/nrfutil/{version.ts → version/version.ts} +0 -0
  104. /package/typings/generated/nrfutil/{jlinkVersion.test.d.ts → version/jlinkVersion.test.d.ts} +0 -0
  105. /package/typings/generated/nrfutil/{version.d.ts → version/version.d.ts} +0 -0
package/Changelog.md CHANGED
@@ -7,6 +7,28 @@ This project does _not_ adhere to
7
7
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html) but contrary to it
8
8
  every new version is a new major version.
9
9
 
10
+ ## 215.0.0 - 2025-06-27
11
+
12
+ ### Added
13
+
14
+ - `generateSystemReport` now includes relevant app information.
15
+
16
+ ### Changed
17
+
18
+ - StateSelector:Refactored with tailwind. Added `size` prop to control the
19
+ height of the selector.
20
+
21
+ ## 214.0.0 - 2025-06-17
22
+
23
+ ### Changed
24
+
25
+ - macOS: Removed check if the universal variant of J-Link is used.
26
+
27
+ ### Fixed
28
+
29
+ - While publishing apps, updated files on files.nordicsemi.com might become
30
+ stale on files.nordicsemi.cn.
31
+
10
32
  ## 213.0.0 - 2025-06-11
11
33
 
12
34
  ### Fixed
@@ -19,10 +41,20 @@ every new version is a new major version.
19
41
 
20
42
  - Specify what core version of nrfutil an app depends on.
21
43
 
44
+ ### Removed
45
+
46
+ - Function `prepareSandbox`.
47
+
48
+ ### Changed
49
+
50
+ - Signature of `xRead`.
51
+
22
52
  ### Steps to upgrade when using this package
23
53
 
24
54
  - In apps in `package.json` set the field `nrfConnectForDesktop.nrfutilCore`
25
55
  to the core version of nrfutil that the nrfutil commands will use.
56
+ - Replace usage of `prepareSandbox` with `NrfutilSandbox.create`
57
+ - Update calls of `xRead`.
26
58
 
27
59
  ## 211.0.0 - 2025-05-29
28
60
 
@@ -0,0 +1,82 @@
1
+ /*
2
+ * Copyright (c) 2025 Nordic Semiconductor ASA
3
+ *
4
+ * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
+ */
6
+
7
+ import { convertNrfutilProgress, parseJsonBuffers } from './common';
8
+ import type {
9
+ NrfutilJson,
10
+ OnLog,
11
+ OnProgress,
12
+ OnTaskBegin,
13
+ OnTaskEnd,
14
+ TaskEnd,
15
+ } from './sandboxTypes';
16
+
17
+ const addPunctuation = (str: string) =>
18
+ str.endsWith('.') ? str.trim() : `${str.trim()}.`;
19
+
20
+ export default class CollectingResultParser<Result> {
21
+ private readonly info: Result[] = [];
22
+ private readonly taskEnd: TaskEnd<Result>[] = [];
23
+
24
+ // eslint-disable-next-line no-useless-constructor
25
+ constructor(
26
+ private onLog: OnLog,
27
+ private onProgress?: OnProgress,
28
+ private onTaskBegin?: OnTaskBegin,
29
+ private onTaskEnd?: OnTaskEnd<Result>
30
+ ) {}
31
+
32
+ public handleData = (data: Buffer, pid?: number) => {
33
+ const parsedData: NrfutilJson<Result>[] | undefined =
34
+ parseJsonBuffers(data);
35
+
36
+ if (!parsedData) {
37
+ return data;
38
+ }
39
+
40
+ const processItem = (item: NrfutilJson<Result>) => {
41
+ switch (item.type) {
42
+ case 'task_progress':
43
+ this.onProgress?.(
44
+ convertNrfutilProgress(item.data.progress),
45
+ item.data.task
46
+ );
47
+ break;
48
+ case 'task_begin':
49
+ this.onTaskBegin?.(item.data);
50
+ break;
51
+ case 'task_end':
52
+ this.taskEnd.push(item.data);
53
+ this.onTaskEnd?.(item.data);
54
+ break;
55
+ case 'info':
56
+ this.info.push(item.data);
57
+ break;
58
+ case 'log':
59
+ this.onLog(item.data, pid);
60
+ break;
61
+ case 'batch_update':
62
+ processItem(item.data.data);
63
+ break;
64
+ }
65
+ };
66
+
67
+ parsedData.forEach(processItem);
68
+ };
69
+
70
+ public hasFailures = () =>
71
+ this.taskEnd.filter(({ result }) => result === 'fail').length > 0;
72
+
73
+ public errorMessage = () =>
74
+ this.taskEnd
75
+ .filter(end => end.result === 'fail' && !!end.message)
76
+ .map(end =>
77
+ end.message ? `Message: ${addPunctuation(end.message)}` : ''
78
+ )
79
+ .join('\n');
80
+
81
+ public result = () => ({ taskEnd: this.taskEnd, info: this.info });
82
+ }
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright (c) 2025 Nordic Semiconductor ASA
3
+ *
4
+ * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
+ */
6
+
7
+ import type { NrfutilProgress, Progress } from './sandboxTypes';
8
+
9
+ export const convertNrfutilProgress = (progress: NrfutilProgress): Progress => {
10
+ const amountOfSteps = progress.amountOfSteps ?? 1;
11
+ const step = progress.step ?? 1;
12
+
13
+ const singleStepWeight = (1 / amountOfSteps) * 100;
14
+
15
+ const totalProgressPercentage =
16
+ singleStepWeight * (step - 1) +
17
+ progress.progressPercentage / amountOfSteps;
18
+
19
+ return {
20
+ ...progress,
21
+ stepProgressPercentage: progress.progressPercentage,
22
+ totalProgressPercentage,
23
+ amountOfSteps,
24
+ step,
25
+ };
26
+ };
27
+
28
+ export const parseJsonBuffers = <T>(data: Buffer): T[] | undefined => {
29
+ const dataString = data.toString().trim();
30
+ if (!dataString.endsWith('}')) {
31
+ return undefined;
32
+ }
33
+ try {
34
+ return JSON.parse(`[${dataString.replaceAll('}\n{', '}\n,{')}]`) ?? [];
35
+ } catch {
36
+ return undefined;
37
+ }
38
+ };
39
+
40
+ export const collectErrorMessages = (...messages: (string | undefined)[]) =>
41
+ messages.filter(Boolean).join('\n').replaceAll('Error: ', '');
@@ -5,14 +5,12 @@
5
5
  */
6
6
 
7
7
  import fs from 'fs';
8
- import os from 'os';
9
- import path from 'path';
10
- import { v4 as uuid } from 'uuid';
11
8
 
12
9
  import { getModule } from '..';
13
10
  import { TaskEnd } from '../sandboxTypes';
14
11
  import { BatchOperationWrapper, Callbacks } from './batchTypes';
15
12
  import {
13
+ coreArg,
16
14
  DeviceCore,
17
15
  DeviceTraits,
18
16
  deviceTraitsToArgs,
@@ -23,11 +21,18 @@ import { DeviceCoreInfo } from './getCoreInfo';
23
21
  import { FWInfo } from './getFwInfo';
24
22
  import { GetProtectionStatusResult } from './getProtectionStatus';
25
23
  import {
26
- FirmwareType,
24
+ createTempFile,
25
+ Firmware,
27
26
  ProgrammingOptions,
28
27
  programmingOptionsToArgs,
29
28
  } from './program';
30
- import { MemoryReadRaw, ReadResult, toIntelHex } from './xRead';
29
+ import {
30
+ MemoryReadRaw,
31
+ ReadResult,
32
+ toIntelHex,
33
+ type XReadOptions,
34
+ xReadOptionsToArgs,
35
+ } from './xRead';
31
36
 
32
37
  type BatchOperationWrapperUnknown = BatchOperationWrapper<unknown>;
33
38
  type CallbacksUnknown = Callbacks<unknown>;
@@ -45,7 +50,7 @@ export class Batch {
45
50
  private enqueueBatchOperationObject(
46
51
  command: string,
47
52
  core: DeviceCore,
48
- callbacks?: Callbacks<unknown>,
53
+ callbacks?: CallbacksUnknown,
49
54
  args: string[] = []
50
55
  ) {
51
56
  const getPromise = async () => {
@@ -55,9 +60,7 @@ export class Batch {
55
60
  await box.singleInfoOperationOptionalData<object>(
56
61
  command,
57
62
  undefined,
58
- ['--generate', ...(core ? ['--core', core] : [])].concat(
59
- args
60
- )
63
+ ['--generate', ...coreArg(core), ...args]
61
64
  );
62
65
 
63
66
  return {
@@ -160,28 +163,9 @@ export class Batch {
160
163
 
161
164
  public xRead(
162
165
  core: DeviceCore,
163
- address: number,
164
- bytes: number,
165
- width?: 8 | 15 | 32,
166
- direct?: boolean,
166
+ options: XReadOptions,
167
167
  callbacks?: Callbacks<ReadResult>
168
168
  ) {
169
- const args: string[] = [
170
- '--address',
171
- address.toString(),
172
- '--bytes',
173
- bytes.toString(),
174
- ];
175
-
176
- if (direct) {
177
- args.push('--direct');
178
- }
179
-
180
- if (width) {
181
- args.push('--width');
182
- args.push(width.toString());
183
- }
184
-
185
169
  this.enqueueBatchOperationObject(
186
170
  'x-read',
187
171
  core,
@@ -204,7 +188,7 @@ export class Batch {
204
188
  }
205
189
  },
206
190
  } as CallbacksUnknown,
207
- args
191
+ xReadOptionsToArgs(options)
208
192
  );
209
193
 
210
194
  return this;
@@ -247,52 +231,31 @@ export class Batch {
247
231
  }
248
232
 
249
233
  public program(
250
- firmware: FirmwareType,
234
+ firmware: Firmware,
251
235
  core: DeviceCore,
252
236
  programmingOptions?: ProgrammingOptions,
253
237
  deviceTraits?: DeviceTraits,
254
- callbacks?: Callbacks
238
+ callbacks?: CallbacksUnknown
255
239
  ) {
256
- let args = [
240
+ const args = [
257
241
  ...(deviceTraits ? deviceTraitsToArgs(deviceTraits) : []),
258
242
  ...programmingOptionsToArgs(programmingOptions),
259
243
  ];
260
- let newCallbacks = { ...callbacks };
244
+ const newCallbacks = { ...callbacks };
261
245
 
262
246
  if (typeof firmware === 'string') {
263
- args = ['--firmware', firmware].concat(args);
247
+ args.unshift('--firmware', firmware);
264
248
  } else {
265
- const saveTemp = (): string => {
266
- let tempFilePath;
267
- do {
268
- tempFilePath = path.join(
269
- os.tmpdir(),
270
- `${uuid()}.${firmware.type}`
271
- );
272
- } while (fs.existsSync(tempFilePath));
249
+ const tempFilePath = createTempFile(firmware);
250
+ args.unshift('--firmware', tempFilePath);
273
251
 
274
- fs.writeFileSync(tempFilePath, firmware.buffer);
275
-
276
- return tempFilePath;
252
+ newCallbacks.onTaskEnd = (taskEnd: TaskEnd<unknown>) => {
253
+ fs.unlinkSync(tempFilePath);
254
+ callbacks?.onTaskEnd?.(taskEnd);
277
255
  };
278
- const tempFilePath = saveTemp();
279
- args = ['--firmware', tempFilePath].concat(args);
280
-
281
- newCallbacks = {
282
- ...callbacks,
283
- onTaskEnd: (taskEnd: TaskEnd<void>) => {
284
- fs.unlinkSync(tempFilePath);
285
- callbacks?.onTaskEnd?.(taskEnd);
286
- },
287
- } as CallbacksUnknown;
288
256
  }
289
257
 
290
- this.enqueueBatchOperationObject(
291
- 'program',
292
- core,
293
- newCallbacks as CallbacksUnknown,
294
- args
295
- );
258
+ this.enqueueBatchOperationObject('program', core, newCallbacks, args);
296
259
 
297
260
  return this;
298
261
  }
@@ -4,27 +4,21 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress, Task, TaskBegin, TaskEnd } from '../sandboxTypes';
8
- import { DeviceCore, ResetKind } from './common';
9
- import {
10
- isJLinkProgrammingOptions,
11
- isMcuBootProgrammingOptions,
12
- isNordicDfuProgrammingOptions,
13
- ProgrammingOptions,
14
- } from './program';
7
+ import type { OnProgress, OnTaskBegin, OnTaskEnd } from '../sandboxTypes';
8
+ import { type DeviceCore, type ResetKind } from './common';
15
9
 
16
10
  export interface BatchOperationWrapper<T = void> {
17
11
  operation: object;
18
- onProgress?: (progress: Progress, task?: Task) => void;
19
- onTaskBegin?: TaskBeginCallback;
20
- onTaskEnd?: TaskEndCallback<T>;
12
+ onProgress?: OnProgress;
13
+ onTaskBegin?: OnTaskBegin;
14
+ onTaskEnd?: OnTaskEnd<T>;
21
15
  onException?: (error: Error) => void;
22
16
  }
23
17
 
24
18
  export type Callbacks<T = void> = {
25
- onTaskBegin?: TaskBeginCallback;
26
- onTaskEnd?: TaskEndCallback<T>;
27
- onProgress?: (progress: Progress, task?: Task) => void;
19
+ onTaskBegin?: OnTaskBegin;
20
+ onTaskEnd?: OnTaskEnd<T>;
21
+ onProgress?: OnProgress;
28
22
  onException?: (error: Error) => void;
29
23
  };
30
24
 
@@ -44,35 +38,6 @@ export const convertDeviceCoreType = (core?: DeviceCore) => {
44
38
  }
45
39
  };
46
40
 
47
- export const convertProgrammingOptionsType = (
48
- programmingOptions?: ProgrammingOptions
49
- ) => {
50
- if (!programmingOptions) {
51
- return undefined;
52
- }
53
-
54
- if (isJLinkProgrammingOptions(programmingOptions)) {
55
- return {
56
- qspi_erase_mode: programmingOptions.chipEraseMode,
57
- reset: programmingOptions.reset,
58
- verify: programmingOptions.verify,
59
- };
60
- }
61
-
62
- if (isMcuBootProgrammingOptions(programmingOptions)) {
63
- return {
64
- mcu_end_state: programmingOptions.mcuEndState,
65
- net_core_upload_delay: programmingOptions.netCoreUploadDelay,
66
- };
67
- }
68
-
69
- if (isNordicDfuProgrammingOptions(programmingOptions)) {
70
- return {
71
- mcu_end_state: programmingOptions.mcuEndState,
72
- };
73
- }
74
- };
75
-
76
41
  export interface ProgrammingOperation {
77
42
  type: 'program';
78
43
  firmware: {
@@ -128,6 +93,3 @@ export type BatchOperation =
128
93
  | EraseOperation
129
94
  | GetCoreInfoOperation
130
95
  | GetFwInfoOperation;
131
-
132
- export type TaskEndCallback<T = void> = (end: TaskEnd<T>) => void;
133
- export type TaskBeginCallback = (begin: TaskBegin) => void;
@@ -4,13 +4,13 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import { deviceSingleTaskEndOperationVoid, NrfutilDevice } from './common';
9
9
 
10
10
  export default (
11
11
  device: NrfutilDevice,
12
12
  data: object,
13
- onProgress?: (progress: Progress) => void,
13
+ onProgress?: OnProgress,
14
14
  controller?: AbortController
15
15
  ) => {
16
16
  // "operation: 2, command_id: 0" is the command to set the configuration for the board controller.
@@ -5,21 +5,15 @@
5
5
  */
6
6
 
7
7
  import { getModule } from '../modules';
8
- import { Progress } from '../sandboxTypes';
8
+ import { type OnProgress } from '../sandboxTypes';
9
9
 
10
10
  export const deviceTraitsToArgs = (traits: DeviceTraits) => {
11
- const args: string[] = [];
12
11
  const traitsString = Object.keys(traits)
13
12
  .map(trait => (traits[trait as keyof DeviceTraits] ? trait : null))
14
13
  .filter(t => t !== null)
15
14
  .join(',');
16
15
 
17
- if (traitsString.length > 0) {
18
- args.push('--traits');
19
- args.push(traitsString);
20
- }
21
-
22
- return args;
16
+ return traitsString.length > 0 ? ['--traits', traitsString] : [];
23
17
  };
24
18
 
25
19
  export type ResetKind =
@@ -157,7 +151,7 @@ export interface SerialPort {
157
151
  export const deviceSingleTaskEndOperation = async <T = void>(
158
152
  device: NrfutilDevice,
159
153
  command: string,
160
- onProgress?: (progress: Progress) => void,
154
+ onProgress?: OnProgress,
161
155
  controller?: AbortController,
162
156
  args: string[] = []
163
157
  ) => {
@@ -178,7 +172,7 @@ export const deviceSingleTaskEndOperation = async <T = void>(
178
172
  export const deviceSingleTaskEndOperationVoid = async (
179
173
  device: NrfutilDevice,
180
174
  command: string,
181
- onProgress?: (progress: Progress) => void,
175
+ onProgress?: OnProgress,
182
176
  controller?: AbortController,
183
177
  args: string[] = []
184
178
  ) => {
@@ -196,3 +190,5 @@ export const deviceSingleTaskEndOperationVoid = async (
196
190
  [...args, '--serial-number', device.serialNumber]
197
191
  );
198
192
  };
193
+
194
+ export const coreArg = (core?: DeviceCore) => (core ? ['--core', core] : []);
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperation,
11
12
  NrfutilDevice,
@@ -68,7 +69,7 @@ export interface DeviceInfoRaw {
68
69
  export default async (
69
70
  device: NrfutilDevice,
70
71
  core?: DeviceCore,
71
- onProgress?: (progress: Progress) => void,
72
+ onProgress?: OnProgress,
72
73
  controller?: AbortController
73
74
  ) => {
74
75
  try {
@@ -81,7 +82,7 @@ export default async (
81
82
  'device-info',
82
83
  onProgress,
83
84
  controller,
84
- core ? ['--core', core] : []
85
+ coreArg(core)
85
86
  )
86
87
  ).deviceInfo
87
88
  : undefined;
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperationVoid,
11
12
  NrfutilDevice,
@@ -14,7 +15,7 @@ import {
14
15
  export default (
15
16
  device: NrfutilDevice,
16
17
  core?: DeviceCore,
17
- onProgress?: (progress: Progress) => void,
18
+ onProgress?: OnProgress,
18
19
  controller?: AbortController
19
20
  ) =>
20
21
  deviceSingleTaskEndOperationVoid(
@@ -22,5 +23,5 @@ export default (
22
23
  'erase',
23
24
  onProgress,
24
25
  controller,
25
- core ? ['--core', core] : []
26
+ coreArg(core)
26
27
  );
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import { deviceSingleTaskEndOperation, NrfutilDevice } from './common';
9
9
 
10
10
  export interface BoardControllerConfigResponse {
@@ -15,7 +15,7 @@ export interface BoardControllerConfigResponse {
15
15
 
16
16
  export default (
17
17
  device: NrfutilDevice,
18
- onProgress?: (progress: Progress) => void,
18
+ onProgress?: OnProgress,
19
19
  controller?: AbortController
20
20
  ) => {
21
21
  // "operation: 0, command_id: 0" is the command to retrieve the configuration from the board controller.
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import { deviceSingleTaskEndOperation, NrfutilDevice } from './common';
9
9
 
10
10
  export interface BoardControllerVersionResponse {
@@ -22,7 +22,7 @@ export interface BoardControllerVersion {
22
22
 
23
23
  export default (
24
24
  device: NrfutilDevice,
25
- onProgress?: (progress: Progress) => void,
25
+ onProgress?: OnProgress,
26
26
  controller?: AbortController
27
27
  ) => {
28
28
  // "operation: 0, command_id: 1" is the command to retrieve version information from the board controller.
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperation,
11
12
  NrfutilDevice,
@@ -32,7 +33,7 @@ export type DeviceCoreInfo = {
32
33
  export default (
33
34
  device: NrfutilDevice,
34
35
  core?: DeviceCore,
35
- onProgress?: (progress: Progress) => void,
36
+ onProgress?: OnProgress,
36
37
  controller?: AbortController
37
38
  ) =>
38
39
  deviceSingleTaskEndOperation<DeviceCoreInfo>(
@@ -40,5 +41,5 @@ export default (
40
41
  'core-info',
41
42
  onProgress,
42
43
  controller,
43
- core ? ['--core', core] : []
44
+ coreArg(core)
44
45
  );
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperation,
11
12
  NrfutilDevice,
@@ -57,7 +58,7 @@ export interface FWInfo {
57
58
  export default (
58
59
  device: NrfutilDevice,
59
60
  core?: DeviceCore,
60
- onProgress?: (progress: Progress) => void,
61
+ onProgress?: OnProgress,
61
62
  controller?: AbortController
62
63
  ) =>
63
64
  deviceSingleTaskEndOperation<FWInfo>(
@@ -65,5 +66,5 @@ export default (
65
66
  'fw-info',
66
67
  onProgress,
67
68
  controller,
68
- core ? ['--core', core] : []
69
+ coreArg(core)
69
70
  );
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { Progress } from '../sandboxTypes';
7
+ import { type OnProgress } from '../sandboxTypes';
8
8
  import {
9
+ coreArg,
9
10
  DeviceCore,
10
11
  deviceSingleTaskEndOperation,
11
12
  NrfutilDevice,
@@ -28,7 +29,7 @@ export interface GetProtectionStatusResult {
28
29
  export default (
29
30
  device: NrfutilDevice,
30
31
  core?: DeviceCore,
31
- onProgress?: (progress: Progress) => void,
32
+ onProgress?: OnProgress,
32
33
  controller?: AbortController
33
34
  ) =>
34
35
  deviceSingleTaskEndOperation<GetProtectionStatusResult>(
@@ -36,5 +37,5 @@ export default (
36
37
  'protection-get',
37
38
  onProgress,
38
39
  controller,
39
- core ? ['--core', core] : []
40
+ coreArg(core)
40
41
  );
@@ -34,16 +34,11 @@ export default async (
34
34
  },
35
35
  timeout?: number
36
36
  ) => {
37
- const args: string[] = deviceTraitsToArgs(traits);
38
-
39
- if (onHotplugEvent) {
40
- args.push('--hotplug');
41
- }
42
-
43
- if (timeout !== undefined) {
44
- args.push('--timeout-ms');
45
- args.push(timeout.toString());
46
- }
37
+ const args = [
38
+ ...deviceTraitsToArgs(traits),
39
+ ...(onHotplugEvent ? ['--hotplug'] : []),
40
+ ...(timeout !== undefined ? ['--timeout-ms', timeout.toString()] : []),
41
+ ];
47
42
 
48
43
  const onData = (data: HotplugEvent | ListEvent) => {
49
44
  if (isListEvent(data)) {