Skip to content

Latest commit

 

History

History
298 lines (206 loc) · 12.6 KB

File metadata and controls

298 lines (206 loc) · 12.6 KB

CommonJS

better_rules_javascript organizes modules and other files into CommonJS "packages."

While the focus is JavaScript, this is also the organization used for other language, like CSS.

Guide

Example

package.json

{}

BUILD.bazel

load("@better_rules_javascript//commonjs:rules.bzl", "cjs_root")

cjs_root(
    name = "root",
    descriptor = "package.json",
    package_name = "example",
)

//commonjs:providers.bzl

CjsInfo

CjsInfo(name, package, transitive_files, transitive_packages, transitive_links)

CommonJS-style package info

FIELDS

Name Description
name Name
package Package
transitive_files Files
transitive_packages Packages
transitive_links Links

cjs_npm_label

cjs_npm_label(repo)

PARAMETERS

Name Description Default Value
repo

-

none

create_cjs_info

create_cjs_info(cjs_root, label, files, deps, globals)

PARAMETERS

Name Description Default Value
cjs_root

-

none
label

-

none
files

-

[]
deps

-

[]
globals

-

[]

create_extra_deps

create_extra_deps(package, label, extra_deps)

PARAMETERS

Name Description Default Value
package

-

none
label

-

none
extra_deps

-

none

create_globals

create_globals(label, cjs_infos)

Create globals.

PARAMETERS

Name Description Default Value
label Source label none
cjs_infos CjsInfo none

create_link

create_link(path, name, dep, label)

Create link for CommonJs package.

PARAMETERS

Name Description Default Value
path Package path none
name Name none
dep Dependency package path none
label Source label none

create_links

create_links(package, label, cjs_infos)

Create deps.

PARAMETERS

Name Description Default Value
package Package struct none
label Source label none
cjs_infos CjsInfo none

create_package

create_package(name, path, short_path, label)

Create CommonJs package definition.

PARAMETERS

Name Description Default Value
name Name none
path Path of root directory none
short_path Short path of root directory none
label Source label none

gen_manifest

gen_manifest(actions, manifest_bin, manifest, packages, deps, package_path)

Create package manifest.

PARAMETERS

Name Description Default Value
actions Actions struct none
manifest_bin Manfiest generation executable none
manifest Manifest output none
packages Depset of packages none
deps Depset of dependencies none
package_path Function for package path none

package_path

package_path(package)

PARAMETERS

Name Description Default Value
package

-

none

//commonjs:rules.bzl

cjs_descriptors

cjs_descriptors(name, prefix, srcs, strip_prefix)

CommonJS descriptors.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
prefix Prefix to add. String optional ""
srcs Descriptors. List of labels required
strip_prefix Package-relative prefix to remove. String optional ""

cjs_root

cjs_root(name, descriptors, package_name, path, prefix, strip_prefix)

CommonJS-style package root.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
descriptors package.json descriptors. List of labels optional []
package_name Package name. By default, @workspace_name/path-to-directory String optional ""
path Root path, relative to package String optional ""
prefix - String optional ""
strip_prefix - String optional ""

//commonjs:workspace.bzl

cjs_directory_npm_plugin

cjs_directory_npm_plugin()

cjs_npm_plugin

cjs_npm_plugin()