Skip to main content

nodejs_binary

A runnable Node.js script, executed with the toolchain's Node runtime and no custom loaders. When deps is non-empty, builds a merged node_modules from transitive deps, stages main and srcs beside it (each at its short path; distinct files staging to the same path fail), and runs the staged main so Node's own resolution finds the deps. The default output is that directory. With no deps, main runs at its original path, files it imports via relative paths must be listed in srcs to be declared as build inputs, and there is no default output. Deps must be loadable as regular node_modules packages: each package's package.json governs whether it is CommonJS or an ES module, and TypeScript must be compiled to JavaScript before it is packaged. The merged tree is also exposed via NODE_PATH at runtime, appended to any NODE_PATH set in env, for CommonJS resolution. Transitive deps' package_name values must be unique, as for nodejs_library.

Function Signature​

def nodejs_binary(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str | target_name_glob] = [],
within_view: list[str | target_name_glob] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_nodejs_toolchain: str = "gh_facebook_buck2_shims_meta//:nodejs",
_target_os_type: str = "prelude//os_lookup/targets:os_lookup",
args: list[str] = [],
contacts: list[str] = [],
deps: list[str] = [],
env: dict[str, str] = {},
labels: list[str] = [],
main: str,
node_args: list[str] = [],
srcs: list[str] = [],
) -> None

Parameters​

  • name: (required)

    name of the target

  • default_target_platform: (defaults to: None)

    specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: (defaults to: [])

    a list of visibility patterns restricting what targets can depend on this one

  • within_view: (defaults to: ["PUBLIC"])

    a list of visibility patterns restricting what this target can depend on

  • metadata: (defaults to: {})

    a key-value map of metadata associated with this target

  • tests: (defaults to: [])

    a list of targets that provide tests for this one

  • modifiers: (defaults to: [])

    an array of modifiers associated with this target

  • contacts: (defaults to: [])

    A list of organizational contacts for this rule. These could be individuals who you would contact in the event of a failure or other issue with the rule.

    contacts = [ 'Joe Sixpack', 'Erika Mustermann' ]
  • labels: (defaults to: [])

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query().