Skip to main content

Package.readPackageDotJson() method

Reads and parses package.json from the package folder.

Signature

readPackageDotJson(input?: {
withThrow?: boolean;
}): Promise<JsonXpmPackage | undefined>;

Parameters

Parameter

Type

Description

{ withThrow, }

(not declared)

(Optional)

input

{ withThrow?: boolean; }

(Optional)

Returns

Promise<JsonXpmPackage | undefined>

The parsed package.json content, or undefined when missing or invalid and withThrow is false.

Exceptions

InputError If package.json is missing or invalid and withThrow is true.

Remarks

This method provides flexible error handling for scenarios where a missing or invalid package.json may be expected (e.g., checking whether a folder is a package) versus scenarios where it indicates a critical error (e.g., operating on a known package).

When withThrow is false, the method returns undefined for missing or invalid files, allowing callers to handle the absence gracefully. When withThrow is true, errors are thrown as InputError for consistent error handling across the application.


Generated via tsdoc2docusaurus 1.3.2 by API Extractor/Documenter 7.57.2.