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", name = "node_modules",
package = "package.json", package = "package.json",
package_lock = "package-lock.json", package_lock = "package-lock.json",
extra_files = {
"lib": "//lib:src"
},
) )
npm_bin( npm_bin(

View File

@ -5,3 +5,9 @@ genrule(
cmd = "$(exe //:browserify) index.js --outfile $OUT", cmd = "$(exe //:browserify) index.js --outfile $OUT",
visibility = ["//component-catalog:public"], 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] node_toolchain = ctx.attrs._node_toolchain[NodeToolchainInfo]
ctx.actions.run( cmd = cmd_args(
[ ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter,
ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter, node_toolchain.build_node_modules[DefaultInfo].default_outputs,
node_toolchain.build_node_modules[DefaultInfo].default_outputs, out.as_output(),
out.as_output(), "--package",
"--package", ctx.attrs.package,
ctx.attrs.package, "--package-lock",
"--package-lock", ctx.attrs.package_lock,
ctx.attrs.package_lock, "--bin-dir",
"--bin-dir", node_toolchain.bin_dir[DefaultInfo].default_outputs,
node_toolchain.bin_dir[DefaultInfo].default_outputs,
],
category = "npm",
) )
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)] return [DefaultInfo(default_output = out)]
node_modules = rule( node_modules = rule(
@ -28,6 +30,13 @@ node_modules = rule(
attrs = { attrs = {
"package": attrs.source(), "package": attrs.source(),
"package_lock": 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( "_node_toolchain": attrs.toolchain_dep(
default = "toolchains//:node", default = "toolchains//:node",
providers = [NodeToolchainInfo], providers = [NodeToolchainInfo],