make it possible to run installation scripts in our repo

This commit is contained in:
Brian Hicks 2023-05-03 15:51:17 -05:00
parent ecfce394df
commit 595dc838a1
No known key found for this signature in database
GPG Key ID: C4F324B9CAAB0D50
3 changed files with 31 additions and 13 deletions

3
BUCK
View File

@ -18,6 +18,9 @@ node_modules(
name = "node_modules",
package = "package.json",
package_lock = "package-lock.json",
extra_files = {
"lib": "//lib:src"
},
)
npm_bin(

View File

@ -5,3 +5,9 @@ genrule(
cmd = "$(exe //:browserify) index.js --outfile $OUT",
visibility = ["//component-catalog:public"],
)
filegroup(
name = "src",
srcs = glob(["**/*.js"]),
visibility = ["//:node_modules"],
)

View File

@ -6,21 +6,23 @@ def _node_modules_impl(ctx: "context") -> [DefaultInfo.type]:
node_toolchain = ctx.attrs._node_toolchain[NodeToolchainInfo]
ctx.actions.run(
[
ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter,
node_toolchain.build_node_modules[DefaultInfo].default_outputs,
out.as_output(),
"--package",
ctx.attrs.package,
"--package-lock",
ctx.attrs.package_lock,
"--bin-dir",
node_toolchain.bin_dir[DefaultInfo].default_outputs,
],
category = "npm",
cmd = cmd_args(
ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter,
node_toolchain.build_node_modules[DefaultInfo].default_outputs,
out.as_output(),
"--package",
ctx.attrs.package,
"--package-lock",
ctx.attrs.package_lock,
"--bin-dir",
node_toolchain.bin_dir[DefaultInfo].default_outputs,
)
for (name, value) in (ctx.attrs.extra_files or {}).items():
cmd.add(cmd_args(value, format = "--extra-file=" + name + "={}"))
ctx.actions.run(cmd, category = "npm")
return [DefaultInfo(default_output = out)]
node_modules = rule(
@ -28,6 +30,13 @@ node_modules = rule(
attrs = {
"package": attrs.source(),
"package_lock": attrs.source(),
"extra_files": attrs.option(
attrs.dict(
attrs.string(),
attrs.source(allow_directory = True),
),
default = None,
),
"_node_toolchain": attrs.toolchain_dep(
default = "toolchains//:node",
providers = [NodeToolchainInfo],