2023-05-01 22:56:57 +03:00
|
|
|
load("//node:toolchain.bzl", "NodeToolchainInfo")
|
|
|
|
load("@prelude//python:toolchain.bzl", "PythonToolchainInfo")
|
|
|
|
|
|
|
|
def _node_modules_impl(ctx: "context") -> [DefaultInfo.type]:
|
|
|
|
out = ctx.actions.declare_output("node_modules")
|
|
|
|
|
2023-05-01 23:03:52 +03:00
|
|
|
node_toolchain = ctx.attrs._node_toolchain[NodeToolchainInfo]
|
|
|
|
|
2023-05-01 22:56:57 +03:00
|
|
|
ctx.actions.run(
|
|
|
|
[
|
|
|
|
ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter,
|
2023-05-01 23:03:52 +03:00
|
|
|
node_toolchain.build_node_modules[DefaultInfo].default_outputs,
|
2023-05-01 22:56:57 +03:00
|
|
|
out.as_output(),
|
2023-05-02 16:48:58 +03:00
|
|
|
"--package",
|
|
|
|
ctx.attrs.package,
|
|
|
|
"--package-lock",
|
|
|
|
ctx.attrs.package_lock,
|
|
|
|
"--bin-dir",
|
|
|
|
node_toolchain.bin_dir[DefaultInfo].default_outputs,
|
2023-05-01 22:56:57 +03:00
|
|
|
],
|
|
|
|
category = "npm",
|
|
|
|
)
|
|
|
|
|
|
|
|
return [DefaultInfo(default_output = out)]
|
|
|
|
|
|
|
|
node_modules = rule(
|
|
|
|
impl = _node_modules_impl,
|
|
|
|
attrs = {
|
|
|
|
"package": attrs.source(),
|
|
|
|
"package_lock": attrs.source(),
|
|
|
|
"_node_toolchain": attrs.toolchain_dep(
|
2023-05-02 16:48:58 +03:00
|
|
|
default = "toolchains//:node",
|
|
|
|
providers = [NodeToolchainInfo],
|
2023-05-01 22:56:57 +03:00
|
|
|
),
|
|
|
|
"_python_toolchain": attrs.toolchain_dep(
|
2023-05-02 16:48:58 +03:00
|
|
|
default = "toolchains//:python",
|
|
|
|
providers = [PythonToolchainInfo],
|
2023-05-01 22:56:57 +03:00
|
|
|
),
|
2023-05-02 16:48:58 +03:00
|
|
|
},
|
2023-05-01 22:56:57 +03:00
|
|
|
)
|
2023-05-02 13:57:56 +03:00
|
|
|
|
|
|
|
def _npm_bin_impl(ctx: "context") -> [[DefaultInfo.type, RunInfo.type]]:
|
|
|
|
bin_name = ctx.attrs.bin_name or ctx.attrs.name
|
|
|
|
|
|
|
|
out = ctx.actions.declare_output(bin_name)
|
|
|
|
|
|
|
|
node_toolchain = ctx.attrs._node_toolchain[NodeToolchainInfo]
|
|
|
|
|
|
|
|
ctx.actions.run(
|
|
|
|
[
|
|
|
|
ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter,
|
|
|
|
node_toolchain.build_npm_bin[DefaultInfo].default_outputs,
|
|
|
|
ctx.attrs.node_modules,
|
|
|
|
bin_name,
|
|
|
|
out.as_output(),
|
2023-05-02 16:48:58 +03:00
|
|
|
"--bin-dir",
|
|
|
|
node_toolchain.bin_dir[DefaultInfo].default_outputs,
|
2023-05-02 13:57:56 +03:00
|
|
|
],
|
|
|
|
category = "build_npm_bin",
|
|
|
|
)
|
|
|
|
|
|
|
|
return [
|
|
|
|
DefaultInfo(default_output = out),
|
|
|
|
RunInfo(out),
|
|
|
|
]
|
|
|
|
|
|
|
|
npm_bin = rule(
|
|
|
|
impl = _npm_bin_impl,
|
|
|
|
attrs = {
|
2023-05-02 16:48:58 +03:00
|
|
|
"bin_name": attrs.option(attrs.string(), default = None),
|
2023-05-02 13:57:56 +03:00
|
|
|
"node_modules": attrs.source(),
|
|
|
|
"_node_toolchain": attrs.toolchain_dep(
|
2023-05-02 16:48:58 +03:00
|
|
|
default = "toolchains//:node",
|
|
|
|
providers = [NodeToolchainInfo],
|
2023-05-02 13:57:56 +03:00
|
|
|
),
|
|
|
|
"_python_toolchain": attrs.toolchain_dep(
|
2023-05-02 16:48:58 +03:00
|
|
|
default = "toolchains//:python",
|
|
|
|
providers = [PythonToolchainInfo],
|
2023-05-02 13:57:56 +03:00
|
|
|
),
|
2023-05-02 16:48:58 +03:00
|
|
|
},
|
2023-05-02 13:57:56 +03:00
|
|
|
)
|