Skip to content

discoverPackageJson ​

Generated reference page for the discoverPackageJson function export.

Signatures ​

ts
function discoverPackageJson(adapter: PackageJsonAdapter, startDir?: string): Promise<PackageJsonData | null>;
ParameterTypeDescription
adapterPackageJsonAdapterAdapter providing readFile + cwd.
startDirstring | undefinedOptional explicit directory or file path to walk up from.

Members ​

Members ​

discoverPackageJson ​

Discover the nearest package.json by walking up from startDir (or adapter.cwd when omitted).

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'
}

See Also ​

Released under the MIT License.