From 1ca6ee9161671027aa71e1e16c7c5088d994ba68 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:44:57 -0700 Subject: [PATCH] feat: monorepoOnly option --- src/constants.ts | 5 ++++ src/detect.ts | 64 +++++++++++++++++++++++++++++------------------- src/types.ts | 4 +++ 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 63990ab..049df37 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -9,6 +9,11 @@ export const AGENTS: Agent[] = [ 'bun', ] +// the order here matters, more specific one comes first +export const WORKSPACE_DEFS: Record = { + 'pnpm-lock.yaml': 'pnpm', +} + // the order here matters, more specific one comes first export const LOCKS: Record = { 'bun.lockb': 'bun', diff --git a/src/detect.ts b/src/detect.ts index e394408..0217c43 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -3,7 +3,7 @@ import fsPromises from 'node:fs/promises' import path from 'node:path' import process from 'node:process' import type { Agent, AgentName, DetectOptions, DetectResult } from './types' -import { AGENTS, LOCKS } from './constants' +import { AGENTS, LOCKS, WORKSPACE_DEFS } from './constants' /** * Detects the package manager used in the project. @@ -15,21 +15,28 @@ export async function detect(options: DetectOptions = {}): Promise { } function parsePackageJsonSync(filepath: string): any | null { - if (!filepath || !fileExists(filepath)) { + if (!filepath || !fileExistsSync(filepath)) { return null } return JSON.parse(fs.readFileSync(filepath, 'utf8')) diff --git a/src/types.ts b/src/types.ts index f933658..64b2867 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,6 +37,10 @@ export interface DetectOptions { * @default `process.cwd()` */ cwd?: string + /** + * Only detect the package manager if within a monorepo + */ + monorepoOnly?: boolean /** * Callback when unknown package manager from package.json. * @param packageManager - The `packageManager` value from package.json file.