def METHOD_NAME(ctx):
    if len(ctx.files.target) != 1:
        fail("target contains more files than expected")
    if not ctx.attr.version_file:
        version_file = ctx.actions.declare_file(ctx.attr.name + "__do_not_reference.version")
        version = ctx.var.get("version", "0.0.0")
        if len(version) == 40:
            # this is a commit SHA, most likely
            version = "0.0.0-{}".format(version)
        ctx.actions.run_shell(
            inputs = [],
            outputs = [version_file],
            command = "echo {} > {}".format(version, version_file.path),
        )
    else:
        version_file = ctx.file.version_file
    args = ctx.actions.args()
    args.add("--package", ctx.files.target[0].path)
    args.add("--output", ctx.outputs.npm_package.path)
    args.add("--version_file", version_file.path)
    ctx.actions.run(
        inputs = ctx.files.target + ctx.files._npm + [version_file],
        outputs = [ctx.outputs.npm_package],
        arguments = [args],
        executable = ctx.executable._assemble_script,
        # note: do not run in RBE
    )