Skip to content

Commit 7f688a9

Browse files
authored
Core providers (bazel-contrib#2934)
* refactor: move some providers to new core package these are the ones we know we want to keep, and will need them to continue building a usable core package with linking and some basic rules working.
1 parent 20f4a8f commit 7f688a9

16 files changed

+137
-435
lines changed

BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ bzl_library(
5454
"//internal/pkg_npm:bzl",
5555
"//internal/pkg_web:bzl",
5656
"//internal/providers:bzl",
57+
"//nodejs/private/providers:bzl",
5758
],
5859
)
5960

@@ -94,6 +95,7 @@ pkg_npm(
9495
"//internal/providers:package_contents",
9596
"//internal/runfiles:package_contents",
9697
"//nodejs:package_contents",
98+
"//nodejs/private/providers:package_contents",
9799
"//third_party/github.com/bazelbuild/bazel:package_contents",
98100
"//third_party/github.com/bazelbuild/bazel-skylib:package_contents",
99101
"//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles:package_contents",
@@ -129,6 +131,8 @@ pkg_tar(
129131
srcs = [
130132
"LICENSE",
131133
"README.md",
134+
"providers.bzl",
135+
"version.bzl",
132136
"//nodejs:package_contents",
133137
# TODO(5.0) remove this and depend on real skylib
134138
"//third_party/github.com/bazelbuild/bazel-skylib:package_contents",

docs/Cypress.html

Lines changed: 0 additions & 403 deletions
This file was deleted.

docs/Providers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Provides data about the build context, like config_setting's
218218

219219
<h4 id="NodeContextInfo-stamp">stamp</h4>
220220

221-
If stamping is enabled
221+
If stamping is enabled for this build
222222

223223

224224
## NodeRuntimeDepsInfo

index.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ load("//internal/npm_install:npm_install.bzl", _npm_install = "npm_install", _ya
3535
load("//internal/pkg_npm:pkg_npm.bzl", _pkg_npm = "pkg_npm_macro")
3636
load("//internal/pkg_web:pkg_web.bzl", _pkg_web = "pkg_web")
3737
load(
38-
"//internal/providers:tree_artifacts.bzl",
38+
"//nodejs/private/providers:directory_file_path_info.bzl",
3939
_directory_file_path = "directory_file_path",
4040
)
4141

internal/common/maybe_directory_file_path.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Helper function to accept either a label or a directory_file_path as dict
1616
"""
1717

18-
load("//internal/providers:tree_artifacts.bzl", "directory_file_path")
18+
load("//nodejs/private/providers:directory_file_path_info.bzl", "directory_file_path")
1919

2020
def maybe_directory_file_path(name, value):
2121
"""Pass-through a value or convert a dict with a single key/value pair to a directory_file_path and return its label

internal/linker/link_node_modules.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ runtimes to locate all the first-party packages.
1212

1313
# Can't load from //:providers.bzl directly as that introduces a circular dep
1414
load("//internal/providers:external_npm_package_info.bzl", "ExternalNpmPackageInfo")
15-
load("//internal/providers:linkable_package_info.bzl", "LinkablePackageInfo")
15+
load("//nodejs/private/providers:linkable_package_info.bzl", "LinkablePackageInfo")
1616

1717
def _debug(vars, *args):
1818
if "VERBOSE_LOGS" in vars.keys():

internal/providers/node_context.bzl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Provide rules access to the config of the current build
2+
3+
Modelled after _GoContextData in rules_go/go/private/context.bzl
4+
"""
5+
6+
NodeContextInfo = provider(
7+
doc = "Provides data about the build context, like config_setting's",
8+
fields = {
9+
"stamp": "If stamping is enabled for this build",
10+
},
11+
)
12+
13+
NODE_CONTEXT_ATTRS = {
14+
"node_context_data": attr.label(
15+
default = "@build_bazel_rules_nodejs//internal:node_context_data",
16+
providers = [NodeContextInfo],
17+
doc = """Provides info about the build context, such as stamping.
18+
19+
By default it reads from the bazel command line, such as the `--stamp` argument.
20+
Use this to override values for this target, such as enabling or disabling stamping.
21+
You can use the `node_context_data` rule in `@build_bazel_rules_nodejs//internal/node:context.bzl`
22+
to create a NodeContextInfo.
23+
""",
24+
),
25+
}

nodejs/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

33
filegroup(
44
name = "package_contents",
5-
srcs = glob(["*"]) + ["//nodejs/private:package_contents"],
5+
srcs = glob(["*"]) + [
6+
"//nodejs/private:package_contents",
7+
],
68
visibility = ["//:__pkg__"],
79
)
810

nodejs/private/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

33
filegroup(
44
name = "package_contents",
5-
srcs = glob(["*"]),
5+
srcs = glob(["*"]) + [
6+
"//nodejs/private/providers:package_contents",
7+
],
68
visibility = ["//nodejs:__pkg__"],
79
)
810

nodejs/private/providers/BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2017 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16+
17+
bzl_library(
18+
name = "bzl",
19+
srcs = glob(["*.bzl"]),
20+
visibility = ["//visibility:public"],
21+
)
22+
23+
filegroup(
24+
name = "package_contents",
25+
srcs = glob(["*.bzl"]) + [
26+
"BUILD.bazel",
27+
],
28+
visibility = ["//:__subpackages__"],
29+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"Pass information about JavaScript modules between rules"
2+
3+
JSModuleInfo = provider(
4+
doc = """JavaScript files and sourcemaps.""",
5+
fields = {
6+
"direct_sources": "Depset of direct JavaScript files and sourcemaps",
7+
"sources": "Depset of direct and transitive JavaScript files and sourcemaps",
8+
},
9+
)
10+
11+
def js_module_info(sources, deps = []):
12+
"""Constructs a JSModuleInfo including all transitive sources from JSModuleInfo providers in a list of deps.
13+
14+
Args:
15+
sources: direct JS files
16+
deps: other targets that provide JSModuleInfo, typically from the deps attribute
17+
18+
Returns:
19+
a single JSModuleInfo.
20+
"""
21+
transitive_depsets = [sources]
22+
for dep in deps:
23+
if JSModuleInfo in dep:
24+
transitive_depsets.append(dep[JSModuleInfo].sources)
25+
26+
return JSModuleInfo(
27+
direct_sources = sources,
28+
sources = depset(transitive = transitive_depsets),
29+
)

nodejs/providers.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Public providers, aspects and helpers that are shipped in the built-in rules_nodejs repository.
3+
"""
4+
5+
load(
6+
"//nodejs/private/providers:declaration_info.bzl",
7+
_DeclarationInfo = "DeclarationInfo",
8+
_declaration_info = "declaration_info",
9+
)
10+
load(
11+
"//nodejs/private/providers:js_providers.bzl",
12+
_JSModuleInfo = "JSModuleInfo",
13+
_js_module_info = "js_module_info",
14+
)
15+
load(
16+
"//nodejs/private/providers:linkable_package_info.bzl",
17+
_LinkablePackageInfo = "LinkablePackageInfo",
18+
)
19+
load(
20+
"//nodejs/private/providers:directory_file_path_info.bzl",
21+
_DirectoryFilePathInfo = "DirectoryFilePathInfo",
22+
)
23+
24+
DeclarationInfo = _DeclarationInfo
25+
declaration_info = _declaration_info
26+
JSModuleInfo = _JSModuleInfo
27+
js_module_info = _js_module_info
28+
LinkablePackageInfo = _LinkablePackageInfo
29+
DirectoryFilePathInfo = _DirectoryFilePathInfo

providers.bzl

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Users should not load files under "/internal"
1919
"""
2020

2121
load(
22-
"//internal/providers:declaration_info.bzl",
22+
"//nodejs/private/providers:declaration_info.bzl",
2323
_DeclarationInfo = "DeclarationInfo",
2424
_declaration_info = "declaration_info",
2525
)
@@ -38,7 +38,7 @@ load(
3838
_js_named_module_info = "js_named_module_info",
3939
)
4040
load(
41-
"//internal/providers:linkable_package_info.bzl",
41+
"//nodejs/private/providers:linkable_package_info.bzl",
4242
_LinkablePackageInfo = "LinkablePackageInfo",
4343
)
4444
load(
@@ -47,9 +47,17 @@ load(
4747
_run_node = "run_node",
4848
)
4949
load(
50-
"//internal/providers:tree_artifacts.bzl",
50+
"//nodejs/private/providers:directory_file_path_info.bzl",
5151
_DirectoryFilePathInfo = "DirectoryFilePathInfo",
5252
)
53+
load(
54+
"//internal/providers:node_context.bzl",
55+
_NODE_CONTEXT_ATTRS = "NODE_CONTEXT_ATTRS",
56+
_NodeContextInfo = "NodeContextInfo",
57+
)
58+
59+
NodeContextInfo = _NodeContextInfo
60+
NODE_CONTEXT_ATTRS = _NODE_CONTEXT_ATTRS
5361

5462
DeclarationInfo = _DeclarationInfo
5563
declaration_info = _declaration_info
@@ -67,29 +75,6 @@ ExternalNpmPackageInfo = _ExternalNpmPackageInfo
6775
NpmPackageInfo = _ExternalNpmPackageInfo
6876
node_modules_aspect = _node_modules_aspect
6977
LinkablePackageInfo = _LinkablePackageInfo
70-
71-
#Modelled after _GoContextData in rules_go/go/private/context.bzl
72-
NodeContextInfo = provider(
73-
doc = "Provides data about the build context, like config_setting's",
74-
fields = {
75-
"stamp": "If stamping is enabled",
76-
},
77-
)
78-
79-
NODE_CONTEXT_ATTRS = {
80-
"node_context_data": attr.label(
81-
default = "@build_bazel_rules_nodejs//internal:node_context_data",
82-
providers = [NodeContextInfo],
83-
doc = """Provides info about the build context, such as stamping.
84-
85-
By default it reads from the bazel command line, such as the `--stamp` argument.
86-
Use this to override values for this target, such as enabling or disabling stamping.
87-
You can use the `node_context_data` rule in `@build_bazel_rules_nodejs//internal/node:context.bzl`
88-
to create a NodeContextInfo.
89-
""",
90-
),
91-
}
92-
9378
NodeRuntimeDepsInfo = _NodeRuntimeDepsInfo
9479
run_node = _run_node
9580
DirectoryFilePathInfo = _DirectoryFilePathInfo

0 commit comments

Comments
 (0)