Skip to content

Commit

Permalink
bun pm pack support files starting with ./
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskyMH committed Feb 7, 2025
1 parent c970922 commit fd06bee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/cli/pack_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,12 @@ pub const PackCommand = struct {
@"has leading **/, (could start with '!')" = true;
}

// `./foo` matches the same as `foo`
if (strings.hasPrefixComptime(remain, "./")) {
remain = remain["./".len..];
if (remain.len == 0) return null;
}

const trailing_slash = remain[remain.len - 1] == '/';
if (trailing_slash) {
// trim trailing slash
Expand Down
26 changes: 22 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,34 @@ 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"],
}),
),
write(join(packageDir, "dist", "index.js"), "console.log('hello ./dist/index.js')"),
]);

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" }]);
});

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 +971,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

0 comments on commit fd06bee

Please sign in to comment.