From fc3fb51c13cb7f244646a3872a5183d03b512c29 Mon Sep 17 00:00:00 2001 From: Yam Borodetsky Date: Thu, 24 Sep 2026 00:00:08 +0500 Subject: [PATCH 1/3] feat: add NubTool for Nub monorepo discovery Co-authored-by: Cursor --- .changeset/nub-tool.md | 8 + README.md | 2 +- .../basic-nub-object-workspaces/nub.lock | 1 + .../basic-nub-object-workspaces/package.json | 13 ++ .../packages/package-one/package.json | 4 + .../packages/package-one/src/index.js | 1 + __fixtures__/basic-nub/nub.lock | 1 + __fixtures__/basic-nub/package.json | 8 + .../packages/package-one/package.json | 5 + .../packages/package-one/src/index.js | 1 + __fixtures__/nub-no-lock/package.json | 8 + .../packages/package-one/package.json | 5 + .../nub-object-workspace-base/nub.lock | 1 + .../nub-object-workspace-base/package.json | 13 ++ .../packages/pkg-a/package.json | 5 + .../packages/pkg-b/package.json | 5 + __fixtures__/nub-workspace-base/nub.lock | 1 + __fixtures__/nub-workspace-base/package.json | 8 + .../packages/pkg-a/package.json | 5 + .../packages/pkg-b/package.json | 5 + packages/cli/README.md | 2 +- packages/cli/src/utils.ts | 6 +- packages/find-root/README.md | 2 +- packages/find-root/src/index.test.ts | 35 ++++ packages/find-root/src/index.ts | 2 + packages/get-packages/README.md | 4 +- packages/get-packages/src/index.test.ts | 42 +++++ packages/tools/src/NubTool.ts | 152 ++++++++++++++++++ packages/tools/src/index.ts | 1 + 29 files changed, 340 insertions(+), 6 deletions(-) create mode 100644 .changeset/nub-tool.md create mode 100644 __fixtures__/basic-nub-object-workspaces/nub.lock create mode 100644 __fixtures__/basic-nub-object-workspaces/package.json create mode 100644 __fixtures__/basic-nub-object-workspaces/packages/package-one/package.json create mode 100644 __fixtures__/basic-nub-object-workspaces/packages/package-one/src/index.js create mode 100644 __fixtures__/basic-nub/nub.lock create mode 100644 __fixtures__/basic-nub/package.json create mode 100644 __fixtures__/basic-nub/packages/package-one/package.json create mode 100644 __fixtures__/basic-nub/packages/package-one/src/index.js create mode 100644 __fixtures__/nub-no-lock/package.json create mode 100644 __fixtures__/nub-no-lock/packages/package-one/package.json create mode 100644 __fixtures__/nub-object-workspace-base/nub.lock create mode 100644 __fixtures__/nub-object-workspace-base/package.json create mode 100644 __fixtures__/nub-object-workspace-base/packages/pkg-a/package.json create mode 100644 __fixtures__/nub-object-workspace-base/packages/pkg-b/package.json create mode 100644 __fixtures__/nub-workspace-base/nub.lock create mode 100644 __fixtures__/nub-workspace-base/package.json create mode 100644 __fixtures__/nub-workspace-base/packages/pkg-a/package.json create mode 100644 __fixtures__/nub-workspace-base/packages/pkg-b/package.json create mode 100644 packages/tools/src/NubTool.ts diff --git a/.changeset/nub-tool.md b/.changeset/nub-tool.md new file mode 100644 index 00000000..b4f2e1eb --- /dev/null +++ b/.changeset/nub-tool.md @@ -0,0 +1,8 @@ +--- +"@manypkg/get-packages": minor +"@manypkg/find-root": minor +"@manypkg/tools": minor +"@manypkg/cli": minor +--- + +Add Nub support diff --git a/README.md b/README.md index a6e2269b..cf76356f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ # Manypkg -Manypkg is a linter for `package.json` files in Yarn, npm, pnpm, Bun or Lerna monorepos. +Manypkg is a linter for `package.json` files in Yarn, npm, pnpm, Bun, Nub or Lerna monorepos. ## Install diff --git a/__fixtures__/basic-nub-object-workspaces/nub.lock b/__fixtures__/basic-nub-object-workspaces/nub.lock new file mode 100644 index 00000000..e632cbb4 --- /dev/null +++ b/__fixtures__/basic-nub-object-workspaces/nub.lock @@ -0,0 +1 @@ +# This is a placeholder nub.lock file for testing purposes diff --git a/__fixtures__/basic-nub-object-workspaces/package.json b/__fixtures__/basic-nub-object-workspaces/package.json new file mode 100644 index 00000000..38f6d42b --- /dev/null +++ b/__fixtures__/basic-nub-object-workspaces/package.json @@ -0,0 +1,13 @@ +{ + "name": "basic-nub-object-workspaces", + "version": "1.0.0", + "private": true, + "workspaces": { + "packages": [ + "packages/*" + ], + "catalog": { + "some-dep": "^1.0.0" + } + } +} diff --git a/__fixtures__/basic-nub-object-workspaces/packages/package-one/package.json b/__fixtures__/basic-nub-object-workspaces/packages/package-one/package.json new file mode 100644 index 00000000..80acbd05 --- /dev/null +++ b/__fixtures__/basic-nub-object-workspaces/packages/package-one/package.json @@ -0,0 +1,4 @@ +{ + "name": "package-one", + "version": "1.0.0" +} diff --git a/__fixtures__/basic-nub-object-workspaces/packages/package-one/src/index.js b/__fixtures__/basic-nub-object-workspaces/packages/package-one/src/index.js new file mode 100644 index 00000000..689f7c15 --- /dev/null +++ b/__fixtures__/basic-nub-object-workspaces/packages/package-one/src/index.js @@ -0,0 +1 @@ +module.exports = "package-one"; diff --git a/__fixtures__/basic-nub/nub.lock b/__fixtures__/basic-nub/nub.lock new file mode 100644 index 00000000..e632cbb4 --- /dev/null +++ b/__fixtures__/basic-nub/nub.lock @@ -0,0 +1 @@ +# This is a placeholder nub.lock file for testing purposes diff --git a/__fixtures__/basic-nub/package.json b/__fixtures__/basic-nub/package.json new file mode 100644 index 00000000..d528b876 --- /dev/null +++ b/__fixtures__/basic-nub/package.json @@ -0,0 +1,8 @@ +{ + "name": "basic-nub", + "version": "1.0.0", + "private": true, + "workspaces": [ + "packages/*" + ] +} diff --git a/__fixtures__/basic-nub/packages/package-one/package.json b/__fixtures__/basic-nub/packages/package-one/package.json new file mode 100644 index 00000000..ccc82342 --- /dev/null +++ b/__fixtures__/basic-nub/packages/package-one/package.json @@ -0,0 +1,5 @@ +{ + "name": "basic-nub-package-one", + "version": "1.0.0", + "main": "src/index.js" +} diff --git a/__fixtures__/basic-nub/packages/package-one/src/index.js b/__fixtures__/basic-nub/packages/package-one/src/index.js new file mode 100644 index 00000000..689f7c15 --- /dev/null +++ b/__fixtures__/basic-nub/packages/package-one/src/index.js @@ -0,0 +1 @@ +module.exports = "package-one"; diff --git a/__fixtures__/nub-no-lock/package.json b/__fixtures__/nub-no-lock/package.json new file mode 100644 index 00000000..7864be73 --- /dev/null +++ b/__fixtures__/nub-no-lock/package.json @@ -0,0 +1,8 @@ +{ + "name": "nub-no-lock", + "version": "1.0.0", + "private": true, + "workspaces": [ + "packages/*" + ] +} diff --git a/__fixtures__/nub-no-lock/packages/package-one/package.json b/__fixtures__/nub-no-lock/packages/package-one/package.json new file mode 100644 index 00000000..c62f5eaf --- /dev/null +++ b/__fixtures__/nub-no-lock/packages/package-one/package.json @@ -0,0 +1,5 @@ +{ + "name": "nub-no-lock-package-one", + "version": "1.0.0", + "main": "src/index.js" +} diff --git a/__fixtures__/nub-object-workspace-base/nub.lock b/__fixtures__/nub-object-workspace-base/nub.lock new file mode 100644 index 00000000..e632cbb4 --- /dev/null +++ b/__fixtures__/nub-object-workspace-base/nub.lock @@ -0,0 +1 @@ +# This is a placeholder nub.lock file for testing purposes diff --git a/__fixtures__/nub-object-workspace-base/package.json b/__fixtures__/nub-object-workspace-base/package.json new file mode 100644 index 00000000..7ac360c9 --- /dev/null +++ b/__fixtures__/nub-object-workspace-base/package.json @@ -0,0 +1,13 @@ +{ + "name": "nub-object-workspace-base", + "version": "1.0.0", + "private": true, + "workspaces": { + "packages": [ + "packages/*" + ], + "catalog": { + "some-dep": "^1.0.0" + } + } +} diff --git a/__fixtures__/nub-object-workspace-base/packages/pkg-a/package.json b/__fixtures__/nub-object-workspace-base/packages/pkg-a/package.json new file mode 100644 index 00000000..3b4c7ff9 --- /dev/null +++ b/__fixtures__/nub-object-workspace-base/packages/pkg-a/package.json @@ -0,0 +1,5 @@ +{ + "name": "nub-object-workspace-base-pkg-a", + "version": "1.0.0", + "main": "src/index.js" +} diff --git a/__fixtures__/nub-object-workspace-base/packages/pkg-b/package.json b/__fixtures__/nub-object-workspace-base/packages/pkg-b/package.json new file mode 100644 index 00000000..90d4e70f --- /dev/null +++ b/__fixtures__/nub-object-workspace-base/packages/pkg-b/package.json @@ -0,0 +1,5 @@ +{ + "name": "nub-object-workspace-base-pkg-b", + "version": "1.0.0", + "main": "src/index.js" +} diff --git a/__fixtures__/nub-workspace-base/nub.lock b/__fixtures__/nub-workspace-base/nub.lock new file mode 100644 index 00000000..e632cbb4 --- /dev/null +++ b/__fixtures__/nub-workspace-base/nub.lock @@ -0,0 +1 @@ +# This is a placeholder nub.lock file for testing purposes diff --git a/__fixtures__/nub-workspace-base/package.json b/__fixtures__/nub-workspace-base/package.json new file mode 100644 index 00000000..9d4e7926 --- /dev/null +++ b/__fixtures__/nub-workspace-base/package.json @@ -0,0 +1,8 @@ +{ + "name": "nub-workspace-base", + "version": "1.0.0", + "private": true, + "workspaces": [ + "packages/*" + ] +} diff --git a/__fixtures__/nub-workspace-base/packages/pkg-a/package.json b/__fixtures__/nub-workspace-base/packages/pkg-a/package.json new file mode 100644 index 00000000..231a508c --- /dev/null +++ b/__fixtures__/nub-workspace-base/packages/pkg-a/package.json @@ -0,0 +1,5 @@ +{ + "name": "nub-workspace-base-pkg-a", + "version": "1.0.0", + "main": "src/index.js" +} diff --git a/__fixtures__/nub-workspace-base/packages/pkg-b/package.json b/__fixtures__/nub-workspace-base/packages/pkg-b/package.json new file mode 100644 index 00000000..316db6fc --- /dev/null +++ b/__fixtures__/nub-workspace-base/packages/pkg-b/package.json @@ -0,0 +1,5 @@ +{ + "name": "nub-workspace-base-pkg-b", + "version": "1.0.0", + "main": "src/index.js" +} diff --git a/packages/cli/README.md b/packages/cli/README.md index 3a6b8c58..ecc49aad 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -1,6 +1,6 @@ # Manypkg -Manypkg is a linter for `package.json` files in Yarn, npm, Lerna, pnpm, Bun or Rush monorepos. +Manypkg is a linter for `package.json` files in Yarn, npm, Lerna, pnpm, Bun, Nub or Rush monorepos. ## Install diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 401f26ef..3350fd83 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -23,6 +23,7 @@ export async function install(toolType: string, cwd: string) { bun: "bun", lerna: "lerna", npm: "npm", + nub: "nub", pnpm: "pnpm", root: "yarn", rush: "rushx", @@ -31,7 +32,10 @@ export async function install(toolType: string, cwd: string) { await exec( cliRunners[toolType], - toolType === "npm" || toolType === "pnpm" || toolType === "bun" + toolType === "npm" || + toolType === "pnpm" || + toolType === "bun" || + toolType === "nub" ? ["install"] : toolType === "lerna" ? ["bootstrap", "--since", "HEAD"] diff --git a/packages/find-root/README.md b/packages/find-root/README.md index 28a5b08c..e5cb5226 100644 --- a/packages/find-root/README.md +++ b/packages/find-root/README.md @@ -1,6 +1,6 @@ # @manypkg/find-root -> Find the root of a monorepo with Yarn workspaces, npm, Lerna, pnpm, Bun or Rush +> Find the root of a monorepo with Yarn workspaces, npm, Lerna, pnpm, Bun, Nub or Rush ## Install diff --git a/packages/find-root/src/index.test.ts b/packages/find-root/src/index.test.ts index 8a9b77e6..6477a408 100644 --- a/packages/find-root/src/index.test.ts +++ b/packages/find-root/src/index.test.ts @@ -7,6 +7,7 @@ import { BunTool, LernaTool, NpmTool, + NubTool, PnpmTool, RootTool, YarnTool, @@ -108,6 +109,40 @@ const runTests = (findRoot: FindRoot) => { }); }); + test("it returns the root of a nub monorepo", async () => { + let tmpPath = f.copy("basic-nub"); + let monorepoRoot = await findRoot( + path.join(tmpPath, "packages", "package-one", "src") + ); + expect(monorepoRoot).toEqual({ + tool: NubTool.type, + rootDir: tmpPath, + }); + }); + + test("it returns the root of a nub monorepo with object-form workspaces", async () => { + let tmpPath = f.copy("basic-nub-object-workspaces"); + let monorepoRoot = await findRoot( + path.join(tmpPath, "packages", "package-one", "src") + ); + expect(monorepoRoot).toEqual({ + tool: NubTool.type, + rootDir: tmpPath, + }); + }); + + test("it does not detect nub monorepo without lock file", async () => { + let tmpPath = f.copy("nub-no-lock"); + let monorepoRoot = await findRoot( + path.join(tmpPath, "packages", "package-one", "src") + ); + // Should be detected as a root tool since it has workspaces but no lock file + expect(monorepoRoot).toEqual({ + tool: RootTool.type, + rootDir: path.join(tmpPath, "packages", "package-one"), + }); + }); + test("it does not detect bun monorepo without lock file", async () => { let tmpPath = f.copy("bun-no-lock"); let monorepoRoot = await findRoot( diff --git a/packages/find-root/src/index.ts b/packages/find-root/src/index.ts index de8b07f4..a5248e73 100644 --- a/packages/find-root/src/index.ts +++ b/packages/find-root/src/index.ts @@ -2,6 +2,7 @@ import { BunTool, LernaTool, NpmTool, + NubTool, PnpmTool, RootTool, RushTool, @@ -25,6 +26,7 @@ export const DEFAULT_TOOLS: Tool[] = [ PnpmTool, NpmTool, BunTool, + NubTool, LernaTool, RushTool, RootTool, diff --git a/packages/get-packages/README.md b/packages/get-packages/README.md index 919a68a2..bb546dc0 100644 --- a/packages/get-packages/README.md +++ b/packages/get-packages/README.md @@ -1,8 +1,8 @@ # @manypkg/get-packages -> A simple utility to get the packages from a monorepo, whether they're using Yarn, npm, Lerna, pnpm, Bun or Rush +> A simple utility to get the packages from a monorepo, whether they're using Yarn, npm, Lerna, pnpm, Bun, Nub or Rush -This library exports `getPackages` and `getPackagesSync`. It is intended mostly for use of developers building tools that want to support different kinds of monorepos as an easy way to write tools without having to write tool-specific code. It supports Yarn, npm, Lerna, pnpm, Bun, Rush and single-package repos(where the only package is the the same as the root package). This library uses `@manypkg/find-root` to search up from the directory that's passed to `getPackages` or `getPackagesSync` to find the project root. +This library exports `getPackages` and `getPackagesSync`. It is intended mostly for use of developers building tools that want to support different kinds of monorepos as an easy way to write tools without having to write tool-specific code. It supports Yarn, npm, Lerna, pnpm, Bun, Nub, Rush and single-package repos(where the only package is the the same as the root package). This library uses `@manypkg/find-root` to search up from the directory that's passed to `getPackages` or `getPackagesSync` to find the project root. ```typescript import { getPackages, getPackagesSync } from "@manypkg/get-packages"; diff --git a/packages/get-packages/src/index.test.ts b/packages/get-packages/src/index.test.ts index 0f24bb6c..65519ddf 100644 --- a/packages/get-packages/src/index.test.ts +++ b/packages/get-packages/src/index.test.ts @@ -162,6 +162,48 @@ let runTests = (getPackages: GetPackages) => { } }); + it("should resolve workspaces for nub", async () => { + const dir = f.copy("nub-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( + "nub-workspace-base-pkg-a" + ); + expect(allPackages.packages[1].packageJson.name).toEqual( + "nub-workspace-base-pkg-b" + ); + expect(allPackages.tool.type).toEqual("nub"); + } + }); + + it("should resolve workspaces for nub with object-form workspaces", async () => { + const dir = f.copy("nub-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( + "nub-object-workspace-base-pkg-a" + ); + expect(allPackages.packages[1].packageJson.name).toEqual( + "nub-object-workspace-base-pkg-b" + ); + expect(allPackages.tool.type).toEqual("nub"); + } + }); + it("should resolve workspaces for lerna", async () => { const dir = f.copy("lerna-workspace-base"); diff --git a/packages/tools/src/NubTool.ts b/packages/tools/src/NubTool.ts new file mode 100644 index 00000000..9baba16c --- /dev/null +++ b/packages/tools/src/NubTool.ts @@ -0,0 +1,152 @@ +import * as path from "node:path"; +import * as fs from "node:fs"; +import * as fsp from "node:fs/promises"; +import { F_OK } from "node:constants"; + +import { + type Tool, + type PackageJSON, + type Packages, + InvalidMonorepoError, +} from "./Tool.ts"; +import { + expandPackageGlobs, + expandPackageGlobsSync, +} from "./expandPackageGlobs.ts"; +import { readJson, readJsonSync } from "./utils.ts"; + +interface NubPackageJSON extends PackageJSON { + workspaces?: + | string[] + | { packages: string[]; catalog?: Record }; +} + +async function hasNubLockFile(directory: string): Promise { + try { + await fsp.access(path.join(directory, "nub.lock"), F_OK); + return true; + } catch (err) { + return false; + } +} + +function hasNubLockFileSync(directory: string): boolean { + try { + fs.accessSync(path.join(directory, "nub.lock"), F_OK); + return true; + } catch (err) { + return false; + } +} + +export const NubTool: Tool = { + type: "nub", + + async isMonorepoRoot(directory: string): Promise { + try { + const [pkgJson, hasLockFile] = await Promise.all([ + readJson(directory, "package.json") as Promise, + hasNubLockFile(directory), + ]); + if (pkgJson.workspaces && hasLockFile) { + if ( + Array.isArray(pkgJson.workspaces) || + Array.isArray(pkgJson.workspaces.packages) + ) { + return true; + } + } + } catch (err) { + if (err && (err as { code: string }).code === "ENOENT") { + return false; + } + throw err; + } + return false; + }, + + isMonorepoRootSync(directory: string): boolean { + try { + const hasLockFile = hasNubLockFileSync(directory); + if (!hasLockFile) { + return false; + } + const pkgJson = readJsonSync(directory, "package.json") as NubPackageJSON; + if (pkgJson.workspaces) { + if ( + Array.isArray(pkgJson.workspaces) || + Array.isArray(pkgJson.workspaces.packages) + ) { + return true; + } + } + } catch (err) { + if (err && (err as { code: string }).code === "ENOENT") { + return false; + } + throw err; + } + return false; + }, + + async getPackages(directory: string): Promise { + const rootDir = path.resolve(directory); + + try { + const pkgJson = (await readJson( + rootDir, + "package.json" + )) as NubPackageJSON; + const packageGlobs: string[] = Array.isArray(pkgJson.workspaces) + ? pkgJson.workspaces + : pkgJson.workspaces?.packages || []; + + return { + tool: NubTool, + packages: await expandPackageGlobs(packageGlobs, rootDir), + rootPackage: { + dir: rootDir, + relativeDir: ".", + packageJson: pkgJson, + }, + rootDir, + }; + } catch (err) { + if (err && (err as { code: string }).code === "ENOENT") { + throw new InvalidMonorepoError( + `Directory ${rootDir} is not a valid ${NubTool.type} monorepo root` + ); + } + throw err; + } + }, + + getPackagesSync(directory: string): Packages { + const rootDir = path.resolve(directory); + + try { + const pkgJson = readJsonSync(rootDir, "package.json") as NubPackageJSON; + const packageGlobs: string[] = Array.isArray(pkgJson.workspaces) + ? pkgJson.workspaces + : pkgJson.workspaces?.packages || []; + + return { + tool: NubTool, + packages: expandPackageGlobsSync(packageGlobs, rootDir), + rootPackage: { + dir: rootDir, + relativeDir: ".", + packageJson: pkgJson, + }, + rootDir, + }; + } catch (err) { + if (err && (err as { code: string }).code === "ENOENT") { + throw new InvalidMonorepoError( + `Directory ${rootDir} is not a valid ${NubTool.type} monorepo root` + ); + } + throw err; + } + }, +}; diff --git a/packages/tools/src/index.ts b/packages/tools/src/index.ts index f39579c9..3e27dcd7 100644 --- a/packages/tools/src/index.ts +++ b/packages/tools/src/index.ts @@ -2,6 +2,7 @@ export * from "./Tool.ts"; export { BunTool } from "./BunTool.ts"; export { LernaTool } from "./LernaTool.ts"; export { NpmTool } from "./NpmTool.ts"; +export { NubTool } from "./NubTool.ts"; export { PnpmTool } from "./PnpmTool.ts"; export { RootTool } from "./RootTool.ts"; export { RushTool } from "./RushTool.ts"; From 8a25f1ad04462adb1556a64de0ce88d42001eaef Mon Sep 17 00:00:00 2001 From: Yam Borodetsky Date: Thu, 24 Sep 2026 00:08:40 +0500 Subject: [PATCH 2/3] Clarify the Nub changeset summary. Co-authored-by: Cursor --- .changeset/nub-tool.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/nub-tool.md b/.changeset/nub-tool.md index b4f2e1eb..d7c58318 100644 --- a/.changeset/nub-tool.md +++ b/.changeset/nub-tool.md @@ -5,4 +5,4 @@ "@manypkg/cli": minor --- -Add Nub support +Add NubTool for nub.lock + package.json workspaces monorepos. From f24a2546bdfb1139f7eb3a000b5246f1b3490560 Mon Sep 17 00:00:00 2001 From: Yam Borodetsky Date: Thu, 24 Sep 2026 00:17:34 +0500 Subject: [PATCH 3/3] Match the Nub changeset summary to existing style. Co-authored-by: Cursor --- .changeset/nub-tool.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/nub-tool.md b/.changeset/nub-tool.md index d7c58318..112e8bbc 100644 --- a/.changeset/nub-tool.md +++ b/.changeset/nub-tool.md @@ -5,4 +5,4 @@ "@manypkg/cli": minor --- -Add NubTool for nub.lock + package.json workspaces monorepos. +Add `NubTool` for monorepos with `nub.lock` and `package.json` workspaces