Skip to content

Commit

Permalink
fix(publish): missing bins bugfix (#14488)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
dylan-conway and Jarred-Sumner authored Oct 12, 2024
1 parent f870293 commit d3323c8
Show file tree
Hide file tree
Showing 8 changed files with 583 additions and 62 deletions.
37 changes: 25 additions & 12 deletions src/cli/pack_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@ pub const PackCommand = struct {
}
}

const edited_package_json = try editRootPackageJSON(ctx.allocator, ctx.lockfile, json);

var this_bundler: bun.bundler.Bundler = undefined;

_ = RunCommand.configureEnvForRun(
Expand Down Expand Up @@ -1401,6 +1403,7 @@ pub const PackCommand = struct {
.publish_script = publish_script,
.postpublish_script = postpublish_script,
.script_env = this_bundler.env,
.normalized_pkg_info = "",
};
}

Expand Down Expand Up @@ -1500,7 +1503,7 @@ pub const PackCommand = struct {

var entry = Archive.Entry.new2(archive);

const package_json = archive_with_progress: {
{
var progress: if (log_level == .silent) void else Progress = if (comptime log_level == .silent) {} else .{};
var node = if (comptime log_level == .silent) {} else node: {
progress.supports_ansi_escape_codes = Output.enable_ansi_colors;
Expand All @@ -1510,7 +1513,7 @@ pub const PackCommand = struct {
};
defer if (comptime log_level != .silent) node.end();

entry, const edited_package_json = try editAndArchivePackageJSON(ctx, archive, entry, root_dir, json);
entry = try archivePackageJSON(ctx, archive, entry, root_dir, edited_package_json);
if (comptime log_level != .silent) node.completeOne();

while (pack_queue.removeOrNull()) |pathname| {
Expand Down Expand Up @@ -1575,9 +1578,7 @@ pub const PackCommand = struct {
bins,
);
}

break :archive_with_progress edited_package_json;
};
}

entry.free();

Expand Down Expand Up @@ -1655,12 +1656,25 @@ pub const PackCommand = struct {
ctx.stats.packed_size = size;
};

const normalized_pkg_info: if (for_publish) string else void = if (comptime for_publish)
try Publish.normalizedPackage(
ctx.allocator,
manager,
package_name,
package_version,
&json.root,
json.source,
shasum,
integrity,
abs_tarball_dest,
);

printArchivedFilesAndPackages(
ctx,
root_dir,
false,
pack_list,
package_json.len,
edited_package_json.len,
);

if (comptime !for_publish) {
Expand Down Expand Up @@ -1715,6 +1729,7 @@ pub const PackCommand = struct {
.publish_script = publish_script,
.postpublish_script = postpublish_script,
.script_env = this_bundler.env,
.normalized_pkg_info = normalized_pkg_info,
};
}
}
Expand Down Expand Up @@ -1785,15 +1800,13 @@ pub const PackCommand = struct {
}
};

fn editAndArchivePackageJSON(
fn archivePackageJSON(
ctx: *Context,
archive: *Archive,
entry: *Archive.Entry,
root_dir: std.fs.Dir,
json: *PackageManager.WorkspacePackageJSONCache.MapEntry,
) OOM!struct { *Archive.Entry, string } {
const edited_package_json = try editRootPackageJSON(ctx.allocator, ctx.lockfile, json);

edited_package_json: string,
) OOM!*Archive.Entry {
const stat = bun.sys.fstatat(bun.toFD(root_dir), "package.json").unwrap() catch |err| {
Output.err(err, "failed to stat package.json", .{});
Global.crash();
Expand All @@ -1818,7 +1831,7 @@ pub const PackCommand = struct {

ctx.stats.unpacked_size += @intCast(archive.writeData(edited_package_json));

return .{ entry.clear(), edited_package_json };
return entry.clear();
}

fn addArchiveEntry(
Expand Down
Loading

0 comments on commit d3323c8

Please sign in to comment.