From b404d47b169a788f0ca93e0b7342096835c7f4d7 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Fri, 31 Aug 2018 14:26:10 -0700 Subject: [PATCH] build(bazel): fix bazel types reference directive resolves (#25774) PR Close #25774 --- .circleci/config.yml | 2 +- WORKSPACE | 6 +++--- integration/bazel/WORKSPACE | 6 +++--- package.json | 4 +--- packages/bazel/src/ng_setup_workspace.bzl | 3 ++- packages/compiler-cli/src/ngtsc/compiler_host.ts | 11 ++++++++++- .../compiler-cli/src/transformers/compiler_host.ts | 7 +++++++ 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b1b5d08bf6..f117477766 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 165882d4c6..6d32e20f77 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -26,9 +26,9 @@ http_archive( http_archive( name = "build_bazel_rules_typescript", - url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.0.zip", - strip_prefix = "rules_typescript-0.16.0", - sha256 = "e65c5639a42e2f6d3f9d2bda62487d6b42734830dda45be1620c3e2b1115070c", + url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.2.zip", + strip_prefix = "rules_typescript-0.16.2", + sha256 = "31601b777840fbf600dbd1893ade0d1de37166e7ba52b90735b107cfb67e38c7", ) http_archive( diff --git a/integration/bazel/WORKSPACE b/integration/bazel/WORKSPACE index 643e978e2b..906af83eb3 100644 --- a/integration/bazel/WORKSPACE +++ b/integration/bazel/WORKSPACE @@ -27,9 +27,9 @@ http_archive( http_archive( name = "build_bazel_rules_typescript", - url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.0.zip", - strip_prefix = "rules_typescript-0.16.0", - sha256 = "e65c5639a42e2f6d3f9d2bda62487d6b42734830dda45be1620c3e2b1115070c", + url = "https://github.com/bazelbuild/rules_typescript/archive/0.16.2.zip", + strip_prefix = "rules_typescript-0.16.2", + sha256 = "31601b777840fbf600dbd1893ade0d1de37166e7ba52b90735b107cfb67e38c7", ) http_archive( diff --git a/package.json b/package.json index 91067044ff..14e09a8ffa 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 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/compiler_host.ts b/packages/compiler-cli/src/ngtsc/compiler_host.ts index d8fef66138..9246385e81 100644 --- a/packages/compiler-cli/src/ngtsc/compiler_host.ts +++ b/packages/compiler-cli/src/ngtsc/compiler_host.ts @@ -34,7 +34,16 @@ export interface CompilerHost extends ts.CompilerHost { * Implementation of `CompilerHost` which delegates to a native TypeScript host in most cases. */ export class NgtscCompilerHost implements CompilerHost { - constructor(private delegate: ts.CompilerHost) {} + constructor(private delegate: ts.CompilerHost) { + 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 683d4a05c3..f286f0c4b6 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -82,6 +82,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( @@ -106,6 +109,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); }