discoverPackageJson
Generated reference page for the discoverPackageJson function export.
- Import:
@kjanat/dreamcli - Export kind: function
- Declared in:
src/core/config/package-json.ts - Source link:
src/core/config/package-json.ts:137
Signatures
ts
function discoverPackageJson(adapter: PackageJsonAdapter, startDir?: string): Promise<PackageJsonData | null>;| Parameter | Type | Description |
|---|---|---|
adapter | PackageJsonAdapter | Adapter providing readFile + cwd. |
startDir | string | undefined | Optional explicit directory or file path to walk up from. Pass an absolute path inside your own package (e.g. fileURLToPath(import.meta.url)) when authoring an installable CLI whoseversion should reflect the CLI's own package, not the consumer's working directory. Defaults to adapter.cwd when undefined. A file path isprobed as a directory first (yielding nothing) before the walk-up reaches its real parent directory, so passing import.meta.url resolves correctly. |
Members
Members
discoverPackageJson
Discover the nearest package.json by walking up from startDir (or adapter.cwd when omitted).
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, startDir?: string): 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'
}