ng-dependency-map

1.0.1 • Public • Published

ng-dependency-map

Dependency Status

(Forked from https://github.com/randing89/ngrequire)

(See also: https://github.com/klei/ng-dependencies)

A utility to analyze Angular module dependencies. It scans files, given by a glob pattern, and builds two maps.

  • A map of files to Angular module dependencies
  • A map of Angular module names to files

Standard case

An Angular module definition looks like this:

// .../src/myCoolModule.js
angular.module('myCoolModule', [ 'myDependency' ])
    .directive(myDirective)
    .service(myService);

The map of files to Angular module dependencies will look like this:

{
    '.../src/myCoolModule.js': [ 'myDependency ']
}

And the map of module names to files will look like this:

{
    'myDependency': [ '.../src/myCoolModule.js' ]
}

Modules across multiple files

Note that passing the second argument to angular.module is what constitutes a module definition. It's possible to have more files that add providers to an existing module after it's defined.

If you add a file like this:

// .../src/myCoolModuleAnotherService.js
angular.module('myCoolModule')
    .service(anotherService);

The map of files to dependencies won't change.

The map of module names to files will look like this:

{
    'myDependency': [ '.../src/myCoolModule.js', '.../src/myCoolModuleAnotherService.js' ]
}

Use with ngMock

ngMock is also supported. You need to use the full name "angular.mock.module" rather than just "module" (to be safe). If you add a test file like this:

// .../src/myCoolModule.test.js
describe('my cool module', function () {
    beforeEach(function () {
        angular.mock.module('myCoolModule');
    });
 
    it('should compile the directive', function () {
        ...
    });
});

The map of module names to files won't change.

The map of files to dependencies will look like this:

{
    '.../src/myCoolModule.js': [ 'myDependency '],
    '.../src/myCoolModule.test.js': [ 'myCoolModule' ]
}

API

update(moduleSourceBase, options)

  • moduleSourceBase: Glob-like file path array. Should contain all your angular modules.
  • options: Optional. Set 'ensureModuleName' to true to require all module names to match their folder names.

The update function will keep track of when a file was last updated, so it won't process a file again if it hasn't changed.

return {
  success: ['successed file list'],
  skipped: ['skipped file list (due to caching)']
}

clean()

Clean the cache.

getFileDependenciesMap()

Get a map of files to dependencies.

getModuleFilesMap()

Get a map of modules to the files they are defined in.

Readme

Keywords

none

Package Sidebar

Install

npm i ng-dependency-map

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • mikeperri