@nordicsemiconductor/pc-nrfconnect-shared 211.0.0 → 213.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.
package/Changelog.md CHANGED
@@ -7,13 +7,30 @@ 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
+ ## 213.0.0 - 2025-06-11
11
+
12
+ ### Fixed
13
+
14
+ - Typecheck error when using a recent version of the dependency logform.
15
+
16
+ ## 212.0.0 - 2025-06-05
17
+
18
+ ### Added
19
+
20
+ - Specify what core version of nrfutil an app depends on.
21
+
22
+ ### Steps to upgrade when using this package
23
+
24
+ - In apps in `package.json` set the field `nrfConnectForDesktop.nrfutilCore`
25
+ to the core version of nrfutil that the nrfutil commands will use.
26
+
10
27
  ## 211.0.0 - 2025-05-29
11
28
 
12
29
  ### Fixed
13
30
 
14
- - It was observed that on mac we get multiple arrive event and the only chnage
15
- is the number if serial ports. Now the selected device in redux will also
16
- update to reflect these chnages
31
+ - It was observed on macOS that we get multiple arrive events and the only
32
+ change is the number of serial ports. Now the selected device in redux is
33
+ also updated to reflect these changes.
17
34
 
18
35
  ## 210.0.0 - 2025-05-15
19
36
 
package/ipc/MetaFiles.ts CHANGED
@@ -22,11 +22,12 @@ export type AppVersions = {
22
22
  [version: string]: AppVersion;
23
23
  };
24
24
 
