Class that stores entries that are either PackageInfo or NodeModulesList objects. The entries are stored in a map keyed by real directory path.

Method Summary

Public Methods
public
contains(path):

Indicate if an entry for a given path exists in the cache.

public

Retrieve an entry from the cache.

public
hasErrors( ):

Indicates if there is at least one error in any object in the cache.

public
loadAddon(addonInstance): PackageInfo

Do the actual processing of the root directory of an addon, when the addon object already exists (i.e. the addon is acting as the root object of a tree, like project does). We need the object in order to find the internal addons. _readPackage takes care of the general processing of the root directory and common locations for addons, filling the cache with each.

public
loadProject(projectInstance): PackageInfo

Process the root directory of a project, given a Project object (we need the object in order to find the internal addons). _readPackage takes care of the general processing of the root directory and common locations for addons, filling the cache with each. Once it returns, we take care of the locations for addons that are specific to projects, not other packages (e.g. internal addons, cli root).

public

To support the project.reloadPkg method, we need the ability to flush the cache and reload from the updated package.json. There are some issues with doing this:

public

Gather all the errors in the PIC and any cached objects, then dump them out to the ui-console.

Private Methods
private

Add an entry to the cache.

private
_clear( )

Clear the cache information.

private
_readModulesList(nodeModulesDir)

Process a directory of modules in a given package directory.

private
_readPackage(pkgDir, isRoot,)

Given a directory that supposedly contains a package, create a PackageInfo object and try to fill it out, EVEN IF the package.json is not readable. Errors will then be stored in the PackageInfo for anything with the package that might be wrong. Because it's possible that the path given to the packageDir is not actually valid, we'll just use the path.resolve() version of that path to search for the path in the cache, before trying to get the 'real' path (which also then resolves links). The cache itself is keyed on either the realPath, if the packageDir is actually a real valid directory path, or the normalized path (before path.resolve()), if it is not.

private

Resolve the node_module dependencies across all packages after they have been loaded into the cache, because we don't know when a particular package will enter the cache.

private

Dump all the errors for a single object in the cache out to the ui-console.

private
getRealDirectoryPath(directoryPath): String

Resolve the real path for a directory, return null if does not exist or is not a directory, return the real path otherwise.

private
getRealFilePath(filePath): String

Resolve the real path for a file, return null if does not exist or is not a file or FIFO, return the real path otherwise.

Public Methods

Indicate if an entry for a given path exists in the cache.

Parameters:

Name Type Attribute Description
path String

the real path to check for in the cache.

Return:

true if the entry is present for the given path, false otherwise.

Retrieve an entry from the cache.

Parameters:

Name Type Attribute Description
path String

the real path whose PackageInfo or NodeModulesList is desired.

Return:

PackageInfo

or {NodeModulesList} the desired entry.

Indicates if there is at least one error in any object in the cache.

Return:

true if there are any errors in the cache, for any entries, else false.

lib/models/package-info-cache/index.js:309

public loadAddon(addonInstance): PackageInfo

Do the actual processing of the root directory of an addon, when the addon object already exists (i.e. the addon is acting as the root object of a tree, like project does). We need the object in order to find the internal addons. _readPackage takes care of the general processing of the root directory and common locations for addons, filling the cache with each.

Once all the addon processing is done, go back through all cache entries to create references between the packageInfo objects.

Parameters:

Name Type Attribute Description
addonInstance Object

the instance of the Addon object to load package data about into the cache.

Return:

PackageInfo

the PackageInfo object for the given Addon object. Note that if the addon path is already in the cache, that will be returned. No copy is made.

lib/models/package-info-cache/index.js:230

public loadProject(projectInstance): PackageInfo

Process the root directory of a project, given a Project object (we need the object in order to find the internal addons). _readPackage takes care of the general processing of the root directory and common locations for addons, filling the cache with each. Once it returns, we take care of the locations for addons that are specific to projects, not other packages (e.g. internal addons, cli root).

Once all the project processing is done, go back through all cache entries to create references between the packageInfo objects.

Parameters:

Name Type Attribute Description
projectInstance Object

the instance of the Project object to load package data about into the cache.

Return:

PackageInfo

