feat(typings): allow defining custom namespace for bundle

Allows declaring a bundle's namespace in generated typings file,
which should correspond to the global object representing the module
inside its bundle.

BREAKING CHANGE
    The router was previously exported as ng.router in the 
    angular.sfx.dev.js bundle, but now it is exported as ngRouter.

Closes #2948

Closes #3544
This commit is contained in:
Jeff Cross 2015-08-07 17:30:36 -07:00
parent 1f692ae263
commit dfa5103b1d
5 changed files with 14 additions and 7 deletions

View File

@ -47,14 +47,15 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
{ {
id: 'angular2/angular2', id: 'angular2/angular2',
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'], references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'],
namespace: 'ng',
modules: { modules: {
'angular2/angular2': 'angular2/angular2', 'angular2/angular2': 'angular2/angular2',
} }
}, },
{ {
id: 'angular2/router', id: 'angular2/router',
//Right now the typings live in the same directory, but eventually will not. See #3458 namespace: 'ngRouter',
references: ['../angular2/angular2.d.ts'], references: ['../es6-promise/es6-promise.d.ts'],
modules: { modules: {
'angular2/router': 'angular2/router' 'angular2/router': 'angular2/router'
} }

View File

@ -33,7 +33,12 @@ module.exports = function createTypeDefinitionFile(log) {
// A type definition may include a number of top level modules // A type definition may include a number of top level modules
// And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2') // And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2')
moduleDocs: _.transform(def.modules, function(moduleDocs, id, alias) { moduleDocs: _.transform(def.modules, function(moduleDocs, id, alias) {
moduleDocs[id] = { id: alias, doc: null, references: def.references }; moduleDocs[id] = {
id: alias,
doc: null,
namespace: def.namespace,
references: def.references
};
}) })
}; };
}); });

View File

@ -30,7 +30,7 @@
// *********************************************************** // ***********************************************************
{% for alias, module in doc.moduleDocs %} {% for alias, module in doc.moduleDocs %}
{%- if module.references.length %} {%- if module.references.length %}
// Angular depends transitively on these libraries. // {$ alias $} depends transitively on these libraries.
// If you don't have them installed you can install them using TSD // If you don't have them installed you can install them using TSD
// https://github.com/DefinitelyTyped/tsd // https://github.com/DefinitelyTyped/tsd
{%- endif %} {%- endif %}
@ -39,7 +39,7 @@
{% block staticDeclarations %}{% endblock %} {% block staticDeclarations %}{% endblock %}
{% for alias, module in doc.moduleDocs %} {% for alias, module in doc.moduleDocs %}
{$ commentBlock(module.doc, 1) $} {$ commentBlock(module.doc, 1) $}
declare module ng { declare module {$ module.namespace $} {
{%- for export in module.doc.exports -%} {%- for export in module.doc.exports -%}
{%- if export.content -%} {%- if export.content -%}
@ -75,7 +75,7 @@ declare module ng {
} }
declare module "{$ alias $}" { declare module "{$ alias $}" {
export = ng; export = {$ module.namespace $};
} }
{% endfor %} {% endfor %}

View File

@ -9,7 +9,7 @@ var _prevNg = (<any>window).ng;
(<any>window).ng = ng; (<any>window).ng = ng;
(<any>ng).router = router; (<any>window).ngRouter = router;
/** /**
* Calling noConflict will restore window.angular to its pre-angular loading state * Calling noConflict will restore window.angular to its pre-angular loading state
* and return the angular module object. * and return the angular module object.

View File

@ -21,6 +21,7 @@ export {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from './src/
export {CanActivate} from './src/router/lifecycle_annotations'; export {CanActivate} from './src/router/lifecycle_annotations';
export {Instruction, ComponentInstruction} from './src/router/instruction'; export {Instruction, ComponentInstruction} from './src/router/instruction';
export {Url} from './src/router/url_parser'; export {Url} from './src/router/url_parser';
export {OpaqueToken, Type} from 'angular2/angular2';
import {LocationStrategy} from './src/router/location_strategy'; import {LocationStrategy} from './src/router/location_strategy';
import {HTML5LocationStrategy} from './src/router/html5_location_strategy'; import {HTML5LocationStrategy} from './src/router/html5_location_strategy';