Skip to content

Latest commit

 

History

History
executable file
·
470 lines (247 loc) · 12.1 KB

Providers.md

File metadata and controls

executable file
·
470 lines (247 loc) · 12.1 KB

Public providers, aspects and helpers that are shipped in the built-in build_bazel_rules_nodejs repository.

Users should not load files under "/internal"

DeclarationInfo

USAGE

DeclarationInfo(declarations, transitive_declarations, type_blacklisted_declarations)

The DeclarationInfo provider allows JS rules to communicate typing information. TypeScript's .d.ts files are used as the interop format for describing types. package.json files are included as well, as TypeScript needs to read the "typings" property.

Do not create DeclarationInfo instances directly, instead use the declaration_info factory function.

Note: historically this was a subset of the string-typed "typescript" provider.

FIELDS

declarations

A depset of typings files produced by this rule

transitive_declarations

A depset of typings files produced by this rule and all its transitive dependencies. This prevents needing an aspect in rules that consume the typings, which improves performance.

type_blacklisted_declarations

A depset of .d.ts files that we should not use to infer JSCompiler types (via tsickle)

DirectoryFilePathInfo

USAGE

DirectoryFilePathInfo(directory, path)

Joins a label pointing to a TreeArtifact with a path nested within that directory.

FIELDS

directory

a TreeArtifact (ctx.actions.declare_directory)

path

path relative to the directory

ExternalNpmPackageInfo

USAGE

ExternalNpmPackageInfo(direct_sources, has_directories, path, sources, workspace)

Provides information about one or more external npm packages

FIELDS

direct_sources

Depset of direct source files in these external npm package(s)

has_directories

True if any sources are directories

path

The local workspace path that these external npm deps should be linked at. If empty, they will be linked at the root.

sources

Depset of direct & transitive source files in these external npm package(s) and transitive dependencies

workspace

The workspace name that these external npm package(s) are provided from

JSEcmaScriptModuleInfo

USAGE

JSEcmaScriptModuleInfo(direct_sources, sources)

JavaScript files (and sourcemaps) that are intended to be consumed by downstream tooling.

They should use modern syntax and ESModules. These files should typically be named "foo.mjs"

Historical note: this was the typescript.es6_sources output

FIELDS

direct_sources

Depset of direct JavaScript files and sourcemaps

sources

Depset of direct and transitive JavaScript files and sourcemaps

JSModuleInfo

USAGE

JSModuleInfo(direct_sources, sources)

JavaScript files and sourcemaps.

FIELDS

direct_sources

Depset of direct JavaScript files and sourcemaps

sources

Depset of direct and transitive JavaScript files and sourcemaps

JSNamedModuleInfo

USAGE

JSNamedModuleInfo(direct_sources, sources)

JavaScript files whose module name is self-contained.

For example named AMD/UMD or goog.module format. These files can be efficiently served with the concatjs bundler. These outputs should be named "foo.umd.js" (note that renaming it from "foo.js" doesn't affect the module id)

Historical note: this was the typescript.es5_sources output.

FIELDS

direct_sources

Depset of direct JavaScript files and sourcemaps

sources

Depset of direct and transitive JavaScript files and sourcemaps

LinkablePackageInfo

USAGE

LinkablePackageInfo(files, package_name, package_path, path)

The LinkablePackageInfo provider provides information to the linker for linking pkg_npm built packages

FIELDS

files

Depset of files in this package (must all be contained within path)

package_name

The package name.

This field is optional. If not set, the target can be made linkable to a package_name with the npm_link rule.

package_path

The directory in the workspace to link to.

If set, link the 1st party dependencies to the node_modules under the package path specified. If unset, the default is to link to the node_modules root of the workspace.

path

The path to link to.

Path must be relative to execroot/wksp. It can either an output dir path such as,

bazel-out/<platform>-<build>/bin/path/to/package or bazel-out/<platform>-<build>/bin/external/external_wksp>/path/to/package

or a source file path such as,

path/to/package or external/<external_wksp>/path/to/package

NodeContextInfo

USAGE

NodeContextInfo(stamp)

Provides data about the build context, like config_setting's

FIELDS

stamp

If stamping is enabled

NodeRuntimeDepsInfo

USAGE

NodeRuntimeDepsInfo(deps, pkgs)

Stores runtime dependencies of a nodejs_binary or nodejs_test

These are files that need to be found by the node module resolver at runtime.

Historically these files were passed using the Runfiles mechanism. However runfiles has a big performance penalty of creating a symlink forest with FS API calls for every file in node_modules. It also causes there to be separate node_modules trees under each binary. This prevents user-contributed modules passed as deps[] to a particular action from being found by node module resolver, which expects everything in one tree.

In node, this resolution is done dynamically by assuming a node_modules tree will exist on disk, so we assume node actions/binary/test executions will do the same.

FIELDS

deps

depset of runtime dependency labels

pkgs

list of labels of packages that provide ExternalNpmPackageInfo

NpmPackageInfo

USAGE

NpmPackageInfo(direct_sources, has_directories, path, sources, workspace)

Provides information about one or more external npm packages

FIELDS

direct_sources

Depset of direct source files in these external npm package(s)

has_directories

True if any sources are directories

path

The local workspace path that these external npm deps should be linked at. If empty, they will be linked at the root.

sources

Depset of direct & transitive source files in these external npm package(s) and transitive dependencies

workspace

The workspace name that these external npm package(s) are provided from

declaration_info

USAGE

declaration_info(declarations, deps)

Constructs a DeclarationInfo including all transitive files needed to type-check from DeclarationInfo providers in a list of deps.

PARAMETERS

declarations

list of typings files

deps

list of labels of dependencies where we should collect their DeclarationInfo to pass transitively

Defaults to []

js_ecma_script_module_info

USAGE

js_ecma_script_module_info(sources, deps)

Constructs a JSEcmaScriptModuleInfo including all transitive sources from JSEcmaScriptModuleInfo providers in a list of deps.

Returns a single JSEcmaScriptModuleInfo.

PARAMETERS

sources

deps

Defaults to []

js_module_info

USAGE

js_module_info(sources, deps)

Constructs a JSModuleInfo including all transitive sources from JSModuleInfo providers in a list of deps.

Returns a single JSModuleInfo.

PARAMETERS

sources

deps

Defaults to []

js_named_module_info

USAGE

js_named_module_info(sources, deps)

Constructs a JSNamedModuleInfo including all transitive sources from JSNamedModuleInfo providers in a list of deps.

Returns a single JSNamedModuleInfo.

PARAMETERS

sources

deps

Defaults to []

run_node

USAGE

run_node(ctx, inputs, arguments, executable, chdir, kwargs)

Helper to replace ctx.actions.run

This calls node programs with a node_modules directory in place

PARAMETERS

ctx

rule context from the calling rule implementation function

inputs

list or depset of inputs to the action

arguments

list or ctx.actions.Args object containing arguments to pass to the executable

executable

stringy representation of the executable this action will run, eg eg. "my_executable" rather than ctx.executable.my_executable

chdir

directory we should change to be the working dir

Defaults to None

kwargs

all other args accepted by ctx.actions.run

node_modules_aspect

USAGE

node_modules_aspect(name)

ASPECT ATTRIBUTES

deps

ATTRIBUTES

name

(Name, {util.mandatoryString(name: "name" doc_string: "A unique name for this target." type: NAME mandatory: true )}) A unique name for this target.