






















@@ -442,6 +442,25 @@ async function preparePackageSourceWorktree(ref) {
442442return { selectedSha, sourceDir, trustedReason };
443443}
444444445+async function cleanupPackageSourceWorktree(
446+sourceDir,
447+{ resolveError, runImpl = run, consoleError = console.error } = {},
448+) {
449+try {
450+await runImpl("git", ["worktree", "remove", "--force", sourceDir]);
451+} catch (cleanupError) {
452+if (!resolveError) {
453+throw cleanupError;
454+}
455+const message = cleanupError instanceof Error ? cleanupError.message : String(cleanupError);
456+consoleError(
457+`warning: failed to remove temporary package source worktree ${sourceDir}: ${message}`,
458+);
459+}
460+}
461+462+export const cleanupPackageSourceWorktreeForTest = cleanupPackageSourceWorktree;
463+445464async function installPackageSourceDeps(sourceDir) {
446465await run(
447466"pnpm",
@@ -1122,6 +1141,7 @@ async function resolveCandidate(options) {
11221141let packageTrustedSourceId = "";
11231142let packageWorktreeDir = "";
11241143let artifactMetadata = {};
1144+let resolveError;
1125114511261146try {
11271147if (options.source === "ref") {
@@ -1198,9 +1218,12 @@ async function resolveCandidate(options) {
11981218`source must be one of: ref, npm, url, trusted-url, artifact. Got: ${options.source}`,
11991219);
12001220}
1221+} catch (error) {
1222+resolveError = error;
1223+throw error;
12011224} finally {
12021225if (packageWorktreeDir) {
1203-await run("git", ["worktree", "remove", "--force", packageWorktreeDir]).catch(() => {});
1226+await cleanupPackageSourceWorktree(packageWorktreeDir, { resolveError });
12041227}
12051228}
12061229此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。