blob: 2dc17288af1d46b4022ceb4fcfd08bf4e4ed1963 [file] [log] [blame] [edit]
load("@aspect_rules_js//js:defs.bzl", "js_test")
load("@aspect_rules_js//npm:defs.bzl", "npm_package", "stamped_package_json")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
copy_file(
name = "copy_LICENSE",
src = "//:LICENSE",
out = "LICENSE",
)
genrule(
name = "buildifier_launcher",
srcs = ["//:launcher.js"],
outs = ["buildifier.js"],
cmd = "sed s/_TOOL_/buildifier/ $< > $@",
)
# npm rules live in this subdirectory to avoid a load() statement
# in the parent package leaking to users. This means we need
# to copy the output files so the pkg_npm will find them in the
# output directory for this package.
_PARENT_PACKAGE_FILES = [
"README.md",
"buildifier-darwin_amd64",
"buildifier-darwin_arm64",
"buildifier-linux_amd64",
"buildifier-linux_arm64",
"buildifier-linux_riscv64",
"buildifier-windows_amd64.exe",
]
[
copy_file(
name = "copy_%s" % s,
# go_binary doesn't give a predeclared output for
# the file in "out" so we have to construct a
# label to reference the go_binary rule itself.
src = "//buildifier:%s" % s.replace("_arm64", "-arm64").replace("_riscv64", "-riscv64").split("_amd64")[0],
out = s,
)
for s in _PARENT_PACKAGE_FILES
]
stamped_package_json(
name = "package",
stamp_var = "BUILD_SCM_VERSION",
)
npm_package(
name = "buildifier",
srcs = [
"LICENSE",
"buildifier.js",
":package",
] + _PARENT_PACKAGE_FILES,
package = "@bazel/buildifier",
publishable = True,
)
js_test(
name = "integration_test",
data = [":buildifier"],
entry_point = "test.js",
)