Skip to content

Commit 0fe018c

Browse files
Cherrypenalosa
andauthored
chore(create-cloudflare): add support for new bun.lock (#6831)
* chore: add support for new bun.lock * chore: changeset * Add tests --------- Co-authored-by: Samuel Macleod <[email protected]>
1 parent bb17205 commit 0fe018c

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

.changeset/four-mayflies-smash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
Adds support for new upcoming bun.lock lockfile

packages/create-cloudflare/src/helpers/__tests__/packageManagers.test.ts

+67-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { existsSync } from "fs";
2-
import { detectPackageManager } from "helpers/packageManagers";
2+
import {
3+
detectPackageManager,
4+
detectPmMismatch,
5+
} from "helpers/packageManagers";
36
import { beforeEach, describe, expect, test, vi } from "vitest";
47
import whichPMRuns from "which-pm-runs";
58
import { mockPackageManager } from "./mocks";
9+
import type { C3Context } from "types";
610

711
vi.mock("fs");
812
vi.mock("which-pm-runs");
@@ -71,4 +75,66 @@ describe("Package Managers", () => {
7175
expect(pm.dlx).toEqual(["yarn"]);
7276
});
7377
});
78+
79+
describe("detectPmMismatch", async () => {
80+
describe("pnpm", () => {
81+
beforeEach(() => {
82+
mockPackageManager("pnpm");
83+
});
84+
85+
test.each([
86+
["yarn.lock", true],
87+
["pnpm-lock.yaml", false],
88+
["bun.lock", true],
89+
["bun.lockb", true],
90+
])("with %s", (file, isMismatch) => {
91+
vi.mocked(existsSync).mockImplementationOnce(
92+
(path) => !!(path as string).includes(file),
93+
);
94+
expect(detectPmMismatch({ project: { path: "" } } as C3Context)).toBe(
95+
isMismatch,
96+
);
97+
});
98+
});
99+
100+
describe("yarn", () => {
101+
beforeEach(() => {
102+
mockPackageManager("yarn");
103+
});
104+
105+
test.each([
106+
["yarn.lock", false],
107+
["pnpm-lock.yaml", true],
108+
["bun.lock", true],
109+
["bun.lockb", true],
110+
])("with %s", (file, isMismatch) => {
111+
vi.mocked(existsSync).mockImplementationOnce(
112+
(path) => !!(path as string).includes(file),
113+
);
114+
expect(detectPmMismatch({ project: { path: "" } } as C3Context)).toBe(
115+
isMismatch,
116+
);
117+
});
118+
});
119+
120+
describe("bun", () => {
121+
beforeEach(() => {
122+
mockPackageManager("bun");
123+
});
124+
125+
test.each([
126+
["yarn.lock", true],
127+
["pnpm-lock.yaml", true],
128+
["bun.lock", false],
129+
["bun.lockb", false],
130+
])("with %s", (file, isMismatch) => {
131+
vi.mocked(existsSync).mockImplementationOnce(
132+
(path) => !!(path as string).includes(file),
133+
);
134+
expect(detectPmMismatch({ project: { path: "" } } as C3Context)).toBe(
135+
isMismatch,
136+
);
137+
});
138+
});
139+
});
74140
});

packages/create-cloudflare/src/helpers/packageManagers.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const rectifyPmMismatch = async (ctx: C3Context) => {
119119
});
120120
};
121121

122-
const detectPmMismatch = (ctx: C3Context) => {
122+
export const detectPmMismatch = (ctx: C3Context) => {
123123
const { npm } = detectPackageManager();
124124
const projectPath = ctx.project.path;
125125

@@ -131,6 +131,9 @@ const detectPmMismatch = (ctx: C3Context) => {
131131
case "pnpm":
132132
return !existsSync(path.join(projectPath, "pnpm-lock.yaml"));
133133
case "bun":
134-
return !existsSync(path.join(projectPath, "bun.lockb"));
134+
return (
135+
!existsSync(path.join(projectPath, "bun.lockb")) &&
136+
!existsSync(path.join(projectPath, "bun.lock"))
137+
);
135138
}
136139
};

0 commit comments

Comments
 (0)