UNPKG

danger-plugin-npm-check-updates

Version:
54 lines (53 loc) 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readPackageLock = exports.readPackageJson = void 0; const fs = require("fs"); const path = require("path"); const lockfile = require("@yarnpkg/lockfile"); exports.readPackageJson = (basePath) => { try { let result = null; const packageJsonPath = path.join(basePath, 'package.json'); if (fs.existsSync(packageJsonPath)) { const packageJson = fs.readFileSync(packageJsonPath, 'utf8'); result = JSON.parse(packageJson); } return result; } catch (e) { console.error(e.message); return null; } }; exports.readPackageLock = (basePath) => { try { let result = null; const packageLockPath = path.join(basePath, 'package-lock.json'); const yarnLockPath = path.join(basePath, 'yarn.lock'); if (fs.existsSync(packageLockPath)) { const packageLock = fs.readFileSync(packageLockPath, 'utf8'); const packageLockParse = JSON.parse(packageLock); if (packageLockParse) { result = { dependencies: packageLockParse.dependencies, type: 'npm', }; } } if (fs.existsSync(yarnLockPath)) { const yarnLock = fs.readFileSync(yarnLockPath, 'utf8'); const lockFileParse = lockfile.parse(yarnLock); if (lockFileParse) { result = { object: lockFileParse.object, type: 'yarn', }; } } return result; } catch (e) { console.error(e.message); return null; } };