Skip to content

Commit

Permalink
fix(midnight-smoker): add overload for normalization to readPackageJson
Browse files Browse the repository at this point in the history
export `ReadPackageJsonResult`
  • Loading branch information
boneskull committed Oct 11, 2023
1 parent 6008e62 commit b4e781f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/midnight-smoker/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<readPkgUp.NormalizedReadResult>;
export async function readPackageJson(
opts: ReadPackageJsonOpts & {strict: true},
): Promise<readPkgUp.ReadResult>;
export async function readPackageJson(
opts?: ReadPackageJsonOpts,
): Promise<readPkgUp.ReadResult | undefined>;
export async function readPackageJson({
cwd,
normalize,
strict,
}: ReadPackageJsonOpts = {}): Promise<readPkgUp.ReadResult | undefined> {
cwd ??= process.cwd();
export async function readPackageJson(
opts: ReadPackageJsonOpts & {normalize: true; strict?: false},
): Promise<readPkgUp.NormalizedReadResult | undefined>;
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});
}
Expand All @@ -163,7 +166,7 @@ export async function readPackageJson({

readPackageJson.cache = new Map<
ReadPackageJsonOpts,
readPkgUp.ReadResult | undefined
readPkgUp.ReadResult | readPkgUp.NormalizedReadResult | undefined
>();

/**
Expand Down

0 comments on commit b4e781f

Please # to comment.