25
- export type AppVersion = {
25
+ type AppVersion = {
26
26
  shasum?: string;
27
27
  publishTimestamp?: string;
28
28
  tarballUrl: UrlString;
29
29
  nrfutilModules?: NrfutilModules;
30
+ nrfutilCore?: NrfutilModuleVersion;
30
31
  };
31
32
 
32
33
  export interface AppInfo {
@@ -57,6 +58,9 @@ const nrfutilModuleVersion = semver;
57
58
  export type NrfutilModuleName = z.infer<typeof nrfutilModuleName>;
58
59
  export type NrfutilModuleVersion = z.infer<typeof nrfutilModuleVersion>;
59
60
 
60
- export const nrfModules = z.record(nrfutilModuleName, z.tuple([semver]));
61
+ export const nrfModules = z.record(
62
+ nrfutilModuleName,
63
+ z.tuple([nrfutilModuleVersion])
64
+ );
61
65
 
62
66
  export type NrfutilModules = z.infer<typeof nrfModules>;
package/ipc/apps.ts CHANGED
@@ -5,7 +5,12 @@
5
5
  */
6
6
 
7
7
  import { handle, invoke } from './infrastructure/rendererToMain';
8
- import type { AppVersions, NrfutilModules, UrlString } from './MetaFiles';
8
+ import type {
9
+ AppVersions,
10
+ NrfutilModules,
11
+ NrfutilModuleVersion,
12
+ UrlString,
13
+ } from './MetaFiles';
9
14
  import { LOCAL, Source, SourceName } from './sources';
10
15
 
11
16
  export interface AppSpec {
@@ -34,6 +39,7 @@ interface Installed {
34
39
  repositoryUrl?: UrlString;
35
40
  html?: string;
36
41
  nrfutil?: NrfutilModules;
42
+ nrfutilCore?: NrfutilModuleVersion;
37
43
  installed: {
38
44
  publishTimestamp?: string;
39
45
  path: string;
@@ -26,6 +26,7 @@ export const parsePackageJson = parseWithPrettifiedErrorMessage(packageJson);
26
26
  const nrfConnectForDesktop = z.object({
27
27
  supportedDevices: z.enum(knownDevicePcas).array().nonempty().optional(),
28
28
  nrfutil: nrfModules.optional(),
29
+ nrfutilCore: semver,
29
30
  html: z.string(),
30
31
  });
31
32
 
@@ -59,11 +60,11 @@ export const parsePackageJsonApp =
59
60
  parseWithPrettifiedErrorMessage(packageJsonApp);
60
61
 
61
62
  // In the launcher we want to handle that the whole nrfConnectForDesktop may be missing
62
- // and the html in it can also be undefined, so there we need to use this legacy variant
63
+ // and html or nrfutilCore in it can also be undefined, so there we need to use this legacy variant
63
64
  const packageJsonLegacyApp = packageJsonApp.extend({
64
65
  nrfConnectForDesktop: nrfConnectForDesktop
65
66
  .extend({ supportedDevices: z.array(z.string()).nonempty().optional() })
66
- .partial({ html: true })
67
+ .partial({ html: true, nrfutilCore: true })
67
68
  .optional(),
68
69
  });
69
70
 
package/nrfutil/index.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  export { default as prepareSandbox } from './sandbox';
8
- export { NrfutilSandbox } from './sandbox';
8
+ export type { NrfutilSandbox } from './sandbox';
9
9
  export type { Progress } from './sandboxTypes';
10
10
  export { getNrfutilLogger, setNrfutilLogger } from './nrfutilLogger';
11
11
  export {
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
5
5
  */
6
6
 
7
- import { packageJsonApp } from '../src/utils/packageJson';
7
+ import { isLauncher, packageJsonApp } from '../src/utils/packageJson';
8
8
  import {
9
9
  type Dependency,
10
10
  hasVersion,
@@ -78,7 +78,7 @@ const versionFromPackageJson = (module: string) =>
78
78
  packageJsonApp().nrfConnectForDesktop.nrfutil?.[module][0];
79
79
 
80
80
  const failToDetermineVersion = (module: string) => {
81
- throw new Error(`No version specified for the bundled nrfutil ${module}`);
81
+ throw new Error(`No version specified for nrfutil ${module}`);
82
82
  };
83
83
 
84
84
  export const versionToInstall = (module: string, version?: string) =>
@@ -86,3 +86,12 @@ export const versionToInstall = (module: string, version?: string) =>
86
86
  overriddenVersion(module) ??
87
87
  versionFromPackageJson(module) ??
88
88
  failToDetermineVersion(module);
89
+
90
+ const coreVersionFromPackageJson = () =>
91
+ isLauncher()
92
+ ? undefined // Will lead to using CORE_VERSION_FOR_LEGACY_APPS
93
+ : packageJsonApp().nrfConnectForDesktop.nrfutilCore ??
94
+ failToDetermineVersion('core');
95
+
96
+ export const coreVersionsToInstall = (coreVersion?: string) =>
97
+ coreVersion ?? overriddenVersion('core') ?? coreVersionFromPackageJson();
@@ -13,7 +13,7 @@ import treeKill from 'tree-kill';
13
13
  import describeError from '../src/logging/describeError';
14
14
  import telemetry from '../src/telemetry/telemetry';
15
15
  import { isDevelopment } from '../src/utils/environment';
16
- import { versionToInstall } from './moduleVersion';
16
+ import { coreVersionsToInstall, versionToInstall } from './moduleVersion';
17
17
  import { getNrfutilLogger } from './nrfutilLogger';
18
18
  import {
19
19
  BackgroundTask,
@@ -40,18 +40,31 @@ const parseJsonBuffers = <T>(data: Buffer): T[] | undefined => {
40
40
  }
41
41
  };
42
42
 
43
- const nrfutilSandboxFolder =
44
- process.platform === 'darwin' && process.arch !== 'x64'
45
- ? path.join('nrfutil-sandboxes', process.arch)
46
- : 'nrfutil-sandboxes';
47
-
48
- const prepareEnv = (baseDir: string, module: string, version: string) => {
43
+ const nrfutilSandboxPathSegments = (
44
+ baseDir: string,
45
+ module: string,
46
+ version: string,
47
+ coreVersion?: string
48
+ ) => [
49
+ baseDir,
50
+ 'nrfutil-sandboxes',
51
+ ...(process.platform === 'darwin' && process.arch !== 'x64'
52
+ ? [process.arch]
53
+ : []),
54
+ ...(coreVersion != null ? [coreVersion] : []),
55
+ module,
56
+ version,
57
+ ];
58
+
59
+ const prepareEnv = (
60
+ baseDir: string,
61
+ module: string,
62
+ version: string,
63
+ coreVersion?: string
64
+ ) => {
49
65
  const env = { ...process.env };
50
66
  env.NRFUTIL_HOME = path.join(
51
- baseDir,
52
- nrfutilSandboxFolder,
53
- module,
54
- version
67
+ ...nrfutilSandboxPathSegments(baseDir, module, version, coreVersion)
55
68
  );
56
69
  fs.mkdirSync(env.NRFUTIL_HOME, { recursive: true });
57
70
 
@@ -124,16 +137,25 @@ export class NrfutilSandbox {
124
137
  baseDir: string;
125
138
  module: string;
126
139
  version: string;
140
+ coreVersion: string | undefined; // Must only be undefined when the launcher creates a sandbox for a legacy app, which does not specify the required core version
127
141
  onLoggingHandlers: ((logging: LogMessage, pid?: number) => void)[] = [];
128
142
  logLevel: LogLevel = isDevelopment ? 'error' : 'off';
129
143
  env: ReturnType<typeof prepareEnv>;
130
144
 
131
- constructor(baseDir: string, module: string, version: string) {
145
+ readonly CORE_VERSION_FOR_LEGACY_APPS = '8.0.0';
146
+
147
+ constructor(
148
+ baseDir: string,
149
+ module: string,
150
+ version: string,
151
+ coreVersion?: string
152
+ ) {
132
153
  this.baseDir = baseDir;
133
154
  this.module = module;
134
155
  this.version = version;
156
+ this.coreVersion = coreVersion;
135
157
 
136
- this.env = prepareEnv(baseDir, module, version);
158
+ this.env = prepareEnv(baseDir, module, version, coreVersion);
137
159
  }
138
160
 
139
161
  private processLoggingData = (data: NrfutilJson, pid?: number) => {
@@ -173,10 +195,12 @@ export class NrfutilSandbox {
173
195
  if (
174
196
  fs.existsSync(
175
197
  path.join(
176
- this.baseDir,
177
- nrfutilSandboxFolder,
178
- this.module,
179
- this.version,
198
+ ...nrfutilSandboxPathSegments(
199
+ this.baseDir,
200
+ this.module,
201
+ this.version,
202
+ this.coreVersion
203
+ ),
180
204
  'bin',
181
205
  `nrfutil-${this.module}${
182
206
  os.platform() === 'win32' ? '.exe' : ''
@@ -201,15 +225,8 @@ export class NrfutilSandbox {
201
225
  force: true,
202
226
  });
203
227
  }
204
- await this.updateNrfUtilCore();
205
- await this.spawnNrfutil(
206
- 'install',
207
- [`${this.module}=${this.version}`, '--force'],
208
- onProgress
209
- );
210
- getNrfutilLogger()?.info(
211
- `Successfully installed nrfutil ${this.module} version: ${this.version}`
212
- );
228
+ await this.installNrfUtilCore(onProgress);
229
+ await this.installNrfUtilCommand(onProgress);
213
230
  } catch (error) {
214
231
  if (this.env.NRFUTIL_HOME && fs.existsSync(this.env.NRFUTIL_HOME)) {
215
232
  fs.rmSync(this.env.NRFUTIL_HOME, {
@@ -218,25 +235,61 @@ export class NrfutilSandbox {
218
235
  });
219
236
  }
220
237
 
221
- getNrfutilLogger()?.error(
222
- `Error while installing nrfutil ${this.module} version: ${
223
- this.version
224
- }. describeError: ${describeError(error)}`
225
- );
226
238
  throw error;
227
239
  }
228
240
  };
229
241
 
230
- public updateNrfUtilCore = async (
242
+ private installNrfUtilCore = async (
243
+ onProgress?: (progress: Progress, task?: Task) => void
244
+ ) => {
245
+ const currentCoreVersion = await this.getCoreVersion();
246
+ const requestedCoreVersion =
247
+ this.coreVersion ?? this.CORE_VERSION_FOR_LEGACY_APPS;
248
+ if (currentCoreVersion.version === requestedCoreVersion) {
249
+ getNrfutilLogger()?.debug(
250
+ `Requested nrfutil core version ${requestedCoreVersion} is already installed.`
251
+ );
252
+
253
+ return;
254
+ }
255
+
256
+ await this.install(
257
+ 'core',
258
+ requestedCoreVersion,
259
+ 'self-upgrade',
260
+ ['--to-version', requestedCoreVersion],
261
+ onProgress
262
+ );
263
+ };
264
+
265
+ public installNrfUtilCommand = (
231
266
  onProgress?: (progress: Progress, task?: Task) => void
267
+ ) =>
268
+ this.install(
269
+ this.module,
270
+ this.version,
271
+ 'install',
272
+ [`${this.module}=${this.version}`, '--force'],
273
+ onProgress
274
+ );
275
+
276
+ public install = async (
277
+ module: string,
278
+ version: string,
279
+ ...args: Parameters<typeof this.spawnNrfutil>
232
280
  ) => {
233
281
  try {
234
- await this.spawnNrfutil('self-upgrade', [], onProgress);
235
- } catch (error) {
236
- // User might not have internet hance fail silently
237
- getNrfutilLogger()?.error(
238
- `Error while updating the bundled core for nrfutil ${this.module}.`
282
+ await this.spawnNrfutil(...args);
283
+ getNrfutilLogger()?.info(
284
+ `Successfully installed nrfutil ${module} version: ${version}`
239
285
  );
286
+ } catch (error) {
287
+ const errorMessage = `Error while installing nrfutil ${module} version ${version}: ${describeError(
288
+ error
289
+ )}`;
290
+
291
+ getNrfutilLogger()?.error(errorMessage);
292
+ throw new Error(errorMessage);
240
293
  }
241
294
  };
242
295
 
@@ -765,22 +818,20 @@ export default async (
765
818
  baseDir: string,
766
819
  module: string,
767
820
  version?: string,
821
+ coreVersion?: string,
768
822
  onProgress?: (progress: Progress, task?: Task) => void
769
823
  ) => {
770
824
  const sandbox = new NrfutilSandbox(
771
825
  baseDir,
772
826
  module,
773
- versionToInstall(module, version)
827
+ versionToInstall(module, version),
828
+ coreVersionsToInstall(coreVersion)
774
829
  );
775
830
 
776
831
  onProgress?.(convertNrfutilProgress({ progressPercentage: 0 }));
777
- const result = await sandbox.isSandboxInstalled();
778
832
 
779
- if (!result) {
833
+ if (!(await sandbox.isSandboxInstalled())) {
780
834
  await sandbox.prepareSandbox(onProgress);
781
- } else {
782
- // update nrfutil core
783
- await sandbox.updateNrfUtilCore(onProgress);
784
835
  }
785
836
 
786
837
  onProgress?.(convertNrfutilProgress({ progressPercentage: 100 }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nordicsemiconductor/pc-nrfconnect-shared",
3
- "version": "211.0.0",
3
+ "version": "213.0.0",
4
4
  "description": "Shared commodities for developing pc-nrfconnect-* packages",
5
5
  "repository": {
6
6
  "type": "git",