Skip to content

Latest commit

 

History

History

helper-npm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

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 the currentDir.

    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 the package.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 of package.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 on MODULE_NOT_FOUND error thrown)
  • locateLatestPackageJson: Find the latest package.json under the give {currentDir} or its ancestor path.

    function locateLatestPackageJson(currentDir: string): string | null 

Related