the PackageInfo object for the given Project object. Note that if the project path is already in the cache, that will be returned. No copy is made.

lib/models/package-info-cache/index.js:284

public reloadProjects( ):

To support the project.reloadPkg method, we need the ability to flush the cache and reload from the updated package.json. There are some issues with doing this:

  • Because of the possible relationship between projects and their addons due to symlinks, it's not trivial to flush only the data related to a given project.
  • If an 'ember-build-cli.js' dynamically adds new projects to the cache, we will not necessarily get called again to redo the loading of those projects. The solution, implemented here:
  • Keep track of the Project objects whose packages are loaded into the cache.
  • If a project is reloaded, flush the cache, then do loadPackage again for all the known Projects.

Return:

null

Gather all the errors in the PIC and any cached objects, then dump them out to the ui-console.

Private Methods

Add an entry to the cache.

Clear the cache information.

lib/models/package-info-cache/index.js:658

private _readModulesList(nodeModulesDir)

Process a directory of modules in a given package directory.

We will allow cache entries for node_modules that actually have no contents, just so we don't have to hit the file system more often than necessary--it's much quicker to check an in-memory object. object.

Note: only a NodeModulesList or null is returned.

Parameters:

Name Type Attribute Description
nodeModulesDir String

the path of the node_modules directory to read the package.json from and process the contents and create a new cache entry or entries.

lib/models/package-info-cache/index.js:474

private _readPackage(pkgDir, isRoot,)

Given a directory that supposedly contains a package, create a PackageInfo object and try to fill it out, EVEN IF the package.json is not readable. Errors will then be stored in the PackageInfo for anything with the package that might be wrong. Because it's possible that the path given to the packageDir is not actually valid, we'll just use the path.resolve() version of that path to search for the path in the cache, before trying to get the 'real' path (which also then resolves links). The cache itself is keyed on either the realPath, if the packageDir is actually a real valid directory path, or the normalized path (before path.resolve()), if it is not.

NOTE: the cache is also used to store the NULL_PROJECT project object, which actually has no package.json or other files, but does have an empty package object. Because of that, and to speed up processing, loadProject() will pass in both the package root directory path and the project's package object, if there is one. If the package object is present, we will use that in preference to trying to find a package.json file.

If there is no package object, and there is no package.json or the package.json is bad or the package is an addon with no main, the only thing we can do is return an ErrorEntry to the caller. Once past all those problems, if any error occurs with any of the contents of the package, they'll be cached in the PackageInfo itself.

In summary, only PackageInfo or ErrorEntry will be returned.

Parameters:

Name Type Attribute Description
pkgDir String

the path of the directory to read the package.json from and process the contents and create a new cache entry or entries.

isRoot, Boolean

for when this is to be considered the root package, whose dependencies we must all consider for discovery.

lib/models/package-info-cache/index.js:341

private _resolveDependencies( )

Resolve the node_module dependencies across all packages after they have been loaded into the cache, because we don't know when a particular package will enter the cache.

Since loadProject can be called multiple times for different projects, we don't want to reprocess any packages that happen to be common between them. We'll handle this by marking any packageInfo once it has been processed here, then ignore it in any later processing.

lib/models/package-info-cache/index.js:161

private _showObjErrors( )

Dump all the errors for a single object in the cache out to the ui-console.

Special case: because package-info-cache also creates PackageInfo objects for entries that do not actually exist (to allow simplifying the code), if there's a case where an object has only the single error ERROR_PACKAGE_DIR_MISSING, do not print anything. The package will have been found as a reference from some other addon or the root project, and we'll print a reference error there. Having both is just confusing to users.

lib/models/package-info-cache/index.js:60

private getRealDirectoryPath(directoryPath): String

Resolve the real path for a directory, return null if does not exist or is not a directory, return the real path otherwise.

Parameters:

Name Type Attribute Description
directoryPath String

the path to the directory of interest

Return:

String

real path or null

lib/models/package-info-cache/index.js:19

private getRealFilePath(filePath): String

Resolve the real path for a file, return null if does not exist or is not a file or FIFO, return the real path otherwise.

Parameters:

Name Type Attribute Description
filePath String

the path to the file of interest

Return:

String

real path or null