test: add bun workspace tests
This commit is contained in:
22
examples/workspace/BUILD.bazel
Normal file
22
examples/workspace/BUILD.bazel
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
load("//bun:defs.bzl", "bun_bundle", "ts_library")
|
||||||
|
|
||||||
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
|
exports_files([
|
||||||
|
"README.md",
|
||||||
|
"package.json",
|
||||||
|
"packages/pkg-a/package.json",
|
||||||
|
"packages/pkg-b/package.json",
|
||||||
|
])
|
||||||
|
|
||||||
|
ts_library(
|
||||||
|
name = "pkg_a_lib",
|
||||||
|
srcs = ["packages/pkg-a/index.ts"],
|
||||||
|
)
|
||||||
|
|
||||||
|
bun_bundle(
|
||||||
|
name = "pkg_b_bundle",
|
||||||
|
entry_points = ["packages/pkg-b/main.ts"],
|
||||||
|
deps = [":pkg_a_lib"],
|
||||||
|
target = "bun",
|
||||||
|
)
|
||||||
14
examples/workspace/README.md
Normal file
14
examples/workspace/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# workspace example
|
||||||
|
|
||||||
|
Minimal Bun workspace-style layout with two packages:
|
||||||
|
|
||||||
|
- `@workspace/pkg-a`: exports a string helper
|
||||||
|
- `@workspace/pkg-b`: imports from `pkg-a` and prints the message
|
||||||
|
|
||||||
|
The workspace root also defines a Bun `catalog` pin for `lodash`, and both packages consume it via `"lodash": "catalog:"` to keep versions consistent across packages.
|
||||||
|
|
||||||
|
This example demonstrates building a target from a workspace-shaped directory tree with Bazel:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bazel build //examples/workspace:pkg_b_bundle
|
||||||
|
```
|
||||||
10
examples/workspace/package.json
Normal file
10
examples/workspace/package.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "workspace-root",
|
||||||
|
"private": true,
|
||||||
|
"workspaces": [
|
||||||
|
"packages/*"
|
||||||
|
],
|
||||||
|
"catalog": {
|
||||||
|
"lodash": "^4.17.21"
|
||||||
|
}
|
||||||
|
}
|
||||||
3
examples/workspace/packages/pkg-a/index.ts
Normal file
3
examples/workspace/packages/pkg-a/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function workspaceMessage(): string {
|
||||||
|
return "workspace-pkg-a";
|
||||||
|
}
|
||||||
8
examples/workspace/packages/pkg-a/package.json
Normal file
8
examples/workspace/packages/pkg-a/package.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "@workspace/pkg-a",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.ts",
|
||||||
|
"dependencies": {
|
||||||
|
"lodash": "catalog:"
|
||||||
|
}
|
||||||
|
}
|
||||||
3
examples/workspace/packages/pkg-b/main.ts
Normal file
3
examples/workspace/packages/pkg-b/main.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { workspaceMessage } from "../pkg-a/index";
|
||||||
|
|
||||||
|
console.log(`hello-${workspaceMessage()}`);
|
||||||
8
examples/workspace/packages/pkg-b/package.json
Normal file
8
examples/workspace/packages/pkg-b/package.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "@workspace/pkg-b",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@workspace/pkg-a": "workspace:*",
|
||||||
|
"lodash": "catalog:"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,28 @@ sh_test(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sh_test(
|
||||||
|
name = "examples_workspace_bundle_e2e_test",
|
||||||
|
srcs = ["examples_workspace_bundle_e2e_test.sh"],
|
||||||
|
args = ["$(location //examples/workspace:pkg_b_bundle)"],
|
||||||
|
data = ["//examples/workspace:pkg_b_bundle"],
|
||||||
|
)
|
||||||
|
|
||||||
|
sh_test(
|
||||||
|
name = "examples_workspace_catalog_shape_test",
|
||||||
|
srcs = ["examples_workspace_catalog_shape_test.sh"],
|
||||||
|
args = [
|
||||||
|
"$(location //examples/workspace:package.json)",
|
||||||
|
"$(location //examples/workspace:packages/pkg-a/package.json)",
|
||||||
|
"$(location //examples/workspace:packages/pkg-b/package.json)",
|
||||||
|
],
|
||||||
|
data = [
|
||||||
|
"//examples/workspace:package.json",
|
||||||
|
"//examples/workspace:packages/pkg-a/package.json",
|
||||||
|
"//examples/workspace:packages/pkg-b/package.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
sh_test(
|
sh_test(
|
||||||
name = "repo_all_targets_test",
|
name = "repo_all_targets_test",
|
||||||
srcs = ["repo_all_targets_test.sh"],
|
srcs = ["repo_all_targets_test.sh"],
|
||||||
|
|||||||
7
tests/integration_test/examples_workspace_bundle_e2e_test.sh
Executable file
7
tests/integration_test/examples_workspace_bundle_e2e_test.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
bundle_file="$1"
|
||||||
|
|
||||||
|
[[ -f ${bundle_file} ]]
|
||||||
|
grep -Eq 'hello-workspace-pkg-a|workspace-pkg-a' "${bundle_file}"
|
||||||
11
tests/integration_test/examples_workspace_catalog_shape_test.sh
Executable file
11
tests/integration_test/examples_workspace_catalog_shape_test.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
root_package_json="$1"
|
||||||
|
pkg_a_package_json="$2"
|
||||||
|
pkg_b_package_json="$3"
|
||||||
|
|
||||||
|
grep -Eq '"catalog"[[:space:]]*:[[:space:]]*\{' "${root_package_json}"
|
||||||
|
grep -Eq '"lodash"[[:space:]]*:[[:space:]]*"\^4\.17\.21"' "${root_package_json}"
|
||||||
|
grep -Eq '"lodash"[[:space:]]*:[[:space:]]*"catalog:"' "${pkg_a_package_json}"
|
||||||
|
grep -Eq '"lodash"[[:space:]]*:[[:space:]]*"catalog:"' "${pkg_b_package_json}"
|
||||||
Reference in New Issue
Block a user