Skip to content

discoverPackageJson

Generated reference page for the discoverPackageJson function export.

Signatures

ts
function discoverPackageJson(adapter: PackageJsonAdapter): Promise<PackageJsonData | null>;

Members

Members

discoverPackageJson

Discover the nearest package.json by walking up from adapter.cwd.

Convenience helper behind CLIBuilder.packageJson(). Most apps should let the CLI runtime discover package metadata automatically; call this directly when testing metadata inference or embedding the behavior in custom tooling.

Returns the parsed metadata on success, null when no package.json is found (not an error). Malformed JSON and non-object roots also return null — the feature is a convenience, not a hard requirement.

ts
(adapter: PackageJsonAdapter): Promise<PackageJsonData | null>;

Examples

ts
import { discoverPackageJson } from '@kjanat/dreamcli';

const pkg = await discoverPackageJson(adapter);
if (pkg !== null) {
  console.log(pkg.version); // '1.2.3'
}

See Also

Released under the MIT License.