From dfa5103b1d390ee9744548ca4fe08bfa73ce2dd5 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Fri, 7 Aug 2015 17:30:36 -0700 Subject: [PATCH] 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 --- docs/typescript-definition-package/index.js | 5 +++-- .../processors/createTypeDefinitionFile.js | 7 ++++++- .../templates/type-definition.template.html | 6 +++--- modules/angular2/angular2_sfx.ts | 2 +- modules/angular2/router.ts | 1 + 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/typescript-definition-package/index.js b/docs/typescript-definition-package/index.js index 23878168d9..e5e1696f7a 100644 --- a/docs/typescript-definition-package/index.js +++ b/docs/typescript-definition-package/index.js @@ -47,14 +47,15 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage, { id: 'angular2/angular2', references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'], + namespace: 'ng', modules: { 'angular2/angular2': 'angular2/angular2', } }, { id: 'angular2/router', - //Right now the typings live in the same directory, but eventually will not. See #3458 - references: ['../angular2/angular2.d.ts'], + namespace: 'ngRouter', + references: ['../es6-promise/es6-promise.d.ts'], modules: { 'angular2/router': 'angular2/router' } diff --git a/docs/typescript-definition-package/processors/createTypeDefinitionFile.js b/docs/typescript-definition-package/processors/createTypeDefinitionFile.js index 800b9d71a0..6f9bd7392a 100644 --- a/docs/typescript-definition-package/processors/createTypeDefinitionFile.js +++ b/docs/typescript-definition-package/processors/createTypeDefinitionFile.js @@ -33,7 +33,12 @@ module.exports = function createTypeDefinitionFile(log) { // A type definition may include a number of top level modules // And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2') 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 + }; }) }; }); diff --git a/docs/typescript-definition-package/templates/type-definition.template.html b/docs/typescript-definition-package/templates/type-definition.template.html index 1c8282fb12..b1667ee54a 100644 --- a/docs/typescript-definition-package/templates/type-definition.template.html +++ b/docs/typescript-definition-package/templates/type-definition.template.html @@ -30,7 +30,7 @@ // *********************************************************** {% for alias, module in doc.moduleDocs %} {%- 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 // https://github.com/DefinitelyTyped/tsd {%- endif %} @@ -39,7 +39,7 @@ {% block staticDeclarations %}{% endblock %} {% for alias, module in doc.moduleDocs %} {$ commentBlock(module.doc, 1) $} -declare module ng { +declare module {$ module.namespace $} { {%- for export in module.doc.exports -%} {%- if export.content -%} @@ -75,7 +75,7 @@ declare module ng { } declare module "{$ alias $}" { - export = ng; + export = {$ module.namespace $}; } {% endfor %} diff --git a/modules/angular2/angular2_sfx.ts b/modules/angular2/angular2_sfx.ts index 63e8b0042a..edd420b58c 100644 --- a/modules/angular2/angular2_sfx.ts +++ b/modules/angular2/angular2_sfx.ts @@ -9,7 +9,7 @@ var _prevNg = (window).ng; (window).ng = ng; -(ng).router = router; +(window).ngRouter = router; /** * Calling noConflict will restore window.angular to its pre-angular loading state * and return the angular module object. diff --git a/modules/angular2/router.ts b/modules/angular2/router.ts index 940103fd19..5dc032fc7e 100644 --- a/modules/angular2/router.ts +++ b/modules/angular2/router.ts @@ -21,6 +21,7 @@ export {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from './src/ export {CanActivate} from './src/router/lifecycle_annotations'; export {Instruction, ComponentInstruction} from './src/router/instruction'; export {Url} from './src/router/url_parser'; +export {OpaqueToken, Type} from 'angular2/angular2'; import {LocationStrategy} from './src/router/location_strategy'; import {HTML5LocationStrategy} from './src/router/html5_location_strategy';