JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q50431F
  • License MIT

An easy way to find and read package json whether from a submodule or the application

Package Exports

  • @libit/pkginfo

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@libit/pkginfo) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@libit/pkginfo

An easy way to find and read package json whether from a submodule or the application

Installation

$ npm install @libit/pkginfo

Highlights

Motivation

How can a module get package data from an application's package.json?

import {pkginfo} from '@libit/pkginfo';

// get applicaiton json data using pkginfo
console.log(await pkginfo(require.main));
// await pkginfo(require.main);
// =>
// [{"name": "application", ...}, '.../resolved-directory']

// or simply using appfino
console.log(await appinfo());
// await appinfo(require.main);
// =>
// [{"name": "application", ...}, '.../resolved-directory']

Usage

import {pkginfo} from '@libit/pkginfo';

console.log(await pkginfo());
// => [{name: '@libit/pkginfo', …}, '.../resolved-directory']

console.log(await pkginfo(require.main));
// => [{name: 'app', …}, '.../resolved-directory']

console.log(await pkginfo('some-other-directory'));
// => [{name: 'unicorn', …}, '.../resolved-directory']

Here's a sample of the output:

[
  '.../fixtures',
  {
    name: 'simple-app',
    description: 'A test fixture for pkginfo',
    version: '0.1.0',
    keywords: ['test', 'fixture'],
    main: './dist/index.js',
    scripts: {test: 'mocha __tests__/**/*.test.js'},
    engines: {node: '>= 12'},
  },
];

API

pkginfo(dirOrModule?: NodeModule | string, normalization?: boolean)

Returns a Promise<[PackageJson, string]> or Promise<[NormalizePackageJson, string]> for package data and package file directory, or Promise<[null, null]> if couldn't be found.

pkginfo.sync(dirOrModule?: NodeModule | string, normalization?: boolean)

Returns a [PackageJson, string] or NormalizePackageJson, string for package data and package file directory, or [null, null] if couldn't be found.

appinfo(normalization?: boolean) and appinfo.sync(normalization?: boolean)

appinfo() <=> pkginfo(require.main);
appinfo(false) <=> pkginfo(require.main, false);