Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/fix-bun-object-workspaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@manypkg/tools": patch
---

Support object-form workspaces in `BunTool` to handle `catalog` usage
4 changes: 4 additions & 0 deletions __fixtures__/basic-bun-object-workspaces/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions __fixtures__/basic-bun-object-workspaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "basic-bun-object-workspaces",
"version": "1.0.0",
"private": true,
"workspaces": {
"packages": [
"packages/*"
],
"catalog": {
"some-dep": "^1.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "package-one",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
Empty file.
13 changes: 13 additions & 0 deletions __fixtures__/bun-object-workspace-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "bun-object-workspace-base",
"version": "1.0.0",
"private": true,
"workspaces": {
"packages": [
"packages/*"
],
"catalog": {
"some-dep": "^1.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "bun-object-workspace-base-pkg-a",
"version": "1.0.0",
"main": "src/index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "bun-object-workspace-base-pkg-b",
"version": "1.0.0",
"main": "src/index.js"
}
11 changes: 11 additions & 0 deletions packages/find-root/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ const runTests = (findRoot: FindRoot) => {
});
});

test("it returns the root of a bun monorepo with object-form workspaces", async () => {
let tmpPath = f.copy("basic-bun-object-workspaces");
let monorepoRoot = await findRoot(
path.join(tmpPath, "packages", "package-one", "src")
);
expect(monorepoRoot).toEqual({
tool: BunTool.type,
rootDir: tmpPath,
});
});

test("it does not detect bun monorepo without lock file", async () => {
let tmpPath = f.copy("bun-no-lock");
let monorepoRoot = await findRoot(
Expand Down
21 changes: 21 additions & 0 deletions packages/get-packages/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,27 @@ let runTests = (getPackages: GetPackages) => {
}
});

it("should resolve workspaces for bun with object-form workspaces", async () => {
const dir = f.copy("bun-object-workspace-base");

// Test for both root and subdirectories
for (const location of [".", "packages", "packages/pkg-a"]) {
const allPackages = await getPackages(path.join(dir, location));

if (allPackages.packages === null) {
return expect(allPackages.packages).not.toBeNull();
}

expect(allPackages.packages[0].packageJson.name).toEqual(
"bun-object-workspace-base-pkg-a"
);
expect(allPackages.packages[1].packageJson.name).toEqual(
"bun-object-workspace-base-pkg-b"
);
expect(allPackages.tool.type).toEqual("bun");
}
});

it("should resolve workspaces for lerna", async () => {
const dir = f.copy("lerna-workspace-base");

Expand Down
22 changes: 17 additions & 5 deletions packages/tools/src/BunTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
import { readJson, readJsonSync } from "./utils.ts";

interface BunPackageJSON extends PackageJSON {
workspaces?: string[];
workspaces?:
| string[]
| { packages: string[]; catalog?: Record<string, string> };
}

async function hasBunLockFile(directory: string): Promise<boolean> {
Expand Down Expand Up @@ -55,7 +57,10 @@ export const BunTool: Tool = {
hasBunLockFile(directory),
]);
if (pkgJson.workspaces && hasLockFile) {
if (Array.isArray(pkgJson.workspaces)) {
if (
Array.isArray(pkgJson.workspaces) ||
Array.isArray(pkgJson.workspaces.packages)
) {
return true;
}
}
Expand All @@ -76,7 +81,10 @@ export const BunTool: Tool = {
}
const pkgJson = readJsonSync(directory, "package.json") as BunPackageJSON;
if (pkgJson.workspaces) {
if (Array.isArray(pkgJson.workspaces)) {
if (
Array.isArray(pkgJson.workspaces) ||
Array.isArray(pkgJson.workspaces.packages)
) {
return true;
}
}
Expand All @@ -97,7 +105,9 @@ export const BunTool: Tool = {
rootDir,
"package.json"
)) as BunPackageJSON;
const packageGlobs: string[] = pkgJson.workspaces || [];
const packageGlobs: string[] = Array.isArray(pkgJson.workspaces)
? pkgJson.workspaces
: pkgJson.workspaces?.packages || [];

return {
tool: BunTool,
Expand All @@ -124,7 +134,9 @@ export const BunTool: Tool = {

try {
const pkgJson = readJsonSync(rootDir, "package.json") as BunPackageJSON;
const packageGlobs: string[] = pkgJson.workspaces || [];
const packageGlobs: string[] = Array.isArray(pkgJson.workspaces)
? pkgJson.workspaces
: pkgJson.workspaces?.packages || [];

return {
tool: BunTool,
Expand Down