blob: 22799745f48ae98136e880be2792d59e401db80d [file]
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test", "npm_package_bin")
load("//internal/js_library:js_library.bzl", "js_library")
load("//internal/node:node_repositories.bzl", "BUILT_IN_NODE_PLATFORMS")
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file")
load(":nodejs_toolchain_test.bzl", "nodejs_toolchain_test")
# You can have a nodejs_binary with no node_modules attribute
# and no fine grained deps
nodejs_binary(
name = "no_deps",
data = ["no-deps.js"],
entry_point = ":no-deps.js",
)
# You can have a nodejs_binary with a node_modules attribute
# and no fine grained deps
nodejs_binary(
name = "has_deps_legacy",
data = ["has-deps.js"],
entry_point = ":has-deps.js",
node_modules = "@fine_grained_deps_yarn//:node_modules",
)
# You can have a nodejs_binary with no node_modules attribute
# and fine grained deps
nodejs_binary(
name = "has_deps",
data = [
"has-deps.js",
"@fine_grained_deps_yarn//typescript",
],
entry_point = ":has-deps.js",
)
# You can have a nodejs_binary with both a node_modules attribute
# and fine grained deps so long as they come from the same root
nodejs_binary(
name = "has_deps_hybrid",
data = [
"has-deps.js",
"@fine_grained_deps_yarn//typescript",
],
entry_point = ":has-deps.js",
node_modules = "@fine_grained_deps_yarn//:node_modules",
)
filegroup(
name = "entry_file",
srcs = ["no-deps.js"],
)
nodejs_binary(
name = "has_entry_file",
entry_point = ":entry_file",
)
# Coverage for issue https://github.com/bazelbuild/rules_nodejs/issues/834
# where module_name is equal to the workspace naem
js_library(
name = "module_name_lib",
srcs = ["module-name.js"],
module_name = "build_bazel_rules_nodejs",
)
nodejs_binary(
name = "module_name_test",
data = [":module_name_lib"],
entry_point = ":module-name.js",
)
nodejs_test(
name = "define_var",
configuration_env_vars = ["SOME_TEST_ENV"],
data = glob(["*.spec.js"]),
entry_point = ":define.spec.js",
)
nodejs_test(
name = "mode_resolution_test",
data = [
"//internal/node/test/lib1",
"@npm//node_resolve_index",
"@npm//node_resolve_index_2",
"@npm//node_resolve_index_3",
"@npm//node_resolve_index_4",
"@npm//node_resolve_main",
"@npm//node_resolve_main_2",
"@npm//node_resolve_nested_main",
],
entry_point = ":module_resolution.spec.js",
)
nodejs_test(
name = "data_resolution_test",
data = [
"data/data.json",
],
entry_point = ":data_resolution.spec.js",
)
# Also test resolution from built files.
copy_file(
name = "module_resolution_lib",
src = "module_resolution.spec.js",
out = "module_resolution_built.spec.js",
)
copy_file(
name = "data_resolution_lib",
src = "data_resolution.spec.js",
out = "data_resolution_built.spec.js",
)
# This rule creates a file that alphabetically comes before any source file in this
# package. This genfile can be then set up as runfile to verify that the "node_loader.js"
# properly determines the local workspace path without incorrectly using the genfile as base
# for the local workspace path. See: https://github.com/bazelbuild/rules_nodejs/issues/352
write_file(
name = "genfile-runfile",
out = "#LEADING.txt",
)
nodejs_test(
name = "mode_resolution_built_test",
data = [
"//internal/node/test/lib1",
"@npm//node_resolve_index",
"@npm//node_resolve_index_2",
"@npm//node_resolve_index_3",
"@npm//node_resolve_index_4",
"@npm//node_resolve_main",
"@npm//node_resolve_main_2",
"@npm//node_resolve_nested_main",
],
entry_point = ":module_resolution_built.spec.js",
)
nodejs_test(
name = "data_resolution_built_test",
data = [
"data/data.json",
":genfile-runfile",
],
entry_point = ":data_resolution_built.spec.js",
)
npm_package_bin(
name = "run_terser",
outs = ["minified.js"],
args = [
"$(location terser_input.js)",
"--output",
"$(location minified.js)",
],
data = ["terser_input.js"],
package = "terser",
)
nodejs_binary(
name = "copy_to_directory",
entry_point = "copy_to_directory.js",
)
npm_package_bin(
name = "dir_output",
args = [
"--output-dir",
"$@",
"$(location terser_input.js)",
],
data = ["terser_input.js"],
output_dir = True,
tool = ":copy_to_directory",
)
nodejs_test(
name = "npm_package_bin_test",
data = [
"dir_output",
"minified.js",
],
entry_point = "npm_package_bin.spec.js",
)
[nodejs_toolchain_test(
name = "nodejs_toolchain_%s_test" % platform,
platform = platform,
# must be run with --platforms=@build_bazel_rules_nodejs//toolchains/node:PLATFORM
# where PLATFORM is one of BUILT_IN_NODE_PLATFORMS
tags = ["manual"],
) for platform in BUILT_IN_NODE_PLATFORMS]