Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(script): Set ngModule to Closure namespace.
Browse files Browse the repository at this point in the history
When using Closure, it is common to reference Angular module
dependencies by the name property of the module.
This looks like:
```
goog.provide('bar.module');
goog.require('foo.module');
bar.module = angular.module('bar.module', [foo.module.name]);
```
This change makes it possible for this kind of reference instead of
having to refer to the dependent module as a string.

Closes #1709.
  • Loading branch information
wesalvaro authored and ThomasBurleson committed Apr 10, 2015
1 parent 84e4504 commit ade76f9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions scripts/gulp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,19 @@ exports.addClosurePrefixes = function() {
var moduleInfo = getModuleInfo(file.contents);
if (moduleInfo.module) {

var provide = 'goog.provide(\'' + moduleNameToClosureName(moduleInfo.module) + '\');';
var closureModuleName = moduleNameToClosureName(moduleInfo.module);
var provide = 'goog.provide(\'' + closureModuleName + '\');';
var requires = (moduleInfo.dependencies || []).sort().map(function(dep) {
return dep.indexOf(moduleInfo.module) === 0 ? '' : 'goog.require(\'' + moduleNameToClosureName(dep) + '\');';
}).join('\n');

var contents = file.contents.toString();

// Assign the module to the provided Closure namespace:
contents = contents.replace('angular.module', closureModuleName + ' = angular.module');

file.contents = new Buffer(
provide + '\n' + requires + '\n' + file.contents.toString()
provide + '\n' + requires + '\n' + contents
);
}
this.push(file);
Expand Down

0 comments on commit ade76f9

Please sign in to comment.