fix(update): keep dist verify compat-safe

This commit is contained in:
Vincent Koc
2026-04-15 09:39:18 +01:00
parent 9e665e4328
commit ea4889ecdc

View File

@@ -13,7 +13,7 @@ import {
} from "./package-dist-inventory.js";
import { readPackageVersion } from "./package-json.js";
import { applyPathPrepend } from "./path-prepend.js";
import { isAtLeast, parseSemver } from "./runtime-guard.js";
import { parseSemver } from "./runtime-guard.js";
export type GlobalInstallManager = "npm" | "pnpm" | "bun";
@@ -108,7 +108,17 @@ export async function collectInstalledGlobalPackageErrors(params: {
}
function shouldRequirePackagedDistInventory(version: string | null | undefined): boolean {
return isAtLeast(parseSemver(version ?? null), FIRST_PACKAGED_DIST_INVENTORY_VERSION);
const parsed = parseSemver(version ?? null);
if (!parsed) {
return false;
}
if (parsed.major !== FIRST_PACKAGED_DIST_INVENTORY_VERSION.major) {
return parsed.major > FIRST_PACKAGED_DIST_INVENTORY_VERSION.major;
}
if (parsed.minor !== FIRST_PACKAGED_DIST_INVENTORY_VERSION.minor) {
return parsed.minor > FIRST_PACKAGED_DIST_INVENTORY_VERSION.minor;
}
return parsed.patch >= FIRST_PACKAGED_DIST_INVENTORY_VERSION.patch;
}
async function collectInstalledPackageDistErrors(params: {
@@ -116,7 +126,7 @@ async function collectInstalledPackageDistErrors(params: {
installedVersion: string | null;
expectedVersion?: string | null;
}): Promise<string[]> {
const criticalPaths = await collectLegacyInstalledPackageDistPaths(params.packageRoot);
const criticalPaths = await collectCriticalInstalledPackageDistPaths(params.packageRoot);
let inventoryFiles: string[] | null = null;
let inventoryError: string | null = null;
try {
@@ -154,7 +164,7 @@ async function collectInstalledPackageDistErrors(params: {
const criticalErrors = await collectInstalledPathErrors({
packageRoot: params.packageRoot,
expectedFiles: criticalPaths,
expectedFiles: await collectLegacyInstalledPackageDistPaths(params.packageRoot),
actualFiles: null,
missingMessage: (relativePath) => `missing bundled runtime sidecar ${relativePath}`,
});
@@ -175,8 +185,19 @@ async function collectInstalledPackageDistErrors(params: {
async function collectLegacyInstalledPackageDistPaths(packageRoot: string): Promise<string[]> {
const expectedFiles = new Set(NPM_UPDATE_COMPAT_SIDECAR_PATHS);
for (const relativePath of await collectCriticalInstalledPackageDistPaths(packageRoot)) {
expectedFiles.add(relativePath);
}
return [...expectedFiles].toSorted((left, right) => left.localeCompare(right));
}
async function collectCriticalInstalledPackageDistPaths(packageRoot: string): Promise<string[]> {
const expectedFiles = new Set<string>();
await Promise.all(
BUNDLED_RUNTIME_SIDECAR_PATHS.map(async (relativePath) => {
if (NPM_UPDATE_COMPAT_SIDECAR_PATHS.has(relativePath)) {
return;
}
const pluginRoot = resolveBundledPluginRoot(relativePath);
if (pluginRoot === null) {
return;