Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions .changeset/nub-package-manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/workers-utils": patch
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Outdated
---

Add nub to the list of recognised package managers

Projects using nub can now be automatically detected by their `nub.lock` file.
1 change: 1 addition & 0 deletions packages/workers-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export {
PnpmPackageManager,
YarnPackageManager,
BunPackageManager,
NubPackageManager,
} from "./package-manager";

export {
Expand Down
12 changes: 11 additions & 1 deletion packages/workers-utils/src/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
export interface PackageManager {
/** The package manager identifier. */
type: "npm" | "yarn" | "pnpm" | "bun";
type: "npm" | "yarn" | "pnpm" | "bun" | "nub";
/** The command used to execute packages (e.g. `npx`, `pnpm`, `bunx`). */
npx: string;
/** The command segments used to download and execute packages (e.g. `["npx"]`, `["pnpm", "dlx"]`). */
Expand Down Expand Up @@ -52,3 +52,13 @@ export const BunPackageManager = {
dlx: ["bunx"],
lockFiles: ["bun.lockb", "bun.lock"],
} as const satisfies PackageManager;

/**
* Manage packages using nub.
*/
export const NubPackageManager = {
type: "nub",
npx: "nubx",
dlx: ["nubx"],
lockFiles: ["nub.lock"],
} as const satisfies PackageManager;
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
47 changes: 47 additions & 0 deletions packages/workers-utils/tests/package-manager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { existsSync } from "node:fs";
import { join } from "node:path";
import { describe, it } from "vitest";
import {
BunPackageManager,
NpmPackageManager,
NubPackageManager,
PnpmPackageManager,
YarnPackageManager,
} from "../src/package-manager";
import { runInTempDir, seed } from "../src/test-helpers";
import type { PackageManager } from "../src/package-manager";

const packageManagers: PackageManager[] = [
NpmPackageManager,
PnpmPackageManager,
YarnPackageManager,
BunPackageManager,
NubPackageManager,
];

describe("package managers", () => {
it("describes nub", ({ expect }) => {
expect(NubPackageManager).toEqual({
type: "nub",
npx: "nubx",
dlx: ["nubx"],
lockFiles: ["nub.lock"],
});
});

describe("lock file detection", () => {
runInTempDir();

// Detection is lock-file-based: a project is managed by the package
// manager whose lock file is present, matching how consumers resolve it.
const findByLockFile = (dir: string) =>
packageManagers.find((pm) =>
pm.lockFiles.some((lockFile) => existsSync(join(dir, lockFile)))
);

it("detects nub from nub.lock", async ({ expect }) => {
await seed({ "nub.lock": "" });
expect(findByLockFile(process.cwd())).toBe(NubPackageManager);
});
});
Comment thread
NuroDev marked this conversation as resolved.
});
Loading