find-and-require-package-json 0.6.8 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 Interweb, Inc. <developers@interweb.co>
3
+ Copyright (c) 2025 Constructive <developers@constructive.io>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -5,15 +5,15 @@
5
5
  <br />
6
6
  Find the package.json file from within a build/package
7
7
  <br />
8
- <a href="https://github.com/hyperweb-io/dev-utils/actions/workflows/ci.yml">
9
- <img height="20" src="https://github.com/hyperweb-io/dev-utils/actions/workflows/ci.yml/badge.svg" />
8
+ <a href="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml">
9
+ <img height="20" src="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml/badge.svg" />
10
10
  </a>
11
- <a href="https://github.com/hyperweb-io/dev-utils/blob/main/LICENSE">
11
+ <a href="https://github.com/constructive-io/dev-utils/blob/main/LICENSE">
12
12
  <img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
13
13
  </a>
14
14
  </p>
15
15
 
16
- This TypeScript module provides a function to locate, read, and parse the `package.json` file from the current directory or any of its parent directories.
16
+ 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.
17
17
 
18
18
  ## install
19
19
 
@@ -26,11 +26,25 @@ npm install find-and-require-package-json
26
26
  ```js
27
27
  import { findAndRequirePackageJson } from 'find-and-require-package-json';
28
28
 
29
- const packageJson = findAndRequirePackageJson();
29
+ // Pass __dirname to find the package.json for your module
30
+ const packageJson = findAndRequirePackageJson(__dirname);
30
31
  console.log('Package name:', packageJson.name);
31
32
  console.log('Version:', packageJson.version);
32
33
  ```
33
34
 
35
+ ### ESM Usage
36
+
37
+ For ESM modules, you'll need to convert `import.meta.url` to a directory path:
38
+
39
+ ```js
40
+ import { findAndRequirePackageJson } from 'find-and-require-package-json';
41
+ import { dirname } from 'path';
42
+ import { fileURLToPath } from 'url';
43
+
44
+ const __dirname = dirname(fileURLToPath(import.meta.url));
45
+ const packageJson = findAndRequirePackageJson(__dirname);
46
+ ```
47
+
34
48
  ---
35
49
 
36
50
  ## Development
@@ -40,7 +54,7 @@ console.log('Version:', packageJson.version);
40
54
  1. Clone the repository:
41
55
 
42
56
  ```bash
43
- git clone https://github.com/hyperweb-io/dev-utils.git
57
+ git clone https://github.com/constructive-io/dev-utils.git
44
58
  ```
45
59
 
46
60
  2. Install dependencies:
package/esm/package.js CHANGED
@@ -16,9 +16,10 @@ function _findPackageJson(currentDir) {
16
16
  // Recursively look in the parent directory
17
17
  return _findPackageJson(parentDir);
18
18
  }
19
- export function findAndRequirePackageJson() {
20
- // Start searching from the current directory
21
- const pkgPath = _findPackageJson(__dirname);
19
+ export function findAndRequirePackageJson(callerDir) {
20
+ // Start searching from the caller's directory
21
+ // The caller should pass __dirname (CJS) or dirname(fileURLToPath(import.meta.url)) (ESM)
22
+ const pkgPath = _findPackageJson(callerDir);
22
23
  // Read and parse the package.json
23
24
  const str = readFileSync(pkgPath, 'utf8');
24
25
  const pkg = JSON.parse(str);
package/package.d.ts CHANGED
@@ -20,4 +20,4 @@ export interface PackageJson {
20
20
  };
21
21
  [key: string]: any;
22
22
  }
23
- export declare function findAndRequirePackageJson(): PackageJson;
23
+ export declare function findAndRequirePackageJson(callerDir: string): PackageJson;
package/package.js CHANGED
@@ -19,9 +19,10 @@ function _findPackageJson(currentDir) {
19
19
  // Recursively look in the parent directory
20
20
  return _findPackageJson(parentDir);
21
21
  }
22
- function findAndRequirePackageJson() {
23
- // Start searching from the current directory
24
- const pkgPath = _findPackageJson(__dirname);
22
+ function findAndRequirePackageJson(callerDir) {
23
+ // Start searching from the caller's directory
24
+ // The caller should pass __dirname (CJS) or dirname(fileURLToPath(import.meta.url)) (ESM)
25
+ const pkgPath = _findPackageJson(callerDir);
25
26
  // Read and parse the package.json
26
27
  const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
27
28
  const pkg = JSON.parse(str);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "find-and-require-package-json",
3
- "version": "0.6.8",
4
- "author": "Dan Lynch <pyramation@gmail.com>",
3
+ "version": "0.8.1",
4
+ "author": "Constructive <pyramation@constructive.io>",
5
5
  "description": "Find the package.json file from within a build/package",
6
6
  "main": "index.js",
7
7
  "module": "esm/index.js",
8
8
  "types": "index.d.ts",
9
- "homepage": "https://github.com/hyperweb-io/dev-utils",
9
+ "homepage": "https://github.com/constructive-io/dev-utils",
10
10
  "license": "MIT",
11
11
  "publishConfig": {
12
12
  "access": "public",
@@ -14,10 +14,10 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "https://github.com/hyperweb-io/dev-utils"
17
+ "url": "https://github.com/constructive-io/dev-utils"
18
18
  },
19
19
  "bugs": {
20
- "url": "https://github.com/hyperweb-io/dev-utils/issues"
20
+ "url": "https://github.com/constructive-io/dev-utils/issues"
21
21
  },
22
22
  "scripts": {
23
23
  "copy": "makage assets",
@@ -32,5 +32,5 @@
32
32
  "makage": "0.1.8"
33
33
  },
34
34
  "keywords": [],
35
- "gitHead": "f354f0835840f2592220167b6e3d0ffd570b6474"
35
+ "gitHead": "a30d0a87aaccc1ae729b86d24b1bc3a0f73aeb19"
36
36
  }