Skip to content

Commit

Permalink
refactor: remove nested build_bazel_rules_typescript workspace (#3036)
Browse files Browse the repository at this point in the history
* refactor: remove nested build_bazel_rules_typescript workspace

Just move the code into the concatjs package where it's used

* chore: remove vendored rules_typescript from third_party

The needed files are now in the concatjs package, so we don't need a nested workspace now
  • Loading branch information
alexeagle authored Oct 27, 2021
1 parent 1a55c2d commit 0da9dfd
Show file tree
Hide file tree
Showing 176 changed files with 230 additions and 4,982 deletions.
16 changes: 7 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ rules_nodejs_dev_dependencies()
# Setup local respositories
#

local_repository(
name = "build_bazel_rules_typescript",
path = "third_party/github.com/bazelbuild/rules_typescript",
)

local_repository(
name = "internal_npm_package_test_vendored_external",
path = "internal/pkg_npm/test/vendored_external",
Expand All @@ -75,12 +70,15 @@ load("@npm_node_patches_lock//:index.bzl", _npm_patches_repositories = "npm_repo
# Declare an external repository for each npm package fetchable by the lock file
_npm_patches_repositories()

# We have a source dependency on build_bazel_rules_typescript
# so we must repeat its transitive toolchain deps
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dev_dependencies")
load("//packages/concatjs:package.bzl", "rules_typescript_dev_dependencies")

rules_typescript_dev_dependencies()

local_repository(
name = "devserver_test_workspace",
path = "packages/concatjs/devserver/devserver/test/test-workspace",
)

# Install labs dependencies
load("//packages/labs:package.bzl", "npm_bazel_labs_dependencies")

Expand All @@ -101,7 +99,7 @@ go_register_toolchains(version = "1.16")

gazelle_dependencies()

load("@build_bazel_rules_typescript//internal:ts_repositories.bzl", "ts_setup_dev_workspace")
load("//packages/concatjs/internal:ts_repositories.bzl", "ts_setup_dev_workspace")

ts_setup_dev_workspace()

Expand Down
2 changes: 1 addition & 1 deletion docs/Concatjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ on packages which aren't declared as dependencies.
For example, if you use [tsickle](https://github.com/angular/tsickle) to generate Closure Compiler-compatible JS,
then it needs to be a data dependency of `tsc_wrapped` so that it can be loaded at runtime.

Defaults to `@build_bazel_rules_typescript//internal:tsc_wrapped_bin`
Defaults to `@npm//@bazel/concatjs/internal:tsc_wrapped_bin`

<h4 id="ts_library-data">data</h4>

Expand Down
7 changes: 0 additions & 7 deletions e2e/symlinked_node_modules_npm/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ local_repository(
path = "../..",
)

# We don't really need to run TypeScript rules, but we'll encounter some during
# the loading phase because some built-in code uses TypeScript
local_repository(
name = "build_bazel_rules_typescript",
path = "../../tools/mock_rules_typescript",
)

# rules_nodejs_dev_dependencies() required since we're using local_repository for
# build_bazel_rules_nodejs above.
load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dev_dependencies")
Expand Down
7 changes: 0 additions & 7 deletions e2e/symlinked_node_modules_yarn/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ local_repository(
path = "../..",
)

# We don't really need to run TypeScript rules, but we'll encounter some during
# the loading phase because some built-in code uses TypeScript
local_repository(
name = "build_bazel_rules_typescript",
path = "../../tools/mock_rules_typescript",
)

# rules_nodejs_dev_dependencies() required since we're using local_repository for
# build_bazel_rules_nodejs above.
load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dev_dependencies")
Expand Down
2 changes: 1 addition & 1 deletion examples/from_source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ bzl_library(
"index.bzl",
],
deps = [
"@build_bazel_rules_nodejs//packages/concatjs/internal:bzl",
"@build_bazel_rules_nodejs//packages/typescript:bzl",
"@build_bazel_rules_typescript//internal:bzl",
],
)

Expand Down
11 changes: 1 addition & 10 deletions examples/from_source/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@ local_repository(
path = "../../",
)

# This is hard for users to grab hold of, as long as rules_typescript is a
# nested workspace within rules_nodejs. Until we've fixed that, you can
# replace this local_repository call with this code to fetch it
# https://github.com/bazelbuild/rules_nodejs/blob/2.2.2/package.bzl#L123-L134
local_repository(
name = "build_bazel_rules_typescript",
path = "../../third_party/github.com/bazelbuild/rules_typescript",
)

load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dev_dependencies")

rules_nodejs_dev_dependencies()

load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dev_dependencies")
load("@build_bazel_rules_nodejs//packages/concatjs:package.bzl", "rules_typescript_dev_dependencies")

rules_typescript_dev_dependencies()

Expand Down
17 changes: 4 additions & 13 deletions examples/user_managed_deps/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
workspace(name = "examples_user_managed_deps")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# In your code, you'd fetch this repository with an `http_archive` call.
# We do this local repository only because this example lives in the same
# repository with the rules_nodejs code and we want to test them together.
Expand Down Expand Up @@ -38,16 +36,9 @@ node_repositories(
package_json = ["//:package.json"],
)

# TODO(gregmagolan): keep this in sync with root WORKSPACE programatically
git_repository(
name = "build_bazel_rules_typescript",
commit = "5d79e42953eb8614d961ccf0e3440884e974eeb3",
remote = "http://github.com/bazelbuild/rules_typescript.git",
)

# We have a source dependency on build_bazel_rules_typescript
# We have a source dependency on rules_typescript
# so we must repeat its transitive toolchain deps
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dev_dependencies")
load("@build_bazel_rules_nodejs//packages/concatjs:package.bzl", "rules_typescript_dev_dependencies")

rules_typescript_dev_dependencies()

Expand All @@ -58,8 +49,8 @@ gazelle_dependencies()

go_rules_dependencies()

go_register_toolchains()
go_register_toolchains(version = "1.15.5")

load("@build_bazel_rules_typescript//internal:ts_repositories.bzl", "ts_setup_dev_workspace")
load("@build_bazel_rules_nodejs//packages/concatjs/internal:ts_repositories.bzl", "ts_setup_dev_workspace")

ts_setup_dev_workspace()
13 changes: 6 additions & 7 deletions packages/concatjs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ bzl_library(
"@build_bazel_rules_nodejs//:bzl",
"@build_bazel_rules_nodejs//internal/common:bzl",
"@build_bazel_rules_nodejs//internal/node:bzl",
"@build_bazel_rules_typescript//internal:bzl",
],
)

Expand Down Expand Up @@ -94,21 +93,21 @@ pkg_npm(
"package.json",
"//packages/concatjs/devserver:package_contents",
"//packages/concatjs/internal:package_contents",
"//packages/concatjs/third_party/github.com/bazelbuild/bazel/src/main/protobuf:npm_package_assets",
"//packages/concatjs/third_party/npm/requirejs:package_contents",
"//packages/concatjs/web_test:package_contents",
],
build_file_content = "",
nested_packages = [
"@build_bazel_rules_typescript//:npm_bazel_typescript_package",
],
substitutions = TYPESCRIPT_REPLACEMENTS,
vendor_external = [
"build_bazel_rules_typescript",
],
deps = [
":README.md",
":bazel_concatjs_lib",
":npm_version_check",
"//packages/concatjs/devserver:devserver-darwin",
"//packages/concatjs/devserver:devserver-linux",
"//packages/concatjs/devserver:devserver-windows",
"//packages/concatjs/internal:BUILD",
"//packages/concatjs/internal:generated_BUILD",
"//packages/concatjs/internal:tsc_wrapped",
],
)
58 changes: 58 additions & 0 deletions packages/concatjs/devserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

# BEGIN-INTERNAL
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

# END-INTERNAL
licenses(["notice"]) # Apache 2.0

package(default_visibility = [
Expand Down Expand Up @@ -147,3 +151,57 @@ filegroup(
srcs = glob(["*"]),
visibility = ["//packages/concatjs:__pkg__"],
)

# BEGIN-INTERNAL
go_library(
name = "go_default_library",
srcs = [
"main.go",
"runfile-filesystem.go",
],
importpath = "github.com/bazelbuild/rules_typescript/devserver",
visibility = ["//visibility:private"],
deps = [
"//packages/concatjs/devserver/concatjs:go_default_library",
"//packages/concatjs/devserver/devserver:go_default_library",
"//packages/concatjs/devserver/runfiles:go_default_library",
],
)

go_binary(
name = "devserver_bin",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)

go_binary(
name = "devserver-darwin",
out = "devserver-darwin_x64",
embed = [":go_default_library"],
goarch = "amd64",
goos = "darwin",
pure = "on",
visibility = ["//visibility:public"],
)

go_binary(
name = "devserver-linux",
out = "devserver-linux_x64",
embed = [":go_default_library"],
goarch = "amd64",
goos = "linux",
pure = "on",
visibility = ["//visibility:public"],
)

go_binary(
name = "devserver-windows",
out = "devserver-windows_x64.exe",
embed = [":go_default_library"],
goarch = "amd64",
goos = "windows",
pure = "on",
visibility = ["//visibility:public"],
)

# END-INTERNAL
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go_library(
importpath = "github.com/bazelbuild/rules_typescript/devserver/devserver",
visibility = ["//visibility:public"],
deps = [
"//devserver/runfiles:go_default_library",
"//packages/concatjs/devserver/runfiles:go_default_library",
],
)

Expand All @@ -20,4 +20,6 @@ go_test(
"@devserver_test_workspace//:sources",
],
embed = [":go_default_library"],
# FIXME: broken on Windows ci
tags = ["no-bazelci-windows"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func TestDevserverFileHandling(t *testing.T) {
handler := CreateFileHandler("/app.js", "manifest.MF", []string{
// This verifies that we can resolve relatively to the current package. Usually the
// devserver Bazel rule adds the current package here.
"build_bazel_rules_typescript/devserver/devserver",
"build_bazel_rules_nodejs/packages/concatjs/devserver/devserver",
// Verifies that we can specify subfolders of workspaces
"build_bazel_rules_typescript/devserver/devserver/test",
"build_bazel_rules_nodejs/packages/concatjs/devserver/devserver/test",
// Verifies that we can specify external workspaces as root dirs.
"devserver_test_workspace",
// Verifies that we can specify subfolders from external workspaces.
Expand Down
File renamed without changes.
Loading

0 comments on commit 0da9dfd

Please sign in to comment.