Class that stores information about a single package (directory tree with a package.json and other data, like and Addon or Project.) It is one of the two types of entries in a PackageInfoCache. It is only created by the PackageInfoCache.

Method Summary

Public Methods
public
addPackages(addonPackageList, packageInfoList, excludeFn)

Add to a list of child addon PackageInfos for this packageInfo.

public

Discover the child addons for this packageInfo, which corresponds to an Addon.

public

Discover the child addons for this packageInfo, which corresponds to a Project.

public
generateAddonPackages(addonPackageList, excludeFn)

Given a list of PackageInfo objects, generate the 'addonPackages' object (keyed by name, value = AddonInfo instance, for all packages marked 'valid'). This is stored in both Addon and Project instances.

public
getAddonInstance(parent, project): Object

Create an instance of the addon represented by this packageInfo or (if we are supporting per-bundle caching and this is an allow-caching-per-bundle addon) check if we should be creating a proxy instead.

public
hasErrors(true)

Indicate if there are any errors in the ErrorList for this package. Note that this does NOT indicate if there are any errors in the objects referred to by this package (e.g., internal addons or dependencies).

public
initChildAddons(addonInstance)

Initialize the child addons array of a newly-created addon instance. Normally when an addon derives from Addon, child addons will be created during 'setupRegistry' and this code is essentially unnecessary. But if an addon is created with custom constructors that don't call 'setupRegistry', any child addons may not yet be initialized.

public

Indicate if this packageInfo is for an Addon.

public

For use with the PerBundleAddonCache, is this packageInfo representing a bundle host (for now, a Project or a lazy engine).

public

Indicate if this packageInfo represents an engine.

public

Indicate if this packageInfo represents a lazy engine.

public

