Skip to content

Commit 775c7a7

Browse files
committed
fyn: avoid logging optional fail if it's due to os/cpu
1 parent 7d3d0bc commit 775c7a7

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

packages/fyn/lib/pkg-dep-resolver.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ class PkgDepResolver {
900900

901901
const metaJson = meta.versions[resolved];
902902

903+
const OPT_FAILED_PLATFORM = 3;
903904
const platformCheck = (): string | true => {
904905
const sysCheck = checkPkgOsCpu(metaJson);
905906
if (sysCheck !== true) {
@@ -922,22 +923,23 @@ class PkgDepResolver {
922923
// - but need to queue them up so when dep resolve queue is drained, need to
923924
// wait for them to complete, and then resolve the next dep tree level
924925
//
926+
const sysCheck = platformCheck();
925927
if (item.dsrc && item.dsrc.includes("opt") && !item.optChecked) {
926-
const sysCheck = platformCheck();
927-
928928
if (sysCheck !== true) {
929929
logger.verbose(`optional dependencies ${sysCheck}`);
930+
// Mark as failed due to platform mismatch so lockfile can record it
931+
if (!item.optFailed) {
932+
item.optFailed = OPT_FAILED_PLATFORM;
933+
}
934+
item.optChecked = true;
930935
} else {
931936
logger.verbose("adding package to opt check:", item.name, item.semver, item.resolved);
932-
933937
this._optResolver.add({ item, meta });
938+
return null;
934939
}
935-
936-
return null;
937940
}
938941

939-
const sysCheck = platformCheck();
940-
if (sysCheck !== true) {
942+
if (sysCheck !== true && !item.optFailed) {
941943
logger.error(sysCheck);
942944
throw new Error(sysCheck);
943945
}
@@ -983,6 +985,15 @@ class PkgDepResolver {
983985
}
984986
}
985987

988+
if (
989+
item.optFailed === OPT_FAILED_PLATFORM &&
990+
!pkgV.json &&
991+
(metaJson.os || metaJson.cpu)
992+
) {
993+
// Store minimal os/cpu info so lockfile can record platform mismatch
994+
pkgV.json = { os: metaJson.os, cpu: metaJson.cpu } as PackageVersionMeta;
995+
}
996+
986997
const localFromMeta = meta.local || metaJson.local;
987998
if (localFromMeta) {
988999
if (!item.localType) {

packages/fyn/lib/pkg-opt-resolver.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,32 @@ class PkgOptResolver {
195195
};
196196

197197
const logFail = (msg: string): void => {
198+
// Skip warning if failure is due to platform/architecture mismatch
199+
// Check using os/cpu from lockfile metadata (saved when platform check originally failed)
200+
const metaJson = data.meta.versions[version];
201+
if (metaJson) {
202+
const OPT_FAILED_PLATFORM = 3;
203+
if (metaJson.optFailed === OPT_FAILED_PLATFORM) {
204+
// Platform mismatch recorded in lockfile
205+
return;
206+
}
207+
// Check if package has os/cpu requirements that don't match current platform
208+
// This works even when optFailed is set in lockfile, as os/cpu are saved there
209+
const platformCheck = fyntil.checkPkgOsCpu(metaJson);
210+
if (platformCheck !== true) {
211+
// Platform/arch mismatch - skip warning, already logged as verbose
212+
return;
213+
}
214+
// Also check if error message indicates platform mismatch
215+
if (
216+
msg.includes("platform") ||
217+
msg.includes("architecture") ||
218+
msg.includes("cpu/arch") ||
219+
msg.includes("doesn't satisfy required")
220+
) {
221+
return;
222+
}
223+
}
198224
logger.warn(chalk.yellow(`optional dep check failed`), displayId, chalk.yellow(`- ${msg}`));
199225
logger.info(
200226
chalk.green(` you may ignore this since it is optional but some features may be missing`)
@@ -224,6 +250,20 @@ class PkgOptResolver {
224250
}
225251

226252
if (!this._fyn.refreshOptionals && _.get(data, ["meta", "versions", version, "optFailed"])) {
253+
// Check if this is a platform mismatch before logging warning
254+
const metaJson = data.meta.versions[version];
255+
if (metaJson) {
256+
const platformCheck = fyntil.checkPkgOsCpu(metaJson);
257+
if (platformCheck !== true) {
258+
// Platform/arch mismatch - skip warning, already logged as verbose
259+
const rx = {
260+
passed: false,
261+
err: new Error("optional dep fail by flag optFailed in lockfile - platform mismatch")
262+
};
263+
addChecked(rx);
264+
return processCheckResult(Promise.resolve(rx));
265+
}
266+
}
227267
logFail("by flag optFailed in lockfile");
228268
const rx = {
229269
passed: false,

0 commit comments

Comments
 (0)