Skip to content
Open
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
8 changes: 8 additions & 0 deletions .changeset/nub-tool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@manypkg/get-packages": minor
"@manypkg/find-root": minor
"@manypkg/tools": minor
"@manypkg/cli": minor
---

Add `NubTool` for monorepos with `nub.lock` and `package.json` workspaces
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions __fixtures__/basic-nub-object-workspaces/nub.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a placeholder nub.lock file for testing purposes
13 changes: 13 additions & 0 deletions __fixtures__/basic-nub-object-workspaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "basic-nub-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 @@
module.exports = "package-one";
1 change: 1 addition & 0 deletions __fixtures__/basic-nub/nub.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a placeholder nub.lock file for testing purposes
8 changes: 8 additions & 0 deletions __fixtures__/basic-nub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "basic-nub",
"version": "1.0.0",
"private": true,
"workspaces": [
"packages/*"
]
}
5 changes: 5 additions & 0 deletions __fixtures__/basic-nub/packages/package-one/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-nub-package-one",
"version": "1.0.0",
"main": "src/index.js"
}
1 change: 1 addition & 0 deletions __fixtures__/basic-nub/packages/package-one/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "package-one";
8 changes: 8 additions & 0 deletions __fixtures__/nub-no-lock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "nub-no-lock",
"version": "1.0.0",
"private": true,
"workspaces": [
"packages/*"
]
}
5 changes: 5 additions & 0 deletions __fixtures__/nub-no-lock/packages/package-one/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "nub-no-lock-package-one",
"version": "1.0.0",
"main": "src/index.js"
}
1 change: 1 addition & 0 deletions __fixtures__/nub-object-workspace-base/nub.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a placeholder nub.lock file for testing purposes
13 changes: 13 additions & 0 deletions __fixtures__/nub-object-workspace-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "nub-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": "nub-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": "nub-object-workspace-base-pkg-b",
"version": "1.0.0",
"main": "src/index.js"
}
1 change: 1 addition & 0 deletions __fixtures__/nub-workspace-base/nub.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a placeholder nub.lock file for testing purposes
8 changes: 8 additions & 0 deletions __fixtures__/nub-workspace-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "nub-workspace-base",
"version": "1.0.0",
"private": true,
"workspaces": [
"packages/*"
]
}
5 changes: 5 additions & 0 deletions __fixtures__/nub-workspace-base/packages/pkg-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "nub-workspace-base-pkg-a",
"version": "1.0.0",
"main": "src/index.js"
}
5 changes: 5 additions & 0 deletions __fixtures__/nub-workspace-base/packages/pkg-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "nub-workspace-base-pkg-b",
"version": "1.0.0",
"main": "src/index.js"
}
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion packages/find-root/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
35 changes: 35 additions & 0 deletions packages/find-root/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BunTool,
LernaTool,
NpmTool,
NubTool,
PnpmTool,
RootTool,
YarnTool,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions packages/find-root/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BunTool,
LernaTool,
NpmTool,
NubTool,
PnpmTool,
RootTool,
RushTool,
Expand All @@ -25,6 +26,7 @@ export const DEFAULT_TOOLS: Tool[] = [
PnpmTool,
NpmTool,
BunTool,
NubTool,
LernaTool,
RushTool,
RootTool,
Expand Down
4 changes: 2 additions & 2 deletions packages/get-packages/README.md
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
42 changes: 42 additions & 0 deletions packages/get-packages/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Loading
Loading