264fb5f681500279c27efb8c35e87b0d8f40d11387239b4ffd7d86c32b3488d8cf942ea98d06ad6c6065656c78b6a4d8e83aecf1e59266bcd918fff0f90a28 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # local-pkg
  2. [![NPM version](https://img.shields.io/npm/v/local-pkg?color=a1b858&label=)](https://www.npmjs.com/package/local-pkg)
  3. Get information on local packages. Works on both CJS and ESM.
  4. ## Install
  5. ```bash
  6. npm i local-pkg
  7. ```
  8. ## Usage
  9. ```ts
  10. import {
  11. getPackageInfo,
  12. importModule,
  13. isPackageExists,
  14. resolveModule,
  15. } from 'local-pkg'
  16. isPackageExists('local-pkg') // true
  17. isPackageExists('foo') // false
  18. await getPackageInfo('local-pkg')
  19. /* {
  20. * name: "local-pkg",
  21. * version: "0.1.0",
  22. * rootPath: "/path/to/node_modules/local-pkg",
  23. * packageJson: {
  24. * ...
  25. * }
  26. * }
  27. */
  28. // similar to `require.resolve` but works also in ESM
  29. resolveModule('local-pkg')
  30. // '/path/to/node_modules/local-pkg/dist/index.cjs'
  31. // similar to `await import()` but works also in CJS
  32. const { importModule } = await importModule('local-pkg')
  33. ```
  34. ## Sponsors
  35. <p align="center">
  36. <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
  37. <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
  38. </a>
  39. </p>
  40. ## License
  41. [MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)