Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

read-pkg-up

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-pkg-up - npm Package Compare versions

Comparing version 7.0.1 to 8.0.0

134

index.d.ts
import {Except} from 'type-fest';
import readPkg = require('read-pkg');
import {readPackageAsync, readPackageSync, Options as ReadPackageOptions, NormalizeOptions as ReadPackageNormalizeOptions, PackageJson, NormalizedPackageJson} from 'read-pkg';
declare namespace readPkgUp {
type Options = {
/**
Directory to start looking for a package.json file.
export type Options = {
/**
Directory to start looking for a package.json file.
@default process.cwd()
*/
cwd?: string;
} & Except<readPkg.Options, 'cwd'>;
@default process.cwd()
*/
cwd?: string;
} & Except<ReadPackageOptions, 'cwd'>;
type NormalizeOptions = {
/**
Directory to start looking for a package.json file.
export type NormalizeOptions = {
/**
Directory to start looking for a package.json file.
@default process.cwd()
*/
cwd?: string;
} & Except<readPkg.NormalizeOptions, 'cwd'>;
@default process.cwd()
*/
cwd?: string;
} & Except<ReadPackageNormalizeOptions, 'cwd'>;
type PackageJson = readPkg.PackageJson;
type NormalizedPackageJson = readPkg.NormalizedPackageJson;
export interface ReadResult {
packageJson: PackageJson;
path: string;
}
interface ReadResult {
packageJson: PackageJson;
path: string;
}
interface NormalizedReadResult {
packageJson: NormalizedPackageJson;
path: string;
}
export interface NormalizedReadResult {
packageJson: NormalizedPackageJson;
path: string;
}
declare const readPkgUp: {
/**
Read the closest `package.json` file.
export {
PackageJson,
NormalizedPackageJson
};
@example
```
import readPkgUp = require('read-pkg-up');
/**
Read the closest `package.json` file.
(async () => {
console.log(await readPkgUp());
// {
// packageJson: {
// name: 'awesome-package',
// version: '1.0.0',
// …
// },
// path: '/Users/sindresorhus/dev/awesome-package/package.json'
// }
})();
```
*/
(options?: readPkgUp.NormalizeOptions): Promise<
readPkgUp.NormalizedReadResult | undefined
>;
(options: readPkgUp.Options): Promise<readPkgUp.ReadResult | undefined>;
@example
```
import {readPackageUpAsync} from 'read-pkg-up';
/**
Synchronously read the closest `package.json` file.
console.log(await readPackageUpAsync());
// {
// packageJson: {
// name: 'awesome-package',
// version: '1.0.0',
// …
// },
// path: '/Users/sindresorhus/dev/awesome-package/package.json'
// }
```
*/
export function readPackageUpAsync(options?: NormalizeOptions): Promise<NormalizedReadResult | undefined>;
export function readPackageUpAsync(options: Options): Promise<ReadResult | undefined>;
@example
```
import readPkgUp = require('read-pkg-up');
/**
Synchronously read the closest `package.json` file.
console.log(readPkgUp.sync());
// {
// packageJson: {
// name: 'awesome-package',
// version: '1.0.0',
// …
// },
// path: '/Users/sindresorhus/dev/awesome-package/package.json'
// }
```
*/
sync(
options?: readPkgUp.NormalizeOptions
): readPkgUp.NormalizedReadResult | undefined;
sync(options: readPkgUp.Options): readPkgUp.ReadResult | undefined;
};
@example
```
import {readPackageUpSync} from 'read-pkg-up';
export = readPkgUp;
console.log(readPackageUpSync());
// {
// packageJson: {
// name: 'awesome-package',
// version: '1.0.0',
// …
// },
// path: '/Users/sindresorhus/dev/awesome-package/package.json'
// }
```
*/
export function readPackageUpSync(options?: NormalizeOptions): NormalizedReadResult | undefined;
export function readPackageUpSync(options: Options): ReadResult | undefined;

@@ -1,9 +0,7 @@

'use strict';
const path = require('path');
const findUp = require('find-up');
const readPkg = require('read-pkg');
import path from 'path';
import findUp from 'find-up';
import {readPackageAsync, readPackageSync} from 'read-pkg';
module.exports = async options => {
export async function readPackageUpAsync(options) {
const filePath = await findUp('package.json', options);
if (!filePath) {

@@ -14,10 +12,9 @@ return;

return {
packageJson: await readPkg({...options, cwd: path.dirname(filePath)}),
packageJson: await readPackageAsync({...options, cwd: path.dirname(filePath)}),
path: filePath
};
};
}
module.exports.sync = options => {
export function readPackageUpSync(options) {
const filePath = findUp.sync('package.json', options);
if (!filePath) {

@@ -28,5 +25,5 @@ return;

return {
packageJson: readPkg.sync({...options, cwd: path.dirname(filePath)}),
packageJson: readPackageSync({...options, cwd: path.dirname(filePath)}),
path: filePath
};
};
}
{
"name": "read-pkg-up",
"version": "7.0.1",
"version": "8.0.0",
"description": "Read the closest package.json file",

@@ -11,6 +11,8 @@ "license": "MIT",

"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},

@@ -51,11 +53,11 @@ "scripts": {

"dependencies": {
"find-up": "^4.1.0",
"read-pkg": "^5.2.0",
"type-fest": "^0.8.1"
"find-up": "^5.0.0",
"read-pkg": "^6.0.0",
"type-fest": "^1.0.1"
},
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.9.0",
"xo": "^0.25.3"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}

@@ -1,2 +0,2 @@

# read-pkg-up [![Build Status](https://travis-ci.org/sindresorhus/read-pkg-up.svg?branch=master)](https://travis-ci.org/sindresorhus/read-pkg-up)
# read-pkg-up

@@ -8,3 +8,2 @@ > Read the closest package.json file

- [Finds the closest package.json](https://github.com/sindresorhus/find-up)
- [Gracefully handles filesystem issues](https://github.com/isaacs/node-graceful-fs)
- [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)

@@ -22,17 +21,15 @@ - [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)

```js
const readPkgUp = require('read-pkg-up');
import {readPackageUpAsync} from 'read-pkg-up';
(async () => {
console.log(await readPkgUp());
/*
{
packageJson: {
name: 'awesome-package',
version: '1.0.0',
},
path: '/Users/sindresorhus/dev/awesome-package/package.json'
}
*/
})();
console.log(await readPackageUpAsync());
/*
{
packageJson: {
name: 'awesome-package',
version: '1.0.0',
},
path: '/Users/sindresorhus/dev/awesome-package/package.json'
}
*/
```

@@ -42,7 +39,7 @@

### readPkgUp(options?)
### readPackageUpAsync(options?)
Returns a `Promise<object>` or `Promise<undefined>` if no `package.json` was found.
### readPkgUp.sync(options?)
### readPackageUpSync(options?)

@@ -49,0 +46,0 @@ Returns the result object or `undefined` if no `package.json` was found.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc