@guanghechen/helper-npm
v6.0.0-alpha.1
Published
Utilities for handling npm repo and `package.json`.
Downloads
41
Readme
Utilities for handling npm repo and package.json
.
Install
npm
npm install --save-dev @guanghechen/helper-npm
yarn
yarn add --dev @guanghechen/helper-npm
Usage
detectMonorepo
: Check whether if it is a monorepo under thecurrentDir
.function detectMonorepo(currentDir: string): boolean
detectPackageAuthor
: Detect package author.function detectPackageAuthor(currentDir: string): string | null
getDefaultDependencyFields
: Return default dependency field names.function getDefaultDependencyFields(): ReadonlyArray< |'dependencies' |'optionalDependencies' |'peerDependencies' >
collectAllDependencies
: Collect all dependencies declared in thepackage.json
and the dependencies of them and so on.function collectAllDependencies( packageJsonPath: string | null, dependenciesFields?: ReadonlyArray<string>, additionalDependencies?: ReadonlyArray<string> | null, isAbsentAllowed?: ((moduleName: string) => boolean) | null, ): string[]
packageJsonPath
: Filepath ofpackage.json
dependenciesFields
: Package dependency field names. (such as['dependencies', 'devDependencies']
)additionalDependencies
: Additional dependency names appended to the results.isAbsentAllowed
: Determine whether if a given moduleName can miss. (called onMODULE_NOT_FOUND
error thrown)
locateLatestPackageJson
: Find the latest package.json under the give {currentDir} or its ancestor path.function locateLatestPackageJson(currentDir: string): string | null