read-pkg
Advanced tools
Comparing version 7.0.0 to 7.1.0
@@ -10,3 +10,3 @@ import * as typeFest from 'type-fest'; | ||
*/ | ||
readonly cwd?: string; | ||
readonly cwd?: URL | string; | ||
@@ -13,0 +13,0 @@ /** |
import process from 'node:process'; | ||
import fs, {promises as fsPromises} from 'node:fs'; | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import parseJson from 'parse-json'; | ||
import normalizePackageData from 'normalize-package-data'; | ||
export async function readPackage({cwd = process.cwd(), normalize = true} = {}) { | ||
const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath; | ||
export async function readPackage({cwd, normalize = true} = {}) { | ||
cwd = toPath(cwd) || process.cwd(); | ||
const filePath = path.resolve(cwd, 'package.json'); | ||
@@ -18,3 +22,4 @@ const json = parseJson(await fsPromises.readFile(filePath, 'utf8')); | ||
export function readPackageSync({cwd = process.cwd(), normalize = true} = {}) { | ||
export function readPackageSync({cwd, normalize = true} = {}) { | ||
cwd = toPath(cwd) || process.cwd(); | ||
const filePath = path.resolve(cwd, 'package.json'); | ||
@@ -21,0 +26,0 @@ const json = parseJson(fs.readFileSync(filePath, 'utf8')); |
{ | ||
"name": "read-pkg", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"description": "Read a package.json file", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -44,3 +44,3 @@ # read-pkg | ||
Type: `string`\ | ||
Type: `URL | string`\ | ||
Default: `process.cwd()` | ||
@@ -47,0 +47,0 @@ |
5981
70