find-and-require-package-json 0.6.8

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 ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Interweb, Inc. <developers@interweb.co>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # find-and-require-package-json
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/hyperweb-io/dev-utils/refs/heads/main/docs/img/logo.svg" width="80">
5
+ <br />
6
+ Find the package.json file from within a build/package
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" />
10
+ </a>
11
+ <a href="https://github.com/hyperweb-io/dev-utils/blob/main/LICENSE">
12
+ <img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
13
+ </a>
14
+ </p>
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.
17
+
18
+ ## install
19
+
20
+ ```sh
21
+ npm install find-and-require-package-json
22
+ ```
23
+
24
+ ### Example
25
+
26
+ ```js
27
+ import { findAndRequirePackageJson } from 'find-and-require-package-json';
28
+
29
+ const packageJson = findAndRequirePackageJson();
30
+ console.log('Package name:', packageJson.name);
31
+ console.log('Version:', packageJson.version);
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Development
37
+
38
+ ### Setup
39
+
40
+ 1. Clone the repository:
41
+
42
+ ```bash
43
+ git clone https://github.com/hyperweb-io/dev-utils.git
44
+ ```
45
+
46
+ 2. Install dependencies:
47
+
48
+ ```bash
49
+ cd dev-utils
50
+ pnpm install
51
+ pnpm build
52
+ ```
53
+
54
+ 3. Test the package of interest:
55
+
56
+ ```bash
57
+ cd packages/<packagename>
58
+ pnpm test:watch
59
+ ```
60
+
61
+ ## Credits
62
+
63
+ Built for developers, with developers.
64
+ 👉 https://launchql.com | https://hyperweb.io
65
+
66
+ ## Disclaimer
67
+
68
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
69
+
70
+ 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.
package/esm/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './package';
package/esm/package.js ADDED
@@ -0,0 +1,26 @@
1
+ import { existsSync, readFileSync } from 'fs';
2
+ import { dirname, join } from 'path';
3
+ // need to search due to the dist/ folder and src/, etc.
4
+ function _findPackageJson(currentDir) {
5
+ const filePath = join(currentDir, 'package.json');
6
+ // Check if package.json exists in the current directory
7
+ if (existsSync(filePath)) {
8
+ return filePath;
9
+ }
10
+ // Get the parent directory
11
+ const parentDir = dirname(currentDir);
12
+ // If reached the root directory, package.json is not found
13
+ if (parentDir === currentDir) {
14
+ throw new Error('package.json not found in any parent directory');
15
+ }
16
+ // Recursively look in the parent directory
17
+ return _findPackageJson(parentDir);
18
+ }
19
+ export function findAndRequirePackageJson() {
20
+ // Start searching from the current directory
21
+ const pkgPath = _findPackageJson(__dirname);
22
+ // Read and parse the package.json
23
+ const str = readFileSync(pkgPath, 'utf8');
24
+ const pkg = JSON.parse(str);
25
+ return pkg;
26
+ }
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './package';
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./package"), exports);
package/package.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ export interface PackageJson {
2
+ name: string;
3
+ version: string;
4
+ description?: string;
5
+ main?: string;
6
+ scripts?: {
7
+ [key: string]: string;
8
+ };
9
+ dependencies?: {
10
+ [key: string]: string;
11
+ };
12
+ devDependencies?: {
13
+ [key: string]: string;
14
+ };
15
+ peerDependencies?: {
16
+ [key: string]: string;
17
+ };
18
+ optionalDependencies?: {
19
+ [key: string]: string;
20
+ };
21
+ [key: string]: any;
22
+ }
23
+ export declare function findAndRequirePackageJson(): PackageJson;
package/package.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findAndRequirePackageJson = findAndRequirePackageJson;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ // need to search due to the dist/ folder and src/, etc.
7
+ function _findPackageJson(currentDir) {
8
+ const filePath = (0, path_1.join)(currentDir, 'package.json');
9
+ // Check if package.json exists in the current directory
10
+ if ((0, fs_1.existsSync)(filePath)) {
11
+ return filePath;
12
+ }
13
+ // Get the parent directory
14
+ const parentDir = (0, path_1.dirname)(currentDir);
15
+ // If reached the root directory, package.json is not found
16
+ if (parentDir === currentDir) {
17
+ throw new Error('package.json not found in any parent directory');
18
+ }
19
+ // Recursively look in the parent directory
20
+ return _findPackageJson(parentDir);
21
+ }
22
+ function findAndRequirePackageJson() {
23
+ // Start searching from the current directory
24
+ const pkgPath = _findPackageJson(__dirname);
25
+ // Read and parse the package.json
26
+ const str = (0, fs_1.readFileSync)(pkgPath, 'utf8');
27
+ const pkg = JSON.parse(str);
28
+ return pkg;
29
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "find-and-require-package-json",
3
+ "version": "0.6.8",
4
+ "author": "Dan Lynch <pyramation@gmail.com>",
5
+ "description": "Find the package.json file from within a build/package",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "homepage": "https://github.com/hyperweb-io/dev-utils",
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "directory": "dist"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/hyperweb-io/dev-utils"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/hyperweb-io/dev-utils/issues"
21
+ },
22
+ "scripts": {
23
+ "copy": "makage assets",
24
+ "clean": "makage clean",
25
+ "prepublishOnly": "npm run build",
26
+ "build": "makage build",
27
+ "lint": "eslint . --fix",
28
+ "test": "jest",
29
+ "test:watch": "jest --watch"
30
+ },
31
+ "devDependencies": {
32
+ "makage": "0.1.8"
33
+ },
34
+ "keywords": [],
35
+ "gitHead": "f354f0835840f2592220167b6e3d0ffd570b6474"
36
+ }