HckApm/node_modules/local-pkg
minicx 99e5f883a3 second commit 2023-12-23 14:56:27 +03:00
..
dist second commit 2023-12-23 14:56:27 +03:00
LICENSE second commit 2023-12-23 14:56:27 +03:00
README.md second commit 2023-12-23 14:56:27 +03:00
index.cjs second commit 2023-12-23 14:56:27 +03:00
index.d.ts second commit 2023-12-23 14:56:27 +03:00
index.mjs second commit 2023-12-23 14:56:27 +03:00
package.json second commit 2023-12-23 14:56:27 +03:00

README.md

local-pkg

NPM version

Get information on local packages. Works on both CJS and ESM.

Install

npm i local-pkg

Usage

import {
  getPackageInfo,
  importModule,
  isPackageExists,
  resolveModule,
} from 'local-pkg'

isPackageExists('local-pkg') // true
isPackageExists('foo') // false

await getPackageInfo('local-pkg')
/* {
 *   name: "local-pkg",
 *   version: "0.1.0",
 *   rootPath: "/path/to/node_modules/local-pkg",
 *   packageJson: {
 *     ...
 *   }
 * }
 */

// similar to `require.resolve` but works also in ESM
resolveModule('local-pkg')
// '/path/to/node_modules/local-pkg/dist/index.cjs'

// similar to `await import()` but works also in CJS
const { importModule } = await importModule('local-pkg')

Sponsors

License

MIT License © 2021 Anthony Fu