Skip to content

Commit a2b41ec

Browse files
committed
fix(server): read npm 12's array-wrapped npm view version
npm 12 prints `npm view --json <pkg>@latest version` as ["x.y.z"] where npm 11 prints "x.y.z". Accept both so npm 12 servers don't fall back to registry.npmjs.org.
1 parent b034fbd commit a2b41ec

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/provider-core/src/server/maintenanceResolver.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,12 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
720720
exitCode: 0,
721721
expected: "1.1.0",
722722
},
723+
{
724+
case: "npm 12's array-wrapped release",
725+
stdout: '[\n "1.1.0"\n]\n',
726+
exitCode: 0,
727+
expected: "1.1.0",
728+
},
723729
{
724730
case: "the npm fallback when the npm probe fails",
725731
stdout: "",

‎packages/provider-core/src/server/maintenanceResolver.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion
424424
return nonEmptyString(listedEntries?.[0]?.dependencies?.[packageName]?.version);
425425
});
426426

427-
const decodeNpmViewVersion = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.String));
427+
// npm 11 prints a single version as a string; npm 12 wraps it in an array.
428+
const decodeNpmViewVersion = Schema.decodeUnknownOption(
429+
Schema.fromJsonString(Schema.Union([Schema.String, Schema.Tuple([Schema.String])])),
430+
);
428431

429432
// npm view reads the registry, scope and auth settings the update installs with,
430433
// so a mirror or private registry answers where registry.npmjs.org is blocked.
@@ -441,7 +444,8 @@ const resolveNpmGlobalLatestVersion = Effect.fn("resolveNpmGlobalLatestVersion")
441444
["view", "--prefix", npmPrefix, "--json", `${packageName}@latest`, "version"],
442445
{},
443446
);
444-
return viewed ? nonEmptyString(Option.getOrNull(decodeNpmViewVersion(viewed.trim()))) : null;
447+
const version = viewed ? Option.getOrNull(decodeNpmViewVersion(viewed.trim())) : null;
448+
return nonEmptyString(typeof version === "string" ? version : version?.[0]);
445449
});
446450

447451
export const resolvePackageManagedProviderMaintenance = Effect.fn(

0 commit comments

Comments
 (0)