/** * Helper functions for working with * [package.json](https://docs.npmjs.com/cli/v10/configuring-npm/package-json) files. * * @module */ import type { ReadonlyRecord } from "complete-common"; import type { DependencyType } from "../types/DependencyType.js"; /** * Helper function to asynchronously get a "package.json" file as an object. * * @param filePathOrDirPath Either the path to a "package.json" file or the path to a directory * which contains a "package.json" file. If undefined is passed, the * current working directory will be used. * @throws If the "package.json" file cannot be found or is otherwise invalid. */ export declare function getPackageJSON(filePathOrDirPath: string | undefined): Promise>; /** * Helper function to asynchronously get the "dependencies" or "devDependencies" or * "peerDependencies" field from a "package.json" file. If the corresponding field does not exist, * `undefined` will be returned. * * @param filePathOrDirPathOrRecord Either the path to a "package.json" file, the path to a * directory which contains a "package.json" file, or a parsed * JavaScript object from a JSON file. If undefined is passed, the * current working directory will be used. * @param dependencyType Optional. The specific dependencies field to get. Defaults to * "dependencies". * @throws If the "package.json" file cannot be found or is otherwise invalid. */ export declare function getPackageJSONDependencies(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined, dependencyType?: DependencyType): Promise | undefined>; /** * Helper function to asynchronously get an arbitrary string field from a "package.json" file. If * the field does not exist, `undefined` will be returned. * * @param filePathOrDirPathOrRecord Either the path to a "package.json" file, the path to a * directory which contains a "package.json" file, or a parsed * JavaScript object from a JSON file. If undefined is passed, the * current working directory will be used. * @param fieldName The name of the field to retrieve. * @throws If the "package.json" file cannot be found or the field is not a string. */ export declare function getPackageJSONField(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined, fieldName: string): Promise; /** * Helper function to asynchronously get an arbitrary string field from a "package.json" file. This * will throw an error if the "package.json" file cannot be found or the field does not exist or if * the field is not a string. * * @param filePathOrDirPathOrRecord Either the path to a "package.json" file, the path to a * directory which contains a "package.json" file, or a parsed * JavaScript object from a JSON file. If undefined is passed, the * current working directory will be used. * @param fieldName The name of the field to retrieve. */ export declare function getPackageJSONFieldMandatory(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined, fieldName: string): Promise; /** * Helper function to asynchronously get N arbitrary string fields from a "package.json" file. This * will throw an error if the "package.json" file cannot be found or any of the fields do not exist * or any of the fields are not strings. * * @param filePathOrDirPath Either the path to a "package.json" file or the path to a directory * which contains a "package.json" file. If undefined is passed, the * current working directory will be used. * @param fieldNames The names of the fields to retrieve. */ export declare function getPackageJSONFieldsMandatory(filePathOrDirPath: string | undefined, ...fieldNames: readonly T[]): Promise>; /** * Helper function to asynchronously get the "scripts" field from a "package.json" file. If the * field does not exist, `undefined` will be returned. * * @param filePathOrDirPathOrRecord Either the path to a "package.json" file, the path to a * directory which contains a "package.json" file, or a parsed * JavaScript object from a JSON file. If undefined is passed, the * current working directory will be used. * @throws If the "package.json" file cannot be found or is otherwise invalid. */ export declare function getPackageJSONScripts(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined): Promise | undefined>; /** * Helper function to asynchronously get the "version" field from a "package.json" file. This will * throw an error if the "package.json" file cannot be found or the "version" field does not exist * or the "version" field is not a string. * * If you want to allow for the "version" field to not exist, use the `getPackageJSONField` helper * function instead. * * @param filePathOrDirPathOrRecord Either the path to a "package.json" file, the path to a * directory which contains a "package.json" file, or a parsed * JavaScript object from a JSON file. If undefined is passed, the * current working directory will be used. */ export declare function getPackageJSONVersion(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined): Promise; /** @see https://bun.com/docs/pm/catalogs */ export declare function packageJSONHasCatalog(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined): Promise; /** * Helper function to asynchronously check for a "dependencies" or "devDependencies" or * "peerDependencies" field from a "package.json" file. * * @param filePathOrDirPathOrRecord Either the path to a "package.json" file, the path to a * directory which contains a "package.json" file, or a parsed * JavaScript object from a JSON file. If undefined is passed, the * current working directory will be used. * @param dependencyName The name of the dependency to check for. * @param dependencyType Optional. The specific dependencies field to get. Defaults to * "dependencies". * @throws If the "package.json" file cannot be found or is otherwise invalid. */ export declare function packageJSONHasDependency(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined, dependencyName: string, dependencyType?: DependencyType): Promise; /** * Helper function to asynchronously check if a "package.json" file has a particular script. This * will throw an error if the "package.json" file cannot be found or is otherwise invalid. * * @param filePathOrDirPathOrRecord Either the path to a "package.json" file, the path to a * directory which contains a "package.json" file, or a parsed * JavaScript object from a JSON file. If undefined is passed, the * current working directory will be used. * @param scriptName The name of the script to check for. */ export declare function packageJSONHasScript(filePathOrDirPathOrRecord: string | ReadonlyRecord | undefined, scriptName: string): Promise; //# sourceMappingURL=packageJSON.d.ts.map