From a9f3e2bd95d7efc9645963937d03dbe27ba7f93d Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 2 Nov 2017 12:15:47 -0700 Subject: [PATCH] build: Upgrade to TypeScript 2.5 (#20175) - update to TypeScript 2.5 - point the 2.4 typings test at the previous typescript version, so we don't break it accidentally - widen the peerDeps from Angular packages that depend on TypeScript - update to latest TypeScript 2.5 compatible Bazel rules - move .bazelrc to tools/bazel.rc per https://docs.bazel.build/versions/master/best-practices.html#bazelrc PR Close #20175 --- .bazelrc | 18 -------- WORKSPACE | 3 +- integration/typings_test_ts24/package.json | 4 +- integration/typings_test_ts25/include-all.ts | 41 +++++++++++++++++ integration/typings_test_ts25/package.json | 27 +++++++++++ integration/typings_test_ts25/tsconfig.json | 24 ++++++++++ package.json | 6 +-- packages/bazel/package.json | 2 +- packages/bazel/src/ngc-wrapped/index.ts | 3 +- packages/compiler-cli/package.json | 4 +- .../src/transformers/compiler_host.ts | 17 +++++-- tools/bazel.rc | 46 +++++++++++++++++++ yarn.lock | 31 ++++++++----- 13 files changed, 180 insertions(+), 46 deletions(-) delete mode 100644 .bazelrc create mode 100644 integration/typings_test_ts25/include-all.ts create mode 100644 integration/typings_test_ts25/package.json create mode 100644 integration/typings_test_ts25/tsconfig.json create mode 100644 tools/bazel.rc diff --git a/.bazelrc b/.bazelrc deleted file mode 100644 index 026b12684f..0000000000 --- a/.bazelrc +++ /dev/null @@ -1,18 +0,0 @@ -# Make compilation fast, by keeping a few copies of the compilers -# running as daemons, and cache SourceFile AST's to reduce parse time. -build --strategy=TypeScriptCompile=worker -build --strategy=AngularTemplateCompile=worker - -# Don't create bazel-* symlinks in the WORKSPACE directory. -# These require .gitignore and may scare users. -# Also, it's a workaround for https://github.com/bazelbuild/rules_typescript/issues/12 -# which affects the common case of having `tsconfig.json` in the WORKSPACE directory. -# -# Instead, you should run `bazel info bazel-bin` to find out where the outputs went. -build --symlink_prefix=/ - -# Performance: avoid stat'ing input files -build --watchfs - -# Don't print all the .d.ts output locations after builds -build --show_result=0 \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index dcb8c4d232..b7461d3bbe 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -5,8 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "build_bazel_rules_nodejs", remote = "https://github.com/bazelbuild/rules_nodejs.git", - # TODO(alexeagle): use the correct tag here. - commit = "2c6243df53fd33fdab283ebdd01582e4eb815db8", + commit = "0.2.1", ) load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories") diff --git a/integration/typings_test_ts24/package.json b/integration/typings_test_ts24/package.json index 33a184bf92..e4e147c6bb 100644 --- a/integration/typings_test_ts24/package.json +++ b/integration/typings_test_ts24/package.json @@ -1,6 +1,6 @@ { "name": "angular-integration", - "description": "Assert that users with TypeScript 2.2 can type-check an Angular application", + "description": "Assert that users with TypeScript 2.4 can type-check an Angular application", "version": "0.0.0", "license": "MIT", "dependencies": { @@ -18,7 +18,7 @@ "@angular/upgrade": "file:../../dist/packages-dist/upgrade", "@types/jasmine": "2.5.41", "rxjs": "file:../../node_modules/rxjs", - "typescript": "file:../../node_modules/typescript", + "typescript": "2.4.x", "zone.js": "file:../../node_modules/zone.js" }, "scripts": { diff --git a/integration/typings_test_ts25/include-all.ts b/integration/typings_test_ts25/include-all.ts new file mode 100644 index 0000000000..eaa53d24c2 --- /dev/null +++ b/integration/typings_test_ts25/include-all.ts @@ -0,0 +1,41 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import * as compiler from '@angular/compiler'; +import * as compilerTesting from '@angular/compiler/testing'; +import * as core from '@angular/core'; +import * as coreTesting from '@angular/core/testing'; +import * as forms from '@angular/forms'; +import * as http from '@angular/http'; +import * as httpTesting from '@angular/http/testing'; +import * as platformBrowserDynamic from '@angular/platform-browser-dynamic'; +import * as platformBrowser from '@angular/platform-browser'; +import * as platformBrowserTesting from '@angular/platform-browser/testing'; +import * as platformServer from '@angular/platform-server'; +import * as platformServerTesting from '@angular/platform-server/testing'; +import * as router from '@angular/router'; +import * as routerTesting from '@angular/router/testing'; +import * as upgrade from '@angular/upgrade'; + +export default { + compiler, + compilerTesting, + core, + coreTesting, + forms, + http, + httpTesting, + platformBrowser, + platformBrowserTesting, + platformBrowserDynamic, + platformServer, + platformServerTesting, + router, + routerTesting, + upgrade +}; diff --git a/integration/typings_test_ts25/package.json b/integration/typings_test_ts25/package.json new file mode 100644 index 0000000000..9283f40ee5 --- /dev/null +++ b/integration/typings_test_ts25/package.json @@ -0,0 +1,27 @@ +{ + "name": "angular-integration", + "description": "Assert that users with TypeScript 2.5 can type-check an Angular application", + "version": "0.0.0", + "license": "MIT", + "dependencies": { + "@angular/animations": "file:../../dist/packages-dist/animations", + "@angular/common": "file:../../dist/packages-dist/common", + "@angular/compiler": "file:../../dist/packages-dist/compiler", + "@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", + "@angular/core": "file:../../dist/packages-dist/core", + "@angular/forms": "file:../../dist/packages-dist/forms", + "@angular/http": "file:../../dist/packages-dist/http", + "@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", + "@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", + "@angular/platform-server": "file:../../dist/packages-dist/platform-server", + "@angular/router": "file:../../dist/packages-dist/router", + "@angular/upgrade": "file:../../dist/packages-dist/upgrade", + "@types/jasmine": "2.5.41", + "rxjs": "file:../../node_modules/rxjs", + "typescript": "2.5.x", + "zone.js": "file:../../node_modules/zone.js" + }, + "scripts": { + "test": "tsc" + } +} diff --git a/integration/typings_test_ts25/tsconfig.json b/integration/typings_test_ts25/tsconfig.json new file mode 100644 index 0000000000..b91d1a97a0 --- /dev/null +++ b/integration/typings_test_ts25/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "../../dist/typings_test_ts25/", + "rootDir": ".", + "target": "es5", + "lib": [ + "es5", + "dom", + "es2015.collection", + "es2015.iterable", + "es2015.promise" + ], + "types": [], + "strictNullChecks": true + }, + "files": [ + "include-all.ts", + "node_modules/@types/jasmine/index.d.ts" + ] +} diff --git a/package.json b/package.json index 7eb1238574..03953d5442 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "fsevents": "1.1.2" }, "devDependencies": { - "@bazel/typescript": "0.2.x", + "@bazel/typescript": "0.3.1", "@types/angularjs": "1.5.14-alpha", "@types/base64-js": "1.2.5", "@types/chokidar": "1.7.3", @@ -95,10 +95,10 @@ "source-map-support": "0.4.18", "systemjs": "0.18.10", "ts-api-guardian": "0.2.2", - "tsickle": "0.24.x", + "tsickle": "0.25.5", "tslint": "5.7.0", "tslint-eslint-rules": "4.1.1", - "typescript": "2.4.2", + "typescript": "2.5.x", "uglify-js": "2.8.29", "universal-analytics": "0.4.15", "vlq": "0.2.2", diff --git a/packages/bazel/package.json b/packages/bazel/package.json index 297bdf3a2e..d756176a6a 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -6,7 +6,7 @@ "license": "MIT", "peerDependencies": { "@angular/compiler-cli": "0.0.0-PLACEHOLDER", - "typescript": ">=2.4.2 <2.5" + "typescript": ">=2.4.2 <2.6" }, "dependencies": { "@bazel/typescript": "0.2.x", diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index b0931ea2b2..4bb2c5fb23 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -5,8 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -// TODO(tbosch): figure out why we need this as it breaks node code within ngc-wrapped -/// + import * as ng from '@angular/compiler-cli'; import {BazelOptions, CachedFileLoader, CompilerHost, FileCache, FileLoader, UncachedFileLoader, constructManifest, debug, fixUmdModuleDeclarations, parseTsconfig, runAsWorker, runWorkerLoop} from '@bazel/typescript'; import * as fs from 'fs'; diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index c4eb69f175..c7fb9a026b 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -11,11 +11,11 @@ "dependencies": { "reflect-metadata": "^0.1.2", "minimist": "^1.2.0", - "tsickle": "^0.24.0", + "tsickle": "^0.25.5", "chokidar": "^1.4.2" }, "peerDependencies": { - "typescript": ">=2.4.2 <2.5", + "typescript": ">=2.4.2 <2.6", "@angular/compiler": "0.0.0-PLACEHOLDER" }, "repository": { diff --git a/packages/compiler-cli/src/transformers/compiler_host.ts b/packages/compiler-cli/src/transformers/compiler_host.ts index 08c25472a3..494359967a 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -41,6 +41,13 @@ export interface CodeGenerator { findGeneratedFileNames(fileName: string): string[]; } +function assert(condition: T | null | undefined) { + if (!condition) { + // TODO(chuckjaz): do the right thing + } + return condition !; +} + /** * Implements the following hosts based on an api.CompilerHost: * - ts.CompilerHost to be consumed by a ts.Program @@ -113,7 +120,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos return sf ? this.metadataProvider.getMetadata(sf) : undefined; }, fileExists: (filePath) => this.originalFileExists(filePath), - readFile: (filePath) => this.context.readFile(filePath), + readFile: (filePath) => assert(this.context.readFile(filePath)), }; } @@ -421,7 +428,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos return summary.text; } if (this.originalFileExists(filePath)) { - return this.context.readFile(filePath); + return assert(this.context.readFile(filePath)); } return null; } @@ -472,7 +479,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos if (!this.originalFileExists(filePath)) { throw syntaxError(`Error: Resource file not found: ${filePath}`); } - return this.context.readFile(filePath); + return assert(this.context.readFile(filePath)); } private hasBundleIndex(filePath: string): boolean { @@ -490,13 +497,13 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos if (this.originalFileExists(packageFile)) { // Once we see a package.json file, assume false until it we find the bundle index. result = false; - const packageContent: any = JSON.parse(this.context.readFile(packageFile)); + const packageContent: any = JSON.parse(assert(this.context.readFile(packageFile))); if (packageContent.typings) { const typings = path.normalize(path.join(directory, packageContent.typings)); if (DTS.test(typings)) { const metadataFile = typings.replace(DTS, '.metadata.json'); if (this.originalFileExists(metadataFile)) { - const metadata = JSON.parse(this.context.readFile(metadataFile)); + const metadata = JSON.parse(assert(this.context.readFile(metadataFile))); if (metadata.flatModuleIndexRedirect) { this.flatModuleIndexRedirectNames.add(typings); // Note: don't set result = true, diff --git a/tools/bazel.rc b/tools/bazel.rc new file mode 100644 index 0000000000..d62883e887 --- /dev/null +++ b/tools/bazel.rc @@ -0,0 +1,46 @@ +############################### +# Typescript / Angular / Sass # +############################### + +# Make compilation fast, by keeping a few copies of the compilers +# running as daemons, and cache SourceFile AST's to reduce parse time. +build --strategy=TypeScriptCompile=worker +build --strategy=AngularTemplateCompile=worker + +############################### +# Filesystem interactions # +############################### + +# Don't create bazel-* symlinks in the WORKSPACE directory. +# These require .gitignore and may scare users. +# Also, it's a workaround for https://github.com/bazelbuild/rules_typescript/issues/12 +# which affects the common case of having `tsconfig.json` in the WORKSPACE directory. +# +# Instead, you should run `bazel info bazel-bin` to find out where the outputs went. +build --symlink_prefix=/ + +# Performance: avoid stat'ing input files +build --watchfs + +############################### +# Output # +############################### + +# Don't print all the .d.ts output locations after builds +build --show_result=0 + +# A more useful default output mode for bazel query +# Prints eg. "ng_module rule //foo:bar" rather than just "//foo:bar" +query --output=label_kind + +# Don't print every dependency in :node_modules, for example +query --noimplicit_deps + +# By default, failing tests don't print any output, it goes to the log file +test --test_output=errors + +# Show which actions are run under workers, +# and print all the actions running in parallel. +# Helps to demonstrate that bazel uses all the cores on the machine. +build --experimental_ui +test --experimental_ui diff --git a/yarn.lock b/yarn.lock index ec673c4ebc..54022638a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,15 +2,15 @@ # yarn lockfile v1 -"@bazel/typescript@0.2.x": - version "0.2.2" - resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.2.2.tgz#0a0d09924508c946de32e6acdb2b5cc1ee32c506" +"@bazel/typescript@0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.3.1.tgz#54367df8f30fa0fb25e41106eb7aa558534c36dd" dependencies: "@types/node" "7.0.18" "@types/source-map" "^0.5.1" protobufjs "5.0.0" - tsickle "0.24.x" - typescript "2.4.x" + tsickle "0.25.x" + typescript "2.5.x" "@google-cloud/common@^0.13.0": version "0.13.5" @@ -7102,9 +7102,18 @@ ts-api-guardian@0.2.2: minimist "^1.2.0" typescript "2.0.10" -tsickle@0.24.x: - version "0.24.1" - resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.24.1.tgz#039343b205bf517a333b0703978892f80a7d848e" +tsickle@0.25.5: + version "0.25.5" + resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.25.5.tgz#2891d29f97c4aab1306e06378d8496d1765a4bfe" + dependencies: + minimist "^1.2.0" + mkdirp "^0.5.1" + source-map "^0.5.6" + source-map-support "^0.4.2" + +tsickle@0.25.x: + version "0.25.5" + resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.25.5.tgz#2891d29f97c4aab1306e06378d8496d1765a4bfe" dependencies: minimist "^1.2.0" mkdirp "^0.5.1" @@ -7199,9 +7208,9 @@ typescript@2.0.10: version "2.0.10" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.0.10.tgz#ccdd4ed86fd5550a407101a0814012e1b3fac3dd" -typescript@2.4.2, typescript@2.4.x: - version "2.4.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844" +typescript@2.5.x: + version "2.5.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d" uglify-js@1.2.6, uglify-js@~1.2.5: version "1.2.6"