1.0.5 • Published 1 year ago

@anyions/node-pkg v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago