From 595dc838a1d6601594dd50feac689dcf68d109bc Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Wed, 3 May 2023 15:51:17 -0500 Subject: [PATCH] make it possible to run installation scripts in our repo --- BUCK | 3 +++ lib/BUCK | 6 ++++++ prelude-nri/node.bzl | 35 ++++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/BUCK b/BUCK index 85a09c17..2f597ec0 100644 --- a/BUCK +++ b/BUCK @@ -18,6 +18,9 @@ node_modules( name = "node_modules", package = "package.json", package_lock = "package-lock.json", + extra_files = { + "lib": "//lib:src" + }, ) npm_bin( diff --git a/lib/BUCK b/lib/BUCK index 33c96342..969dd7a2 100644 --- a/lib/BUCK +++ b/lib/BUCK @@ -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"], +) diff --git a/prelude-nri/node.bzl b/prelude-nri/node.bzl index 7280af19..b844cdd5 100644 --- a/prelude-nri/node.bzl +++ b/prelude-nri/node.bzl @@ -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],