fix(setup): retain regular-file cleanup ownership through workflows
Thread the existing resource scope through skill and client configuration reads. Keep failed-close handles owned, wait for admitted reads, and surface unresolved cleanup alongside doctor, uninstall and update results. Validated focused setup/doctor/update and filesystem boundary checks, temporary-file hygiene, packaged setup/update/uninstall workflows, and static checks. No external provider installation was performed.
This commit is contained in:
@@ -6,6 +6,7 @@ import spawn from "cross-spawn";
|
||||
import { lt, valid } from "semver";
|
||||
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { safeParseJson } from "../domain/safeJson.js";
|
||||
import {
|
||||
@@ -292,74 +293,86 @@ export const systemUpdateHost = (
|
||||
packageRoot = fileURLToPath(new URL("../..", import.meta.url)),
|
||||
home: string | undefined = undefined,
|
||||
environment: Readonly<NodeJS.ProcessEnv> = process.env,
|
||||
): UpdateHost => ({
|
||||
installation: async () =>
|
||||
(await detectBunInstallation(
|
||||
packageRoot,
|
||||
bunGlobalDirectory(environment, process.platform),
|
||||
{ canonicalPath: realpath, isFile },
|
||||
)) ??
|
||||
detectNpmInstallation(packageRoot, {
|
||||
canonicalPath: realpath,
|
||||
globalRoot: () =>
|
||||
requireCommandOutput(["npm", "root", "--global"], environment),
|
||||
globalPrefix: () =>
|
||||
requireCommandOutput(["npm", "prefix", "--global"], environment),
|
||||
}),
|
||||
latestVersion: async (installation) => {
|
||||
const context = packageManagerContext(installation, environment);
|
||||
if (installation?.manager === "bun") {
|
||||
const version = await runUpdateCommand(
|
||||
["bun", "--version"],
|
||||
): UpdateHost => {
|
||||
const resources = new ArtifactResourceScope();
|
||||
return {
|
||||
installation: async () =>
|
||||
(await detectBunInstallation(
|
||||
packageRoot,
|
||||
bunGlobalDirectory(environment, process.platform),
|
||||
{ canonicalPath: realpath, isFile },
|
||||
)) ??
|
||||
detectNpmInstallation(packageRoot, {
|
||||
canonicalPath: realpath,
|
||||
globalRoot: () =>
|
||||
requireCommandOutput(["npm", "root", "--global"], environment),
|
||||
globalPrefix: () =>
|
||||
requireCommandOutput(["npm", "prefix", "--global"], environment),
|
||||
}),
|
||||
latestVersion: async (installation) => {
|
||||
const context = packageManagerContext(installation, environment);
|
||||
if (installation?.manager === "bun") {
|
||||
const version = await runUpdateCommand(
|
||||
["bun", "--version"],
|
||||
context.environment,
|
||||
"structured",
|
||||
context.workingDirectory,
|
||||
);
|
||||
if (!version.ok)
|
||||
return err({ kind: "unavailable", detail: version.error });
|
||||
const bunVersion = valid(version.value);
|
||||
// bun info was introduced in 1.2.17; older releases reserve the command.
|
||||
if (bunVersion === null || lt(bunVersion, "1.2.17"))
|
||||
return err({
|
||||
kind: "unsupported-package-manager",
|
||||
detail: `REA updates for Bun global installations require Bun 1.2.17 or later; bun --version returned ${JSON.stringify(version.value)}. Upgrade Bun manually, then rerun rea update.`,
|
||||
});
|
||||
}
|
||||
return npmReleaseLookup(
|
||||
await runUpdateCommand(
|
||||
installation?.manager === "bun"
|
||||
? BUN_LATEST_VERSION_COMMAND
|
||||
: npmLatestVersionCommand(installation),
|
||||
context.environment,
|
||||
"structured",
|
||||
context.workingDirectory,
|
||||
),
|
||||
);
|
||||
},
|
||||
installVersion: async (installation, version, output) => {
|
||||
const context = packageManagerContext(installation, environment);
|
||||
const result = await runUpdateCommand(
|
||||
updateInstallCommand(installation, version),
|
||||
context.environment,
|
||||
"structured",
|
||||
output,
|
||||
context.workingDirectory,
|
||||
);
|
||||
if (!version.ok)
|
||||
return err({ kind: "unavailable", detail: version.error });
|
||||
const bunVersion = valid(version.value);
|
||||
// bun info was introduced in 1.2.17; older releases reserve the command.
|
||||
if (bunVersion === null || lt(bunVersion, "1.2.17"))
|
||||
return err({
|
||||
kind: "unsupported-package-manager",
|
||||
detail: `REA updates for Bun global installations require Bun 1.2.17 or later; bun --version returned ${JSON.stringify(version.value)}. Upgrade Bun manually, then rerun rea update.`,
|
||||
});
|
||||
}
|
||||
return npmReleaseLookup(
|
||||
await runUpdateCommand(
|
||||
installation?.manager === "bun"
|
||||
? BUN_LATEST_VERSION_COMMAND
|
||||
: npmLatestVersionCommand(installation),
|
||||
context.environment,
|
||||
"structured",
|
||||
context.workingDirectory,
|
||||
return result.ok ? ok(undefined) : result;
|
||||
},
|
||||
installedVersion: (installation) =>
|
||||
runUpdateCommand(
|
||||
[
|
||||
process.execPath,
|
||||
join(installation.packageRoot, "scripts", "rea.mjs"),
|
||||
"--version",
|
||||
],
|
||||
environment,
|
||||
),
|
||||
);
|
||||
},
|
||||
installVersion: async (installation, version, output) => {
|
||||
const context = packageManagerContext(installation, environment);
|
||||
const result = await runUpdateCommand(
|
||||
updateInstallCommand(installation, version),
|
||||
context.environment,
|
||||
output,
|
||||
context.workingDirectory,
|
||||
);
|
||||
return result.ok ? ok(undefined) : result;
|
||||
},
|
||||
installedVersion: (installation) =>
|
||||
runUpdateCommand(
|
||||
[
|
||||
process.execPath,
|
||||
planMaintenance: (installation) =>
|
||||
planIntegrationMaintenance(
|
||||
home ?? homeDirectoryFromEnvironment(environment, process.platform),
|
||||
join(installation.packageRoot, "scripts", "rea.mjs"),
|
||||
"--version",
|
||||
],
|
||||
environment,
|
||||
),
|
||||
planMaintenance: (installation) =>
|
||||
planIntegrationMaintenance(
|
||||
home ?? homeDirectoryFromEnvironment(environment, process.platform),
|
||||
join(installation.packageRoot, "scripts", "rea.mjs"),
|
||||
environment,
|
||||
(command) => runUpdateCommand(command, environment),
|
||||
),
|
||||
});
|
||||
environment,
|
||||
(command) => runUpdateCommand(command, environment),
|
||||
resources,
|
||||
),
|
||||
close: async () => {
|
||||
try {
|
||||
await resources.close();
|
||||
return undefined;
|
||||
} catch (cause: unknown) {
|
||||
return `Update resource cleanup failed: ${cause instanceof Error ? cause.message : String(cause)}`;
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user