Skip to content

Commit 2cc9033

Browse files
fix(bun): ensure tarball is created in expected directory in monorepos (#483)
1 parent 6c0ca9f commit 2cc9033

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

packages/cli/index.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -696,36 +696,39 @@ async function resolveTarball(pm: PackMethod, p: string, pJson: PackageJson) {
696696
if (pm === "yarn") {
697697
cmd += ` --filename ${filename}`;
698698
} else if (pm === "bun") {
699-
cmd = `bun pm pack --quiet --filename ${filename}`;
699+
cmd = `bun pm pack --quiet --destination ${p}`;
700700
}
701701
const { stdout } = await ezSpawn.async(cmd, {
702702
stdio: "overlapped",
703703
cwd: p,
704704
});
705-
const lines = stdout.split("\n").filter(Boolean);
706705

707-
if (pm !== "yarn" && pm !== "bun") {
708-
filename = lines[lines.length - 1].trim();
706+
if (pm !== "yarn") {
707+
const lines = stdout.split("\n").filter(Boolean);
708+
filename = lines[lines.length - 1].trim().split(path.sep).pop()!;
709709
}
710-
if (pm === "bun") {
710+
711+
try {
712+
const shasum = createHash("sha1")
713+
.update(await fs.readFile(path.resolve(p, filename)))
714+
.digest("hex");
715+
716+
return { filename, shasum };
717+
} catch (error) {
718+
console.error(`Failed to read tarball for shasum calculation`);
719+
console.error(`[${pm} pack] expected filename: ${filename}`);
720+
console.error(`[${pm} pack] stdout:\n${stdout}`);
721+
711722
const tgzFiles = fsSync
712723
.readdirSync(p)
713724
.filter((file) => file.endsWith(".tgz"));
714-
const bunFilename = stdout.trim();
715-
if (bunFilename) {
716-
filename = bunFilename;
717-
}
718-
console.warn(`[bun pack] stdout:\n${stdout}`);
719-
console.warn(
720-
`[bun pack] expected filename: ${filename}; tgz files: ${tgzFiles.join(", ") || "(none)"}`,
721-
);
722-
}
723725

724-
const shasum = createHash("sha1")
725-
.update(await fs.readFile(path.resolve(p, filename)))
726-
.digest("hex");
726+
console.error(
727+
`[${pm} pack] tgz files in directory: ${tgzFiles.join(", ") || "(none)"}`,
728+
);
727729

728-
return { filename, shasum };
730+
throw error;
731+
}
729732
}
730733

731734
async function writeDeps(

0 commit comments

Comments
 (0)