From 4fe1a170e588e0002b2addb9617dc415ab43c5fa Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Mon, 17 Aug 2020 21:19:27 +0100 Subject: [PATCH] feat(builtin): new js_library rule (#2109) Removes `node_module_library` private API and renames it to `js_library` the latter will be promoted to a public API in a followup change --- WORKSPACE | 6 +- internal/js_library/js_library.bzl | 195 ++++++++++++++---- internal/node/test/lib2/BUILD.bazel | 4 +- internal/npm_install/generate_build_file.ts | 27 ++- internal/npm_install/index.js | 18 +- internal/npm_install/node_module_library.bzl | 105 ---------- .../golden/@angular/core/BUILD.bazel.golden | 8 +- .../golden/@gregmagolan/BUILD.bazel.golden | 4 +- .../@gregmagolan/test-a/BUILD.bazel.golden | 8 +- .../@gregmagolan/test-b/BUILD.bazel.golden | 8 +- .../test/golden/BUILD.bazel.golden | 4 +- .../test/golden/ajv/BUILD.bazel.golden | 8 +- .../test/golden/jasmine/BUILD.bazel.golden | 8 +- .../test/golden/rxjs/BUILD.bazel.golden | 8 +- .../test/golden/unidiff/BUILD.bazel.golden | 8 +- .../test/golden/zone.js/BUILD.bazel.golden | 8 +- internal/npm_install/test/package/BUILD.bazel | 6 +- internal/providers/npm_package_info.bzl | 4 +- packages/jasmine/BUILD.bazel | 19 +- packages/labs/grpc_web/BUILD.bazel | 2 +- .../rollup/test/integration/far/a/BUILD.bazel | 2 +- .../test/integration/far/a/b/c/BUILD.bazel | 2 +- packages/typescript/internal/ts_project.bzl | 3 +- 23 files changed, 249 insertions(+), 216 deletions(-) delete mode 100644 internal/npm_install/node_module_library.bzl diff --git a/WORKSPACE b/WORKSPACE index a24b2aa0d4..d345a1de80 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -51,9 +51,9 @@ yarn_install( # The @npm//:node_modules_filegroup generated by manual_build_file_contents # is used in the //packages/typescript/test/reference_types_directive:tsconfig_types # test. For now we're still supporting node_modules as a filegroup tho this may - # change in the future. The default generated //:node_modules target is a node_module_library - # rule which provides NpmPackageInfo but that rule is not yet in the public API and we - # have not yet dropped support for filegroup based node_modules target. + # change in the future. The default generated //:node_modules target is a js_library + # rule which provides NpmPackageInfo but we have not yet dropped support for + # filegroup based node_modules target. manual_build_file_contents = """ filegroup( name = "node_modules_filegroup", diff --git a/internal/js_library/js_library.bzl b/internal/js_library/js_library.bzl index e8054658dc..e023fd2653 100644 --- a/internal/js_library/js_library.bzl +++ b/internal/js_library/js_library.bzl @@ -12,13 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""js_library allows defining a set of javascript sources and assigning a package_name. +"""js_library can be used to expose and share any library package. -DO NOT USE - this is not fully designed, and exists only to enable testing within this repo. +DO NOT USE - this is not fully designed yet and it is a work in progress. """ -load("//:providers.bzl", "LinkablePackageInfo", "declaration_info", "js_module_info") -load("//third_party/github.com/bazelbuild/bazel-skylib:rules/private/copy_file_private.bzl", "copy_bash", "copy_cmd") +load( + "//:providers.bzl", + "DeclarationInfo", + "JSModuleInfo", + "JSNamedModuleInfo", + "LinkablePackageInfo", + "NpmPackageInfo", + "declaration_info", + "js_module_info", + "js_named_module_info", +) +load( + "//third_party/github.com/bazelbuild/bazel-skylib:rules/private/copy_file_private.bzl", + "copy_bash", + "copy_cmd", +) _AMD_NAMES_DOC = """Mapping from require module names to global variables. This allows devmode JS sources to load unnamed UMD bundles from third-party libraries.""" @@ -50,39 +64,111 @@ def write_amd_names_shim(actions, amd_names_shim, targets): actions.write(amd_names_shim, amd_names_shim_content) def _impl(ctx): - files = [] + input_files = ctx.files.srcs + ctx.files.named_module_srcs + all_files = [] typings = [] js_files = [] + named_module_files = [] + include_npm_package_info = False - for src in ctx.files.srcs: - if src.is_source and not src.path.startswith("external/"): - dst = ctx.actions.declare_file(src.basename, sibling = src) + for idx, f in enumerate(input_files): + file = f + + # copy files into bin if needed + if file.is_source and not file.path.startswith("external/"): + dst = ctx.actions.declare_file(file.basename, sibling = file) if ctx.attr.is_windows: - copy_cmd(ctx, src, dst) - else: - copy_bash(ctx, src, dst) - if dst.basename.endswith(".d.ts"): - typings.append(dst) + copy_cmd(ctx, file, dst) else: - files.append(dst) - elif src.basename.endswith(".d.ts"): - typings.append(src) - else: - files.append(src) + copy_bash(ctx, file, dst) + + # re-assign file to the one now copied into the bin folder + file = dst + + # register js files + if file.basename.endswith(".js") or file.basename.endswith(".js.map") or file.basename.endswith(".json"): + js_files.append(file) + + # register typings + if ( + ( + file.path.endswith(".d.ts") or + file.path.endswith(".d.ts.map") or + # package.json may be required to resolve "typings" key + file.path.endswith("/package.json") + ) and + # exclude eg. external/npm/node_modules/protobufjs/node_modules/@types/node/index.d.ts + # these would be duplicates of the typings provided directly in another dependency. + # also exclude all /node_modules/typescript/lib/lib.*.d.ts files as these are determined by + # the tsconfig "lib" attribute + len(file.path.split("/node_modules/")) < 3 and file.path.find("/node_modules/typescript/lib/lib.") == -1 + ): + typings.append(file) - for p in files: - if p.basename.endswith(".js") or p.basename.endswith(".js.map") or p.basename.endswith(".json"): - js_files.append(p) + # auto detect if it entirely an npm package + # + # NOTE: it probably can be removed once we support node_modules from more than + # a single workspace + if file.is_source and file.path.startswith("external/"): + # We cannot always expose the NpmPackageInfo as the linker + # only allow us to reference node modules from a single workspace at a time. + # Here we are automatically decide if we should or not including that provider + # by running through the sources and check if we have a src coming from an external + # workspace which indicates we should include the provider. + include_npm_package_info = True - files_depset = depset(files) + # ctx.files.named_module_srcs are merged after ctx.files.srcs + if idx >= len(ctx.files.srcs): + named_module_files.append(file) + + # every single file on bin should be added here + all_files.append(file) + + files_depset = depset(all_files) + js_files_depset = depset(js_files) + named_module_files_depset = depset(named_module_files) + typings_depset = depset(typings) + + files_depsets = [files_depset] + npm_sources_depsets = [files_depset] + direct_sources_depsets = [files_depset] + direct_named_module_sources_depsets = [named_module_files_depset] + typings_depsets = [typings_depset] + js_files_depsets = [js_files_depset] + + for dep in ctx.attr.deps: + if NpmPackageInfo in dep: + npm_sources_depsets.append(dep[NpmPackageInfo].sources) + else: + if JSModuleInfo in dep: + js_files_depsets.append(dep[JSModuleInfo].direct_sources) + direct_sources_depsets.append(dep[JSModuleInfo].direct_sources) + if JSNamedModuleInfo in dep: + direct_named_module_sources_depsets.append(dep[JSNamedModuleInfo].direct_sources) + direct_sources_depsets.append(dep[JSNamedModuleInfo].direct_sources) + if DeclarationInfo in dep: + typings_depsets.append(dep[DeclarationInfo].declarations) + direct_sources_depsets.append(dep[DeclarationInfo].declarations) + if DefaultInfo in dep: + files_depsets.append(dep[DefaultInfo].files) providers = [ DefaultInfo( - files = files_depset, - runfiles = ctx.runfiles(files = ctx.files.srcs), + files = depset(transitive = files_depsets), + runfiles = ctx.runfiles( + files = all_files, + transitive_files = depset(transitive = files_depsets), + ), ), AmdNamesInfo(names = ctx.attr.amd_names), - js_module_info(depset(js_files)), + js_module_info( + sources = depset(transitive = js_files_depsets), + deps = ctx.attr.deps, + ), + js_named_module_info( + sources = depset(transitive = direct_named_module_sources_depsets), + deps = ctx.attr.deps, + ), ] if ctx.attr.package_name: @@ -90,39 +176,75 @@ def _impl(ctx): providers.append(LinkablePackageInfo( package_name = ctx.attr.package_name, path = path, - files = files_depset, + files = depset(transitive = direct_sources_depsets), + )) + + if include_npm_package_info: + workspace_name = ctx.label.workspace_name if ctx.label.workspace_name else ctx.workspace_name + providers.append(NpmPackageInfo( + direct_sources = depset(transitive = direct_sources_depsets), + sources = depset(transitive = npm_sources_depsets), + workspace = workspace_name, )) # Don't provide DeclarationInfo if there are no typings to provide. # Improves error messaging downstream if DeclarationInfo is required. if len(typings): - providers.append(declaration_info(depset(typings))) + providers.append(declaration_info( + declarations = depset(transitive = typings_depsets), + deps = ctx.attr.deps, + )) return providers _js_library = rule( implementation = _impl, attrs = { - "amd_names": attr.string_dict(doc = _AMD_NAMES_DOC), - "is_windows": attr.bool(mandatory = True, doc = "Automatically set by macro"), + "amd_names": attr.string_dict( + doc = _AMD_NAMES_DOC, + ), + "deps": attr.label_list( + doc = """Transitive dependencies of the package. + It should include fine grained npm dependencies from the sources + or other targets we want to include in the library but also propagate their own deps.""", + ), + "is_windows": attr.bool( + doc = "Automatically set by macro", + mandatory = True, + ), # module_name for legacy ts_library module_mapping support + # which is still being used in a couple of tests # TODO: remove once legacy module_mapping is removed - "module_name": attr.string(), - "package_name": attr.string(), + "module_name": attr.string( + doc = "Internal use only. It will be removed soon.", + ), + "named_module_srcs": attr.label_list( + doc = """A subset of srcs that are javascript named-UMD or + named-AMD for use in rules such as ts_devserver. + They will be copied into the package bin folder if needed.""", + allow_files = True, + ), + "package_name": attr.string( + doc = """Optional package_name that this package may be imported as.""", + ), "srcs": attr.label_list( + doc = """The list of files that comprise the package. + They will be copied into the package bin folder if needed.""", allow_files = True, - mandatory = True, ), }, + doc = "Defines a js_library package", ) def js_library( name, - srcs, + srcs = [], amd_names = {}, package_name = None, + deps = [], + named_module_srcs = [], **kwargs): - """Internal use only. May be published to the public API in a future release.""" + """Internal use only yet. It will be released into a public API in a future release.""" module_name = kwargs.pop("module_name", None) if module_name: fail("use package_name instead of module_name in target //%s:%s" % (native.package_name(), name)) @@ -130,10 +252,13 @@ def js_library( fail("is_windows is set by the js_library macro and should not be set explicitely") _js_library( name = name, - srcs = srcs, amd_names = amd_names, + srcs = srcs, + named_module_srcs = named_module_srcs, + deps = deps, package_name = package_name, # module_name for legacy ts_library module_mapping support + # which is still being used in a couple of tests # TODO: remove once legacy module_mapping is removed module_name = package_name, is_windows = select({ diff --git a/internal/node/test/lib2/BUILD.bazel b/internal/node/test/lib2/BUILD.bazel index 48b0ca52a6..796c867d6e 100644 --- a/internal/node/test/lib2/BUILD.bazel +++ b/internal/node/test/lib2/BUILD.bazel @@ -13,8 +13,10 @@ js_library( name = "lib2", package_name = "lib2", srcs = [ - "main.js", "package.json", "src/some.js", ], + deps = [ + ":tsconfig", + ], ) diff --git a/internal/npm_install/generate_build_file.ts b/internal/npm_install/generate_build_file.ts index 8daf1270ed..425d054c5a 100644 --- a/internal/npm_install/generate_build_file.ts +++ b/internal/npm_install/generate_build_file.ts @@ -17,7 +17,7 @@ /** * @fileoverview This script generates BUILD.bazel files by analyzing * the node_modules folder layed out by yarn or npm. It generates - * fine grained Bazel `node_module_library` targets for each root npm package + * fine grained Bazel `js_library` targets for each root npm package * and all files for that package and its transitive deps are included * in the target. For example, `@//jasmine` would * include all files in the jasmine npm package and all of its @@ -28,7 +28,7 @@ * target will be generated for the `jasmine` binary in the `jasmine` * npm package. * - * Additionally, a `@//:node_modules` `node_module_library` + * Additionally, a `@//:node_modules` `js_library` * is generated that includes all packages under node_modules * as well as the .bin folder. * @@ -158,16 +158,16 @@ function generateRootBuildFile(pkgs: Dep[]) { })}); let buildFile = BUILD_FILE_HEADER + - `load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") + `load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") exports_files([ ${exportsStarlark}]) -# The node_modules directory in one catch-all node_module_library. +# The node_modules directory in one catch-all js_library. # NB: Using this target may have bad performance implications if # there are many files in target. # See https://github.com/bazelbuild/bazel/issues/5153. -node_module_library( +js_library( name = "node_modules",${pkgFilesStarlark}${depsStarlark} ) @@ -861,7 +861,7 @@ function findFile(pkg: Dep, m: string) { } /** - * Given a pkg, return the skylark `node_module_library` targets for the package. + * Given a pkg, return the skylark `js_library` targets for the package. */ function printPackage(pkg: Dep) { function starlarkFiles(attr: string, files: string[], comment: string = '') { @@ -919,8 +919,7 @@ function printPackage(pkg: Dep) { const depsStarlark = deps.map(dep => `"//${dep._dir}:${dep._name}__contents",`).join('\n '); - let result = - `load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") + let result = `load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") # Generated targets for npm package "${pkg._dir}" ${printJson(pkg)} @@ -955,7 +954,7 @@ filegroup( ) # The primary target for this package for use in rule deps -node_module_library( +js_library( name = "${pkg._name}", # direct sources listed for strict deps support srcs = [":${pkg._name}__files"], @@ -967,14 +966,14 @@ node_module_library( ) # Target is used as dep for main targets to prevent circular dependencies errors -node_module_library( +js_library( name = "${pkg._name}__contents", srcs = [":${pkg._name}__files", ":${pkg._name}__nested_node_modules"],${namedSourcesStarlark} visibility = ["//:__subpackages__"], ) # Typings files that are part of the npm package not including nested node_modules -node_module_library( +js_library( name = "${pkg._name}__typings",${dtsStarlark} ) @@ -1137,7 +1136,7 @@ type Dep = { } /** - * Given a scope, return the skylark `node_module_library` target for the scope. + * Given a scope, return the skylark `js_library` target for the scope. */ function printScope(scope: string, pkgs: Dep[]) { pkgs = pkgs.filter(pkg => !pkg._isNested && pkg._dir.startsWith(`${scope}/`)); @@ -1168,10 +1167,10 @@ function printScope(scope: string, pkgs: Dep[]) { ],`; } - return `load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") + return `load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") # Generated target for npm scope ${scope} -node_module_library( +js_library( name = "${scope}",${pkgFilesStarlark}${depsStarlark} ) diff --git a/internal/npm_install/index.js b/internal/npm_install/index.js index 08a3d148c9..042b5131ca 100644 --- a/internal/npm_install/index.js +++ b/internal/npm_install/index.js @@ -80,16 +80,16 @@ function generateRootBuildFile(pkgs) { }); }); let buildFile = BUILD_FILE_HEADER + - `load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") + `load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") exports_files([ ${exportsStarlark}]) -# The node_modules directory in one catch-all node_module_library. +# The node_modules directory in one catch-all js_library. # NB: Using this target may have bad performance implications if # there are many files in target. # See https://github.com/bazelbuild/bazel/issues/5153. -node_module_library( +js_library( name = "node_modules",${pkgFilesStarlark}${depsStarlark} ) @@ -529,7 +529,7 @@ function printPackage(pkg) { ''; const deps = [pkg].concat(pkg._dependencies.filter(dep => dep !== pkg && !dep._isNested)); const depsStarlark = deps.map(dep => `"//${dep._dir}:${dep._name}__contents",`).join('\n '); - let result = `load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") + let result = `load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") # Generated targets for npm package "${pkg._dir}" ${printJson(pkg)} @@ -564,7 +564,7 @@ filegroup( ) # The primary target for this package for use in rule deps -node_module_library( +js_library( name = "${pkg._name}", # direct sources listed for strict deps support srcs = [":${pkg._name}__files"], @@ -576,14 +576,14 @@ node_module_library( ) # Target is used as dep for main targets to prevent circular dependencies errors -node_module_library( +js_library( name = "${pkg._name}__contents", srcs = [":${pkg._name}__files", ":${pkg._name}__nested_node_modules"],${namedSourcesStarlark} visibility = ["//:__subpackages__"], ) # Typings files that are part of the npm package not including nested node_modules -node_module_library( +js_library( name = "${pkg._name}__typings",${dtsStarlark} ) @@ -732,10 +732,10 @@ function printScope(scope, pkgs) { ${list} ],`; } - return `load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") + return `load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") # Generated target for npm scope ${scope} -node_module_library( +js_library( name = "${scope}",${pkgFilesStarlark}${depsStarlark} ) diff --git a/internal/npm_install/node_module_library.bzl b/internal/npm_install/node_module_library.bzl deleted file mode 100644 index ccedaa2f9e..0000000000 --- a/internal/npm_install/node_module_library.bzl +++ /dev/null @@ -1,105 +0,0 @@ -# Copyright 2019 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Contains the node_module_library which is used by yarn_install & npm_install. -""" - -load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "NpmPackageInfo", "js_module_info", "js_named_module_info") - -def _node_module_library_impl(ctx): - workspace_name = ctx.label.workspace_name if ctx.label.workspace_name else ctx.workspace_name - - direct_sources = depset(ctx.files.srcs) - sources_depsets = [direct_sources] - - declarations = depset([ - f - for f in ctx.files.srcs - if ( - f.path.endswith(".d.ts") or - # package.json may be required to resolve "typings" key - f.path.endswith("/package.json") - ) and - # exclude eg. external/npm/node_modules/protobufjs/node_modules/@types/node/index.d.ts - # these would be duplicates of the typings provided directly in another dependency. - # also exclude all /node_modules/typescript/lib/lib.*.d.ts files as these are determined by - # the tsconfig "lib" attribute - len(f.path.split("/node_modules/")) < 3 and f.path.find("/node_modules/typescript/lib/lib.") == -1 - ]) - - transitive_declarations_depsets = [declarations] - - for dep in ctx.attr.deps: - if DeclarationInfo in dep: - transitive_declarations_depsets.append(dep[DeclarationInfo].transitive_declarations) - if NpmPackageInfo in dep: - sources_depsets.append(dep[NpmPackageInfo].sources) - - transitive_declarations = depset(transitive = transitive_declarations_depsets) - - return struct( - typescript = struct( - declarations = declarations, - devmode_manifest = None, - es5_sources = depset(), - es6_sources = depset(), - replay_params = None, - transitive_declarations = transitive_declarations, - transitive_es5_sources = depset(), - transitive_es6_sources = depset(), - tsickle_externs = [], - type_blacklisted_declarations = depset(), - ), - providers = [ - DefaultInfo( - files = direct_sources, - ), - NpmPackageInfo( - direct_sources = direct_sources, - sources = depset(transitive = sources_depsets), - workspace = workspace_name, - ), - DeclarationInfo( - declarations = declarations, - transitive_declarations = transitive_declarations, - type_blacklisted_declarations = depset([]), - ), - js_module_info( - sources = direct_sources, - deps = ctx.attr.deps, - ), - js_named_module_info( - sources = depset(ctx.files.named_module_srcs), - deps = ctx.attr.deps, - ), - ], - ) - -node_module_library = rule( - implementation = _node_module_library_impl, - attrs = { - "deps": attr.label_list( - doc = "Transitive dependencies of the package", - ), - "named_module_srcs": attr.label_list( - doc = "A subset of srcs that are javascript named-UMD or named-AMD for use in rules such as ts_devserver", - allow_files = True, - ), - "srcs": attr.label_list( - doc = "The list of files that comprise the package", - allow_files = True, - ), - }, - doc = "Defines an npm package under node_modules", -) diff --git a/internal/npm_install/test/golden/@angular/core/BUILD.bazel.golden b/internal/npm_install/test/golden/@angular/core/BUILD.bazel.golden index a7fe7c8578..69c034448a 100644 --- a/internal/npm_install/test/golden/@angular/core/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/@angular/core/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "core__files", srcs = [ @@ -678,7 +678,7 @@ filegroup( name = "core__all_files", srcs = [":core__files", ":core__not_files"], ) -node_module_library( +js_library( name = "core", srcs = [":core__files"], deps = [ @@ -688,7 +688,7 @@ node_module_library( "//zone.js:zone.js__contents", ], ) -node_module_library( +js_library( name = "core__contents", srcs = [":core__files", ":core__nested_node_modules"], named_module_srcs = [ @@ -697,7 +697,7 @@ node_module_library( ], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "core__typings", srcs = [ "//:node_modules/@angular/core/core.d.ts", diff --git a/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden b/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden index 0cbf7c526e..573707b275 100644 --- a/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden @@ -1,7 +1,7 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") -node_module_library( +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") +js_library( name = "@gregmagolan", srcs = [ "//@gregmagolan/test-a:test-a__files", diff --git a/internal/npm_install/test/golden/@gregmagolan/test-a/BUILD.bazel.golden b/internal/npm_install/test/golden/@gregmagolan/test-a/BUILD.bazel.golden index e480bc011d..da5e848940 100644 --- a/internal/npm_install/test/golden/@gregmagolan/test-a/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/@gregmagolan/test-a/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "test-a__files", srcs = [ @@ -25,19 +25,19 @@ filegroup( name = "test-a__all_files", srcs = [":test-a__files", ":test-a__not_files"], ) -node_module_library( +js_library( name = "test-a", srcs = [":test-a__files"], deps = [ "//@gregmagolan/test-a:test-a__contents", ], ) -node_module_library( +js_library( name = "test-a__contents", srcs = [":test-a__files", ":test-a__nested_node_modules"], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "test-a__typings", ) load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle") diff --git a/internal/npm_install/test/golden/@gregmagolan/test-b/BUILD.bazel.golden b/internal/npm_install/test/golden/@gregmagolan/test-b/BUILD.bazel.golden index 585d7a324f..53fedd1b2b 100644 --- a/internal/npm_install/test/golden/@gregmagolan/test-b/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/@gregmagolan/test-b/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "test-b__files", srcs = [ @@ -24,19 +24,19 @@ filegroup( name = "test-b__all_files", srcs = [":test-b__files", ":test-b__not_files"], ) -node_module_library( +js_library( name = "test-b", srcs = [":test-b__files"], deps = [ "//@gregmagolan/test-b:test-b__contents", ], ) -node_module_library( +js_library( name = "test-b__contents", srcs = [":test-b__files", ":test-b__nested_node_modules"], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "test-b__typings", ) load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle") diff --git a/internal/npm_install/test/golden/BUILD.bazel.golden b/internal/npm_install/test/golden/BUILD.bazel.golden index 77459dcaa9..a3ff10780c 100644 --- a/internal/npm_install/test/golden/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") exports_files([ "node_modules/ajv/.tonic_example.js", "node_modules/ajv/LICENSE", @@ -4686,7 +4686,7 @@ exports_files([ "node_modules/@gregmagolan/test-b/node_modules/@gregmagolan/test-a/package.json", "node_modules/@gregmagolan/test-b/package.json", ]) -node_module_library( +js_library( name = "node_modules", srcs = [ "//ajv:ajv__files", diff --git a/internal/npm_install/test/golden/ajv/BUILD.bazel.golden b/internal/npm_install/test/golden/ajv/BUILD.bazel.golden index 2b1e5931f4..c3bc98a5d9 100644 --- a/internal/npm_install/test/golden/ajv/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/ajv/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "ajv__files", srcs = [ @@ -108,7 +108,7 @@ filegroup( name = "ajv__all_files", srcs = [":ajv__files", ":ajv__not_files"], ) -node_module_library( +js_library( name = "ajv", srcs = [":ajv__files"], deps = [ @@ -119,12 +119,12 @@ node_module_library( "//json-schema-traverse:json-schema-traverse__contents", ], ) -node_module_library( +js_library( name = "ajv__contents", srcs = [":ajv__files", ":ajv__nested_node_modules"], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "ajv__typings", srcs = [ "//:node_modules/ajv/lib/ajv.d.ts", diff --git a/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden b/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden index 59d80d504b..0d57facd75 100644 --- a/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "jasmine__files", srcs = [ @@ -34,7 +34,7 @@ filegroup( name = "jasmine__all_files", srcs = [":jasmine__files", ":jasmine__not_files"], ) -node_module_library( +js_library( name = "jasmine", srcs = [":jasmine__files"], deps = [ @@ -53,12 +53,12 @@ node_module_library( "//jasmine-core:jasmine-core__contents", ], ) -node_module_library( +js_library( name = "jasmine__contents", srcs = [":jasmine__files", ":jasmine__nested_node_modules"], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "jasmine__typings", ) load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle") diff --git a/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden b/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden index 20edd2b0f6..d12907f8ca 100644 --- a/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "rxjs__files", srcs = [ @@ -3627,7 +3627,7 @@ filegroup( name = "rxjs__all_files", srcs = [":rxjs__files", ":rxjs__not_files"], ) -node_module_library( +js_library( name = "rxjs", srcs = [":rxjs__files"], deps = [ @@ -3635,12 +3635,12 @@ node_module_library( "//tslib:tslib__contents", ], ) -node_module_library( +js_library( name = "rxjs__contents", srcs = [":rxjs__files", ":rxjs__nested_node_modules"], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "rxjs__typings", srcs = [ "//:node_modules/rxjs/AsyncSubject.d.ts", diff --git a/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden b/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden index 7aaea8236d..7aaabca354 100644 --- a/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "unidiff__files", srcs = [ @@ -30,7 +30,7 @@ filegroup( name = "unidiff__all_files", srcs = [":unidiff__files", ":unidiff__not_files"], ) -node_module_library( +js_library( name = "unidiff", srcs = [":unidiff__files"], deps = [ @@ -38,12 +38,12 @@ node_module_library( "//diff:diff__contents", ], ) -node_module_library( +js_library( name = "unidiff__contents", srcs = [":unidiff__files", ":unidiff__nested_node_modules"], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "unidiff__typings", ) load("@build_bazel_rules_nodejs//internal/npm_install:npm_umd_bundle.bzl", "npm_umd_bundle") diff --git a/internal/npm_install/test/golden/zone.js/BUILD.bazel.golden b/internal/npm_install/test/golden/zone.js/BUILD.bazel.golden index e2079693df..fd4ba0167b 100644 --- a/internal/npm_install/test/golden/zone.js/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/zone.js/BUILD.bazel.golden @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") filegroup( name = "zone.js__files", srcs = [ @@ -148,19 +148,19 @@ filegroup( name = "zone.js__all_files", srcs = [":zone.js__files", ":zone.js__not_files"], ) -node_module_library( +js_library( name = "zone.js", srcs = [":zone.js__files"], deps = [ "//zone.js:zone.js__contents", ], ) -node_module_library( +js_library( name = "zone.js__contents", srcs = [":zone.js__files", ":zone.js__nested_node_modules"], visibility = ["//:__subpackages__"], ) -node_module_library( +js_library( name = "zone.js__typings", srcs = [ "//:node_modules/zone.js/dist/zone.js.d.ts", diff --git a/internal/npm_install/test/package/BUILD.bazel b/internal/npm_install/test/package/BUILD.bazel index e4ee7c2cf0..1db44f198d 100644 --- a/internal/npm_install/test/package/BUILD.bazel +++ b/internal/npm_install/test/package/BUILD.bazel @@ -1,15 +1,15 @@ # Generated file from yarn_install/npm_install rule. # See rules_nodejs/internal/npm_install/generate_build_file.ts -load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", "node_module_library") +load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") # All rules in other repositories can use these targets package(default_visibility = ["//visibility:public"]) -# The node_modules directory in one catch-all node_module_library. +# The node_modules directory in one catch-all js_library. # NB: Using this target may have bad performance implications if # there are many files in target. # See https://github.com/bazelbuild/bazel/issues/5153. -node_module_library( +js_library( name = "node_modules", ) diff --git a/internal/providers/npm_package_info.bzl b/internal/providers/npm_package_info.bzl index f1967af5e9..f5749bac2b 100644 --- a/internal/providers/npm_package_info.bzl +++ b/internal/providers/npm_package_info.bzl @@ -16,8 +16,8 @@ """ # NpmPackageInfo provider is provided by targets that are npm dependencies by the -# `node_module_library` rule as well as other targets that have direct or transitive deps on -# `node_module_library` targets via the `node_modules_aspect` below. +# `js_library` rule as well as other targets that have direct or transitive deps on +# `js_library` targets via the `node_modules_aspect` below. NpmPackageInfo = provider( doc = "Provides information about npm dependencies", fields = { diff --git a/packages/jasmine/BUILD.bazel b/packages/jasmine/BUILD.bazel index b4d04115cc..dafd621b4a 100644 --- a/packages/jasmine/BUILD.bazel +++ b/packages/jasmine/BUILD.bazel @@ -13,7 +13,7 @@ # limitations under the License. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test") +load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "nodejs_test") load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") load("@build_bazel_rules_nodejs//tools/stardoc:index.bzl", "stardoc") @@ -53,15 +53,26 @@ nodejs_test( ], ) -js_library( - name = "jasmine", - package_name = "@bazel/jasmine", +copy_to_bin( + name = "srcs", srcs = [ "index.js", "jasmine_runner.js", ], ) +# We need to use ":srcs" here instead of an +# array for the source files otherwise our +# logic on js_library will consider this a +# node_module when used in examples/user_managed_deps +# which will endup failing as we cannot use node_modules +# from multiple workspaces. +js_library( + name = "jasmine", + package_name = "@bazel/jasmine", + srcs = [":srcs"], +) + # Ugly genrule depending on local linux environment to build the README out of skylark doc generation. # Only referenced when we do a release. # TODO: This ought to be possible with stardoc alone. Need to coordinate with Chris Parsons. diff --git a/packages/labs/grpc_web/BUILD.bazel b/packages/labs/grpc_web/BUILD.bazel index 6249f84dc6..ee26a9f3ca 100644 --- a/packages/labs/grpc_web/BUILD.bazel +++ b/packages/labs/grpc_web/BUILD.bazel @@ -42,7 +42,7 @@ well_known_protos = [ js_library( name = "bootstrap_scripts", - srcs = [ + named_module_srcs = [ "@npm//google-protobuf:google-protobuf__umd", "@npm//grpc-web:grpc-web__umd", ] + [":google-protobuf-%s__umd" % p for p in well_known_protos], diff --git a/packages/rollup/test/integration/far/a/BUILD.bazel b/packages/rollup/test/integration/far/a/BUILD.bazel index 9b308edbdb..616ac98324 100644 --- a/packages/rollup/test/integration/far/a/BUILD.bazel +++ b/packages/rollup/test/integration/far/a/BUILD.bazel @@ -10,5 +10,5 @@ ts_project( js_library( name = "a", package_name = "@far/a", - srcs = [":index.js"], + deps = [":tsconfig"], ) diff --git a/packages/rollup/test/integration/far/a/b/c/BUILD.bazel b/packages/rollup/test/integration/far/a/b/c/BUILD.bazel index 5888dd598c..ea6ee75c94 100644 --- a/packages/rollup/test/integration/far/a/b/c/BUILD.bazel +++ b/packages/rollup/test/integration/far/a/b/c/BUILD.bazel @@ -10,5 +10,5 @@ ts_project( js_library( name = "c", package_name = "@far/a/b/c", - srcs = [":tsconfig"], + deps = [":tsconfig"], ) diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index 6d53f0c874..c996ec26ad 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -1,6 +1,7 @@ "ts_project rule" load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "NpmPackageInfo", "declaration_info", "js_module_info", "run_node") +load("@build_bazel_rules_nodejs//internal/linker:link_node_modules.bzl", "module_mappings_aspect") _DEFAULT_TSC = ( # BEGIN-INTERNAL @@ -12,7 +13,7 @@ _DEFAULT_TSC = ( _ATTRS = { "args": attr.string_list(), "declaration_dir": attr.string(), - "deps": attr.label_list(providers = [DeclarationInfo]), + "deps": attr.label_list(providers = [DeclarationInfo], aspects = [module_mappings_aspect]), "extends": attr.label_list(allow_files = [".json"]), "out_dir": attr.string(), "root_dir": attr.string(),