JSPM

find-and-require-package-json

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

Find the package.json file from within a build/package

Package Exports

  • find-and-require-package-json
  • find-and-require-package-json/esm/index.js
  • find-and-require-package-json/index.js

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 (find-and-require-package-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

find-and-require-package-json


Find the package.json file from within a build/package

This TypeScript module provides a function to locate, read, and parse the package.json file starting from a specified directory and searching up through parent directories.

install

npm install find-and-require-package-json

Example

import { findAndRequirePackageJson } from 'find-and-require-package-json';

// Pass __dirname to find the package.json for your module
const packageJson = findAndRequirePackageJson(__dirname);
console.log('Package name:', packageJson.name);
console.log('Version:', packageJson.version);

ESM Usage

For ESM modules, you'll need to convert import.meta.url to a directory path:

import { findAndRequirePackageJson } from 'find-and-require-package-json';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));
const packageJson = findAndRequirePackageJson(__dirname);

Development

Setup

  1. Clone the repository:
git clone https://github.com/constructive-io/dev-utils.git
  1. Install dependencies:
cd dev-utils
pnpm install
pnpm build
  1. Test the package of interest:
cd packages/<packagename>
pnpm test:watch

Credits

🛠 Built by the Constructive team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.

Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.