UNPKG

@better-builds/lets-version

Version:

A package that reads your conventional commits and git history and recommends (or applies) a SemVer version bump for you

35 lines (34 loc) 1.34 kB
import appRootPath from 'app-root-path'; import { detect } from 'detect-package-manager'; import fs from 'fs-extra'; import path from 'path'; import yaml from 'yaml'; import { fixCWD } from './cwd.js'; /** * Attempts to detect whether this repository is a multi-package monorepo. */ export async function detectIfMonorepo(cwd = appRootPath.toString()) { const fixedCWD = fixCWD(cwd); const pm = await detect({ cwd: fixedCWD }); switch (pm) { case 'pnpm': { const pnpmWorkspaceFilePath = path.join(fixedCWD, 'pnpm-workspace.yaml'); try { const workspaceFileContents = await fs.readFile(pnpmWorkspaceFilePath, 'utf-8'); const parsedYaml = yaml.parse(workspaceFileContents) ?? {}; return Boolean(parsedYaml); // eslint-disable-next-line @typescript-eslint/no-unused-vars } catch (err) { /* file doesn't exist or the input is malformed */ return false; } } default: { const rootPJSONPath = path.join(fixedCWD, 'package.json'); /** @type {import('type-fest').PackageJson} */ const rootpjson = JSON.parse(await fs.readFile(rootPJSONPath, 'utf-8')); return Boolean(rootpjson.workspaces); } } }