diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index bf3cc86b4e..d729a52247 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -49,7 +49,6 @@ stardoc( "node_modules_aspect", "NodeRuntimeDepsInfo", "run_node", - "NpmPackageInfo", ], tags = ["fix-windows"], deps = [ diff --git a/docs/Built-ins.md b/docs/Built-ins.md index 8a7a5905eb..c650ec4a31 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -13,6 +13,37 @@ via the `WORKSPACE` install of the `build_bazel_rules_nodejs` workspace. This is necessary to bootstrap Bazel to run the package manager to download other rules from NPM. +## directory_file_path + +**USAGE** + +
+directory_file_path(name, directory, path)
+
+ +Provide DirectoryFilePathInfo to reference some file within a directory. + + Otherwise there is no way to give a Bazel label for it. + +**ATTRIBUTES** + + +

name

+ +(*Name, mandatory*): A unique name for this target. + + +

directory

+ +(*Label, mandatory*): a directory + + +

path

+ +(*String, mandatory*): a path within that directory + + + ## nodejs_binary **USAGE** @@ -1557,6 +1588,118 @@ Defaults to `@yarn//:bin/yarn` +## DeclarationInfo + +**USAGE** + +
+DeclarationInfo(declarations, transitive_declarations, type_blocklisted_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_blocklisted_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 + + +## 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 + + +## 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/-/bin/path/to/package` or +`bazel-out/-/bin/external/external_wksp>/path/to/package` + +or a source file path such as, + +`path/to/package` or +`external//path/to/package` + + ## copy_to_bin **USAGE** @@ -1599,6 +1742,32 @@ further keyword arguments, e.g. `visibility` +## 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_library **USAGE** @@ -1714,6 +1883,32 @@ Other attributes +## js_module_info + +**USAGE** + +
+js_module_info(sources, deps)
+
+ +Constructs a JSModuleInfo including all transitive sources from JSModuleInfo providers in a list of deps. + +**PARAMETERS** + + +

sources

+ +direct JS files + + + +

deps

+ +other targets that provide JSModuleInfo, typically from the deps attribute + +Defaults to `[]` + + ## npm_package_bin **USAGE** diff --git a/docs/Core.md b/docs/Core.md index ecf9aa6aa7..6c3b015126 100644 --- a/docs/Core.md +++ b/docs/Core.md @@ -21,37 +21,6 @@ Most features, such as `npm_install` and `nodejs_binary` are still in the `build We plan to clean these up and port into `rules_nodejs` in a future major release. -## directory_file_path - -**USAGE** - -
-directory_file_path(name, directory, path)
-
- -Provide DirectoryFilePathInfo to reference some file within a directory. - - Otherwise there is no way to give a Bazel label for it. - -**ATTRIBUTES** - - -

name

- -(*Name, mandatory*): A unique name for this target. - - -

directory

- -(*Label, mandatory*): a directory - - -

path

- -(*String, mandatory*): a path within that directory - - - ## node_repositories **USAGE** @@ -379,118 +348,6 @@ Defaults to `["https://github.com/yarnpkg/yarn/releases/download/v{version}/{fil Defaults to `"1.22.11"` -## DeclarationInfo - -**USAGE** - -
-DeclarationInfo(declarations, transitive_declarations, type_blocklisted_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_blocklisted_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 - - -## 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 - - -## 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/-/bin/path/to/package` or -`bazel-out/-/bin/external/external_wksp>/path/to/package` - -or a source file path such as, - -`path/to/package` or -`external//path/to/package` - - ## UserBuildSettingInfo **USAGE** @@ -508,55 +365,3 @@ UserBuildSettingInfo(value) (Undocumented) -## 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_module_info - -**USAGE** - -
-js_module_info(sources, deps)
-
- -Constructs a JSModuleInfo including all transitive sources from JSModuleInfo providers in a list of deps. - -**PARAMETERS** - - -

sources

- -direct JS files - - - -

deps

- -other targets that provide JSModuleInfo, typically from the deps attribute - -Defaults to `[]` - - diff --git a/docs/Providers.md b/docs/Providers.md index 160798b126..8037967095 100755 --- a/docs/Providers.md +++ b/docs/Providers.md @@ -7,8 +7,6 @@ Public providers, aspects and helpers that are shipped in the built-in build_bazel_rules_nodejs repository. -Note that many providers have moved to the rules_nodejs "core" package. See [Core API doc](./Core.md) - Users should not load files under "/internal" @@ -124,32 +122,6 @@ do the same. list of labels of packages that provide ExternalNpmPackageInfo -## NpmPackageInfo - -**USAGE** - -
-NpmPackageInfo(direct_sources, 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) -

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 - - ## js_ecma_script_module_info **USAGE** diff --git a/index.for_docs.bzl b/index.for_docs.bzl index cc5fe42686..b5c3712970 100644 --- a/index.for_docs.bzl +++ b/index.for_docs.bzl @@ -40,3 +40,11 @@ npm_install = _npm_install yarn_install = _yarn_install npm_package_bin = _npm_bin js_library = _js_library + +DeclarationInfo = _DeclarationInfo +declaration_info = _declaration_info +directory_file_path = _directory_file_path +JSModuleInfo = _JSModuleInfo +js_module_info = _js_module_info +LinkablePackageInfo = _LinkablePackageInfo +DirectoryFilePathInfo = _DirectoryFilePathInfo diff --git a/internal/common/maybe_directory_file_path.bzl b/internal/common/maybe_directory_file_path.bzl index dd76d25f57..c37c79711d 100644 --- a/internal/common/maybe_directory_file_path.bzl +++ b/internal/common/maybe_directory_file_path.bzl @@ -15,7 +15,7 @@ """Helper function to accept either a label or a directory_file_path as dict """ -load("@rules_nodejs//nodejs:directory_file_path.bzl", "directory_file_path") +load("//internal/providers:directory_file_path.bzl", "directory_file_path") def maybe_directory_file_path(name, value): """Pass-through a value or convert a dict with a single key/value pair to a directory_file_path and return its label diff --git a/internal/js_library/js_library.bzl b/internal/js_library/js_library.bzl index f175c1df63..c3604f2d18 100644 --- a/internal/js_library/js_library.bzl +++ b/internal/js_library/js_library.bzl @@ -14,20 +14,17 @@ "js_library can be used to expose and share any library package." -load( - "@rules_nodejs//nodejs:providers.bzl", - "DeclarationInfo", - "JSModuleInfo", - "LinkablePackageInfo", - "declaration_info", - "js_module_info", -) load( "//:providers.bzl", + "DeclarationInfo", "ExternalNpmPackageInfo", "JSEcmaScriptModuleInfo", + "JSModuleInfo", "JSNamedModuleInfo", + "LinkablePackageInfo", + "declaration_info", "js_ecma_script_module_info", + "js_module_info", "js_named_module_info", ) load("//internal/common:is_js_file.bzl", "is_javascript_file") diff --git a/internal/js_library/test/transitive/transitive_declarations_test.bzl b/internal/js_library/test/transitive/transitive_declarations_test.bzl index 1954591864..1470138ad2 100644 --- a/internal/js_library/test/transitive/transitive_declarations_test.bzl +++ b/internal/js_library/test/transitive/transitive_declarations_test.bzl @@ -1,7 +1,7 @@ "Unit tests for js_library rule" load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") -load("@rules_nodejs//nodejs:providers.bzl", "DeclarationInfo") +load("//internal/providers:declaration_info.bzl", "DeclarationInfo") def _impl(ctx): env = unittest.begin(ctx) diff --git a/internal/linker/link_node_modules.bzl b/internal/linker/link_node_modules.bzl index c04e109e3b..f29439f70e 100644 --- a/internal/linker/link_node_modules.bzl +++ b/internal/linker/link_node_modules.bzl @@ -12,7 +12,7 @@ runtimes to locate all the first-party packages. # Can't load from //:providers.bzl directly as that introduces a circular dep load("//internal/providers:external_npm_package_info.bzl", "ExternalNpmPackageInfo") -load("@rules_nodejs//nodejs:providers.bzl", "LinkablePackageInfo") +load("//internal/providers:linkable_package_info.bzl", "LinkablePackageInfo") def _debug(vars, format, args_tuple): if "VERBOSE_LOGS" in vars.keys(): diff --git a/internal/linker/npm_link.bzl b/internal/linker/npm_link.bzl index 29a4b65610..35b33fdc1e 100644 --- a/internal/linker/npm_link.bzl +++ b/internal/linker/npm_link.bzl @@ -20,16 +20,13 @@ provides a LinkablePackageInfo. If a target already provides a package_name, the package_name set here must match. """ -load( - "@rules_nodejs//nodejs:providers.bzl", - "DeclarationInfo", - "JSModuleInfo", - "LinkablePackageInfo", -) load( "//:providers.bzl", + "DeclarationInfo", "ExternalNpmPackageInfo", + "JSModuleInfo", "JSNamedModuleInfo", + "LinkablePackageInfo", ) load( "//third_party/github.com/bazelbuild/bazel-skylib:rules/private/copy_file_private.bzl", diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 30a734a50d..a4d523634d 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -20,8 +20,8 @@ They support module mapping: any targets in the transitive dependencies with a `module_name` attribute can be `require`d by that name. """ -load("@rules_nodejs//nodejs:providers.bzl", "DirectoryFilePathInfo", "JSModuleInfo", "UserBuildSettingInfo") -load("//:providers.bzl", "ExternalNpmPackageInfo", "JSNamedModuleInfo", "NodeRuntimeDepsInfo", "node_modules_aspect") +load("@rules_nodejs//nodejs:providers.bzl", "UserBuildSettingInfo") +load("//:providers.bzl", "DirectoryFilePathInfo", "ExternalNpmPackageInfo", "JSModuleInfo", "JSNamedModuleInfo", "NodeRuntimeDepsInfo", "node_modules_aspect") load("//internal/common:expand_into_runfiles.bzl", "expand_location_into_runfiles") load("//internal/common:is_js_file.bzl", "is_javascript_file") load("//internal/common:maybe_directory_file_path.bzl", "maybe_directory_file_path") diff --git a/internal/node/npm_package_bin.bzl b/internal/node/npm_package_bin.bzl index 6e1c0087c4..4c5c06123c 100644 --- a/internal/node/npm_package_bin.bzl +++ b/internal/node/npm_package_bin.bzl @@ -1,7 +1,7 @@ "A generic rule to run a tool that appears in node_modules/.bin" -load("@rules_nodejs//nodejs:providers.bzl", "DeclarationInfo", "JSModuleInfo", "STAMP_ATTR") -load("//:providers.bzl", "ExternalNpmPackageInfo", "node_modules_aspect", "run_node") +load("@rules_nodejs//nodejs:providers.bzl", "STAMP_ATTR") +load("//:providers.bzl", "DeclarationInfo", "ExternalNpmPackageInfo", "JSModuleInfo", "node_modules_aspect", "run_node") load("//internal/common:expand_variables.bzl", "expand_variables") load("//internal/linker:link_node_modules.bzl", "module_mappings_aspect") diff --git a/internal/node/test/dir_entry_point/BUILD.bazel b/internal/node/test/dir_entry_point/BUILD.bazel index d1e19bf220..2bdb823396 100644 --- a/internal/node/test/dir_entry_point/BUILD.bazel +++ b/internal/node/test/dir_entry_point/BUILD.bazel @@ -1,5 +1,5 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file") -load("@rules_nodejs//nodejs:directory_file_path.bzl", "directory_file_path") +load("//internal/providers:directory_file_path.bzl", "directory_file_path") load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "pkg_npm") load("@npm//typescript:index.bzl", "tsc") load("//internal/common:assert.bzl", "assert_program_produces_stdout") diff --git a/internal/npm_install/npm_umd_bundle.bzl b/internal/npm_install/npm_umd_bundle.bzl index 173e6c6167..f245ef2260 100644 --- a/internal/npm_install/npm_umd_bundle.bzl +++ b/internal/npm_install/npm_umd_bundle.bzl @@ -17,8 +17,7 @@ For use by yarn_install and npm_install. Not meant to be part of the public API. """ -load("@rules_nodejs//nodejs:providers.bzl", "DirectoryFilePathInfo", "LinkablePackageInfo") -load("//:providers.bzl", "ExternalNpmPackageInfo", "node_modules_aspect") +load("//:providers.bzl", "DirectoryFilePathInfo", "ExternalNpmPackageInfo", "LinkablePackageInfo", "node_modules_aspect") load("//internal/common:maybe_directory_file_path.bzl", "maybe_directory_file_path") def _entry_point_path(ctx): diff --git a/internal/pkg_npm/pkg_npm.bzl b/internal/pkg_npm/pkg_npm.bzl index d67b09182a..442d910559 100644 --- a/internal/pkg_npm/pkg_npm.bzl +++ b/internal/pkg_npm/pkg_npm.bzl @@ -6,8 +6,8 @@ If all users of your library code use Bazel, they should just add your library to the `deps` of one of their targets. """ -load("@rules_nodejs//nodejs:providers.bzl", "DeclarationInfo", "JSModuleInfo", "LinkablePackageInfo", "STAMP_ATTR", "StampSettingInfo") -load("//:providers.bzl", "JSEcmaScriptModuleInfo", "JSNamedModuleInfo") +load("@rules_nodejs//nodejs:providers.bzl", "STAMP_ATTR", "StampSettingInfo") +load("//:providers.bzl", "DeclarationInfo", "JSEcmaScriptModuleInfo", "JSModuleInfo", "JSNamedModuleInfo", "LinkablePackageInfo") _DOC = """The pkg_npm rule creates a directory containing a publishable npm artifact. diff --git a/nodejs/private/providers/declaration_info.bzl b/internal/providers/declaration_info.bzl similarity index 100% rename from nodejs/private/providers/declaration_info.bzl rename to internal/providers/declaration_info.bzl diff --git a/nodejs/private/providers/directory_file_path_info.bzl b/internal/providers/directory_file_path.bzl similarity index 90% rename from nodejs/private/providers/directory_file_path_info.bzl rename to internal/providers/directory_file_path.bzl index 8ce59eeafd..713f7038c8 100644 --- a/nodejs/private/providers/directory_file_path_info.bzl +++ b/internal/providers/directory_file_path.bzl @@ -29,8 +29,8 @@ DirectoryFilePathInfo = provider( ) def _directory_file_path(ctx): - if not ctx.file.directory.is_source and not ctx.file.directory.is_directory: - fail("directory attribute must be a source directory or created with Bazel declare_directory (TreeArtifact)") + if not ctx.file.directory.is_directory: + fail("directory attribute must be created with ctx.declare_directory (TreeArtifact)") return [DirectoryFilePathInfo(path = ctx.attr.path, directory = ctx.file.directory)] directory_file_path = rule( diff --git a/internal/providers/js_providers.bzl b/internal/providers/js_providers.bzl index c6e9a9d198..38c9099379 100644 --- a/internal/providers/js_providers.bzl +++ b/internal/providers/js_providers.bzl @@ -94,3 +94,31 @@ def js_ecma_script_module_info(sources, deps = []): direct_sources = sources, sources = depset(transitive = transitive_depsets), ) + +JSModuleInfo = provider( + doc = """JavaScript files and sourcemaps.""", + fields = { + "direct_sources": "Depset of direct JavaScript files and sourcemaps", + "sources": "Depset of direct and transitive JavaScript files and sourcemaps", + }, +) + +def js_module_info(sources, deps = []): + """Constructs a JSModuleInfo including all transitive sources from JSModuleInfo providers in a list of deps. + + Args: + sources: direct JS files + deps: other targets that provide JSModuleInfo, typically from the deps attribute + + Returns: + a single JSModuleInfo. + """ + transitive_depsets = [sources] + for dep in deps: + if JSModuleInfo in dep: + transitive_depsets.append(dep[JSModuleInfo].sources) + + return JSModuleInfo( + direct_sources = sources, + sources = depset(transitive = transitive_depsets), + ) diff --git a/nodejs/private/providers/linkable_package_info.bzl b/internal/providers/linkable_package_info.bzl similarity index 100% rename from nodejs/private/providers/linkable_package_info.bzl rename to internal/providers/linkable_package_info.bzl diff --git a/nodejs/directory_file_path.bzl b/nodejs/directory_file_path.bzl deleted file mode 100644 index 846a1197c5..0000000000 --- a/nodejs/directory_file_path.bzl +++ /dev/null @@ -1,32 +0,0 @@ -"""This module contains providers for working with TreeArtifacts. - -See https://github.com/bazelbuild/bazel-skylib/issues/300 -(this feature could be upstreamed to bazel-skylib in the future) - -These are also called output directories, created by `ctx.actions.declare_directory`. -""" - -load("//nodejs/private/providers:directory_file_path_info.bzl", "DirectoryFilePathInfo") - -def _directory_file_path(ctx): - if not ctx.file.directory.is_directory: - fail("directory attribute must be created with ctx.declare_directory (TreeArtifact)") - return [DirectoryFilePathInfo(path = ctx.attr.path, directory = ctx.file.directory)] - -directory_file_path = rule( - doc = """Provide DirectoryFilePathInfo to reference some file within a directory. - - Otherwise there is no way to give a Bazel label for it.""", - implementation = _directory_file_path, - attrs = { - "directory": attr.label( - doc = "a directory", - mandatory = True, - allow_single_file = True, - ), - "path": attr.string( - doc = "a path within that directory", - mandatory = True, - ), - }, -) diff --git a/nodejs/index.for_docs.bzl b/nodejs/index.for_docs.bzl index 4275c0dd59..d5c1954b6f 100644 --- a/nodejs/index.for_docs.bzl +++ b/nodejs/index.for_docs.bzl @@ -17,26 +17,12 @@ We plan to clean these up and port into `rules_nodejs` in a future major release load( ":providers.bzl", - _DeclarationInfo = "DeclarationInfo", - _DirectoryFilePathInfo = "DirectoryFilePathInfo", - _JSModuleInfo = "JSModuleInfo", - _LinkablePackageInfo = "LinkablePackageInfo", _UserBuildSettingInfo = "UserBuildSettingInfo", - _declaration_info = "declaration_info", - _js_module_info = "js_module_info", ) -load(":directory_file_path.bzl", _directory_file_path = "directory_file_path") load(":repositories.bzl", _node_repositories = "node_repositories") load(":yarn_repositories.bzl", _yarn_repositories = "yarn_repositories") load(":toolchain.bzl", _node_toolchain = "node_toolchain") -DeclarationInfo = _DeclarationInfo -declaration_info = _declaration_info -directory_file_path = _directory_file_path -JSModuleInfo = _JSModuleInfo -js_module_info = _js_module_info -LinkablePackageInfo = _LinkablePackageInfo -DirectoryFilePathInfo = _DirectoryFilePathInfo UserBuildSettingInfo = _UserBuildSettingInfo node_repositories = _node_repositories node_toolchain = _node_toolchain diff --git a/nodejs/private/providers/js_providers.bzl b/nodejs/private/providers/js_providers.bzl deleted file mode 100644 index 99a3139623..0000000000 --- a/nodejs/private/providers/js_providers.bzl +++ /dev/null @@ -1,29 +0,0 @@ -"Pass information about JavaScript modules between rules" - -JSModuleInfo = provider( - doc = """JavaScript files and sourcemaps.""", - fields = { - "direct_sources": "Depset of direct JavaScript files and sourcemaps", - "sources": "Depset of direct and transitive JavaScript files and sourcemaps", - }, -) - -def js_module_info(sources, deps = []): - """Constructs a JSModuleInfo including all transitive sources from JSModuleInfo providers in a list of deps. - - Args: - sources: direct JS files - deps: other targets that provide JSModuleInfo, typically from the deps attribute - - Returns: - a single JSModuleInfo. - """ - transitive_depsets = [sources] - for dep in deps: - if JSModuleInfo in dep: - transitive_depsets.append(dep[JSModuleInfo].sources) - - return JSModuleInfo( - direct_sources = sources, - sources = depset(transitive = transitive_depsets), - ) diff --git a/nodejs/providers.bzl b/nodejs/providers.bzl index 237cf1ae5b..170a0f759e 100644 --- a/nodejs/providers.bzl +++ b/nodejs/providers.bzl @@ -1,23 +1,5 @@ "Public providers, aspects and helpers that are shipped in the built-in rules_nodejs repository." -load( - "//nodejs/private/providers:declaration_info.bzl", - _DeclarationInfo = "DeclarationInfo", - _declaration_info = "declaration_info", -) -load( - "//nodejs/private/providers:js_providers.bzl", - _JSModuleInfo = "JSModuleInfo", - _js_module_info = "js_module_info", -) -load( - "//nodejs/private/providers:linkable_package_info.bzl", - _LinkablePackageInfo = "LinkablePackageInfo", -) -load( - "//nodejs/private/providers:directory_file_path_info.bzl", - _DirectoryFilePathInfo = "DirectoryFilePathInfo", -) load( "//nodejs/private/providers:user_build_settings.bzl", _UserBuildSettingInfo = "UserBuildSettingInfo", @@ -28,12 +10,6 @@ load( _StampSettingInfo = "StampSettingInfo", ) -DeclarationInfo = _DeclarationInfo -declaration_info = _declaration_info -JSModuleInfo = _JSModuleInfo -js_module_info = _js_module_info -LinkablePackageInfo = _LinkablePackageInfo -DirectoryFilePathInfo = _DirectoryFilePathInfo UserBuildSettingInfo = _UserBuildSettingInfo StampSettingInfo = _StampSettingInfo STAMP_ATTR = _STAMP_ATTR diff --git a/providers.bzl b/providers.bzl index 796876b046..93e76a01fe 100644 --- a/providers.bzl +++ b/providers.bzl @@ -15,21 +15,35 @@ """ Public providers, aspects and helpers that are shipped in the built-in build_bazel_rules_nodejs repository. -Note that many providers have moved to the rules_nodejs "core" package. See [Core API doc](./Core.md) - Users should not load files under "/internal" """ +load( + "//internal/providers:declaration_info.bzl", + _DeclarationInfo = "DeclarationInfo", + _declaration_info = "declaration_info", +) +load( + "//internal/providers:directory_file_path.bzl", + _DirectoryFilePathInfo = "DirectoryFilePathInfo", + _directory_file_path = "directory_file_path", +) load( "//internal/providers:external_npm_package_info.bzl", _ExternalNpmPackageInfo = "ExternalNpmPackageInfo", _node_modules_aspect = "node_modules_aspect", ) +load( + "//internal/providers:linkable_package_info.bzl", + _LinkablePackageInfo = "LinkablePackageInfo", +) load( "//internal/providers:js_providers.bzl", _JSEcmaScriptModuleInfo = "JSEcmaScriptModuleInfo", + _JSModuleInfo = "JSModuleInfo", _JSNamedModuleInfo = "JSNamedModuleInfo", _js_ecma_script_module_info = "js_ecma_script_module_info", + _js_module_info = "js_module_info", _js_named_module_info = "js_named_module_info", ) load( @@ -38,35 +52,18 @@ load( _run_node = "run_node", ) -# TODO(6.0): remove these re-exports, they are just for easier migration to 5.0.0 -# This includes everything from -# https://github.com/bazelbuild/rules_nodejs/blob/4.x/providers.bzl -# which wasn't removed in 5.0 (NodeContextInfo, NODE_CONTEXT_ATTRS) -load( - "@rules_nodejs//nodejs:providers.bzl", - _DeclarationInfo = "DeclarationInfo", - _DirectoryFilePathInfo = "DirectoryFilePathInfo", - _JSModuleInfo = "JSModuleInfo", - _LinkablePackageInfo = "LinkablePackageInfo", - _declaration_info = "declaration_info", -) - DeclarationInfo = _DeclarationInfo declaration_info = _declaration_info -JSModuleInfo = _JSModuleInfo -LinkablePackageInfo = _LinkablePackageInfo DirectoryFilePathInfo = _DirectoryFilePathInfo - +directory_file_path = _directory_file_path ExternalNpmPackageInfo = _ExternalNpmPackageInfo -js_ecma_script_module_info = _js_ecma_script_module_info -js_named_module_info = _js_named_module_info JSEcmaScriptModuleInfo = _JSEcmaScriptModuleInfo +js_ecma_script_module_info = _js_ecma_script_module_info +JSModuleInfo = _JSModuleInfo +js_module_info = _js_module_info JSNamedModuleInfo = _JSNamedModuleInfo +js_named_module_info = _js_named_module_info +LinkablePackageInfo = _LinkablePackageInfo node_modules_aspect = _node_modules_aspect NodeRuntimeDepsInfo = _NodeRuntimeDepsInfo run_node = _run_node - -# Export NpmPackageInfo for pre-3.0 legacy support in downstream rule sets -# such as rules_docker -# TODO(6.0): remove NpmPackageInfo from rules_docker & then remove it here -NpmPackageInfo = _ExternalNpmPackageInfo