-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d443393
commit 8a3fcef
Showing
4 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as typeFest from 'type-fest'; | ||
import normalize = require('normalize-package-data'); | ||
|
||
declare namespace readPkg { | ||
interface Options { | ||
/** | ||
[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data. | ||
@default true | ||
*/ | ||
normalize?: boolean; | ||
|
||
/** | ||
Current working directory. | ||
@default process.cwd() | ||
*/ | ||
cwd?: string; | ||
} | ||
|
||
interface NormalizeOptions extends Options { | ||
normalize: true; | ||
} | ||
|
||
type NormalizedPackageJson = PackageJson & normalize.Package; | ||
type PackageJson = typeFest.PackageJson; | ||
} | ||
|
||
declare const readPkg: { | ||
/** | ||
@returns The parsed JSON. | ||
@example | ||
``` | ||
import readPkg = require('read-pkg'); | ||
(async () => { | ||
console.log(await readPkg()); | ||
//=> {name: 'read-pkg', …} | ||
console.log(await readPkg({cwd: 'some-other-directory'}); | ||
//=> {name: 'unicorn', …} | ||
})(); | ||
``` | ||
*/ | ||
(options?: readPkg.NormalizeOptions): Promise<readPkg.NormalizedPackageJson>; | ||
(options: readPkg.Options): Promise<readPkg.PackageJson>; | ||
|
||
/** | ||
@returns The parsed JSON. | ||
@example | ||
``` | ||
import readPkg = require('read-pkg'); | ||
console.log(readPkg.sync()); | ||
//=> {name: 'read-pkg', …} | ||
console.log(readPkg.sync({cwd: 'some-other-directory'}); | ||
//=> {name: 'unicorn', …} | ||
``` | ||
*/ | ||
sync(options?: readPkg.NormalizeOptions): readPkg.NormalizedPackageJson; | ||
sync(options: readPkg.Options): readPkg.PackageJson; | ||
}; | ||
|
||
export = readPkg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {expectType, expectError} from 'tsd'; | ||
import readPkg = require('.'); | ||
|
||
const options: readPkg.Options = {}; | ||
expectError<readPkg.NormalizedPackageJson>({}); | ||
expectType<readPkg.PackageJson>({}); | ||
|
||
expectType<Promise<readPkg.NormalizedPackageJson>>(readPkg()); | ||
expectType<Promise<readPkg.NormalizedPackageJson>>(readPkg({normalize: true})); | ||
expectType<Promise<readPkg.PackageJson>>(readPkg({normalize: false})); | ||
expectError<Promise<readPkg.NormalizedPackageJson>>( | ||
readPkg({normalize: false}) | ||
); | ||
expectType<Promise<readPkg.PackageJson>>(readPkg({cwd: './'})); | ||
|
||
expectType<readPkg.NormalizedPackageJson>(readPkg.sync()); | ||
expectType<readPkg.NormalizedPackageJson>(readPkg.sync({normalize: true})); | ||
expectType<readPkg.PackageJson>(readPkg.sync({normalize: false})); | ||
expectError<readPkg.NormalizedPackageJson>(readPkg.sync({normalize: false})); | ||
expectType<readPkg.PackageJson>(readPkg.sync({cwd: './'})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters