From 910381ddbdf5609e28be0c5dbef213746ac2faea Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 20 Aug 2018 12:58:33 -0700 Subject: [PATCH] build(bazel): fix bazel types reference directive resolves (#25581) PR Close #25581 --- .circleci/config.yml | 2 +- WORKSPACE | 6 +++--- integration/bazel/package.json | 2 +- integration/bazel/yarn.lock | 17 +++-------------- package.json | 4 +--- packages/bazel/src/ng_setup_workspace.bzl | 3 ++- .../src/ngtsc/factories/src/host.ts | 11 ++++++++++- .../src/transformers/compiler_host.ts | 7 +++++++ 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e951c4bb80..d78ded91c7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ # If you change the `docker_image` version, also change the `cache_key` suffix and the version of # `com_github_bazelbuild_buildtools` in the `/WORKSPACE` file. var_1: &docker_image angular/ngcontainer:0.4.0 -var_2: &cache_key v2-angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-0.4.0 +var_2: &cache_key v2-angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-bust1-0.4.0 # Define common ENV vars var_3: &define_env_vars diff --git a/WORKSPACE b/WORKSPACE index 1a208e220b..68f46ef803 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -12,9 +12,9 @@ http_archive( http_archive( name = "build_bazel_rules_typescript", - url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.1.zip", - strip_prefix = "rules_typescript-0.16.1", - sha256 = "5b2b0bc63cfcffe7bf97cad2dad3b26a73362f806de66207051f66c87956a995", + url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.2.zip", + strip_prefix = "rules_typescript-0.16.2", + sha256 = "31601b777840fbf600dbd1893ade0d1de37166e7ba52b90735b107cfb67e38c7", ) load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies") rules_typescript_dependencies() diff --git a/integration/bazel/package.json b/integration/bazel/package.json index c3285bc7ab..8238b46ff5 100644 --- a/integration/bazel/package.json +++ b/integration/bazel/package.json @@ -10,7 +10,7 @@ "zone.js": "file:../../node_modules/zone.js" }, "devDependencies": { - "@bazel/typescript": "0.16.1", + "@bazel/typescript": "0.16.2", "@types/jasmine": "file:../../node_modules/@types/jasmine", "@types/source-map": "0.5.1", "http-server": "0.11.1", diff --git a/integration/bazel/yarn.lock b/integration/bazel/yarn.lock index fd86e10969..88da845c79 100644 --- a/integration/bazel/yarn.lock +++ b/integration/bazel/yarn.lock @@ -2,12 +2,11 @@ # yarn lockfile v1 -"@bazel/typescript@0.16.1": - version "0.16.1" - resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.16.1.tgz#5a5d145a17898bfadae8268cf942815424119412" +"@bazel/typescript@0.16.2": + version "0.16.2" + resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.16.2.tgz#42474e029b0c6fa42a058fc86e2f593b7a367d56" dependencies: protobufjs "5.0.0" - tsickle "0.32.1" tsutils "2.20.0" "@types/jasmine@file:../../node_modules/@types/jasmine": @@ -853,16 +852,6 @@ tough-cookie@~2.4.3: psl "^1.1.24" punycode "^1.4.1" -tsickle@0.32.1: - version "0.32.1" - resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.32.1.tgz#f16e94ba80b32fc9ebe320dc94fbc2ca7f3521a5" - dependencies: - jasmine-diff "^0.1.3" - minimist "^1.2.0" - mkdirp "^0.5.1" - source-map "^0.6.0" - source-map-support "^0.5.0" - "tsickle@file:../../node_modules/tsickle": version "0.32.0" dependencies: diff --git a/package.json b/package.json index 3ab089a5ad..2ca3fe98a8 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,7 @@ "prebuildifier": "bazel build --noshow_progress @com_github_bazelbuild_buildtools//buildifier", "buildifier": "find . -type f \\( -name \"*.bzl\" -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs $(bazel info bazel-bin)/external/com_github_bazelbuild_buildtools/buildifier/*/buildifier", "preinstall": "node tools/yarn/check-yarn.js", - "postinstall": "yarn update-webdriver && node ./tools/postinstall-patches.js && yarn patch-types", - "//patch-types": "work-around for issue https://github.com/angular/angular/issues/25051", - "patch-types": "node -e \"var sh = require('shelljs'); sh.set('-e'); sh.mkdir('-p', 'node_modules/@types/zone.js'); sh.cp('-f', 'node_modules/zone.js/dist/zone.js.d.ts', 'node_modules/@types/zone.js/index.d.ts')\"", + "postinstall": "yarn update-webdriver && node ./tools/postinstall-patches.js", "update-webdriver": "webdriver-manager update --gecko false $CHROMEDRIVER_VERSION_ARG", "check-env": "gulp check-env", "commitmsg": "node ./scripts/git/commit-msg.js" diff --git a/packages/bazel/src/ng_setup_workspace.bzl b/packages/bazel/src/ng_setup_workspace.bzl index 18b7e8c0d5..e939fd856e 100644 --- a/packages/bazel/src/ng_setup_workspace.bzl +++ b/packages/bazel/src/ng_setup_workspace.bzl @@ -21,4 +21,5 @@ def ng_setup_workspace(): ) # 0.16.0: minimal version required to work with ng_module - check_rules_typescript_version("0.16.0") + # 0.16.2: bazel type resolution for zone.js types + check_rules_typescript_version("0.16.2") diff --git a/packages/compiler-cli/src/ngtsc/factories/src/host.ts b/packages/compiler-cli/src/ngtsc/factories/src/host.ts index 4e5b1e9b33..f22b9abf9e 100644 --- a/packages/compiler-cli/src/ngtsc/factories/src/host.ts +++ b/packages/compiler-cli/src/ngtsc/factories/src/host.ts @@ -17,7 +17,16 @@ import {FactoryGenerator} from './generator'; export class GeneratedFactoryHostWrapper implements ts.CompilerHost { constructor( private delegate: ts.CompilerHost, private generator: FactoryGenerator, - private factoryToSourceMap: Map) {} + private factoryToSourceMap: Map) { + if (delegate.resolveTypeReferenceDirectives) { + this.resolveTypeReferenceDirectives = (names: string[], containingFile: string) => + delegate.resolveTypeReferenceDirectives !(names, containingFile); + } + } + + resolveTypeReferenceDirectives?: + (names: string[], + containingFile: string) => (ts.ResolvedTypeReferenceDirective | undefined)[]; getSourceFile( fileName: string, languageVersion: ts.ScriptTarget, diff --git a/packages/compiler-cli/src/transformers/compiler_host.ts b/packages/compiler-cli/src/transformers/compiler_host.ts index eb54ffd943..218f3d6306 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -78,6 +78,9 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos trace !: (s: string) => void; // TODO(issue/24571): remove '!'. getDirectories !: (path: string) => string[]; + resolveTypeReferenceDirectives?: + (names: string[], + containingFile: string) => (ts.ResolvedTypeReferenceDirective | undefined)[]; directoryExists?: (directoryName: string) => boolean; constructor( @@ -102,6 +105,10 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos if (context.getDefaultLibLocation) { this.getDefaultLibLocation = () => context.getDefaultLibLocation !(); } + if (context.resolveTypeReferenceDirectives) { + this.resolveTypeReferenceDirectives = (names: string[], containingFile: string) => + context.resolveTypeReferenceDirectives !(names, containingFile); + } if (context.trace) { this.trace = s => context.trace !(s); }