feat: proper windows support
This commit is contained in:
@@ -34,6 +34,7 @@ config_setting(
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_clean_install_test",
|
||||
size = "small",
|
||||
srcs = ["clean_install.sh"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
@@ -53,6 +54,7 @@ sh_test(
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_stale_lockfile_test",
|
||||
size = "small",
|
||||
srcs = ["stale_lockfile.sh"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
@@ -72,6 +74,7 @@ sh_test(
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_determinism_test",
|
||||
size = "small",
|
||||
srcs = ["determinism.sh"],
|
||||
args = ["$(location //internal:bun_install.bzl)"],
|
||||
data = ["//internal:bun_install.bzl"],
|
||||
@@ -79,6 +82,7 @@ sh_test(
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_environment_shape_test",
|
||||
size = "small",
|
||||
srcs = ["environment_shape.sh"],
|
||||
args = ["$(location //internal:bun_install.bzl)"],
|
||||
data = ["//internal:bun_install.bzl"],
|
||||
@@ -86,6 +90,7 @@ sh_test(
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_workspaces_test",
|
||||
size = "small",
|
||||
srcs = ["workspaces.sh"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
@@ -105,6 +110,7 @@ sh_test(
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_workspaces_catalog_test",
|
||||
size = "small",
|
||||
srcs = ["workspaces_catalog.sh"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
@@ -125,7 +131,6 @@ sh_test(
|
||||
sh_test(
|
||||
name = "bun_install_workspace_parity_test",
|
||||
srcs = ["workspace_parity.sh"],
|
||||
env_inherit = ["PATH"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
":linux_aarch64": ["$(location @bun_linux_aarch64//:bun)"],
|
||||
@@ -144,11 +149,63 @@ sh_test(
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
],
|
||||
env_inherit = ["PATH"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_install_flags_shape_test",
|
||||
size = "small",
|
||||
srcs = ["install_flags_shape.sh"],
|
||||
args = ["$(location //internal:bun_install.bzl)"],
|
||||
data = ["//internal:bun_install.bzl"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_repeatability_test",
|
||||
size = "small",
|
||||
srcs = ["repeatability.sh"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
":linux_aarch64": ["$(location @bun_linux_aarch64//:bun)"],
|
||||
":darwin_x86_64": ["$(location @bun_darwin_x64//:bun)"],
|
||||
":darwin_aarch64": ["$(location @bun_darwin_aarch64//:bun)"],
|
||||
"//conditions:default": ["$(location @bun_linux_x64//:bun)"],
|
||||
}),
|
||||
data = select({
|
||||
":linux_x86_64": ["@bun_linux_x64//:bun"],
|
||||
":linux_aarch64": ["@bun_linux_aarch64//:bun"],
|
||||
":darwin_x86_64": ["@bun_darwin_x64//:bun"],
|
||||
":darwin_aarch64": ["@bun_darwin_aarch64//:bun"],
|
||||
"//conditions:default": ["@bun_linux_x64//:bun"],
|
||||
}) + [
|
||||
"//:repo_runtime_files",
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
],
|
||||
env_inherit = ["PATH"],
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "bun_install_lifecycle_scripts_test",
|
||||
size = "small",
|
||||
srcs = ["lifecycle_scripts.sh"],
|
||||
args = select({
|
||||
":linux_x86_64": ["$(location @bun_linux_x64//:bun)"],
|
||||
":linux_aarch64": ["$(location @bun_linux_aarch64//:bun)"],
|
||||
":darwin_x86_64": ["$(location @bun_darwin_x64//:bun)"],
|
||||
":darwin_aarch64": ["$(location @bun_darwin_aarch64//:bun)"],
|
||||
"//conditions:default": ["$(location @bun_linux_x64//:bun)"],
|
||||
}),
|
||||
data = select({
|
||||
":linux_x86_64": ["@bun_linux_x64//:bun"],
|
||||
":linux_aarch64": ["@bun_linux_aarch64//:bun"],
|
||||
":darwin_x86_64": ["@bun_darwin_x64//:bun"],
|
||||
":darwin_aarch64": ["@bun_darwin_aarch64//:bun"],
|
||||
"//conditions:default": ["@bun_linux_x64//:bun"],
|
||||
}) + [
|
||||
"//:repo_runtime_files",
|
||||
"//bun:repo_runtime_files",
|
||||
"//internal:repo_runtime_files",
|
||||
],
|
||||
env_inherit = ["PATH"],
|
||||
)
|
||||
|
||||
118
tests/install_test/lifecycle_scripts.sh
Executable file
118
tests/install_test/lifecycle_scripts.sh
Executable file
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
bun_path="$1"
|
||||
|
||||
if command -v bazel >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazel)
|
||||
elif command -v bazelisk >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazelisk)
|
||||
else
|
||||
echo "bazel or bazelisk is required on PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
|
||||
|
||||
workdir="$(mktemp -d)"
|
||||
trap 'rm -rf "${workdir}"' EXIT
|
||||
|
||||
fixture_dir="${workdir}/fixture"
|
||||
mkdir -p "${fixture_dir}"
|
||||
|
||||
cat >"${fixture_dir}/package.json" <<'JSON'
|
||||
{
|
||||
"name": "lifecycle-script-test",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"is-number": "7.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "bun -e \"require('node:fs').writeFileSync('postinstall.txt', 'ran')\""
|
||||
}
|
||||
}
|
||||
JSON
|
||||
|
||||
"${bun_path}" install --cwd "${fixture_dir}" >/dev/null
|
||||
rm -rf "${fixture_dir}/node_modules" "${fixture_dir}/postinstall.txt"
|
||||
|
||||
cat >"${fixture_dir}/MODULE.bazel" <<EOF
|
||||
module(
|
||||
name = "bun_install_lifecycle_scripts_test",
|
||||
)
|
||||
|
||||
bazel_dep(name = "rules_bun", version = "0.2.2")
|
||||
|
||||
local_path_override(
|
||||
module_name = "rules_bun",
|
||||
path = "${rules_bun_root}",
|
||||
)
|
||||
|
||||
bun_ext = use_extension("@rules_bun//bun:extensions.bzl", "bun")
|
||||
use_repo(
|
||||
bun_ext,
|
||||
"bun_darwin_aarch64",
|
||||
"bun_darwin_x64",
|
||||
"bun_linux_aarch64",
|
||||
"bun_linux_x64",
|
||||
"bun_windows_x64",
|
||||
)
|
||||
|
||||
bun_install_ext = use_extension("@rules_bun//bun:extensions.bzl", "bun_install")
|
||||
bun_install_ext.install(
|
||||
name = "scripts_blocked",
|
||||
package_json = "//:package.json",
|
||||
bun_lockfile = "//:bun.lock",
|
||||
)
|
||||
bun_install_ext.install(
|
||||
name = "scripts_allowed",
|
||||
package_json = "//:package.json",
|
||||
bun_lockfile = "//:bun.lock",
|
||||
ignore_scripts = False,
|
||||
)
|
||||
use_repo(
|
||||
bun_install_ext,
|
||||
"scripts_allowed",
|
||||
"scripts_blocked",
|
||||
)
|
||||
|
||||
register_toolchains(
|
||||
"@rules_bun//bun:darwin_aarch64_toolchain",
|
||||
"@rules_bun//bun:darwin_x64_toolchain",
|
||||
"@rules_bun//bun:linux_aarch64_toolchain",
|
||||
"@rules_bun//bun:linux_x64_toolchain",
|
||||
"@rules_bun//bun:windows_x64_toolchain",
|
||||
)
|
||||
EOF
|
||||
|
||||
cat >"${fixture_dir}/BUILD.bazel" <<'EOF'
|
||||
exports_files([
|
||||
"package.json",
|
||||
"bun.lock",
|
||||
])
|
||||
EOF
|
||||
|
||||
(
|
||||
cd "${fixture_dir}"
|
||||
"${bazel_cmd[@]}" build @scripts_blocked//:node_modules @scripts_allowed//:node_modules >/dev/null
|
||||
)
|
||||
|
||||
output_base="$(cd "${fixture_dir}" && "${bazel_cmd[@]}" info output_base)"
|
||||
blocked_repo="$(find "${output_base}/external" -maxdepth 1 -type d -name '*+scripts_blocked' | head -n 1)"
|
||||
allowed_repo="$(find "${output_base}/external" -maxdepth 1 -type d -name '*+scripts_allowed' | head -n 1)"
|
||||
|
||||
if [[ -z ${blocked_repo} || -z ${allowed_repo} ]]; then
|
||||
echo "Unable to locate generated lifecycle test repositories" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -e "${blocked_repo}/postinstall.txt" ]]; then
|
||||
echo "Lifecycle scripts should be disabled by default" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "${allowed_repo}/postinstall.txt" ]]; then
|
||||
echo "Lifecycle scripts should run when ignore_scripts = False" >&2
|
||||
exit 1
|
||||
fi
|
||||
128
tests/install_test/repeatability.sh
Executable file
128
tests/install_test/repeatability.sh
Executable file
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
bun_path="$1"
|
||||
|
||||
if command -v bazel >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazel)
|
||||
elif command -v bazelisk >/dev/null 2>&1; then
|
||||
bazel_cmd=(bazelisk)
|
||||
else
|
||||
echo "bazel or bazelisk is required on PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
|
||||
|
||||
workdir="$(mktemp -d)"
|
||||
trap 'rm -rf "${workdir}"' EXIT
|
||||
|
||||
fixture_dir="${workdir}/fixture"
|
||||
mkdir -p "${fixture_dir}"
|
||||
|
||||
cat >"${fixture_dir}/package.json" <<'JSON'
|
||||
{
|
||||
"name": "repeatability-test",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"is-number": "7.0.0"
|
||||
}
|
||||
}
|
||||
JSON
|
||||
|
||||
"${bun_path}" install --cwd "${fixture_dir}" >/dev/null
|
||||
rm -rf "${fixture_dir}/node_modules"
|
||||
|
||||
cat >"${fixture_dir}/MODULE.bazel" <<EOF
|
||||
module(
|
||||
name = "bun_install_repeatability_test",
|
||||
)
|
||||
|
||||
bazel_dep(name = "rules_bun", version = "0.2.2")
|
||||
|
||||
local_path_override(
|
||||
module_name = "rules_bun",
|
||||
path = "${rules_bun_root}",
|
||||
)
|
||||
|
||||
bun_ext = use_extension("@rules_bun//bun:extensions.bzl", "bun")
|
||||
use_repo(
|
||||
bun_ext,
|
||||
"bun_darwin_aarch64",
|
||||
"bun_darwin_x64",
|
||||
"bun_linux_aarch64",
|
||||
"bun_linux_x64",
|
||||
"bun_windows_x64",
|
||||
)
|
||||
|
||||
bun_install_ext = use_extension("@rules_bun//bun:extensions.bzl", "bun_install")
|
||||
bun_install_ext.install(
|
||||
name = "node_modules_a",
|
||||
package_json = "//:package.json",
|
||||
bun_lockfile = "//:bun.lock",
|
||||
)
|
||||
bun_install_ext.install(
|
||||
name = "node_modules_b",
|
||||
package_json = "//:package.json",
|
||||
bun_lockfile = "//:bun.lock",
|
||||
)
|
||||
use_repo(
|
||||
bun_install_ext,
|
||||
"node_modules_a",
|
||||
"node_modules_b",
|
||||
)
|
||||
|
||||
register_toolchains(
|
||||
"@rules_bun//bun:darwin_aarch64_toolchain",
|
||||
"@rules_bun//bun:darwin_x64_toolchain",
|
||||
"@rules_bun//bun:linux_aarch64_toolchain",
|
||||
"@rules_bun//bun:linux_x64_toolchain",
|
||||
"@rules_bun//bun:windows_x64_toolchain",
|
||||
)
|
||||
EOF
|
||||
|
||||
cat >"${fixture_dir}/BUILD.bazel" <<'EOF'
|
||||
exports_files([
|
||||
"package.json",
|
||||
"bun.lock",
|
||||
])
|
||||
EOF
|
||||
|
||||
(
|
||||
cd "${fixture_dir}"
|
||||
"${bazel_cmd[@]}" build @node_modules_a//:node_modules @node_modules_b//:node_modules >/dev/null
|
||||
)
|
||||
|
||||
output_base="$(cd "${fixture_dir}" && "${bazel_cmd[@]}" info output_base)"
|
||||
repo_a="$(find "${output_base}/external" -maxdepth 1 -type d -name '*+node_modules_a' | head -n 1)"
|
||||
repo_b="$(find "${output_base}/external" -maxdepth 1 -type d -name '*+node_modules_b' | head -n 1)"
|
||||
|
||||
if [[ -z ${repo_a} || -z ${repo_b} ]]; then
|
||||
echo "Unable to locate generated node_modules repositories" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
snapshot_tree() {
|
||||
local root="$1"
|
||||
(
|
||||
cd "${root}"
|
||||
while IFS= read -r -d '' path; do
|
||||
local rel="${path#./}"
|
||||
if [[ -L ${path} ]]; then
|
||||
local target
|
||||
target="$(readlink "${path}")"
|
||||
target="${target//node_modules_a/node_modules}"
|
||||
target="${target//node_modules_b/node_modules}"
|
||||
printf 'L %s %s\n' "${rel}" "${target}"
|
||||
else
|
||||
printf 'F %s %s\n' "${rel}" "$(shasum -a 256 "${path}" | awk '{print $1}')"
|
||||
fi
|
||||
done < <(find . \( -type f -o -type l \) -print0 | sort -z)
|
||||
)
|
||||
}
|
||||
|
||||
snapshot_tree "${repo_a}/node_modules" >"${workdir}/repo_a.snapshot"
|
||||
snapshot_tree "${repo_b}/node_modules" >"${workdir}/repo_b.snapshot"
|
||||
|
||||
diff -u "${workdir}/repo_a.snapshot" "${workdir}/repo_b.snapshot"
|
||||
@@ -2,6 +2,9 @@
|
||||
set -euo pipefail
|
||||
|
||||
bun_path="$1"
|
||||
if [[ ${bun_path} != /* ]]; then
|
||||
bun_path="$(cd "$(dirname "${bun_path}")" && pwd -P)/$(basename "${bun_path}")"
|
||||
fi
|
||||
workdir="$(mktemp -d)"
|
||||
trap 'rm -rf "${workdir}"' EXIT
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
set -euo pipefail
|
||||
|
||||
bun_path="$1"
|
||||
if [[ ${bun_path} != /* ]]; then
|
||||
bun_path="$(cd "$(dirname "${bun_path}")" && pwd -P)/$(basename "${bun_path}")"
|
||||
fi
|
||||
workdir="$(mktemp -d)"
|
||||
trap 'rm -rf "${workdir}"' EXIT
|
||||
|
||||
|
||||
Reference in New Issue
Block a user