diff --git a/internal/npm_install/generate_build_file.js b/internal/npm_install/generate_build_file.js index f80d62038c..9f87887ece 100644 --- a/internal/npm_install/generate_build_file.js +++ b/internal/npm_install/generate_build_file.js @@ -172,10 +172,10 @@ for installation instructions.`); `; }); }); - let srcsStarlark = ''; + let filesStarlark = ''; if (pkgs.length) { - const list = pkgs.map(pkg => `"//${pkg._dir}:${pkg._name}__files",`).join('\n '); - srcsStarlark = ` + const list = pkgs.map(pkg => `"//${pkg._dir}:${pkg._name}__all_files",`).join('\n '); + filesStarlark = ` # direct sources listed for strict deps support srcs = [ ${list} @@ -201,7 +201,7 @@ ${exportsStarlark}]) # there are many files in target. # See https://github.com/bazelbuild/bazel/issues/5153. node_module_library( - name = "node_modules",${srcsStarlark}${depsStarlark} + name = "node_modules",${filesStarlark}${depsStarlark} ) `; @@ -775,6 +775,8 @@ def _maybe(repo_rule, name, **kwargs): */ function printPackage(pkg) { const sources = filterFiles(pkg._files, INCLUDED_FILES); + const files = sources.filter((f) => !f.startsWith('node_modules/')); + const nestedNodeModules = sources.filter((f) => f.startsWith('node_modules/')); const dtsSources = filterFiles(pkg._files, ['.d.ts']); // TODO(gmagolan): add UMD & AMD scripts to scripts even if not an APF package _but_ only if they // are named? @@ -788,12 +790,21 @@ def _maybe(repo_rule, name, **kwargs): ${namedSources.map((f) => `"//:node_modules/${pkg._dir}/${f}",`).join('\n ')} ],`; } - let srcsStarlark = ''; - if (sources.length) { - srcsStarlark = ` + let filesStarlark = ''; + if (files.length) { + filesStarlark = ` # ${pkg._dir} package files (and files in nested node_modules) srcs = [ - ${sources.map((f) => `"//:node_modules/${pkg._dir}/${f}",`).join('\n ')} + ${files.map((f) => `"//:node_modules/${pkg._dir}/${f}",`).join('\n ')} + ],`; + } + let nestedNodeModulesStarlark = ''; + if (nestedNodeModules.length) { + nestedNodeModulesStarlark = ` + # ${pkg._dir} package files (and files in nested node_modules) + srcs = [ + ${nestedNodeModules.map((f) => `"//:node_modules/${pkg._dir}/${f}",`) + .join('\n ')} ],`; } let depsStarlark = ''; @@ -819,20 +830,32 @@ def _maybe(repo_rule, name, **kwargs): ${printJson(pkg)} filegroup( - name = "${pkg._name}__files",${srcsStarlark} + name = "${pkg._name}__files",${filesStarlark} +) + +filegroup( + name = "${pkg._name}__nested_node_modules",${nestedNodeModulesStarlark} + visibility = ["//visibility:private"], +) + +filegroup( + name = "${pkg._name}__all_files", + srcs = [":${pkg._name}__files", ":${pkg._name}__nested_node_modules"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "${pkg._name}", # direct sources listed for strict deps support - srcs = [":${pkg._name}__files"],${depsStarlark} + srcs = [":${pkg._name}__all_files"],${depsStarlark} ) # ${pkg._name}__contents target is used as dep for main targets to prevent # circular dependencies errors node_module_library( name = "${pkg._name}__contents", - srcs = [":${pkg._name}__files"],${namedSourcesStarlark} + srcs = [":${pkg._name}__all_files"],${namedSourcesStarlark} + visibility = ["//:__subpackages__"], ) # ${pkg._name}__typings is the subset of ${pkg._name}__contents that are declarations @@ -987,10 +1010,10 @@ def ${name.replace(/-/g, '_')}_test(**kwargs): }); // filter out duplicate deps deps = [...pkgs, ...new Set(deps)]; - let srcsStarlark = ''; + let filesStarlark = ''; if (deps.length) { - const list = deps.map(dep => `"//${dep._dir}:${dep._name}__files",`).join('\n '); - srcsStarlark = ` + const list = deps.map(dep => `"//${dep._dir}:${dep._name}__all_files",`).join('\n '); + filesStarlark = ` # direct sources listed for strict deps support srcs = [ ${list} @@ -1009,7 +1032,7 @@ def ${name.replace(/-/g, '_')}_test(**kwargs): # Generated target for npm scope ${scope} node_module_library( - name = "${scope}",${srcsStarlark}${depsStarlark} + name = "${scope}",${filesStarlark}${depsStarlark} ) `; diff --git a/internal/npm_install/generate_build_file.ts b/internal/npm_install/generate_build_file.ts index 6eddaaed4d..2b6aa69a21 100644 --- a/internal/npm_install/generate_build_file.ts +++ b/internal/npm_install/generate_build_file.ts @@ -176,10 +176,10 @@ function generateRootBuildFile(pkgs: Dep[]) { `; })}); - let srcsStarlark = ''; + let filesStarlark = ''; if (pkgs.length) { - const list = pkgs.map(pkg => `"//${pkg._dir}:${pkg._name}__files",`).join('\n '); - srcsStarlark = ` + const list = pkgs.map(pkg => `"//${pkg._dir}:${pkg._name}__all_files",`).join('\n '); + filesStarlark = ` # direct sources listed for strict deps support srcs = [ ${list} @@ -207,7 +207,7 @@ ${exportsStarlark}]) # there are many files in target. # See https://github.com/bazelbuild/bazel/issues/5153. node_module_library( - name = "node_modules",${srcsStarlark}${depsStarlark} + name = "node_modules",${filesStarlark}${depsStarlark} ) ` @@ -859,6 +859,8 @@ function findFile(pkg: Dep, m: string) { */ function printPackage(pkg: Dep) { const sources = filterFiles(pkg._files, INCLUDED_FILES); + const files = sources.filter((f: string) => !f.startsWith('node_modules/')); + const nestedNodeModules = sources.filter((f: string) => f.startsWith('node_modules/')); const dtsSources = filterFiles(pkg._files, ['.d.ts']); // TODO(gmagolan): add UMD & AMD scripts to scripts even if not an APF package _but_ only if they // are named? @@ -874,12 +876,23 @@ function printPackage(pkg: Dep) { ],`; } - let srcsStarlark = ''; - if (sources.length) { - srcsStarlark = ` + let filesStarlark = ''; + if (files.length) { + filesStarlark = ` # ${pkg._dir} package files (and files in nested node_modules) srcs = [ - ${sources.map((f: string) => `"//:node_modules/${pkg._dir}/${f}",`).join('\n ')} + ${files.map((f: string) => `"//:node_modules/${pkg._dir}/${f}",`).join('\n ')} + ],`; + } + + let nestedNodeModulesStarlark = ''; + if (nestedNodeModules.length) { + nestedNodeModulesStarlark = ` + # ${pkg._dir} package files (and files in nested node_modules) + srcs = [ + ${ + nestedNodeModules.map((f: string) => `"//:node_modules/${pkg._dir}/${f}",`) + .join('\n ')} ],`; } @@ -909,20 +922,32 @@ function printPackage(pkg: Dep) { ${printJson(pkg)} filegroup( - name = "${pkg._name}__files",${srcsStarlark} + name = "${pkg._name}__files",${filesStarlark} +) + +filegroup( + name = "${pkg._name}__nested_node_modules",${nestedNodeModulesStarlark} + visibility = ["//visibility:private"], +) + +filegroup( + name = "${pkg._name}__all_files", + srcs = [":${pkg._name}__files", ":${pkg._name}__nested_node_modules"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "${pkg._name}", # direct sources listed for strict deps support - srcs = [":${pkg._name}__files"],${depsStarlark} + srcs = [":${pkg._name}__all_files"],${depsStarlark} ) # ${pkg._name}__contents target is used as dep for main targets to prevent # circular dependencies errors node_module_library( name = "${pkg._name}__contents", - srcs = [":${pkg._name}__files"],${namedSourcesStarlark} + srcs = [":${pkg._name}__all_files"],${namedSourcesStarlark} + visibility = ["//:__subpackages__"], ) # ${pkg._name}__typings is the subset of ${pkg._name}__contents that are declarations @@ -1099,10 +1124,10 @@ function printScope(scope: string, pkgs: Dep[]) { // filter out duplicate deps deps = [...pkgs, ...new Set(deps)]; - let srcsStarlark = ''; + let filesStarlark = ''; if (deps.length) { - const list = deps.map(dep => `"//${dep._dir}:${dep._name}__files",`).join('\n '); - srcsStarlark = ` + const list = deps.map(dep => `"//${dep._dir}:${dep._name}__all_files",`).join('\n '); + filesStarlark = ` # direct sources listed for strict deps support srcs = [ ${list} @@ -1123,7 +1148,7 @@ function printScope(scope: string, pkgs: Dep[]) { # Generated target for npm scope ${scope} node_module_library( - name = "${scope}",${srcsStarlark}${depsStarlark} + name = "${scope}",${filesStarlark}${depsStarlark} ) `; 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 06b3a74433..8c92b8e636 100644 --- a/internal/npm_install/test/golden/@angular/core/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/@angular/core/BUILD.bazel.golden @@ -664,9 +664,18 @@ filegroup( "//:node_modules/@angular/core/testing/testing.metadata.json", ], ) +filegroup( + name = "core__nested_node_modules", + visibility = ["//visibility:private"], +) +filegroup( + name = "core__all_files", + srcs = [":core__files", ":core__nested_node_modules"], + visibility = ["//:__subpackages__"], +) node_module_library( name = "core", - srcs = [":core__files"], + srcs = [":core__all_files"], deps = [ "//@angular/core:core__contents", "//tslib:tslib__contents", @@ -676,11 +685,12 @@ node_module_library( ) node_module_library( name = "core__contents", - srcs = [":core__files"], + srcs = [":core__all_files"], named_module_srcs = [ "//:node_modules/@angular/core/bundles/core-testing.umd.js", "//:node_modules/@angular/core/bundles/core.umd.js", ], + visibility = ["//:__subpackages__"], ) node_module_library( name = "core__typings", diff --git a/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden b/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden index 0cbf7c526e..795893c9df 100644 --- a/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden @@ -4,8 +4,8 @@ load("@build_bazel_rules_nodejs//internal/npm_install:node_module_library.bzl", node_module_library( name = "@gregmagolan", srcs = [ - "//@gregmagolan/test-a:test-a__files", - "//@gregmagolan/test-b:test-b__files", + "//@gregmagolan/test-a:test-a__all_files", + "//@gregmagolan/test-b:test-b__all_files", ], deps = [ "//@gregmagolan/test-a:test-a__contents", 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 8a25780643..af7f998df3 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 @@ -9,16 +9,26 @@ filegroup( "//:node_modules/@gregmagolan/test-a/package.json", ], ) +filegroup( + name = "test-a__nested_node_modules", + visibility = ["//visibility:private"], +) +filegroup( + name = "test-a__all_files", + srcs = [":test-a__files", ":test-a__nested_node_modules"], + visibility = ["//:__subpackages__"], +) node_module_library( name = "test-a", - srcs = [":test-a__files"], + srcs = [":test-a__all_files"], deps = [ "//@gregmagolan/test-a:test-a__contents", ], ) node_module_library( name = "test-a__contents", - srcs = [":test-a__files"], + srcs = [":test-a__all_files"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "test-a__typings", 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 bfd3767a72..9894f6d3c6 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 @@ -5,21 +5,33 @@ filegroup( name = "test-b__files", srcs = [ "//:node_modules/@gregmagolan/test-b/main.js", + "//:node_modules/@gregmagolan/test-b/package.json", + ], +) +filegroup( + name = "test-b__nested_node_modules", + srcs = [ "//:node_modules/@gregmagolan/test-b/node_modules/@gregmagolan/test-a/main.js", "//:node_modules/@gregmagolan/test-b/node_modules/@gregmagolan/test-a/package.json", - "//:node_modules/@gregmagolan/test-b/package.json", ], + visibility = ["//visibility:private"], +) +filegroup( + name = "test-b__all_files", + srcs = [":test-b__files", ":test-b__nested_node_modules"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "test-b", - srcs = [":test-b__files"], + srcs = [":test-b__all_files"], deps = [ "//@gregmagolan/test-b:test-b__contents", ], ) node_module_library( name = "test-b__contents", - srcs = [":test-b__files"], + srcs = [":test-b__all_files"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "test-b__typings", diff --git a/internal/npm_install/test/golden/BUILD.bazel.golden b/internal/npm_install/test/golden/BUILD.bazel.golden index cdc72241d4..26d3c9ac4c 100644 --- a/internal/npm_install/test/golden/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/BUILD.bazel.golden @@ -4687,32 +4687,32 @@ exports_files([ node_module_library( name = "node_modules", srcs = [ - "//ajv:ajv__files", - "//balanced-match:balanced-match__files", - "//brace-expansion:brace-expansion__files", - "//co:co__files", - "//concat-map:concat-map__files", - "//diff:diff__files", - "//fast-deep-equal:fast-deep-equal__files", - "//fast-json-stable-stringify:fast-json-stable-stringify__files", - "//fs.realpath:fs.realpath__files", - "//glob:glob__files", - "//inflight:inflight__files", - "//inherits:inherits__files", - "//jasmine:jasmine__files", - "//jasmine-core:jasmine-core__files", - "//json-schema-traverse:json-schema-traverse__files", - "//minimatch:minimatch__files", - "//once:once__files", - "//path-is-absolute:path-is-absolute__files", - "//rxjs:rxjs__files", - "//tslib:tslib__files", - "//unidiff:unidiff__files", - "//wrappy:wrappy__files", - "//zone.js:zone.js__files", - "//@angular/core:core__files", - "//@gregmagolan/test-a:test-a__files", - "//@gregmagolan/test-b:test-b__files", + "//ajv:ajv__all_files", + "//balanced-match:balanced-match__all_files", + "//brace-expansion:brace-expansion__all_files", + "//co:co__all_files", + "//concat-map:concat-map__all_files", + "//diff:diff__all_files", + "//fast-deep-equal:fast-deep-equal__all_files", + "//fast-json-stable-stringify:fast-json-stable-stringify__all_files", + "//fs.realpath:fs.realpath__all_files", + "//glob:glob__all_files", + "//inflight:inflight__all_files", + "//inherits:inherits__all_files", + "//jasmine:jasmine__all_files", + "//jasmine-core:jasmine-core__all_files", + "//json-schema-traverse:json-schema-traverse__all_files", + "//minimatch:minimatch__all_files", + "//once:once__all_files", + "//path-is-absolute:path-is-absolute__all_files", + "//rxjs:rxjs__all_files", + "//tslib:tslib__all_files", + "//unidiff:unidiff__all_files", + "//wrappy:wrappy__all_files", + "//zone.js:zone.js__all_files", + "//@angular/core:core__all_files", + "//@gregmagolan/test-a:test-a__all_files", + "//@gregmagolan/test-b:test-b__all_files", ], deps = [ "//ajv:ajv__contents", diff --git a/internal/npm_install/test/golden/ajv/BUILD.bazel.golden b/internal/npm_install/test/golden/ajv/BUILD.bazel.golden index 7b6ddbd96c..85e801865f 100644 --- a/internal/npm_install/test/golden/ajv/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/ajv/BUILD.bazel.golden @@ -94,9 +94,18 @@ filegroup( "//:node_modules/ajv/scripts/travis-gh-pages", ], ) +filegroup( + name = "ajv__nested_node_modules", + visibility = ["//visibility:private"], +) +filegroup( + name = "ajv__all_files", + srcs = [":ajv__files", ":ajv__nested_node_modules"], + visibility = ["//:__subpackages__"], +) node_module_library( name = "ajv", - srcs = [":ajv__files"], + srcs = [":ajv__all_files"], deps = [ "//ajv:ajv__contents", "//co:co__contents", @@ -107,7 +116,8 @@ node_module_library( ) node_module_library( name = "ajv__contents", - srcs = [":ajv__files"], + srcs = [":ajv__all_files"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "ajv__typings", diff --git a/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden b/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden index e871e44a4a..9dd37d5a27 100644 --- a/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden @@ -20,9 +20,18 @@ filegroup( "//:node_modules/jasmine/tasks/jasmine.js", ], ) +filegroup( + name = "jasmine__nested_node_modules", + visibility = ["//visibility:private"], +) +filegroup( + name = "jasmine__all_files", + srcs = [":jasmine__files", ":jasmine__nested_node_modules"], + visibility = ["//:__subpackages__"], +) node_module_library( name = "jasmine", - srcs = [":jasmine__files"], + srcs = [":jasmine__all_files"], deps = [ "//jasmine:jasmine__contents", "//glob:glob__contents", @@ -41,7 +50,8 @@ node_module_library( ) node_module_library( name = "jasmine__contents", - srcs = [":jasmine__files"], + srcs = [":jasmine__all_files"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "jasmine__typings", diff --git a/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden b/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden index aa4f43855f..66dc614088 100644 --- a/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/rxjs/BUILD.bazel.golden @@ -3613,9 +3613,18 @@ filegroup( "//:node_modules/rxjs/webSocket/package.json", ], ) +filegroup( + name = "rxjs__nested_node_modules", + visibility = ["//visibility:private"], +) +filegroup( + name = "rxjs__all_files", + srcs = [":rxjs__files", ":rxjs__nested_node_modules"], + visibility = ["//:__subpackages__"], +) node_module_library( name = "rxjs", - srcs = [":rxjs__files"], + srcs = [":rxjs__all_files"], deps = [ "//rxjs:rxjs__contents", "//tslib:tslib__contents", @@ -3623,7 +3632,8 @@ node_module_library( ) node_module_library( name = "rxjs__contents", - srcs = [":rxjs__files"], + srcs = [":rxjs__all_files"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "rxjs__typings", diff --git a/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden b/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden index 3001b4b7f5..075beb88b7 100644 --- a/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden @@ -16,9 +16,18 @@ filegroup( "//:node_modules/unidiff/unidiff.js", ], ) +filegroup( + name = "unidiff__nested_node_modules", + visibility = ["//visibility:private"], +) +filegroup( + name = "unidiff__all_files", + srcs = [":unidiff__files", ":unidiff__nested_node_modules"], + visibility = ["//:__subpackages__"], +) node_module_library( name = "unidiff", - srcs = [":unidiff__files"], + srcs = [":unidiff__all_files"], deps = [ "//unidiff:unidiff__contents", "//diff:diff__contents", @@ -26,7 +35,8 @@ node_module_library( ) node_module_library( name = "unidiff__contents", - srcs = [":unidiff__files"], + srcs = [":unidiff__all_files"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "unidiff__typings", 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 8acdd31585..c2969711f0 100644 --- a/internal/npm_install/test/golden/zone.js/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/zone.js/BUILD.bazel.golden @@ -134,16 +134,26 @@ filegroup( "//:node_modules/zone.js/package.json", ], ) +filegroup( + name = "zone.js__nested_node_modules", + visibility = ["//visibility:private"], +) +filegroup( + name = "zone.js__all_files", + srcs = [":zone.js__files", ":zone.js__nested_node_modules"], + visibility = ["//:__subpackages__"], +) node_module_library( name = "zone.js", - srcs = [":zone.js__files"], + srcs = [":zone.js__all_files"], deps = [ "//zone.js:zone.js__contents", ], ) node_module_library( name = "zone.js__contents", - srcs = [":zone.js__files"], + srcs = [":zone.js__all_files"], + visibility = ["//:__subpackages__"], ) node_module_library( name = "zone.js__typings",