Skip to content

Commit 95f9846

Browse files
committed
Produce .d.ts files from our typescript compilation.
Deliver them into our npm module output so users can consume them directly. Fixes #3082
1 parent 393b052 commit 95f9846

30 files changed

Lines changed: 130 additions & 81 deletions

File tree

docs/typescript-definition-package/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
5050
createTypeDefinitionFile.typeDefinitions = [
5151
{
5252
id: 'angular2/angular2',
53-
references: ['../es6-shim/es6-shim.d.ts'],
53+
references: [],
5454
modules: {
5555
'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'},
5656
'angular2/web_worker/worker': {namespace: 'ngWorker', id: 'angular2/web_worker/worker'},
@@ -71,7 +71,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
7171
},
7272
{
7373
id: 'angular2/test_lib',
74-
references: ['./angular2.d.ts', '../jasmine/jasmine.d.ts'],
74+
references: ['./angular2.d.ts'],
7575
remapTypes: { Type: 'ng.Type', Binding: 'ng.Binding', ViewMetadata: 'ng.ViewMetadata', Injector: 'ng.Injector',
7676
Predicate: 'ng.Predicate', ElementRef: 'ng.ElementRef', DebugElement: 'ng.DebugElement',
7777
InjectableReference: 'ng.InjectableReference', ComponentRef: 'ng.ComponentRef' },

gulpfile.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ function runKarma(configFile, done) {
446446

447447
gulp.task('test.js', function(done) {
448448
runSequence('test.unit.tools/ci', 'test.transpiler.unittest', 'test.unit.js/ci',
449-
'test.unit.cjs/ci', 'test.typings', sequenceComplete(done));
449+
'test.unit.cjs/ci', 'test.typings', 'test.typings.npm', sequenceComplete(done));
450450
});
451451

452452
gulp.task('test.dart', function(done) {
@@ -771,8 +771,25 @@ gulp.task('!pre.test.typings', ['docs/typings'], function() {
771771
});
772772

773773
// -----------------
774+
// Tests for the typings we deliver for TS users
775+
//
776+
// There are currently two mechanisms for this.
777+
// The first is the legacy, bundled .d.ts file produced by dgeni.
778+
// This is tested by 'test.typings'.
779+
//
780+
// The second is individual .d.ts files produced by the compiler,
781+
// distributed in our npm package, and loaded from node_modules by
782+
// the typescript compiler.
783+
// This is tested by 'test.typings.npm'.
784+
//
785+
// During the transition, we support both packaging/delivery types.
786+
// TODO(alexeagle): remove the dgeni bundle when users have switched
787+
774788
gulp.task('test.typings', ['!pre.test.typings'], function() {
775-
return gulp.src(['typing_spec/*.ts', 'dist/docs/typings/angular2/*.d.ts', 'dist/docs/typings/http.d.ts'])
789+
return gulp.src(['typing_spec/*.ts', 'dist/docs/typings/angular2/*.d.ts',
790+
'dist/docs/typings/http.d.ts',
791+
'dist/docs/typings/es6-shim/es6-shim.d.ts',
792+
'dist/docs/typings/jasmine/jasmine.d.ts'])
776793
.pipe(tsc({target: 'ES5', module: 'commonjs',
777794
experimentalDecorators: true,
778795
noImplicitAny: true,
@@ -781,6 +798,29 @@ gulp.task('test.typings', ['!pre.test.typings'], function() {
781798
typescript: require('typescript')}));
782799
});
783800

801+
// Make sure the two typings tests are isolated, by running this one in a tempdir
802+
var tmpdir = path.join(os.tmpdir(), 'test.typings', new Date().getTime().toString());
803+
gulp.task('!pre.test.typings.layoutNodeModule', function() {
804+
return gulp
805+
.src(['dist/js/dev/es5/angular2/**/*'], {base: 'dist/js/dev/es5'})
806+
.pipe(gulp.dest(path.join(tmpdir, 'node_modules')));
807+
});
808+
gulp.task('!pre.test.typings.copyTypingsSpec', function() {
809+
return gulp
810+
.src(['typing_spec/basic_spec.ts'], {base: 'typing_spec'})
811+
.pipe(gulp.dest(path.join(tmpdir)));
812+
});
813+
gulp.task('test.typings.npm', [
814+
'!pre.test.typings.layoutNodeModule',
815+
'!pre.test.typings.copyTypingsSpec'
816+
], function() {
817+
return gulp.src([tmpdir + '/**'])
818+
.pipe(tsc({target: 'ES5', module: 'commonjs',
819+
experimentalDecorators: true,
820+
noImplicitAny: true,
821+
typescript: require('typescript')}));
822+
});
823+
784824
// -----------------
785825
// orchestrated targets
786826

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Declarations angular depends on for compilation to ES6.
3+
* This file is also used to propagate our transitive typings
4+
* to users.
5+
*/
6+
7+
/// <reference path="../typings/zone/zone.d.ts"/>
8+
/// <reference path="../typings/hammerjs/hammerjs.d.ts"/>
9+
/// <reference path="../typings/jasmine/jasmine.d.ts"/>
10+
/// <reference path="../typings/angular-protractor/angular-protractor.d.ts"/>
11+
declare var assert: any;
12+
13+
interface BrowserNodeGlobal {
14+
Object: typeof Object;
15+
Array: typeof Array;
16+
Map: typeof Map;
17+
Set: typeof Set;
18+
Date: typeof Date;
19+
RegExp: typeof RegExp;
20+
JSON: typeof JSON;
21+
Math: typeof Math;
22+
assert(condition: any): void;
23+
Reflect: any;
24+
zone: Zone;
25+
getAngularTestability: Function;
26+
getAllAngularTestabilities: Function;
27+
setTimeout: Function;
28+
clearTimeout: Function;
29+
setInterval: Function;
30+
clearInterval: Function;
31+
}
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
/**
2-
* This file contains declarations of global symbols we reference in our code
2+
* Declarations angular depends on for compilation to ES6.
3+
* This file is also used to propagate our transitive typings
4+
* to users.
35
*/
4-
5-
/// <reference path="../typings/zone/zone.d.ts"/>
6-
declare var assert: any;
7-
8-
interface BrowserNodeGlobal {
9-
Object: typeof Object;
10-
Array: typeof Array;
11-
Map: typeof Map;
12-
Set: typeof Set;
13-
Date: typeof Date;
14-
RegExp: typeof RegExp;
15-
JSON: typeof JSON;
16-
Math: typeof Math;
17-
assert(condition): void;
18-
Reflect: any;
19-
zone: Zone;
20-
getAngularTestability: Function;
21-
getAllAngularTestabilities: Function;
22-
setTimeout: Function;
23-
clearTimeout: Function;
24-
setInterval: Function;
25-
clearInterval: Function;
26-
}
6+
/// <reference path="../typings/es6-shim/es6-shim.d.ts"/>
7+
/// <reference path="./globals-es6.d.ts"/>

modules/angular2/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"zone.js": "<%= packageJson.dependencies['zone.js'] %>"
1414
},
1515
"devDependencies": <%= JSON.stringify(packageJson.defaultDevDependencies) %>,
16+
"typings": "./angular2.d.ts",
1617
"typescript": {
1718
"definitions": [
1819
"bundles/typings/angular2/angular2.d.ts",

modules/angular2/src/core/application_ref.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ export function createNgZone(): NgZone {
117117

118118
var _platform: PlatformRef;
119119

120-
/**
121-
* @internal
122-
*/
123120
export function platformCommon(bindings?: Array<Type | Binding | any[]>, initializer?: () => void):
124121
PlatformRef {
125122
if (isPresent(_platform)) {

modules/angular2/src/core/change_detection/parser/locals.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import {isPresent} from 'angular2/src/core/facade/lang';
22
import {BaseException} from 'angular2/src/core/facade/exceptions';
33
import {ListWrapper, MapWrapper} from 'angular2/src/core/facade/collection';
44

5-
/**
6-
* @internal
7-
*/
85
export class Locals {
96
constructor(public parent: Locals, public current: Map<any, any>) {}
107

modules/angular2/src/core/di/binding.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ import {
3030
} from './exceptions';
3131
import {resolveForwardRef} from './forward_ref';
3232

33-
/**
34-
* @internal
35-
*/
3633
export class Dependency {
3734
constructor(public key: Key, public optional: boolean, public lowerBoundVisibility: any,
3835
public upperBoundVisibility: any, public properties: any[]) {}
@@ -280,7 +277,6 @@ export class ResolvedBinding_ implements ResolvedBinding {
280277
}
281278

282279
/**
283-
* @internal
284280
* An internal resolved representation of a factory function created by resolving {@link Binding}.
285281
*/
286282
export class ResolvedFactory {

modules/angular2/src/core/di/injector.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ export class BindingWithVisibility {
387387
}
388388

389389
/**
390-
* @internal
391390
* Used to provide dependencies that cannot be easily expressed as bindings.
392391
*/
393392
export interface DependencyProvider {

modules/angular2/src/core/di/type_literal.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
2-
* @internal
32
* Type literals is a Dart-only feature. This is here only so we can x-compile
43
* to multiple languages.
54
*/

0 commit comments

Comments
 (0)