From b4e781f37ecb11e119eb5ad5b9efa620141c1c02 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 9 Oct 2023 17:34:32 -0700 Subject: [PATCH] fix(midnight-smoker): add overload for normalization to readPackageJson export `ReadPackageJsonResult` --- packages/midnight-smoker/src/util.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/midnight-smoker/src/util.ts b/packages/midnight-smoker/src/util.ts index 1609ef608..1fa0ff2e5 100644 --- a/packages/midnight-smoker/src/util.ts +++ b/packages/midnight-smoker/src/util.ts @@ -6,6 +6,7 @@ import path from 'node:path'; import readPkgUp, {type ReadResult} from 'read-pkg-up'; import {MissingPackageJsonError, UnreadablePackageJsonError} from './error'; +export type {ReadResult as ReadPackageJsonResult}; /** * Trims all strings in an array and removes empty strings. * Returns empty array if input is falsy. @@ -127,18 +128,20 @@ export interface ReadPackageJsonOpts { * @param Options * @returns Object with `packageJson` and `path` properties or `undefined` if not in `strict` mode */ +export async function readPackageJson( + opts: ReadPackageJsonOpts & {strict: true; normalize: true}, +): Promise; export async function readPackageJson( opts: ReadPackageJsonOpts & {strict: true}, ): Promise; export async function readPackageJson( opts?: ReadPackageJsonOpts, ): Promise; -export async function readPackageJson({ - cwd, - normalize, - strict, -}: ReadPackageJsonOpts = {}): Promise { - cwd ??= process.cwd(); +export async function readPackageJson( + opts: ReadPackageJsonOpts & {normalize: true; strict?: false}, +): Promise; +export async function readPackageJson(opts: ReadPackageJsonOpts = {}) { + const {cwd = process.cwd(), normalize, strict} = opts; if (readPackageJson.cache.has({cwd, normalize})) { return readPackageJson.cache.get({cwd, normalize}); } @@ -163,7 +166,7 @@ export async function readPackageJson({ readPackageJson.cache = new Map< ReadPackageJsonOpts, - readPkgUp.ReadResult | undefined + readPkgUp.ReadResult | readPkgUp.NormalizedReadResult | undefined >(); /**