Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- appstash
- clean-ansi
- fetch-api-client
- find-pkg
- find-and-require-package-json
- http-errors
- jsonld-tools
- komoji
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A comprehensive collection of TypeScript utilities for working with schemas, JSO
| **strfy-js** | [![npm](https://img.shields.io/npm/v/strfy-js.svg)](https://www.npmjs.com/package/strfy-js) | [GitHub](./packages/strfy-js) | Stringify JSON as JavaScript with extended serialization capabilities |
| **yanse** | [![npm](https://img.shields.io/npm/v/yanse.svg)](https://www.npmjs.com/package/yanse) | [GitHub](./packages/yanse) | Fast and lightweight terminal color styling library with chalk-like API |
| **@interweb/fetch-api-client** | [![npm](https://img.shields.io/npm/v/@interweb/fetch-api-client.svg)](https://www.npmjs.com/package/@interweb/fetch-api-client) | [GitHub](./packages/fetch-api-client) | Universal Fetch-based HTTP client for Node.js and browsers |
| **@interweb/find-pkg** | [![npm](https://img.shields.io/npm/v/@interweb/find-pkg.svg)](https://www.npmjs.com/package/@interweb/find-pkg) | [GitHub](./packages/find-pkg) | Find the package.json file from within a build/package |
| **find-and-require-package-json** | [![npm](https://img.shields.io/npm/v/find-and-require-package-json.svg)](https://www.npmjs.com/package/find-and-require-package-json) | [GitHub](./packages/find-and-require-package-json) | Find the package.json file from within a build/package |
| **@interweb/http-errors** | [![npm](https://img.shields.io/npm/v/@interweb/http-errors.svg)](https://www.npmjs.com/package/@interweb/http-errors) | [GitHub](./packages/http-errors) | HTTP error handling utilities for API clients |
| **@interweb/node-api-client** | [![npm](https://img.shields.io/npm/v/@interweb/node-api-client.svg)](https://www.npmjs.com/package/@interweb/node-api-client) | [GitHub](./packages/node-api-client) | Lightweight HTTP client for Node.js RESTful APIs |
| **@schema-typescript/cli** | [![npm](https://img.shields.io/npm/v/@schema-typescript/cli.svg)](https://www.npmjs.com/package/@schema-typescript/cli) | [GitHub](./packages/schema-ts-cli) | schema-typescript CLI |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @interweb-utils/find-pkg
# find-and-require-package-json

<p align="center">
<img src="https://raw.githubusercontent.com/hyperweb-io/dev-utils/refs/heads/main/docs/img/logo.svg" width="80">
Expand All @@ -18,15 +18,15 @@ This TypeScript module provides a function to locate, read, and parse the `packa
## install

```sh
npm install @interweb-utils/find-pkg
npm install find-and-require-package-json
```

### Example

```js
import { findPackageJson } from '@interweb-utils/find-pkg';
import { findAndRequirePackageJson } from 'find-and-require-package-json';

const packageJson = findPackageJson();
const packageJson = findAndRequirePackageJson();
console.log('Package name:', packageJson.name);
console.log('Version:', packageJson.version);
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { existsSync, readFileSync } from 'fs';
import { dirname, join } from 'path';

import { findPackageJson } from '../src';
import { findAndRequirePackageJson } from '../src';

// Mock dependencies
jest.mock('fs');
jest.mock('path');

describe('findPackageJson', () => {
describe('findAndRequirePackageJson', () => {
const mockPackageJson = {
name: 'mock-package',
version: '1.0.0',
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('findPackageJson', () => {

jest.spyOn(process, 'cwd').mockReturnValue(mockCurrentDir);

const result = findPackageJson();
const result = findAndRequirePackageJson();

expect(result).toEqual(mockPackageJson);
expect(existsSync).toHaveBeenCalledWith(mockFilePath);
Expand All @@ -57,7 +57,7 @@ describe('findPackageJson', () => {

jest.spyOn(process, 'cwd').mockReturnValue(mockCurrentDir);

expect(() => findPackageJson()).toThrow(
expect(() => findAndRequirePackageJson()).toThrow(
'package.json not found in any parent directory'
);
expect(existsSync).toHaveBeenCalledWith(mockFilePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@interweb/find-pkg",
"name": "find-and-require-package-json",
"version": "0.6.7",
"author": "Dan Lynch <[email protected]>",
"description": "Find the package.json file from within a build/package",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function _findPackageJson(currentDir: string): string {
return _findPackageJson(parentDir);
}

export function findPackageJson(): PackageJson {
export function findAndRequirePackageJson(): PackageJson {
// Start searching from the current directory
const pkgPath = _findPackageJson(__dirname);

Expand Down
1 change: 1 addition & 0 deletions packages/inquirerer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"deepmerge": "^4.3.1",
"find-and-require-package-json": "workspace:*",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"yanse": "workspace:*"
Expand Down
33 changes: 0 additions & 33 deletions packages/inquirerer/src/package.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/inquirerer/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { green, blue } from 'yanse';

import { readAndParsePackageJson } from "./package";
import { findAndRequirePackageJson } from "find-and-require-package-json";

// Function to display the version information
export function displayVersion(): any {
const pkg = readAndParsePackageJson();
const pkg = findAndRequirePackageJson();
console.log(green(`Name: ${pkg.name}`));
console.log(blue(`Version: ${pkg.version}`));
}


export function getVersion(): string {
const pkg = readAndParsePackageJson();
const pkg = findAndRequirePackageJson();
return pkg.version;
}
Loading
Loading