read-pkg-up
Advanced tools
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; |
21
index.js
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
1
6605
87
75
+ Addedfind-up@5.0.0(transitive)
+ Addedhosted-git-info@4.1.0(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addednormalize-package-data@3.0.3(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedread-pkg@6.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedtype-fest@1.4.0(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedread-pkg@5.2.0(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtype-fest@0.6.00.8.1(transitive)
Updatedfind-up@^5.0.0
Updatedread-pkg@^6.0.0
Updatedtype-fest@^1.0.1