X Tutup
Skip to content

Commit dfa5103

Browse files
committed
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
1 parent 1f692ae commit dfa5103

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

docs/typescript-definition-package/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
4747
{
4848
id: 'angular2/angular2',
4949
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'],
50+
namespace: 'ng',
5051
modules: {
5152
'angular2/angular2': 'angular2/angular2',
5253
}
5354
},
5455
{
5556
id: 'angular2/router',
56-
//Right now the typings live in the same directory, but eventually will not. See #3458
57-
references: ['../angular2/angular2.d.ts'],
57+
namespace: 'ngRouter',
58+
references: ['../es6-promise/es6-promise.d.ts'],
5859
modules: {
5960
'angular2/router': 'angular2/router'
6061
}

docs/typescript-definition-package/processors/createTypeDefinitionFile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ module.exports = function createTypeDefinitionFile(log) {
3333
// A type definition may include a number of top level modules
3434
// And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2')
3535
moduleDocs: _.transform(def.modules, function(moduleDocs, id, alias) {
36-
moduleDocs[id] = { id: alias, doc: null, references: def.references };
36+
moduleDocs[id] = {
37+
id: alias,
38+
doc: null,
39+
namespace: def.namespace,
40+
references: def.references
41+
};
3742
})
3843
};
3944
});

docs/typescript-definition-package/templates/type-definition.template.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// ***********************************************************
3131
{% for alias, module in doc.moduleDocs %}
3232
{%- if module.references.length %}
33-
// Angular depends transitively on these libraries.
33+
// {$ alias $} depends transitively on these libraries.
3434
// If you don't have them installed you can install them using TSD
3535
// https://github.com/DefinitelyTyped/tsd
3636
{%- endif %}
@@ -39,7 +39,7 @@
3939
{% block staticDeclarations %}{% endblock %}
4040
{% for alias, module in doc.moduleDocs %}
4141
{$ commentBlock(module.doc, 1) $}
42-
declare module ng {
42+
declare module {$ module.namespace $} {
4343

4444
{%- for export in module.doc.exports -%}
4545
{%- if export.content -%}
@@ -75,7 +75,7 @@
7575
}
7676

7777
declare module "{$ alias $}" {
78-
export = ng;
78+
export = {$ module.namespace $};
7979
}
8080

8181
{% endfor %}

modules/angular2/angular2_sfx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var _prevNg = (<any>window).ng;
99
(<any>window).ng = ng;
1010

1111

12-
(<any>ng).router = router;
12+
(<any>window).ngRouter = router;
1313
/**
1414
* Calling noConflict will restore window.angular to its pre-angular loading state
1515
* and return the angular module object.

modules/angular2/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from './src/
2121
export {CanActivate} from './src/router/lifecycle_annotations';
2222
export {Instruction, ComponentInstruction} from './src/router/instruction';
2323
export {Url} from './src/router/url_parser';
24+
export {OpaqueToken, Type} from 'angular2/angular2';
2425

2526
import {LocationStrategy} from './src/router/location_strategy';
2627
import {HTML5LocationStrategy} from './src/router/html5_location_strategy';

0 commit comments

Comments
 (0)
X Tutup