Home Reference Source
import Package from 'comptroller/src/package.js'
public class | source

Package

Direct Subclass:

Comptroller

This is the package class. It serves as encapsulation for individual packages, as a means of querying for package info, and as an outlet for changes to a package.

Static Method Summary

Static Public Methods
public static

Generates an exclude array

Constructor Summary

Public Constructor
public

Creates a new package instance.

Member Summary

Public Members
public get

An object representing the package's dependencies.

public get

The options to pass through to detective.

public get

A glob that matches the package's dev files

public get

An object representing the package's devDependencies.

public get

An array of package names to ignore in all operations.

public get

An array of globs that match files not to be included with the package's source files.

public get

An array of field names the package should inherit from it's parent package.json.

public get

An object representing the package's package.json.

public get

The "maximum fixed character width" parameter to pass to json-beautify.

public get

Whether or not unused dependencies should be pruned from the package.json.

public get

The package's root directory.

public get

A glob that matches the package's source files

Method Summary

Public Methods
public

Analyzes the package's source files and returns all of the invoked dependencies mapped to the files invoking them.

public

applyPatch(patch: Patch)

Applies a given patch to Package#packageJson.

public

Compares a dependency object (as returned from Package#analyzeSourceDependencies) with the dependencies listed in {@link Package@packageJson} and returns an array of patches.

public

Generates the patches that will satisfy Package#inherits

public

resolveDependency(dependency: string): string | boolean

Takes a dependency name and resolves it to the actual dependency name, stripping any subdirectories from the dependency name (retaining @org style dependencies).

public

Writes Package#packageJson to it's respective package.json file.

Static Public Methods

public static generateExcludes(excludes: Array<string|object>): * source

Generates an exclude array

Params:

NameTypeAttributeDescription
excludes Array<string|object>

The excludes array to use as a base.

Return:

*

Public Constructors

public constructor(opts: object) source

Creates a new package instance. It can accept it's configuration either through the package.json file or through the constructor arguments.

Params:

NameTypeAttributeDescription
opts object

The package options.

opts.root string

The root directory of the package.

opts.packageJson object
  • optional
  • default: fs.readJson('root package.json')

The package's package.json. If not specified, it's read from the root directory.

opts.config object
  • optional
  • default: opts.packageJson.comptroller || {}

The Comptroller configurations options.

opts.config.source glob
  • optional
  • default: '⚹⚹/⚹.js'

A glob that selects the packages source files.

opts.config.dev glob
  • optional
  • default: '⚹⚹/test/⚹⚹/⚹.js'

A glob that selects the packages that should also include devDependencies

opts.config.ignore glob[]
  • optional
  • default: ['⚹⚹/node_modules/⚹⚹']

An array of globs to pass into glob's ignore option when searching for source files.

opts.config.exclude Array<string|object>
  • optional
  • default: builtins

An array of package names to ignore in all operations. Defaults to builtin-modules.

opts.config.inherits string[]
  • optional
  • default: []

An array of field names to inherit from the parent package.json. This is useful for values that remain the same across all packages.

opts.config.detective object
  • optional
  • default: {}

The options to pass through to detective.

opts.config.prune boolean
  • optional
  • default: false

Whether or not unused dependencies should be pruned from the package.json.

opts.config.pretty boolean | number
  • optional
  • default: false

The "maximum fixed character width" parameter to pass to json-beautify.

Public Members

public get dependencies: object source

An object representing the package's dependencies.

public get detective: object source

The options to pass through to detective.

public get dev: minimatch source

A glob that matches the package's dev files

public get devDependencies: object source

An object representing the package's devDependencies.

public get exclude: string[] source

An array of package names to ignore in all operations.

public get ignore: glob[] source

An array of globs that match files not to be included with the package's source files.

public get inherits: string[] source

An array of field names the package should inherit from it's parent package.json.

public get packageJson: object source

An object representing the package's package.json.

public get pretty: boolean | number source

The "maximum fixed character width" parameter to pass to json-beautify.

public get prune: boolean source

Whether or not unused dependencies should be pruned from the package.json.

public get root: string source

The package's root directory.

public get source: glob source

A glob that matches the package's source files

Public Methods

public async analyzeSourceDependencies(): Map<string, object> source

Analyzes the package's source files and returns all of the invoked dependencies mapped to the files invoking them.

Return:

Map<string, object>

A map with the dependency names as keys and the dependency metadata as values.

public applyPatch(patch: Patch) source

Applies a given patch to Package#packageJson.

Params:

NameTypeAttributeDescription
patch Patch

The patch to apply,

public generateDependencyPatches(dependencies: object): Patch[] source

Compares a dependency object (as returned from Package#analyzeSourceDependencies) with the dependencies listed in {@link Package@packageJson} and returns an array of patches.

Params:

NameTypeAttributeDescription
dependencies object

The dependencies to generate a patch for.

Return:

Patch[]

The patches that will make Package#packageJson match the inputted dependencies

public generateInheritPatches(): Patch[] source

Generates the patches that will satisfy Package#inherits

Return:

Patch[]

The patches that will update Package#packageJson with the inherited fields.

public resolveDependency(dependency: string): string | boolean source

Takes a dependency name and resolves it to the actual dependency name, stripping any subdirectories from the dependency name (retaining @org style dependencies). It also excludes dependencies with relative paths (./ or ../ style) and any dependencies listed in Package#exclude

Params:

NameTypeAttributeDescription
dependency string

The dependency to resolve

Return:

string | boolean

The resolved dependency name, or false if the the dependency is excluded.

public async writePackageJson() source

Writes Package#packageJson to it's respective package.json file.