Skip to content

Commit

Permalink
test: add a regression test using ts_project() in an external works…
Browse files Browse the repository at this point in the history
…pace

Closes #284.

This sets up two workspaces, one with a `ts_project()` and another which depends on the first. When the second workspace is built, it triggers a build of the `ts_project()` which is under `@lib_wksp`, not the main workspace. This would trigger #284 if not properly fixed. Note that we don't actually need to do anything with the `ts_project()` output, we just need to trigger to build, so a `build_test()` is sufficient to reproduce the error.
  • Loading branch information
dgp1130 committed Feb 11, 2023
1 parent d29b857 commit 0139263
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
folder:
- '.'
- 'e2e/bzlmod'
- 'e2e/external_dep'
- 'e2e/external_dep/app'
- 'e2e/worker'
- 'e2e/workspace'
exclude:
Expand Down
2 changes: 2 additions & 0 deletions e2e/external_dep/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app/
node_modules/
2 changes: 2 additions & 0 deletions e2e/external_dep/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# import common bazelrc shared with e2e workspaces
import %workspace%/../../.bazelrc.common
1 change: 1 addition & 0 deletions e2e/external_dep/.bazelversion
16 changes: 16 additions & 0 deletions e2e/external_dep/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Tests a `ts_project()` in one workspace being used in another."""

load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_skylib//rules:build_test.bzl", "build_test")

ts_project(
name = "lib",
srcs = ["lib.ts"],
declaration = True,
visibility = ["//visibility:public"],
)

build_test(
name = "test",
targets = [":lib"],
)
29 changes: 29 additions & 0 deletions e2e/external_dep/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
workspace(name = "lib_wksp")

local_repository(
name = "aspect_rules_ts",
path = "../..",
)

load("@aspect_rules_ts//ts:repositories.bzl", "LATEST_VERSION", "rules_ts_dependencies")
rules_ts_dependencies(ts_version = LATEST_VERSION)

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()
1 change: 1 addition & 0 deletions e2e/external_dep/app/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
2 changes: 2 additions & 0 deletions e2e/external_dep/app/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# import common bazelrc shared with e2e workspaces
import %workspace%/../../../.bazelrc.common
1 change: 1 addition & 0 deletions e2e/external_dep/app/.bazelversion
7 changes: 7 additions & 0 deletions e2e/external_dep/app/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")

# `ts_project()` should be able to build from the non-main workspace.
build_test(
name = "test",
targets = ["@lib_wksp//:lib"],
)
31 changes: 31 additions & 0 deletions e2e/external_dep/app/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local_repository(
name = "aspect_rules_ts",
path = "../../..",
)
local_repository(
name = "lib_wksp",
path = "..",
)

load("@aspect_rules_ts//ts:repositories.bzl", "LATEST_VERSION", "rules_ts_dependencies")
rules_ts_dependencies(ts_version = LATEST_VERSION)

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()
5 changes: 5 additions & 0 deletions e2e/external_dep/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"typescript": "4.8.4"
}
}
15 changes: 15 additions & 0 deletions e2e/external_dep/app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/external_dep/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 'bar';
5 changes: 5 additions & 0 deletions e2e/external_dep/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"typescript": "4.8.4"
}
}
15 changes: 15 additions & 0 deletions e2e/external_dep/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions e2e/external_dep/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"declaration": true,
},
}

0 comments on commit 0139263

Please sign in to comment.