From d93b74ef1af0102dd30618899b90e6a1879ad9ca Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Wed, 17 Feb 2016 13:41:50 -0800 Subject: [PATCH] chore(): update to Beta.6, including having our own typings. --- .gitignore | 1 + .travis.yml | 2 +- DEV_ENVIRONMENT.md | 4 +-- ember-cli-build.js | 9 +++---- package.json | 12 +++++---- scripts/ci/build-and-test.sh | 1 + src/components/sidenav/sidenav.spec.ts | 4 ++- src/index.html | 2 +- src/typings.d.ts | 1 + test/karma-test-shim.js | 30 ++++++++++++++++++++--- test/karma.config.ts | 14 +++++++---- tools/broccoli/broccoli-ts2dart.ts | 34 +++++++++++++++++--------- tools/build/dart_analyzer.ts | 2 +- typings.json | 11 +++++++++ 14 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 src/typings.d.ts create mode 100644 typings.json diff --git a/.gitignore b/.gitignore index 59d6031380c6..d1efe016312c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # compiled output /dist /tmp +/typings # dependencies /node_modules diff --git a/.travis.yml b/.travis.yml index c42c7b27f146..f81cd2d2730f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ node_js: cache: directories: - - node_modules - $HOME/.pub-cache env: @@ -50,6 +49,7 @@ before_install: install: - npm install + - npm run typings before_script: # Necessary to run test on Travis CI that require a graphical interface. diff --git a/DEV_ENVIRONMENT.md b/DEV_ENVIRONMENT.md index 6252a1b35661..ede5a445598d 100644 --- a/DEV_ENVIRONMENT.md +++ b/DEV_ENVIRONMENT.md @@ -6,7 +6,7 @@ 4. Clone your fork. Recommendation: name your git remotes `upstream` for `angular/material2` and `` for your fork. Also see the [team git shortcuts](https://github.com/angular/material2/wiki/Team-git----bash-shortcuts). -5. From the root of the project, run `npm install` +5. From the root of the project, run `npm install`, then run `npm run typings` to install typescript definitions. To build the project, run `ng build`. @@ -15,7 +15,7 @@ To watch for changes and automatically rebuild, run `ng build --watch` To bring up a local server, run `ng serve`. This will automatically watch for changes and rebuild. After the changes rebuild, the browser currently needs to be manually refreshed. -To run unit tests, run `ng test`. +To run unit tests, run `npm test`. Running e2e tests: Running benchmarks: diff --git a/ember-cli-build.js b/ember-cli-build.js index 581dd98bc131..b48f9dc39ec1 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -11,6 +11,7 @@ var Angular2App = require('angular-cli/lib/broccoli/angular2-app'); var BroccoliSass = require('broccoli-sass'); var broccoliAutoprefixer = require('broccoli-autoprefixer'); +const BroccoliTypescript = require('./tools/broccoli/broccoli-typescript').default; const BroccoliTs2Dart = require('./tools/broccoli/broccoli-ts2dart').default; const BroccoliDestCopy = require('./tools/broccoli/broccoli-dest-copy').default; const BroccoliDartFmt = require('./tools/broccoli/broccoli-dartfmt').default; @@ -24,6 +25,7 @@ module.exports = function(defaults) { var demoCssTree = getCssTree('demo-app'); var componentCssTree = getCssTree('components'); var angularAppTree = new Angular2App(defaults); + var dartAppTree = getDartTree('src/'); return mergeTrees([ @@ -51,6 +53,8 @@ function getDartTree(root) { generateLibraryName: true, generateSourceMap: false, translateBuiltins: true, + typingsRoot: '../../typings/browser/ambient/', + additionalFiles: [path.join(process.cwd(), root, 'typings.d.ts')], }); const formatter = new BroccoliDartFmt(ts2dart, { dartSDK }); @@ -65,11 +69,6 @@ function getDartTree(root) { formatter ]); - //const pubSpecTree = new BroccoliFunnel('.', { - // files: ['pubspec.yaml'], - // //exclude: ['**/*'], - // destDir: 'dart' - //}); const pubSpecTree = new BroccoliFunnel(new BroccoliSource.UnwatchedDir('.'), { files: ['pubspec.yaml'], destDir: 'dart', diff --git a/package.json b/package.json index 215a664164e3..ce9efcda84d3 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "build": "ng build", "dartanalyzer": "cd dist/dart && pub install && cd ../.. && ts-node scripts/ci/dart_analyzer", "demo-app": "cd src && ng serve", - "test": "karma start test/karma.conf.js" + "test": "karma start test/karma.conf.js", + "typings": "typings install --ambient" }, "version": "2.0.0-alpha.0", "license": "MIT", @@ -19,16 +20,16 @@ "node": ">= 4.2.1 < 5" }, "dependencies": { - "angular2": "2.0.0-beta.0", + "angular2": "2.0.0-beta.6", "es6-promise": "^3.0.2", "es6-shim": "^0.33.3", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.0", "systemjs": "0.19.4", - "zone.js": "0.5.10" + "zone.js": "0.5.14" }, "devDependencies": { - "angular-cli": "0.0.*", + "angular-cli": "^0.0.24", "angular-cli-github-pages": "^0.2.0", "broccoli-autoprefixer": "^4.1.0", "broccoli-funnel": "^1.0.1", @@ -51,9 +52,10 @@ "strip-ansi": "^3.0.0", "symlink-or-copy": "^1.0.1", "ts-node": "^0.5.5", - "ts2dart": "^0.7.25", + "ts2dart": "^0.7.27", "tslint": "^3.2.2", "typescript": "^1.7.5", + "typings": "^0.6.8", "which": "^1.2.4" } } diff --git a/scripts/ci/build-and-test.sh b/scripts/ci/build-and-test.sh index abdba6e17a3c..8b26341064d9 100755 --- a/scripts/ci/build-and-test.sh +++ b/scripts/ci/build-and-test.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e echo "======= Starting build-and-test.sh ========================================" diff --git a/src/components/sidenav/sidenav.spec.ts b/src/components/sidenav/sidenav.spec.ts index 9a883f9e9811..c2c8c533f1ef 100644 --- a/src/components/sidenav/sidenav.spec.ts +++ b/src/components/sidenav/sidenav.spec.ts @@ -156,7 +156,7 @@ export function main() { .then((_: any) => { done(); }); }, 8000); - it('open() twice returns the same promise', (done: any) => { + it('open/close() twice returns the same promise', (done: any) => { let fixture: ComponentFixture; let sidenav: MdSidenav; @@ -169,12 +169,14 @@ export function main() { promise = sidenav.open(); expect(sidenav.open()).toBe(promise); + return wait(1); }) .then((_: any) => { return wait(1); }) .then((_: any) => { fixture.detectChanges(); return promise; }) + .then((_: any) => { return wait(1); }) .then((_: any) => { promise = sidenav.close(); expect(sidenav.close()).toBe(promise); diff --git a/src/index.html b/src/index.html index 680b352267d8..8118f53babcf 100644 --- a/src/index.html +++ b/src/index.html @@ -14,7 +14,7 @@ Loading... - + diff --git a/src/typings.d.ts b/src/typings.d.ts new file mode 100644 index 000000000000..beb6cefcecec --- /dev/null +++ b/src/typings.d.ts @@ -0,0 +1 @@ +/// diff --git a/test/karma-test-shim.js b/test/karma-test-shim.js index aa8cf881ae3b..ef5d75a21b83 100644 --- a/test/karma-test-shim.js +++ b/test/karma-test-shim.js @@ -41,10 +41,32 @@ System.config({ } }); -System.import('angular2/platform/browser').then(function(browser_adapter) { - // TODO: once beta is out we should change this code to use a "test platform" - browser_adapter.BrowserDomAdapter.makeCurrent(); -}).then(function() { + +/** + * Bootstrap the browser testing providers from Angular2. The equivalent code in TypeScript + * would be: + * + * + * import {setBaseTestProviders} from 'angular2/testing'; + * import * as browser from 'angular2/platform/testing/browser'; + * + * setBaseTestProviders(browser.TEST_BROWSER_PLATFORM_PROVIDERS, + * browser.TEST_BROWSER_APPLICATION_PROVIDERS); + * + * + * See https://github.com/angular/angular/blob/master/CHANGELOG.md#200-beta2-2016-01-28 + * + * Followed by the normal import of all spec files, then bootstrap Karma. + */ +Promise.all([ + System.import('angular2/testing'), + System.import('angular2/platform/testing/browser'), +]).then(function(imports) { + var testing = imports[0]; + var browser = imports[1]; + testing.setBaseTestProviders(browser.TEST_BROWSER_PLATFORM_PROVIDERS, + browser.TEST_BROWSER_APPLICATION_PROVIDERS); + return Promise.all( Object.keys(window.__karma__.files) .filter(isSpecFile) diff --git a/test/karma.config.ts b/test/karma.config.ts index 2d33658705bc..780a7db7ece2 100644 --- a/test/karma.config.ts +++ b/test/karma.config.ts @@ -19,13 +19,15 @@ export function config(config) { require('karma-firefox-launcher'), ], files: [ - {pattern: 'node_modules/es6-shim/es6-shim.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, - watched: true}, + {pattern: 'node_modules/es6-shim/es6-shim.min.js', included: true, watched: true}, {pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: true}, + 'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js', + + {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true}, {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true}, {pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true}, + 'node_modules/reflect-metadata/Reflect.js', + {pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true}, {pattern: 'test/karma-test-shim.js', included: true, watched: true}, @@ -78,9 +80,11 @@ export function config(config) { startTunnel: false, retryLimit: 1, timeout: 600, - pollingTimeout: 10000 + pollingTimeout: 20000 }, + browserDisconnectTimeout: 20000, + browserNoActivityTimeout: 100000, browsers: ['Chrome'], singleRun: false diff --git a/tools/broccoli/broccoli-ts2dart.ts b/tools/broccoli/broccoli-ts2dart.ts index 6df6fbacccb1..6acd88878e9c 100644 --- a/tools/broccoli/broccoli-ts2dart.ts +++ b/tools/broccoli/broccoli-ts2dart.ts @@ -4,17 +4,26 @@ import fs = require('fs'); import fse = require('fs-extra'); import path = require('path'); -import * as ts2dart from 'ts2dart'; import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-broccoli-plugin'; class TSToDartTranspiler implements DiffingBroccoliPlugin { static includeExtensions = ['.ts']; - private transpiler: ts2dart.Transpiler; + private transpiler: any /*ts2dart.Transpiler*/; + private additionalFiles: string[]; constructor(public inputPath: string, public cachePath: string, - public options: ts2dart.TranspilerOptions) { + public options: any /*ts2dart.TranspilerOptions*/) { + // Additional files to include in the transpile call. These files could include, e.g., + // .d.ts files. They will always be included in the transpile call below, even if they + // weren't modified. + this.additionalFiles = options.additionalFiles || []; + // Delete additionalFiles as the transpiler does not support that option. + delete options.additionalFiles; + options.basePath = inputPath; + // Workaround for https://github.com/dart-lang/dart_style/issues/493 + var ts2dart = require('ts2dart'); this.transpiler = new ts2dart.Transpiler(options); } @@ -22,16 +31,17 @@ class TSToDartTranspiler implements DiffingBroccoliPlugin { let toEmit = [path.resolve(this.inputPath, 'angular2/manual_typings/globals.d.ts')]; let getDartFilePath = (path: string) => path.replace(/((\.js)|(\.ts))$/i, '.dart'); treeDiff.addedPaths.concat(treeDiff.changedPaths) - .forEach((changedPath) => { - let inputFilePath = path.resolve(this.inputPath, changedPath); + .filter(name => !name.match(/\.d\.ts$/)) + .forEach((changedPath) => { + let inputFilePath = path.resolve(this.inputPath, changedPath); - // Ignore files which don't need to be transpiled to Dart - let dartInputFilePath = getDartFilePath(inputFilePath); - if (fs.existsSync(dartInputFilePath)) return; + // Ignore files which don't need to be transpiled to Dart + let dartInputFilePath = getDartFilePath(inputFilePath); + if (fs.existsSync(dartInputFilePath)) return; - // Prepare to rebuild - toEmit.push(path.resolve(this.inputPath, changedPath)); - }); + // Prepare to rebuild + toEmit.push(path.resolve(this.inputPath, changedPath)); + }); treeDiff.removedPaths.forEach((removedPath) => { let absolutePath = path.resolve(this.inputPath, removedPath); @@ -43,7 +53,7 @@ class TSToDartTranspiler implements DiffingBroccoliPlugin { let dartOutputFilePath = getDartFilePath(removedPath); fs.unlinkSync(path.join(this.cachePath, dartOutputFilePath)); }); - this.transpiler.transpile(toEmit, this.cachePath); + this.transpiler.transpile(this.additionalFiles.concat(toEmit), this.cachePath); } } diff --git a/tools/build/dart_analyzer.ts b/tools/build/dart_analyzer.ts index d4c15887f8d2..cd27f62e90e5 100644 --- a/tools/build/dart_analyzer.ts +++ b/tools/build/dart_analyzer.ts @@ -54,7 +54,7 @@ export function analyze(dir: string, command: string, use_ddc: boolean = false): function analyze_(command, dirName, done, useDdc) { // TODO remove --package-warnings once dartanalyzer handles transitive libraries - var flags = ['--fatal-warnings', '--package-warnings', '--format=machine']; + var flags = ['--fatal-warnings', '--format=machine']; if (useDdc) { console.log('Using DDC analyzer to analyze', dirName); diff --git a/typings.json b/typings.json new file mode 100644 index 000000000000..ecaa2d12a7dd --- /dev/null +++ b/typings.json @@ -0,0 +1,11 @@ +{ + "name": "material2", + "dependencies": {}, + "devDependencies": {}, + "ambientDevDependencies": { + "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#26c98c8a9530c44f8c801ccc3b2057e2101187ee" + }, + "ambientDependencies": { + "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2" + } +}