Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bun pm pack support "files" starting with ./ #17135

Merged
merged 5 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cli/pack_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,9 @@ pub const PackCommand = struct {
var files_array = _files_array;
while (files_array.next()) |files_entry| {
if (files_entry.asString(ctx.allocator)) |file_entry_str| {
const parsed = try Pattern.fromUTF8(ctx.allocator, file_entry_str) orelse continue;
var path_buf: PathBuffer = undefined;
RiskyMH marked this conversation as resolved.
Show resolved Hide resolved
const normalized = bun.path.normalizeBuf(file_entry_str, &path_buf, .posix);
const parsed = try Pattern.fromUTF8(ctx.allocator, try ctx.allocator.dupe(u8, normalized)) orelse continue;
RiskyMH marked this conversation as resolved.
Show resolved Hide resolved
try includes.append(ctx.allocator, parsed);
continue;
}
Expand Down
33 changes: 29 additions & 4 deletions test/cli/install/bun-pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ describe("files", () => {
write(
join(packageDir, "package.json"),
JSON.stringify({
name: "pack-files-3",
name: "pack-files-2",
version: "1.2.3",
files: ["index.js"],
}),
Expand All @@ -932,16 +932,41 @@ describe("files", () => {
]);

await pack(packageDir, bunEnv);
const tarball = readTarball(join(packageDir, "pack-files-3-1.2.3.tgz"));
const tarball = readTarball(join(packageDir, "pack-files-2-1.2.3.tgz"));
expect(tarball.entries).toMatchObject([{ "pathname": "package/package.json" }, { "pathname": "package/index.js" }]);
});

test("matches './' as the root", async () => {
await Promise.all([
write(
join(packageDir, "package.json"),
JSON.stringify({
name: "pack-files-3",
version: "1.2.3",
files: ["./dist", "!./subdir", "!./dist/index.js", "./////src//index.ts"],
}),
),
write(join(packageDir, "dist", "index.js"), "console.log('hello ./dist/index.js')"),
write(join(packageDir, "subdir", "index.js"), "console.log('hello ./subdir/index.js')"),
write(join(packageDir, "src", "dist", "index.js"), "console.log('hello ./src/dist/index.js')"),
write(join(packageDir, "src", "index.ts"), "console.log('hello ./src/index.ts')"),
]);

await pack(packageDir, bunEnv);
const tarball = readTarball(join(packageDir, "pack-files-3-1.2.3.tgz"));
expect(tarball.entries).toMatchObject([
{ "pathname": "package/package.json" },
{ "pathname": "package/dist/index.js" },
{ "pathname": "package/src/index.ts" },
]);
});

test("recursive only if leading **/", async () => {
await Promise.all([
write(
join(packageDir, "package.json"),
JSON.stringify({
name: "pack-files-2",
name: "pack-files-4",
version: "1.2.123",
files: ["**/index.js"],
}),
Expand All @@ -953,7 +978,7 @@ describe("files", () => {
]);

await pack(packageDir, bunEnv);
const tarball = readTarball(join(packageDir, "pack-files-2-1.2.123.tgz"));
const tarball = readTarball(join(packageDir, "pack-files-4-1.2.123.tgz"));
expect(tarball.entries).toMatchObject([
{ "pathname": "package/package.json" },
{ "pathname": "package/index.js" },
Expand Down