npm.io
2.0.0 • Published 2 weeks ago

local-pkg

Licence
MIT
Version
2.0.0
Deps
3
Size
11 kB
Vulns
0
Weekly
0
Stars
186

local-pkg

NPM version

Get information on local packages.

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 in ESM
resolveModule('local-pkg')
// '/path/to/node_modules/local-pkg/dist/index.mjs'

const { importModule } = await importModule('local-pkg')

Sponsors

Sponsors

License

MIT License 2021 Anthony Fu

Keywords