index.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {JsonObject} from 'type-fest';
  2. declare namespace writePackage {
  3. interface Options {
  4. /**
  5. Remove empty `dependencies`, `devDependencies`, `optionalDependencies` and `peerDependencies` objects.
  6. @default true
  7. */
  8. readonly normalize?: boolean;
  9. }
  10. }
  11. declare const writePackage: {
  12. /**
  13. Write a `package.json` file.
  14. Writes atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.
  15. @param path - Path to where the `package.json` file should be written or its directory.
  16. @example
  17. ```
  18. import * as path from 'path';
  19. import writePackage = require('write-pkg');
  20. (async () => {
  21. await writePackage({foo: true});
  22. console.log('done');
  23. await writePackage(__dirname, {foo: true});
  24. console.log('done');
  25. await writePackage(path.join('unicorn', 'package.json'), {foo: true});
  26. console.log('done');
  27. })();
  28. ```
  29. */
  30. (path: string, data: JsonObject, options?: writePackage.Options): Promise<void>;
  31. (data: JsonObject, options?: writePackage.Options): Promise<void>;
  32. /**
  33. Synchronously write a `package.json` file.
  34. Writes atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.
  35. @param path - Path to where the `package.json` file should be written or its directory.
  36. @example
  37. ```
  38. import * as path from 'path';
  39. import writePackage = require('write-pkg');
  40. writePackage.sync({foo: true});
  41. console.log('done');
  42. writePackage.sync(__dirname, {foo: true});
  43. console.log('done');
  44. writePackage.sync(path.join('unicorn', 'package.json'), {foo: true});
  45. console.log('done');
  46. ```
  47. */
  48. sync(path: string, data: JsonObject, options?: writePackage.Options): void;
  49. sync(data: JsonObject, options?: writePackage.Options): void;
  50. };
  51. export = writePackage;