From 808999950d9691c0f191a778d4c2e128ae3e369e Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 2 Mar 2020 08:09:32 -0800 Subject: [PATCH] fix(builtin): don't include external files when pkg_npm is in root package (#1677) This logic assumed that package_path was non-empty, but when a pkg_npm rule appears in the workspace root, package_path will be empty string and the startswith guard has no effect. Fixes #1499 --- WORKSPACE | 1 + internal/pkg_npm/pkg_npm.bzl | 2 +- packages/worker/BUILD.bazel | 2 +- rules_typescript.patch | 12 ++++++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 rules_typescript.patch diff --git a/WORKSPACE b/WORKSPACE index 3d32ad1e87..acb65e9999 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -102,6 +102,7 @@ install_bazel_dependencies() git_repository( name = "build_bazel_rules_typescript", commit = "10a5a86885f95ab788fd841ade47b6a16e0c13d6", + patches = ["//:rules_typescript.patch"], remote = "http://github.com/bazelbuild/rules_typescript.git", shallow_since = "1582757372 -0800", ) diff --git a/internal/pkg_npm/pkg_npm.bzl b/internal/pkg_npm/pkg_npm.bzl index be857b3f7b..f2d70dc520 100644 --- a/internal/pkg_npm/pkg_npm.bzl +++ b/internal/pkg_npm/pkg_npm.bzl @@ -138,7 +138,7 @@ PKG_NPM_OUTPUTS = { def _filter_out_external_files(ctx, files, package_path): result = [] for file in files: - if file.short_path.startswith(package_path): + if file.short_path.startswith(package_path) and not file.short_path.startswith("../"): result.append(file.path) else: for v in ctx.attr.vendor_external: diff --git a/packages/worker/BUILD.bazel b/packages/worker/BUILD.bazel index 9b0b322f6b..8def63f824 100644 --- a/packages/worker/BUILD.bazel +++ b/packages/worker/BUILD.bazel @@ -17,7 +17,7 @@ load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "co # We reach inside the @bazel/typescript npm package to grab this one .js file # This avoids a complex refactoring where we extract that .ts file from tsc_wrapped to a common library -_worker_path = "external/build_bazel_rules_typescript/internal/tsc_wrapped/worker" +_worker_path = "internal/tsc_wrapped/worker" # Copy the proto file to a matching third_party/... nested directory # so the runtime require() statements still work diff --git a/rules_typescript.patch b/rules_typescript.patch new file mode 100644 index 0000000000..f92fad44fc --- /dev/null +++ b/rules_typescript.patch @@ -0,0 +1,12 @@ +diff BUILD.bazel BUILD.bazel +index 3a519c5..6121ef6 100644 +--- BUILD.bazel ++++ BUILD.bazel +@@ -38,6 +38,7 @@ pkg_npm( + "//internal:npm_package_assets", + "//third_party/github.com/bazelbuild/bazel/src/main/protobuf:npm_package_assets", + ], ++ vendor_external = ["build_bazel_rules_typescript"], + visibility = ["//visibility:public"], + deps = [ + "//devserver:devserver-darwin",