UNPKG

@inlang/paraglide-js

Version:

[![NPM Downloads](https://img.shields.io/npm/dw/%40inlang%2Fparaglide-js?logo=npm&logoColor=red&label=npm%20downloads)](https://www.npmjs.com/package/@inlang/paraglide-js) [![GitHub Issues](https://img.shields.io/github/issues-closed/opral/paraglide-js?lo

31 lines 1.06 kB
import path from "node:path"; import { pathExists } from "../file-handling/exists.js"; /** * Attempts to find the package.json file that's closest to the current working directory. * * @param fs The filesystem to use. * @param cwd The current working directory. * @returns The path to the package.json file, or undefined if none was found. */ export async function findPackageJson(fs, cwd) { const potentialPackageJsonPath = path.resolve(cwd, "package.json"); const packageJsonExists = await pathExists(potentialPackageJsonPath, fs); if (packageJsonExists) return potentialPackageJsonPath; return undefined; } export async function getPackageJson(fs, cwd) { const packageJsonPath = await findPackageJson(fs, cwd); if (!packageJsonPath) return undefined; try { const packageJsonContents = await fs.readFile(packageJsonPath, { encoding: "utf-8", }); return JSON.parse(packageJsonContents); } catch { return undefined; } } //# sourceMappingURL=package.js.map