@anyions/node-pkg
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

node-pkg

NPM version NPM License Static Badge

Node pakcages management, based on @antfu/local-pkg & @antfu/install-pkg.

  • Get information on local packages. works on both CJS and ESM.
  • Install package programmatically. Detect package managers automatically (npm, yarn, bun and pnpm).

Install

npm i @anyions/node-pkg

Usage

Get information on local packages

import {
  getPackageInfo,
  importModule,
  isPackageExists,
  resolveModule,
} from "@anyions/node-pkg";

isPackageExists("@anyions/node-pkg"); // true
isPackageExists("foo"); // false

await getPackageInfo("@anyions/node-pkg");
/* {
 *   name: "@anyions/node-pkg",
 *   version: "1.0.0",
 *   rootPath: "/path/to/node_modules/@anyions/node-pkg",
 *   packageJson: {
 *     ...
 *   }
 * }
 */

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

// similar to `await import()` but works also in CJS
const { importModule } = await importModule("@anyions/node-pkg");

Install package programmatically

import { installPackage } from "@anyions/node-pkg";

await installPackage("vite", { silent: true });

License

MIT License © 2020 AnyIons

Readme

Keywords

Package Sidebar

Install

npm i @anyions/node-pkg

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

22.2 kB

Total Files

7

Last publish

Collaborators

  • anyions