Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

Commit 3af26c7

Browse files
mgechevjeffbcross
authored andcommitted
chore(typings): generate typings for worker (#16)
1. Update to TypeScript (1.9 has fix for TS4020). 2. Update ts-node and typings. 3. Add ambient type definitions for CacheStorage, CacheOptions, Cache. 4. Add ambient type definitions for jshashes. 5. Remove useless require from `gulpfile.ts`. 6. Add `merge-stream` in order to merge both js and dts streams of `gulp-typescript`. 7. Publish `typings` field in `package.json`. 8. Remove inline Promise interface definition and take the one from `es6-shim` typings.
1 parent 176aa07 commit 3af26c7

File tree

19 files changed

+198
-150
lines changed

19 files changed

+198
-150
lines changed

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.DS_STORE
2+
3+
# Don’t commit the following directories created by pub.
4+
packages
5+
pubspec.lock
6+
.pub
7+
.packages
8+
9+
/dist/
10+
.buildlog
11+
node_modules
12+
bower_components
13+
14+
# Or broccoli working directory
15+
tmp
16+
17+
# Or the files created by dart2js.
18+
*.dart.js
19+
*.dart.precompiled.js
20+
*.js_
21+
*.js.deps
22+
*.js.map
23+
24+
# Files created by the template compiler
25+
**/*.ngfactory.ts
26+
**/*.css.ts
27+
**/*.css.shim.ts
28+
29+
# Or type definitions we mirror from github
30+
# (NB: these lines are removed in publish-build-artifacts.sh)
31+
**/typings/**/*.d.ts
32+
**/typings/tsd.cached.json
33+
34+
# Include when developing application packages.
35+
pubspec.lock
36+
.c9
37+
.idea/
38+
.settings/
39+
*.swo
40+
.vscode
41+
42+
# Don't check in secret files
43+
*secret.js
44+
45+
# Ignore npm debug log
46+
npm-debug.log

install.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
22
cd ./service-worker/worker
33
npm install
4-
tsd install
5-
tsc --version
4+

service-worker/worker/gulpfile.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ var concat = require('gulp-concat');
1010
let jsmn = require('gulp-jasmine');
1111
var runSequence = require('run-sequence');
1212
var process = require('process');
13+
var merge = require('merge-stream');
1314

1415
var systemCompilerConfig = JSON.parse(fs.readFileSync('./tsconfig.json')).compilerOptions;
1516
var commonCompilerConfig = JSON.parse(fs.readFileSync('./tsconfig.cjs.json')).compilerOptions;
1617

1718
commonCompilerConfig.typescript = require('typescript');
19+
systemCompilerConfig.typescript = require('typescript');
1820

1921
gulp.task('default', ['build']);
2022

@@ -32,27 +34,37 @@ gulp.task('prepublish', done => runSequence(
3234
['!bundle', 'copy:generator'],
3335
done));
3436

35-
gulp.task('!build:system', () => gulp
36-
.src([
37-
'src/**/*.ts',
38-
'!src/**/*.spec.ts',
39-
'typings/browser/**/*.d.ts'
40-
])
41-
.pipe(ts(systemCompilerConfig))
42-
.pipe(gulp.dest('dist/src')));
37+
gulp.task('!build:system', () => {
38+
const stream = gulp
39+
.src([
40+
'src/**/*.ts',
41+
'!src/**/*.spec.ts',
42+
'typings/globals/**/*.d.ts'
43+
])
44+
.pipe(ts(systemCompilerConfig));
45+
return merge([
46+
stream.js.pipe(gulp.dest(systemCompilerConfig.outDir)),
47+
stream.dts.pipe(gulp.dest(systemCompilerConfig.outDir))
48+
]);
49+
});
4350

44-
gulp.task('!build:commonjs', () => gulp
45-
.src([
46-
'src/**/*.ts',
47-
'typings/browser/**/*.d.ts'
48-
])
49-
.pipe(ts(commonCompilerConfig))
50-
.pipe(gulp.dest('dist/src')));
51+
gulp.task('!build:commonjs', () => {
52+
const stream = gulp
53+
.src([
54+
'src/**/*.ts',
55+
'typings/globals/**/*.d.ts'
56+
])
57+
.pipe(ts(commonCompilerConfig));
58+
return merge([
59+
stream.js.pipe(gulp.dest(commonCompilerConfig.outDir)),
60+
stream.dts.pipe(gulp.dest(commonCompilerConfig.outDir))
61+
]);
62+
});
5163

5264
gulp.task('build:generator', () => gulp
5365
.src([
5466
'src/generator/**.ts',
55-
'typings/main/**/*.d.ts'
67+
'typings/globals/**/*.d.ts'
5668
])
5769
.pipe(ts(commonCompilerConfig))
5870
.pipe(gulp.dest('dist/src/generator')));
@@ -71,7 +83,7 @@ gulp.task('build:test', (done) => runSequence(
7183

7284
gulp.task('test', ['build:test'], () => gulp
7385
.src([
74-
'dist/src/**/*.spec.js'
86+
'dist/**/*.spec.js'
7587
], {base: '.'})
7688
.pipe(jsmn({
7789
verbose: true,

service-worker/worker/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "0.2.0",
44
"description": "Experimental service worker by the Angular Mobile team",
55
"main": "dist/generator/index.js",
6+
"typings": "dist/src/worker.d.ts",
67
"scripts": {
7-
"prepublish": "gulp prepublish",
8+
"prepublish": "typings install && gulp prepublish",
89
"build": "gulp build && gulp build:generator",
910
"test": "gulp test"
1011
},
@@ -28,15 +29,16 @@
2829
"gulp-typescript": "^2.12.1",
2930
"gulp-util": "^3.0.7",
3031
"jasmine": "^2.4.1",
32+
"merge-stream": "^1.0.0",
3133
"reflect-metadata": "0.1.2",
3234
"rimraf": "^2.5.2",
3335
"run-sequence": "^1.1.5",
3436
"rxjs": "5.0.0-beta.6",
3537
"systemjs": "^0.19.17",
3638
"systemjs-builder": "^0.15.5",
37-
"ts-node": "^0.5.5",
38-
"tsd": "^0.6.5",
39-
"typescript": "^1.8.9",
39+
"ts-node": "^0.7.3",
40+
"typescript": "1.9.0-dev.20160527-1.0",
41+
"typings": "^1.0.4",
4042
"vinyl": "^1.1.1",
4143
"zone.js": "^0.6.5"
4244
},

service-worker/worker/src/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class CacheManager {
1717
}
1818

1919
load(cache: string, req: string | Request): Observable<Response> {
20-
return Observable.defer(() => Observable.fromPromise(this
20+
return <Observable<Response>>Observable.defer(() => Observable.fromPromise(this
2121
.caches
2222
.open(cache)
2323
.then(cache => cache.match(this.normalize(req)))));

service-worker/worker/src/generator/cli-sw.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
declare var require;
22
declare var module;
33

4-
54
import {ManifestWriter, SourceResolver} from './generator';
65

7-
8-
declare class Promise<T> {
9-
constructor(fn: Function);
10-
static all<T>(promises: Promise<T>[]): Promise<T[]>;
11-
static resolve<T>(val: T): Promise<T>;
12-
then<V>(fn: (T) => V | Promise<V>): Promise<V>;
13-
}
14-
156
const fse = require('fs-extra');
167
const path = require('path');
17-
const BroccoliPlugin:BroccoliPluginConstructor = require('broccoli-caching-writer');;
188
const MANIFEST_NAME = 'ngsw-manifest.json';
19-
const WORKER_NAME = 'worker.js';
9+
const WORKER_NAME = 'worker.js';
10+
export const BroccoliPlugin: BroccoliPluginConstructor = require('broccoli-caching-writer');
2011

21-
interface BroccoliPluginConstructor {
22-
new(inputNodes:any[], options?:any): BroccoliPluginConstructor
23-
inputPaths: string[];
24-
outputPath: string;
12+
export interface BroccoliPluginConstructor {
13+
new(inputNodes: any[], options?: any): BroccoliPluginConstructor;
14+
inputPaths: string[];
15+
outputPath: string;
2516
}
2617

2718
class BroccoliSourceResolver implements SourceResolver {
@@ -35,7 +26,7 @@ class BroccoliSourceResolver implements SourceResolver {
3526
}
3627

3728
export class ServiceWorkerPlugin extends BroccoliPlugin {
38-
constructor(inputNodes:any, options?:any) {
29+
constructor(inputNodes: any, options?: any) {
3930
super([inputNodes]);
4031
}
4132

@@ -79,3 +70,4 @@ function recursiveReaddirSync(src) {
7970
})
8071
return files;
8172
}
73+

service-worker/worker/src/generator/generator.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ let File = require('vinyl');
55

66
let sha1 = new SHA1();
77

8-
declare class Promise<T> {
9-
constructor(fn: Function);
10-
static all<T>(promises: Promise<T>[]): Promise<T[]>;
11-
then<V>(fn: (T) => V | Promise<V>, errFn?: any): Promise<V>;
12-
}
13-
148
declare class Buffer {
159
constructor(data: string);
1610
}
@@ -72,9 +66,9 @@ export function gulpGenManifest(manifest: Manifest, base?: string): any {
7266
}
7367

7468
export class ManifestWriter {
75-
69+
7670
constructor(private resolver: SourceResolver) {}
77-
71+
7872
processRoute(out: any, route: Route): void {
7973
if (!out.routing.hasOwnPropert('route')) {
8074
out.routing.route = {};
@@ -83,7 +77,7 @@ export class ManifestWriter {
8377
prefix: route.prefix
8478
};
8579
}
86-
80+
8781
processGroup(out: any, group: Group): Promise<any> {
8882
if (!out.group.hasOwnProperty(group.name)) {
8983
out.group[group.name] = {
@@ -104,7 +98,7 @@ export class ManifestWriter {
10498
})
10599
);
106100
}
107-
101+
108102
process(manifest: Manifest, base?: string): Promise<string> {
109103
let baseObj = base ? JSON.parse(base) : '';
110104
let out = <any>{
@@ -113,11 +107,11 @@ export class ManifestWriter {
113107
index: '/index.html'
114108
}
115109
};
116-
110+
117111
if (!!manifest.routing && !!manifest.routing.index) {
118112
out.routing.index = manifest.routing.index;
119113
}
120-
114+
121115
if (!!manifest.routing && !!manifest.routing.routes) {
122116
manifest.routing.routes.forEach(route => this.processRoute(out, route));
123117
}
@@ -128,7 +122,7 @@ export class ManifestWriter {
128122
.then(() => _mergeObjects(baseObj, out))
129123
.then(() => out);
130124
}
131-
125+
132126
generate(manifest: Manifest, base?: string): Promise<string> {
133127
return this
134128
.process(manifest, base)

service-worker/worker/src/generator/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ declare var module;
22

33
export * from './cli-sw';
44
export * from './generator';
5+

service-worker/worker/src/manifest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import {stringStartsWith} from './builtins';
32
import {SHA1} from 'jshashes';
43

@@ -57,7 +56,7 @@ export interface CacheEntryMap {
5756
export interface CacheEntry {
5857
url: string;
5958
group: CacheGroup;
60-
59+
6160
hash?: string;
6261
}
6362

@@ -101,12 +100,12 @@ export function diffManifests(current: string, previous: string): ManifestDelta
101100
return delta;
102101
}
103102
delta.previous = parseManifest(previous);
104-
103+
105104
let groups = _mergeKeys(
106105
delta.current.group,
107106
delta.previous.group
108107
);
109-
108+
110109
groups.forEach(name => {
111110
let prevGroup = _groupOrEmpty(delta.previous, name);
112111
let currGroup = _groupOrEmpty(delta.current, name);
@@ -178,3 +177,4 @@ function postProcessGroup(group: CacheGroup) {
178177
.join(':'));
179178
}
180179
}
180+

0 commit comments

Comments
 (0)