index.d.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Find the package.json file, either from a TypeScript file somewhere not
  3. * in a 'dist' folder, or a built and/or installed 'dist' folder.
  4. *
  5. * Note: this *only* works if you build your code into `'./dist'`, and that the
  6. * source path does not also contain `'dist'`! If you don't build into
  7. * `'./dist'`, or if you have files at `./src/dist/dist.ts`, then this will
  8. * not work properly!
  9. *
  10. * The default `pathFromSrc` option assumes that the calling code lives one
  11. * folder below the root of the package. Otherwise, it must be specified.
  12. *
  13. * Example:
  14. *
  15. * ```ts
  16. * // src/index.ts
  17. * import { findPackageJson } from 'package-json-from-dist'
  18. *
  19. * const pj = findPackageJson(import.meta.url)
  20. * console.log(`package.json found at ${pj}`)
  21. * ```
  22. *
  23. * If the caller is deeper within the project source, then you must provide
  24. * the appropriate fallback path:
  25. *
  26. * ```ts
  27. * // src/components/something.ts
  28. * import { findPackageJson } from 'package-json-from-dist'
  29. *
  30. * const pj = findPackageJson(import.meta.url, '../../package.json')
  31. * console.log(`package.json found at ${pj}`)
  32. * ```
  33. *
  34. * When running from CommmonJS, use `__filename` instead of `import.meta.url`
  35. *
  36. * ```ts
  37. * // src/index.cts
  38. * import { findPackageJson } from 'package-json-from-dist'
  39. *
  40. * const pj = findPackageJson(__filename)
  41. * console.log(`package.json found at ${pj}`)
  42. * ```
  43. */
  44. export declare const findPackageJson: (from: string | URL, pathFromSrc?: string) => string;
  45. /**
  46. * Load the package.json file, either from a TypeScript file somewhere not
  47. * in a 'dist' folder, or a built and/or installed 'dist' folder.
  48. *
  49. * Note: this *only* works if you build your code into `'./dist'`, and that the
  50. * source path does not also contain `'dist'`! If you don't build into
  51. * `'./dist'`, or if you have files at `./src/dist/dist.ts`, then this will
  52. * not work properly!
  53. *
  54. * The default `pathFromSrc` option assumes that the calling code lives one
  55. * folder below the root of the package. Otherwise, it must be specified.
  56. *
  57. * Example:
  58. *
  59. * ```ts
  60. * // src/index.ts
  61. * import { loadPackageJson } from 'package-json-from-dist'
  62. *
  63. * const pj = loadPackageJson(import.meta.url)
  64. * console.log(`Hello from ${pj.name}@${pj.version}`)
  65. * ```
  66. *
  67. * If the caller is deeper within the project source, then you must provide
  68. * the appropriate fallback path:
  69. *
  70. * ```ts
  71. * // src/components/something.ts
  72. * import { loadPackageJson } from 'package-json-from-dist'
  73. *
  74. * const pj = loadPackageJson(import.meta.url, '../../package.json')
  75. * console.log(`Hello from ${pj.name}@${pj.version}`)
  76. * ```
  77. *
  78. * When running from CommmonJS, use `__filename` instead of `import.meta.url`
  79. *
  80. * ```ts
  81. * // src/index.cts
  82. * import { loadPackageJson } from 'package-json-from-dist'
  83. *
  84. * const pj = loadPackageJson(__filename)
  85. * console.log(`Hello from ${pj.name}@${pj.version}`)
  86. * ```
  87. */
  88. export declare const loadPackageJson: (from: string | URL, pathFromSrc?: string) => any;
  89. //# sourceMappingURL=index.d.ts.map