allow customizing extra args

This commit is contained in:
Brian Hicks 2023-05-04 11:11:30 -05:00
parent bd08b25e85
commit 2cc0bff87e
No known key found for this signature in database
GPG Key ID: C4F324B9CAAB0D50
3 changed files with 18 additions and 3 deletions

1
BUCK
View File

@ -21,6 +21,7 @@ node_modules(
extra_files = {
"lib": "//lib:src"
},
extra_args = ["--include=dev"],
)
npm_bin(

View File

@ -21,6 +21,10 @@ def _node_modules_impl(ctx: "context") -> [DefaultInfo.type]:
for (name, value) in (ctx.attrs.extra_files or {}).items():
cmd.add(cmd_args(value, format = "--extra-file=" + name + "={}"))
if ctx.attrs.extra_args:
cmd.add("--")
cmd.add(ctx.attrs.extra_args)
ctx.actions.run(cmd, category = "npm")
return [DefaultInfo(default_output = out)]
@ -37,6 +41,10 @@ node_modules = rule(
),
default = None,
),
"extra_args": attrs.option(
attrs.list(attrs.arg()),
default = None,
),
"_node_toolchain": attrs.toolchain_dep(
default = "toolchains//:node",
providers = [NodeToolchainInfo],

View File

@ -11,7 +11,6 @@ import tempfile
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("out", help="Where you want node_modules to end up")
parser.add_argument(
"--package",
help="The package.json to install dependencies from",
@ -32,8 +31,14 @@ if __name__ == "__main__":
metavar="FILE=SRC",
help="Add a file that the package needs, sourced from the given path. This may be used, for example, to add files needed by a prepublish script.",
)
parser.add_argument("out", help="Where you want node_modules to end up")
parser.add_argument(
"npm_args",
nargs="*",
help="Specify extra args for the call to `npm clean-install`",
)
args = parser.parse_args()
args = parser.parse_intermixed_args()
if args.bin_dir:
os.environ["PATH"] = "{}:{}".format(
@ -56,7 +61,8 @@ if __name__ == "__main__":
os.symlink(os.path.abspath(src), os.path.join(tempdir, target))
cmd = ["npm", "clean-install", "--foreground-scripts"]
cmd = ["npm", "clean-install"] + args.npm_args
print(cmd)
proc = subprocess.Popen(cmd, cwd=tempdir)
proc.communicate()