Skip to content

Commit 5d2a232

Browse files
Update shared to 191
1 parent c21afe2 commit 5d2a232

File tree

7 files changed

+51
-424
lines changed

7 files changed

+51
-424
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
},
9797
"devDependencies": {
9898
"@electron/notarize": "^2.2.0",
99-
"@nordicsemiconductor/pc-nrfconnect-shared": "^188.0.0",
99+
"@nordicsemiconductor/pc-nrfconnect-shared": "^191.0.0",
100100
"@playwright/test": "^1.16.3",
101101
"@testing-library/user-event": "^14.4.3",
102102
"@types/chmodr": "1.0.0",

src/launcher/util/appCompatibilityWarning.test.ts

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
55
*/
66

7-
import { NrfutilSandbox } from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil';
8-
import { resolveModuleVersion } from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil/moduleVersion';
7+
import {
8+
getJlinkCompatibility,
9+
prepareSandbox,
10+
} from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil';
911
import { inspect } from 'util';
1012

1113
import { LaunchableApp } from '../../ipc/apps';
@@ -30,13 +32,7 @@ const undecidedCheck = {
3032
isDecided: false,
3133
};
3234

33-
jest.mock('@nordicsemiconductor/pc-nrfconnect-shared/nrfutil/sandbox', () => ({
34-
__esModule: true,
35-
default: () =>
36-
Promise.resolve({
37-
getModuleVersion: () => Promise.resolve([]),
38-
} as unknown as NrfutilSandbox),
39-
}));
35+
jest.mock('@nordicsemiconductor/pc-nrfconnect-shared/nrfutil');
4036

4137
jest.mock('@nordicsemiconductor/pc-nrfconnect-shared', () => ({
4238
...jest.requireActual('@nordicsemiconductor/pc-nrfconnect-shared'),
@@ -109,65 +105,20 @@ describe('check compatibility of an app with the launcher', () => {
109105
describe('Check if the tested version of J-Link is installed', () => {
110106
const app = (nrfutilDeviceVersion: string) =>
111107
createDownloadableTestApp(undefined, {
112-
// @ts-expect-error -- Needs to be added to Installed in shared as `nrfutil?: NrfutilModules;`
113108
nrfutil: { device: [nrfutilDeviceVersion] },
114109
});
115110

116-
it(`No installed J-Link as reported before nrfutil-device 2.7`, async () => {
117-
jest.mocked(resolveModuleVersion).mockReturnValue(undefined);
118-
119-
expect(
120-
await checkJLinkRequirements(app('2.0.0'), '5.0.0')
121-
).toMatchObject(
122-
failingCheck(
123-
'Required SEGGER J-Link not found: expected version V7.88j'
124-
)
125-
);
126-
});
127-
128-
it(`No installed J-Link as reported since nrfutil-device 2.7`, async () => {
129-
// @ts-expect-error -- The type for dependencies still needs to be updated in shared
130-
jest.mocked(resolveModuleVersion).mockReturnValue({
131-
expectedVersion: {
132-
versionFormat: 'string',
133-
version: 'JLink_V7.94i',
134-
},
135-
name: 'JlinkARM',
136-
});
137-
138-
expect(
139-
await checkJLinkRequirements(app('2.0.1'), '5.0.0')
140-
).toMatchObject(
141-
failingCheck(
142-
'Required SEGGER J-Link not found: expected version V7.88j'
143-
)
144-
);
145-
});
146-
147-
it(`Wrong JLink version`, async () => {
148-
jest.mocked(resolveModuleVersion).mockReturnValue({
149-
expectedVersion: {
150-
versionFormat: 'string',
151-
version: 'JLink_V7.94i',
152-
},
153-
name: 'JlinkARM',
154-
versionFormat: 'string',
155-
version: 'JLink_V7.94e',
111+
it('Calls resolveModuleVersion exactly once per version of nrfutil-device', async () => {
112+
jest.mocked(prepareSandbox).mockResolvedValue({
113+
// @ts-expect-error -- I do not understand et how to fix this TypeScript error, but this is only a test, test ¯\_(ツ)_/¯
114+
getModuleVersion: () => [],
156115
});
157116

158-
expect(
159-
await checkJLinkRequirements(app('2.0.2'), '5.0.0')
160-
).toMatchObject(
161-
failingCheck(
162-
'Untested version V7.94e of SEGGER J-Link found: expected at least version V7.94i'
163-
)
164-
);
165-
});
166-
167-
it('Calls resolveModuleVersion exactly once per version of nrfutil-device', async () => {
168117
const mockedGetSandbox = jest
169-
.mocked(resolveModuleVersion)
170-
.mockReset();
118+
.mocked(getJlinkCompatibility)
119+
.mockClear()
120+
// @ts-expect-error -- As above
121+
.mockResolvedValue({});
171122

172123
await checkJLinkRequirements(app('3.0.0'), '5.0.0');
173124
await checkJLinkRequirements(app('3.0.0'), '5.0.0');

src/launcher/util/appCompatibilityWarning.tsx

Lines changed: 32 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
getUserDataDir,
1010
launcherConfig,
1111
} from '@nordicsemiconductor/pc-nrfconnect-shared';
12-
import type { NrfutilModules } from '@nordicsemiconductor/pc-nrfconnect-shared/ipc/MetaFiles';
13-
import { resolveModuleVersion } from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil/moduleVersion';
14-
import getSandbox from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil/sandbox';
12+
import {
13+
getJlinkCompatibility as getJlinkCompatibilityFromModuleVersion,
14+
prepareSandbox,
15+
} from '@nordicsemiconductor/pc-nrfconnect-shared/nrfutil';
1516
import { memoize } from 'lodash';
1617
import semver from 'semver';
1718

@@ -21,10 +22,6 @@ import {
2122
isWithdrawn,
2223
LaunchableApp,
2324
} from '../../ipc/apps';
24-
import {
25-
existingIsOlderThanExpected,
26-
strippedVersionName,
27-
} from './jlinkVersion';
2825
import Link from './Link';
2926
import minimalRequiredAppVersions from './minimalRequiredAppVersions';
3027

@@ -169,36 +166,17 @@ const checkMinimalRequiredAppVersions: AppCompatibilityChecker = app => {
169166
);
170167
};
171168

172-
const nrfutilDeviceToJLink = (device: string) => {
173-
// According to https://docs.nordicsemi.com/bundle/nrfutil/page/guides/installing.html#prerequisites
174-
if (semver.lt(device, '2.0.0')) {
175-
return 'V7.80c';
176-
}
177-
178-
if (semver.lt(device, '2.1.0')) {
179-
return 'V7.88j';
180-
}
181-
182-
if (semver.lt(device, '2.5.4')) {
183-
return 'V7.94e';
184-
}
185-
186-
return 'V7.94i';
187-
};
188-
189-
const getJlinkVersionDependency = memoize(
190-
async (nrfutilDeviceVersion: string) => {
191-
const userDir = getUserDataDir();
192-
const sandbox = await getSandbox(
193-
userDir,
194-
'device',
195-
nrfutilDeviceVersion
196-
);
197-
const moduleVersion = await sandbox.getModuleVersion();
169+
const getJlinkCompatibility = memoize(async (nrfutilDeviceVersion: string) => {
170+
const userDir = getUserDataDir();
171+
const sandbox = await prepareSandbox(
172+
userDir,
173+
'device',
174+
nrfutilDeviceVersion
175+
);
176+
const moduleVersion = await sandbox.getModuleVersion();
198177

199-
return resolveModuleVersion('JlinkARM', moduleVersion.dependencies);
200-
}
201-
);
178+
return getJlinkCompatibilityFromModuleVersion(moduleVersion);
179+
});
202180

203181
export const checkJLinkRequirements: AppCompatibilityChecker = async (
204182
app: LaunchableApp
@@ -207,80 +185,67 @@ export const checkJLinkRequirements: AppCompatibilityChecker = async (
207185
return undecided;
208186
}
209187

210-
const deviceVersion =
211-
// @ts-expect-error -- Needs to be added to Installed in shared as `nrfutil?: NrfutilModules;`. Then the typecast should also be removed.
212-
(app.nrfutil as NrfutilModules | undefined)?.device?.at(0);
188+
const deviceVersion = app.nrfutil?.device?.at(0);
213189

214190
if (!deviceVersion) {
215191
return undecided;
216192
}
217193

218-
const jlinkVersionDependency = await getJlinkVersionDependency(
219-
deviceVersion
220-
);
221-
const noJlinkInstalled = jlinkVersionDependency?.version == null;
222-
if (noJlinkInstalled) {
223-
const requiredVersion = nrfutilDeviceToJLink(deviceVersion);
194+
const jlinkCompatibility = await getJlinkCompatibility(deviceVersion);
195+
196+
if (jlinkCompatibility.kind === 'No J-Link installed') {
197+
const { requiredJlink } = jlinkCompatibility;
224198

225199
return incompatible(
226200
'Missing dependency',
227-
`Required SEGGER J-Link not found: expected version ${requiredVersion}`,
201+
`Required SEGGER J-Link not found: expected version V${requiredJlink}`,
228202
<div className="tw-flex tw-flex-col tw-gap-2">
229-
<div>This app requires SEGGER J-Link {requiredVersion}.</div>
203+
<div>This app requires SEGGER J-Link V{requiredJlink}.</div>
230204
<div>
231205
<Link href="https://www.segger.com/downloads/jlink/">
232206
Download
233207
</Link>{' '}
234208
and install the SEGGER J-Link Software and Documentation
235-
pack {requiredVersion}. Restart nRF Connect for Desktop
209+
pack V{requiredJlink}. Restart nRF Connect for Desktop
236210
afterwards.
237211
</div>
238212
</div>,
239213
{
240214
warningKind: WarningKind.JLINK,
241215
app: app.name,
242216
nrfutilDevice: deviceVersion,
243-
requiredJlink: requiredVersion,
244-
actualJlink: 'none',
217+
...jlinkCompatibility,
245218
}
246219
);
247220
}
248221

249-
if (
250-
jlinkVersionDependency.expectedVersion &&
251-
existingIsOlderThanExpected(jlinkVersionDependency)
252-
) {
253-
const expectedVersionNumber = strippedVersionName(
254-
jlinkVersionDependency.expectedVersion
255-
);
256-
const actualVersionNumber = strippedVersionName(jlinkVersionDependency);
222+
if (jlinkCompatibility.kind === 'Outdated J-Link') {
223+
const { actualJlink, requiredJlink } = jlinkCompatibility;
257224

258225
return incompatible(
259226
'Outdated dependency',
260-
`Untested version V${actualVersionNumber} of SEGGER J-Link found: ` +
261-
`expected at least version V${expectedVersionNumber}`,
227+
`Untested version V${actualJlink} of SEGGER J-Link found: ` +
228+
`expected at least version V${requiredJlink}`,
262229
<div className="tw-flex tw-flex-col tw-gap-2">
263230
<div>
264-
This app was tested with SEGGER J-Link V
265-
{expectedVersionNumber} but version V{actualVersionNumber}{' '}
266-
was found on your system.
231+
This app was tested with SEGGER J-Link V{requiredJlink} but
232+
version V{actualJlink} was found on your system.
267233
</div>
268234
<div>This app might not work as expected!</div>
269235
<div>
270236
<Link href="https://www.segger.com/downloads/jlink/">
271237
Download
272238
</Link>{' '}
273239
and install the SEGGER J-Link Software and Documentation
274-
pack V{expectedVersionNumber}. Restart nRF Connect for
275-
Desktop afterwards.
240+
pack V{requiredJlink}. Restart nRF Connect for Desktop
241+
afterwards.
276242
</div>
277243
</div>,
278244
{
279245
warningKind: WarningKind.JLINK,
280246
app: app.name,
281247
nrfutilDevice: deviceVersion,
282-
requiredJlink: jlinkVersionDependency.expectedVersion.version,
283-
actualJlink: jlinkVersionDependency.version,
248+
...jlinkCompatibility,
284249
}
285250
);
286251
}

0 commit comments

Comments
 (0)