Indicate if this packageInfo is for a project. Should be called only after the project has been loaded (see {@link PackageInfoCache#loadProject} for details).

Protected Methods
protected
addDependencies(dependencies): Object

For each dependency in the given list, find the corresponding PackageInfo object in the cache (going up the file tree if necessary, as in the node resolution algorithm). Return a map of the dependencyName to PackageInfo object. Caller can then store it wherever they like.

protected
addError(errorType, errorData)

Given error data, add an ErrorEntry to the ErrorList for this object. This is used by the _readPackage and _readNodeModulesList methods. It should not be called otherwise.

protected
addInRepoAddon(inRepoAddonPkg):

Add a reference to an in-repo addon PackageInfo object.

protected
addInternalAddon(internalAddonPkg):

Add a reference to an internal addon PackageInfo object. "internal" addons (note: not in-repo addons) only exist in Projects, not other packages. Since the cache is loaded from 'loadProject', this can be done appropriately.

Private Methods
private

Gets the addon entry point

private
constructAddonInstance(parent, project)

Construct an addon instance.

private
getAddonConstructor( ): AddonConstructor

This is only supposed to be called by the addon instantiation code. Also, the assumption here is that this PackageInfo really is for an Addon, so we don't need to check each time.

Public Methods

lib/models/package-info-cache/package-info.js:279

public addPackages(addonPackageList, packageInfoList, excludeFn)

Add to a list of child addon PackageInfos for this packageInfo.

Parameters:

Name Type Attribute Description
addonPackageList Array

the list of child addon PackageInfos being constructed from various sources in this packageInfo.

packageInfoList Array | Object

a list or map of PackageInfos being considered (e.g., pkgInfo.dependencyPackages) for inclusion in the addonPackageList.

excludeFn Function

an optional function. If passed in, each child PackageInfo will be tested against the function and only included in the package map if the function returns a truthy value.

Discover the child addons for this packageInfo, which corresponds to an Addon.

lib/models/package-info-cache/package-info.js:336

public discoverProjectAddons( )

Discover the child addons for this packageInfo, which corresponds to a Project.

lib/models/package-info-cache/package-info.js:356

public generateAddonPackages(addonPackageList, excludeFn)

Given a list of PackageInfo objects, generate the 'addonPackages' object (keyed by name, value = AddonInfo instance, for all packages marked 'valid'). This is stored in both Addon and Project instances.

Parameters:

Name Type Attribute Description
addonPackageList Array

the list of child addon PackageInfos to work from

excludeFn Function

an optional function. If passed in, each child PackageInfo will be tested against the function and only included in the package map if the function returns a truthy value.

lib/models/package-info-cache/package-info.js:492

public getAddonInstance(parent, project): Object

Create an instance of the addon represented by this packageInfo or (if we are supporting per-bundle caching and this is an allow-caching-per-bundle addon) check if we should be creating a proxy instead.

NOTE: we assume that the value of 'allowCachingPerBundle' does not change between calls to the constructor! A given addon is either allowing or not allowing caching for an entire run.

Parameters:

Name Type Attribute Description
parent Object

the addon/project that is to be the direct parent of the addon instance created here

project

the project that is to contain this addon instance

Return:

Object

the constructed instance of the addon

Indicate if there are any errors in the ErrorList for this package. Note that this does NOT indicate if there are any errors in the objects referred to by this package (e.g., internal addons or dependencies).

Parameters:

Name Type Attribute Description
true Boolean

if there are errors in the ErrorList, else false.

lib/models/package-info-cache/package-info.js:525

public initChildAddons(addonInstance)

Initialize the child addons array of a newly-created addon instance. Normally when an addon derives from Addon, child addons will be created during 'setupRegistry' and this code is essentially unnecessary. But if an addon is created with custom constructors that don't call 'setupRegistry', any child addons may not yet be initialized.

Parameters:

Name Type Attribute Description
addonInstance Addon

Indicate if this packageInfo is for an Addon.

Return:

Boolean

true if this packageInfo is for an Addon, false otherwise.

For use with the PerBundleAddonCache, is this packageInfo representing a bundle host (for now, a Project or a lazy engine).

Return:

Boolean

true if this pkgInfo is for a bundle host, false otherwise.

Indicate if this packageInfo represents an engine.

Return:

Boolean

true if this pkgInfo is configured as an engine & false otherwise

Indicate if this packageInfo represents a lazy engine.

Return:

Boolean

true if this pkgInfo is configured as an engine and the module this represents has lazyLoading enabled, false otherwise.

Indicate if this packageInfo is for a project. Should be called only after the project has been loaded (see {@link PackageInfoCache#loadProject} for details).

Return:

Boolean

true if this packageInfo is for a Project, false otherwise.

Protected Methods

lib/models/package-info-cache/package-info.js:157

protected addDependencies(dependencies): Object

For each dependency in the given list, find the corresponding PackageInfo object in the cache (going up the file tree if necessary, as in the node resolution algorithm). Return a map of the dependencyName to PackageInfo object. Caller can then store it wherever they like.

Note: this is not to be called until all packages that can be have been added to the cache.

Note: this is for ALL dependencies, not just addons. To get just addons, filter the result by calling pkgInfo.isForAddon().

Note: this is only intended for use from PackageInfoCache._resolveDependencies. It is not to be called directly by anything else.

Parameters:

Name Type Attribute Description
dependencies PackageInfo

value of 'dependencies' or 'devDependencies' attributes of a package.json.

Return:

Object

a JavaScript object keyed on dependency name/path with values the corresponding PackageInfo object from the cache.

lib/models/package-info-cache/package-info.js:96

protected addError(errorType, errorData)

Given error data, add an ErrorEntry to the ErrorList for this object. This is used by the _readPackage and _readNodeModulesList methods. It should not be called otherwise.

Parameters:

Name Type Attribute Description
errorType String

one of the Errors.ERROR_* constants.

errorData Object

any error data relevant to the type of error being created. See showErrors().

lib/models/package-info-cache/package-info.js:124

protected addInRepoAddon(inRepoAddonPkg):

Add a reference to an in-repo addon PackageInfo object.

Parameters:

Name Type Attribute Description
inRepoAddonPkg PackageInfo

the PackageInfo for the in-repo addon

Return:

null

lib/models/package-info-cache/package-info.js:139

protected addInternalAddon(internalAddonPkg):

Add a reference to an internal addon PackageInfo object. "internal" addons (note: not in-repo addons) only exist in Projects, not other packages. Since the cache is loaded from 'loadProject', this can be done appropriately.

Parameters:

Name Type Attribute Description
internalAddonPkg PackageInfo

the PackageInfo for the internal addon

Return:

null

Private Methods

Gets the addon entry point

Return:

Object | Function

The exported addon entry point

lib/models/package-info-cache/package-info.js:457

private constructAddonInstance(parent, project)

Construct an addon instance.

NOTE: this does NOT call constructors for the child addons. That is left to the caller to do, so they can insert any other logic they want.

Parameters:

Name Type Attribute Description
parent Project | Addon

the parent that directly contains this addon

project Project

the project that is/contains this addon

lib/models/package-info-cache/package-info.js:419

private getAddonConstructor( ): AddonConstructor

This is only supposed to be called by the addon instantiation code. Also, the assumption here is that this PackageInfo really is for an Addon, so we don't need to check each time.

Return:

AddonConstructor

an instance of a constructor function for the Addon class whose package information is stored in this object.