UNPKG

workspace-tools

Version:

A collection of tools that are useful in a git-controlled monorepo that is managed by one of these software:

49 lines (48 loc) 2.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const find_up_1 = __importDefault(require("find-up")); const fs_extra_1 = __importDefault(require("fs-extra")); const read_yaml_file_1 = __importDefault(require("read-yaml-file")); const nameAtVersion_1 = require("./nameAtVersion"); exports.nameAtVersion = nameAtVersion_1.nameAtVersion; const parsePnpmLock_1 = require("./parsePnpmLock"); const memoization = {}; async function parseLockFile(packageRoot) { const yarnLockPath = await find_up_1.default(["yarn.lock", "common/config/rush/yarn.lock"], { cwd: packageRoot }); // First, test out whether this works for yarn if (yarnLockPath) { if (memoization[yarnLockPath]) { return memoization[yarnLockPath]; } const parseYarnLock = (await Promise.resolve().then(() => __importStar(require("@yarnpkg/lockfile")))).parse; const yarnLock = fs_extra_1.default.readFileSync(yarnLockPath).toString(); const parsed = parseYarnLock(yarnLock); memoization[yarnLockPath] = parsed; return parsed; } // Second, test out whether this works for pnpm let pnpmLockPath = await find_up_1.default(["pnpm-lock.yaml", "common/config/rush/pnpm-lock.yaml"], { cwd: packageRoot }); if (pnpmLockPath) { if (memoization[pnpmLockPath]) { return memoization[pnpmLockPath]; } const yaml = await read_yaml_file_1.default(pnpmLockPath); const parsed = parsePnpmLock_1.parsePnpmLock(yaml); memoization[pnpmLockPath] = parsed; return memoization[pnpmLockPath]; } throw new Error("You do not have either yarn.lock nor pnpm-lock.yaml. Please use one of these package managers"); } exports.parseLockFile = parseLockFile; var queryLockFile_1 = require("./queryLockFile"); exports.queryLockFile = queryLockFile_1.queryLockFile;