/** * @file Npm.ts * @author Gage Sorrell * @copyright (c) 2026 Gage Sorrell * @license MIT */ import type { IPackageJson } from "package-json-type"; /** * Get the `package.json` of the Node.js project in which the * given path, or the current working directory, resides. * * @param Path - The given path from which to look for a root directory. * * @throws {RootDirectoryNotFoundError | PackageJsonParseError} An error * describing either failure to identify a root directory, or failing to * parse the discovered `package.json`. * * @returns {Promise} The {@link IPackageJson} of {@link Path} * if provided, otherwise of `process.cwd()`. * * @example * Suppose `process.cwd() === "./MyPackage"`, * ```typescript * const PackageJson: IPackageJson = await GetPackageJson(); * // `PackageJson` <- *The parsed `package.json` of `MyPackage`.* * ``` */ export declare function GetPackageJson(Path?: string): Promise; /** * Get the root directory of the Node.js project in which the * current working directory resides. * * @param Path - The given path from which to look for a root directory. * * @throws {RootDirectoryNotFoundError} An error iff the root directory * of a NodeJS package could not be found. * * @returns {Promise} The path to the root directory of the package * containing {@link Path} if specified, otherwise containing `process.cwd()`. * * @example * Suppose `process.cwd()` is any one of the following, * - `/home/alex/myPackage`, * - `/home/alex/myPackage/src/MyModule`, * - `/home/alex/myPackage/resource/Images`, * * then, * * ```typescript * const Root: string = await GetPackageRootDirectory(); * // `Root` <- `"/home/alex/myPackage"` * ``` * * @example * Suppose `TestPath === "/home/alex/Documents"` is *not* a NodeJS package root * (of course, neither are `/home/alex` or `/home`). Then, * * ```typescript * const TestPath: string = "/home/alex/Documents"; * let Root: string | undefined = undefined; * try * { * Root = await GetPackageRootDirectory(TestPath); * } * catch (Error: unknown) * { * // `Error instanceof RootDirectoryNotFound` * } * * // `Root` <- `undefined` * ``` * * @example * Suppose `process.cwd() === /home/alex/Downloads`, which is *not* a NodeJS package * (of course, neither are `/home/alex` or `/home`). Then, * * ```typescript * let Root: string | undefined = undefined; * try * { * Root = await GetPackageRootDirectory(); * } * catch (Error: unknown) * { * // `Error instanceof RootDirectoryNotFound` * } * // `Root` <- `undefined` * ``` */ export declare function GetPackageRootDirectory(Path?: string): Promise; /** * Determine whether a given {@link ImportSpecifier} is valid. That is, whether * it consists of a valid package name, possibly followed by a `/`-delimited path * that may be specified by the package's `"exports"` property in its `package.json`. * * @param ImportSpecifier - The `import` specifier `string` to test. * * @returns {boolean} Whether the given {@link ImportSpecifier} is a valid `string` * to use in an `import` statement. */ export declare function IsValidDependencyImportSpecifier(ImportSpecifier: string): boolean; //# sourceMappingURL=Npm.d.mts.map