index.d.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Except} from 'type-fest';
  2. import readPkg = require('read-pkg');
  3. declare namespace readPkgUp {
  4. type Options = {
  5. /**
  6. Directory to start looking for a package.json file.
  7. @default process.cwd()
  8. */
  9. cwd?: string;
  10. } & Except<readPkg.Options, 'cwd'>;
  11. type NormalizeOptions = {
  12. /**
  13. Directory to start looking for a package.json file.
  14. @default process.cwd()
  15. */
  16. cwd?: string;
  17. } & Except<readPkg.NormalizeOptions, 'cwd'>;
  18. type PackageJson = readPkg.PackageJson;
  19. type NormalizedPackageJson = readPkg.NormalizedPackageJson;
  20. interface ReadResult {
  21. packageJson: PackageJson;
  22. path: string;
  23. }
  24. interface NormalizedReadResult {
  25. packageJson: NormalizedPackageJson;
  26. path: string;
  27. }
  28. }
  29. declare const readPkgUp: {
  30. /**
  31. Read the closest `package.json` file.
  32. @example
  33. ```
  34. import readPkgUp = require('read-pkg-up');
  35. (async () => {
  36. console.log(await readPkgUp());
  37. // {
  38. // packageJson: {
  39. // name: 'awesome-package',
  40. // version: '1.0.0',
  41. // …
  42. // },
  43. // path: '/Users/sindresorhus/dev/awesome-package/package.json'
  44. // }
  45. })();
  46. ```
  47. */
  48. (options?: readPkgUp.NormalizeOptions): Promise<
  49. readPkgUp.NormalizedReadResult | undefined
  50. >;
  51. (options: readPkgUp.Options): Promise<readPkgUp.ReadResult | undefined>;
  52. /**
  53. Synchronously read the closest `package.json` file.
  54. @example
  55. ```
  56. import readPkgUp = require('read-pkg-up');
  57. console.log(readPkgUp.sync());
  58. // {
  59. // packageJson: {
  60. // name: 'awesome-package',
  61. // version: '1.0.0',
  62. // …
  63. // },
  64. // path: '/Users/sindresorhus/dev/awesome-package/package.json'
  65. // }
  66. ```
  67. */
  68. sync(
  69. options?: readPkgUp.NormalizeOptions
  70. ): readPkgUp.NormalizedReadResult | undefined;
  71. sync(options: readPkgUp.Options): readPkgUp.ReadResult | undefined;
  72. };
  73. export = readPkgUp;