Skip to content

Commit

Permalink
fix: support Bun's new lockfile (#3531)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Feb 26, 2025
1 parent 0bc1d47 commit 66961be
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-wolves-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rnx-kit/tools-react-native": minor
"@rnx-kit/tools-workspaces": patch
---

Add support for Bun's text-based lockfile
1 change: 1 addition & 0 deletions packages/tools-react-native/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function getCurrentState(projectRoot: string): string {
"yarn.lock",
"package-lock.json",
"pnpm-lock.yaml",
"bun.lock",
"bun.lockb",
];
updateHash(sha2, lockfiles, projectRoot, "first-only");
Expand Down
4 changes: 4 additions & 0 deletions packages/tools-workspaces/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PackageManager = {
getPackageFilters: (sentinel: string) => string[] | undefined;
};

export const BUN_LOCK = "bun.lock";
export const BUN_LOCKB = "bun.lockb";
export const LERNA_JSON = "lerna.json";
export const PACKAGE_LOCK_JSON = "package-lock.json";
Expand All @@ -25,6 +26,7 @@ export const WORKSPACE_ROOT_SENTINELS = [
YARN_LOCK,
PACKAGE_LOCK_JSON,
PNPM_WORKSPACE_YAML,
BUN_LOCK,
BUN_LOCKB,
];

Expand Down Expand Up @@ -79,6 +81,7 @@ export const findSentinelSync = makeFindSentinel(findUp.sync);

export function getImplementation(sentinel: string): Promise<PackageManager> {
switch (path.basename(sentinel)) {
case BUN_LOCK: // fallthrough — logic defining workspaces config is the same as for npm and yarn
case BUN_LOCKB: // fallthrough — logic defining workspaces config is the same as for npm and yarn
case PACKAGE_LOCK_JSON: // fallthrough — logic defining workspaces config is the same for npm and yarn
case YARN_LOCK:
Expand All @@ -101,6 +104,7 @@ export function getImplementation(sentinel: string): Promise<PackageManager> {

export function getImplementationSync(sentinel: string): PackageManager {
switch (path.basename(sentinel)) {
case BUN_LOCK: // fallthrough — logic defining workspaces config is the same as for npm and yarn
case BUN_LOCKB: // fallthrough — logic defining workspaces config is the same as for npm and yarn
case PACKAGE_LOCK_JSON: // fallthrough — logic defining workspaces config is the same for npm and yarn
case YARN_LOCK:
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workspaces": {
"packages": [
"packages/*"
]
}
}
36 changes: 23 additions & 13 deletions packages/tools-workspaces/test/bun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,42 @@ describe("findSentinel", () => {
unsetFixture();
});

it("returns sentinel for Bun", async () => {
setFixture("bun");
it("returns sentinel for Bun (text)", async () => {
setFixture("bun.lock");
match((await findSentinel()) ?? "", /[/\\]bun.lock$/);
});

it("returns sentinel for Bun (text, sync)", () => {
setFixture("bun.lock");
match(findSentinelSync() ?? "", /[/\\]bun.lock$/);
});

it("returns sentinel for Bun (binary)", async () => {
setFixture("bun.lockb");
match((await findSentinel()) ?? "", /[/\\]bun.lockb$/);
});

it("returns sentinel for Bun (sync)", () => {
setFixture("bun");
it("returns sentinel for Bun (binary, sync)", () => {
setFixture("bun.lockb");
match(findSentinelSync() ?? "", /[/\\]bun.lockb$/);
});
});

describe("findWorkspacePackages", () => {
const packages = [
/__fixtures__[/\\]bun[/\\]packages[/\\]conan$/,
/__fixtures__[/\\]bun[/\\]packages[/\\]dutch$/,
/__fixtures__[/\\]bun[/\\]packages[/\\]john$/,
/__fixtures__[/\\]bun[/\\]packages[/\\]quaid$/,
/__fixtures__[/\\]bun[/\\]packages[/\\]t-800$/,
/__fixtures__[/\\]bun.lock[/\\]packages[/\\]conan$/,
/__fixtures__[/\\]bun.lock[/\\]packages[/\\]dutch$/,
/__fixtures__[/\\]bun.lock[/\\]packages[/\\]john$/,
/__fixtures__[/\\]bun.lock[/\\]packages[/\\]quaid$/,
/__fixtures__[/\\]bun.lock[/\\]packages[/\\]t-800$/,
];

afterEach(() => {
unsetFixture();
});

it("returns packages for Bun workspaces", async () => {
setFixture("bun");
setFixture("bun.lock");

const result = (await findWorkspacePackages()).sort();
for (let i = 0; i < result.length; ++i) {
Expand All @@ -48,7 +58,7 @@ describe("findWorkspacePackages", () => {
});

it("returns packages for Bun workspaces (sync)", () => {
setFixture("bun");
setFixture("bun.lock");

const result = findWorkspacePackagesSync().sort();
for (let i = 0; i < result.length; ++i) {
Expand All @@ -63,12 +73,12 @@ describe("findWorkspaceRoot", () => {
});

it("returns workspace root for Bun workspaces", async () => {
const root = setFixture("bun");
const root = setFixture("bun.lock");
equal(await findWorkspaceRoot(), root);
});

it("returns workspace root for Bun workspaces (sync)", () => {
const root = setFixture("bun");
const root = setFixture("bun.lock");
equal(findWorkspaceRootSync(), root);
});
});
1 change: 1 addition & 0 deletions test-repos/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bun.lock
bun.lockb
package-lock.json
pnpm-lock.yaml
Expand Down

0 comments on commit 66961be

Please sign in to comment.