diff --git a/.circleci/bazel.rc b/.circleci/bazel.rc index db2bc43dbe..237885f131 100644 --- a/.circleci/bazel.rc +++ b/.circleci/bazel.rc @@ -4,9 +4,6 @@ # Don't be spammy in the logs build --noshow_progress -# Don't run manual tests -test --test_tag_filters=-manual - # Print all the options that apply to the build. # This helps us diagnose which options override others # (e.g. /etc/bazel.bazelrc vs. tools/bazel.rc) diff --git a/.circleci/config.yml b/.circleci/config.yml index d08b86a1b4..50c48b6ebf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,7 +81,8 @@ jobs: - run: bazel run @nodejs//:yarn - run: bazel build ... - - run: bazel test ... --define=some_env=some_value + - run: bazel test ... + - run: bazel test //examples/define_var --define=some_env=some_value # TODO(alexeagle): move this into the example proper - run: bazel run examples/rollup -- --help diff --git a/README.md b/README.md index 6102c51aca..ce32d4f29a 100644 --- a/README.md +++ b/README.md @@ -202,8 +202,8 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") nodejs_binary( name = "bar", data = [ - "@npm//:foo", - "@npm//:baz", + "@npm//foo", + "@npm//baz", ] ... ) @@ -220,9 +220,9 @@ jasmine_node_test( name = "test", ... deps = [ - "@npm//:jasmine", - "@npm//:foo", - "@npm//:baz", + "@npm//jasmine", + "@npm//foo", + "@npm//baz", ... ], ) @@ -236,8 +236,9 @@ there are also filegroups defined by `yarn_install` and `npm_install` that include all packages under `node_modules` and which can be used with the `node_modules` attribute of nodejs rules. -* `@npm//:node_modules` is includes **all** files under `node_modules` -* `@npm//:node_modules_lite` is includes only `.js`, `.d.ts`, `.json` and `./bin/*` under `node_modules` (this reduces the number of input files) +* `@npm//:node_modules` includes **all** files under `node_modules` (including the `.bin` folder) +* `@npm//:node_modules_lite` includes only `.js`, `.d.ts`, `.json` and `./bin/*` under `node_modules` (this reduces the number of input files) +* `@npm//:node_modules_bin` includes all files under `node_modules/.bin` ```python load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") @@ -260,8 +261,14 @@ filegroup( name = "node_modules", srcs = glob( include = ["node_modules/**/*"], - # Files with spaces in the name are not legal Bazel labels exclude = [ + # Files under test & docs may contain file names that + # are not legal Bazel labels (e.g., + # node_modules/ecstatic/test/public/中文/檔案.html) + "node_modules/test/**", + "node_modules/docs/**", + # Files with spaces are not allowed in Bazel runfiles + # See https://github.com/bazelbuild/bazel/issues/4327 "node_modules/**/* */**", "node_modules/**/* *", ], diff --git a/examples/bazel_managed_deps/BUILD.bazel b/examples/bazel_managed_deps/BUILD.bazel index 5eab51b3ef..fe2d6e1776 100644 --- a/examples/bazel_managed_deps/BUILD.bazel +++ b/examples/bazel_managed_deps/BUILD.bazel @@ -16,7 +16,7 @@ jasmine_node_test( name = "fine_grained_test", srcs = glob(["*.spec.js"]), deps = [ - "@npm//:jasmine", - "@npm//:typescript", + "@npm//jasmine", + "@npm//typescript", ], ) diff --git a/examples/bazel_managed_deps/README.md b/examples/bazel_managed_deps/README.md index 1d98b72736..db6257a96a 100644 --- a/examples/bazel_managed_deps/README.md +++ b/examples/bazel_managed_deps/README.md @@ -9,7 +9,7 @@ Instead, we can declare individual npm packages as dependencies, e.g.: ``` nodejs_binary( name = "fast", - data = ["@npm//:jasmine"] + data = ["@npm//jasmine"] ) ``` diff --git a/examples/bazel_managed_deps/WORKSPACE b/examples/bazel_managed_deps/WORKSPACE index 9ee7c0ef84..9837978e78 100644 --- a/examples/bazel_managed_deps/WORKSPACE +++ b/examples/bazel_managed_deps/WORKSPACE @@ -14,7 +14,7 @@ node_repositories() # This runs yarn install, then our generate_build_file.js to create BUILD files # inside the resulting node_modules directory. # The name "npm" here means the resulting modules are referenced like -# @npm//:jasmine +# @npm//jasmine yarn_install( name = "npm", package_json = "//:package.json", diff --git a/examples/define_var/BUILD.bazel b/examples/define_var/BUILD.bazel index 385210b0e9..d2de3755b5 100644 --- a/examples/define_var/BUILD.bazel +++ b/examples/define_var/BUILD.bazel @@ -7,11 +7,12 @@ jasmine_node_test( name = "define_var", srcs = glob(["*.spec.js"]), # Just here as a smoke test for this attribute. - # Test must be run with --define=some_env=some_value. - # Use `bazel test ... --define=some_env=some_value` or - # `bazel test //examples/rollup:test --define=some_env=some_value`. + # This test must be run with --define=some_env=some_value. + # Use `bazel test //examples/define_var --define=some_env=some_value`. + # Note that use of --define causes the entire build to be non-incremental + # since --define can affect the output of any action. configuration_env_vars = ["some_env"], - data = ["@fine_grained_deps_yarn//:jasmine"], + data = ["@fine_grained_deps_yarn//jasmine"], # Don't include this test in //... pattern since it requires special # --define option tags = ["manual"], diff --git a/internal/e2e/fine_grained_deps/BUILD.bazel b/internal/e2e/fine_grained_deps/BUILD.bazel index 6a2ef388f6..5cbe5e9a6b 100644 --- a/internal/e2e/fine_grained_deps/BUILD.bazel +++ b/internal/e2e/fine_grained_deps/BUILD.bazel @@ -25,11 +25,11 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") "fine.spec.js", ], deps = [ - "@fine_grained_deps_%s//:jasmine" % pkgmgr, - "@fine_grained_deps_%s//:typescript" % pkgmgr, + "@fine_grained_deps_%s//jasmine" % pkgmgr, + "@fine_grained_deps_%s//typescript" % pkgmgr, # Note, test-b depends on test-a@0.0.1 which should get # hoisted to node_modules/test-b/node_modules/test-a - "@fine_grained_deps_%s//:@gregmagolan/test-b" % pkgmgr, + "@fine_grained_deps_%s//@gregmagolan/test-b" % pkgmgr, ], ) for pkgmgr in [ "yarn", diff --git a/internal/e2e/rollup_fine_grained_deps/BUILD.bazel b/internal/e2e/rollup_fine_grained_deps/BUILD.bazel index 7d39c59ee8..0984a2c05d 100644 --- a/internal/e2e/rollup_fine_grained_deps/BUILD.bazel +++ b/internal/e2e/rollup_fine_grained_deps/BUILD.bazel @@ -15,7 +15,7 @@ rollup_bundle( srcs = ["has-deps.js"], entry_point = "internal/e2e/rollup_fine_grained_deps/has-deps.js", deps = [ - "@fine_grained_deps_yarn//:@gregmagolan/test-b", + "@fine_grained_deps_yarn//@gregmagolan/test-b", ], ) @@ -36,7 +36,7 @@ rollup_bundle( entry_point = "internal/e2e/rollup_fine_grained_deps/has-deps.js", node_modules = "@fine_grained_deps_yarn//:node_modules_lite", deps = [ - "@fine_grained_deps_yarn//:@gregmagolan/test-b", + "@fine_grained_deps_yarn//@gregmagolan/test-b", ], ) @@ -60,7 +60,7 @@ jasmine_node_test( ":bundle_no_deps.js", ":bundle_no_deps.min.js", ":bundle_no_deps.min_debug.js", - "@fine_grained_deps_yarn//:@gregmagolan/test-a", - "@fine_grained_deps_yarn//:jasmine", + "@fine_grained_deps_yarn//@gregmagolan/test-a", + "@fine_grained_deps_yarn//jasmine", ], ) diff --git a/internal/jasmine_node_test/jasmine_runner.js b/internal/jasmine_node_test/jasmine_runner.js index e5b388027d..760422369b 100644 --- a/internal/jasmine_node_test/jasmine_runner.js +++ b/internal/jasmine_node_test/jasmine_runner.js @@ -30,8 +30,8 @@ function main(args) { .filter(l => l.length > 0) // Filter here so that only files ending in `spec.js` and `test.js` // are added to jasmine as spec files. This is important as other - // deps such as "@npm//:typescript" if executed may cause the test to - // fail or have unexpected side-effects. "@npm//:typescript" would + // deps such as "@npm//typescript" if executed may cause the test to + // fail or have unexpected side-effects. "@npm//typescript" would // try to execute tsc, print its help, and process.exit(1) .filter(f => /[^a-zA-Z0-9](spec|test)\.js$/i.test(f)) // Filter out files from node_modules that match test.js or spec.js diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 7f1fcb35c1..6c6aa61d1f 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -198,8 +198,8 @@ _NODEJS_EXECUTABLE_ATTRS = { name = "my_binary", ... data = [ - "@npm//:foo", - "@npm//:bar", + "@npm//foo", + "@npm//bar", ... ], ) @@ -228,9 +228,9 @@ _NODEJS_EXECUTABLE_ATTRS = { name = "my_test", ... deps = [ - "@npm//:jasmine", - "@npm//:foo", - "@npm//:bar", + "@npm//jasmine", + "@npm//foo", + "@npm//bar", ... ], ) diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel index 8515be8c18..d733f64a49 100644 --- a/internal/node/test/BUILD.bazel +++ b/internal/node/test/BUILD.bazel @@ -23,7 +23,7 @@ nodejs_binary( name = "has_deps", data = [ "has-deps.js", - "@fine_grained_deps_yarn//:typescript", + "@fine_grained_deps_yarn//typescript", ], entry_point = "build_bazel_rules_nodejs/internal/node/test/has-deps", ) @@ -34,7 +34,7 @@ nodejs_binary( name = "has_deps_hybrid", data = [ "has-deps.js", - "@fine_grained_deps_yarn//:typescript", + "@fine_grained_deps_yarn//typescript", ], entry_point = "build_bazel_rules_nodejs/internal/node/test/has-deps", node_modules = "@fine_grained_deps_yarn//:node_modules_lite", diff --git a/internal/npm_install/generate_build_file.js b/internal/npm_install/generate_build_file.js index df0fec21f6..ebd8e5d109 100644 --- a/internal/npm_install/generate_build_file.js +++ b/internal/npm_install/generate_build_file.js @@ -50,7 +50,7 @@ * that includes only js, d.ts and json files as well as the .bin folder. This * can be used in some cases to improve performance by reducing the number * of runfiles. The recommended approach to reducing performance - * is to use fine grained deps such as ["@npm//:a", "@npm://b", ...]. + * is to use fine grained deps such as ["@npm//a", "@npm//b", ...]. * There are cases where the node_modules_lite filegroup will * not include files with no extension that are needed. The feature request * https://github.com/bazelbuild/bazel/issues/5769 would allow this @@ -66,106 +66,130 @@ const fs = require('fs'); const path = require('path'); -const BUILD_FILE_HEADER = `# Generated file from yarn_install rule. +const BUILD_FILE_HEADER = `# Generated file from yarn_install/npm_install rule. # See $(bazel info output_base)/external/build_bazel_rules_nodejs/internal/npm_install/generate_build_file.js # All rules in other repositories can use these targets package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") +` + +if (require.main === module) { + main(); +} + +function mkdirp(dirname) { + if (!fs.existsSync(dirname)) { + mkdirp(path.dirname(dirname)); + fs.mkdirSync(dirname); + } +} + +function writeFileSync(filePath, contents) { + mkdirp(path.dirname(filePath)); + fs.writeFileSync(filePath, contents); +} + +/** + * Main entrypoint. + * Write BUILD files. + */ +function main() { + // find all packages (including packages in nested node_modules) + const pkgs = findPackages(); + const scopes = findScopes(); + + // flatten dependencies + const pkgsMap = new Map(); + pkgs.forEach(pkg => pkgsMap.set(pkg._dir, pkg)); + pkgs.forEach(pkg => flattenDependencies(pkg, pkg, pkgsMap)); + + // generate BUILD files + generateRootBuildFile(pkgs) + pkgs.filter(pkg => !pkg._isNested).forEach(pkg => generatePackageBuildFiles(pkg)); + scopes.forEach(scope => generateScopeBuildFiles(scope, pkgs)); +} + +module.exports = {main}; + +function generateRootBuildFile(pkgs) { + const srcsFiles = pkgs.filter(pkg => !pkg._isNested) + .map(pkg => `"//node_modules/${pkg._dir}:${pkg._name}__files",`) + .join('\n '); -# The entire node_modules directory in one catch-all filegroup. + const srcsLite = pkgs.filter(pkg => !pkg._isNested) + .map(pkg => `"//node_modules/${pkg._dir}:${pkg._name}__lite",`) + .join('\n '); + + let buildFile = + BUILD_FILE_HEADER + `# The entire node_modules directory in one catch-all filegroup. # NB: Using this target may have bad performance implications if # there are many files in filegroup. # See https://github.com/bazelbuild/bazel/issues/5153. filegroup( name = "node_modules", - srcs = glob( - include = ["node_modules/**/*"], - exclude = [ - # Files under test & docs may contain file names that - # are not legal Bazel labels (e.g., - # node_modules/ecstatic/test/public/中文/檔案.html) - "node_modules/**/test/**", - "node_modules/**/docs/**", - # Files with spaces in the name are not legal Bazel labels - "node_modules/**/* */**", - "node_modules/**/* *", - ], - ), + srcs = glob(["node_modules/.bin/*"]) + [ + ${srcsFiles} + ], ) # A lite version of the node_modules filegroup that includes # only js, d.ts and json files as well as the .bin folder. This can # be used in some cases to improve performance by reducing the number # of runfiles. The recommended approach to reducing performance -# is to use fine grained deps such as ["@npm//:a", "@npm://b", ...]. +# is to use fine grained deps such as ["@npm//a", "@npm//b", ...]. # There are cases where the node_modules_lite filegroup will # not include files with no extension that are needed. The feature request # https://github.com/bazelbuild/bazel/issues/5769 would allow this # filegroup to include those files. filegroup( name = "node_modules_lite", - srcs = glob( - include = [ - "node_modules/**/*.js", - "node_modules/**/*.d.ts", - "node_modules/**/*.json", - "node_modules/.bin/*", - ], - exclude = [ - # Files under test & docs may contain file names that - # are not legal Bazel labels (e.g., - # node_modules/ecstatic/test/public/中文/檔案.html) - "node_modules/**/test/**", - "node_modules/**/docs/**", - # Files with spaces in the name are not legal Bazel labels - "node_modules/**/* */**", - "node_modules/**/* *", - ], - ), + srcs = glob(["node_modules/.bin/*"]) + [ + ${srcsLite} + ], +) + +# Just the bin folder of node_modules since this +# folder is not covered by fine grained deps targets +filegroup( + name = "node_modules_bin", + srcs = glob(["node_modules/.bin/*"]), ) ` -if (require.main === module) { - main(); + // Add the manual build file contents if they exists + try { + buildFile += fs.readFileSync(`manual_build_file_contents`, {encoding: 'utf8'}); + } catch (e) { + } + + writeFileSync('BUILD.bazel', buildFile); } -/** - * Main entrypoint. - * Write BUILD file. - */ -function main() { - // find all packages (including packages in nested node_modules) - const pkgs = findPackages(); - const scopes = findScopes(); +function generatePackageBuildFiles(pkg) { + const buildFile = + BUILD_FILE_HEADER + `load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") - // flatten dependencies - const pkgsMap = new Map(); - pkgs.forEach(pkg => pkgsMap.set(pkg._dir, pkg)); - pkgs.forEach(pkg => flattenDependencies(pkg, pkg, pkgsMap)); +` + printPackage(pkg); + writeFileSync(path.posix.join('node_modules', pkg._dir, 'BUILD.bazel'), buildFile); - // generate the BUILD file - let buildFile = BUILD_FILE_HEADER; - pkgs.filter(pkg => !pkg._isNested).forEach(pkg => buildFile += printPackage(pkg)); - scopes.forEach(scope => buildFile += printScope(scope, pkgs)); - try { - const manualContents = fs.readFileSync(`manual_build_file_contents`, {encoding: 'utf8'}); - buildFile += '\n\n'; - buildFile += manualContents; - } catch (e) { - } - fs.writeFileSync('BUILD.bazel', buildFile); + const aliasBuildFile = BUILD_FILE_HEADER + printPackageAlias(pkg); + writeFileSync(path.posix.join(pkg._dir, 'BUILD.bazel'), aliasBuildFile); } -module.exports = {main}; +function generateScopeBuildFiles(scope, pkgs) { + const buildFile = BUILD_FILE_HEADER + printScope(scope, pkgs); + writeFileSync(path.posix.join('node_modules', scope, 'BUILD.bazel'), buildFile); + + const aliasBuildFile = BUILD_FILE_HEADER + printScopeAlias(scope); + writeFileSync(path.posix.join(scope, 'BUILD.bazel'), aliasBuildFile); +} /** * Checks if a path is an npm package which is is a directory with a package.json file. */ function isPackage(p) { - // const packageJson = path.posix.join(p, 'package.json'); return fs.statSync(p).isDirectory() && fs.existsSync(packageJson) && fs.statSync(packageJson).isFile(); @@ -226,6 +250,9 @@ function parsePackage(p) { // assign to _dir for future use pkg._dir = p.replace(/^node_modules\//, ''); + // Stash the package directory name for future use + pkg._name = pkg._dir.split('/').pop(); + // Keep track of whether or not this is a nested package pkg._isNested = p.match(/\/node_modules\//); @@ -340,54 +367,79 @@ function printJson(pkg) { */ function printPackage(pkg) { let result = ` -# Generated target for npm package "${pkg._dir}" +# Generated targets for npm package "${pkg._dir}" ${printJson(pkg)} filegroup( - name = "${pkg._dir}", + name = "${pkg._name}", srcs = [ # ${pkg._dir} package contents (and contents of nested node_modules) - ":${pkg._dir}__files", + ":${pkg._name}__files", # direct or transitive dependencies hoisted to root by the package manager ${ pkg._dependencies.filter(dep => dep != pkg) .filter(dep => !dep._isNested) - .map(dep => `":${dep._dir}__files",`) + .map(dep => `"//node_modules/${dep._dir}:${dep._name}__files",`) .join('\n ')} ], tags = ["NODE_MODULE_MARKER"], ) filegroup( - name = "${pkg._dir}__files", + name = "${pkg._name}__files", srcs = glob( - include = ["node_modules/${pkg._dir}/**/*"], + include = ["**/*"], exclude = [ # Files under test & docs may contain file names that # are not legal Bazel labels (e.g., # node_modules/ecstatic/test/public/中文/檔案.html) - "node_modules/${pkg._dir}/test/**", - "node_modules/${pkg._dir}/docs/**", - # Files with spaces in the name are not legal Bazel labels - "node_modules/${pkg._dir}/**/* */**", - "node_modules/${pkg._dir}/**/* *", + "test/**", + "docs/**", + # Files with spaces are not allowed in Bazel runfiles + # See https://github.com/bazelbuild/bazel/issues/4327 + "**/* */**", + "**/* *", ], ), tags = ["NODE_MODULE_MARKER"], ) filegroup( - name = "${pkg._dir}__typings", + name = "${pkg._name}__lite", srcs = glob( - include = ["node_modules/${pkg._dir}/**/*.d.ts"], + include = [ + "**/*.js", + "**/*.d.ts", + "**/*.json", + ], exclude = [ # Files under test & docs may contain file names that # are not legal Bazel labels (e.g., # node_modules/ecstatic/test/public/中文/檔案.html) - "node_modules/${pkg._dir}/test/**", - "node_modules/${pkg._dir}/docs/**", - # Files with spaces in the name are not legal Bazel labels - "node_modules/${pkg._dir}/**/* */**", - "node_modules/${pkg._dir}/**/* *", + "test/**", + "docs/**", + # Files with spaces are not allowed in Bazel runfiles + # See https://github.com/bazelbuild/bazel/issues/4327 + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) + +filegroup( + name = "${pkg._name}__typings", + srcs = glob( + include = ["**/*.d.ts"], + exclude = [ + # Files under test & docs may contain file names that + # are not legal Bazel labels (e.g., + # node_modules/ecstatic/test/public/中文/檔案.html) + "test/**", + "docs/**", + # Files with spaces are not allowed in Bazel runfiles + # See https://github.com/bazelbuild/bazel/issues/4327 + "**/* */**", + "**/* *", ], ), tags = ["NODE_MODULE_MARKER"], @@ -398,10 +450,35 @@ filegroup( for (const [name, path] of pkg._executables.entries()) { result += `# Wire up the \`bin\` entry \`${name}\` nodejs_binary( - name = "${pkg._dir}/${name}", + name = "${name}__bin", entry_point = "${pkg._dir}/${path}", install_source_map_support = False, - data = [":${pkg._dir}"], + data = [":${pkg._name}"], +) + +`; + } + } + + return result; +} + +function printPackageAlias(pkg) { + let result = ` +# Generated target alias for npm package "${pkg._dir}" +${printJson(pkg)} +alias( + name = "${pkg._name}", + actual = "//node_modules/${pkg._dir}", +) +`; + + if (pkg._executables) { + for (const [name, path] of pkg._executables.entries()) { + result += `# Wire up the \`bin\` entry \`${name}\` +alias( + name = "${name}__bin", + actual = "//node_modules/${pkg._dir}:${name}__bin", ) `; @@ -421,10 +498,21 @@ function printScope(scope, pkgs) { filegroup( name = "${scope}", srcs = [ - ${scopePkgs.map(pkg => `":${pkg._dir}",`).join('\n ')} + ${scopePkgs.map(pkg => `"//node_modules/${pkg._dir}",`).join('\n ')} ], tags = ["NODE_MODULE_MARKER"], ) `; } + +function printScopeAlias(scope) { + return ` +# Generated alias target for npm scope ${scope} +alias( + name = "${scope}", + actual = "//node_modules/${scope}", +) + +`; +} diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl index 98818df8b4..d334bbf0bb 100644 --- a/internal/npm_install/npm_install.bzl +++ b/internal/npm_install/npm_install.bzl @@ -27,12 +27,12 @@ load("//internal/common:os_name.bzl", "os_name") def _create_build_file(repository_ctx, node): if repository_ctx.attr.manual_build_file_contents: repository_ctx.file("manual_build_file_contents", repository_ctx.attr.manual_build_file_contents) - result = repository_ctx.execute([node, "internal/generate_build_file.js"]) + result = repository_ctx.execute([node, "generate_build_file.js"]) if result.return_code: fail("node failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr)) def _add_build_file_generator(repository_ctx): - repository_ctx.template("internal/generate_build_file.js", + repository_ctx.template("generate_build_file.js", repository_ctx.path(Label("//internal/npm_install:generate_build_file.js")), {}) def _add_data_dependencies(repository_ctx): diff --git a/internal/npm_install/test/BUILD.bazel b/internal/npm_install/test/BUILD.bazel index b92a7d0eb0..7b5babcd09 100644 --- a/internal/npm_install/test/BUILD.bazel +++ b/internal/npm_install/test/BUILD.bazel @@ -5,12 +5,17 @@ filegroup( srcs = glob(["node_modules/**"]), ) +filegroup( + name = "goldens", + srcs = glob(["golden/**"]), +) + jasmine_node_test( name = "test", srcs = glob(["*.spec.js"]), data = [ - ":BUILD.bazel.golden", ":check.js", + ":goldens", ":node_modules", ":yarn.lock", ], @@ -21,8 +26,8 @@ jasmine_node_test( nodejs_binary( name = "test.accept", data = [ - ":BUILD.bazel.golden", ":check.js", + ":goldens", ":node_modules", ":update_golden.js", ":yarn.lock", diff --git a/internal/npm_install/test/BUILD.bazel.golden b/internal/npm_install/test/BUILD.bazel.golden deleted file mode 100644 index 5381ef2e3e..0000000000 --- a/internal/npm_install/test/BUILD.bazel.golden +++ /dev/null @@ -1,689 +0,0 @@ - -package(default_visibility = ["//visibility:public"]) -load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") -filegroup( - name = "node_modules", - srcs = glob( - include = ["node_modules/**/*"], - exclude = [ - "node_modules/**/test/**", - "node_modules/**/docs/**", - "node_modules/**/* */**", - "node_modules/**/* *", - ], - ), -) -filegroup( - name = "node_modules_lite", - srcs = glob( - include = [ - "node_modules/**/*.js", - "node_modules/**/*.d.ts", - "node_modules/**/*.json", - "node_modules/.bin/*", - ], - exclude = [ - "node_modules/**/test/**", - "node_modules/**/docs/**", - "node_modules/**/* */**", - "node_modules/**/* *", - ], - ), -) -filegroup( - name = "balanced-match", - srcs = [ - ":balanced-match__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "balanced-match__files", - srcs = glob( - include = ["node_modules/balanced-match/**/*"], - exclude = [ - "node_modules/balanced-match/test/**", - "node_modules/balanced-match/docs/**", - "node_modules/balanced-match/**/* */**", - "node_modules/balanced-match/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "balanced-match__typings", - srcs = glob( - include = ["node_modules/balanced-match/**/*.d.ts"], - exclude = [ - "node_modules/balanced-match/test/**", - "node_modules/balanced-match/docs/**", - "node_modules/balanced-match/**/* */**", - "node_modules/balanced-match/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "brace-expansion", - srcs = [ - ":brace-expansion__files", - ":balanced-match__files", - ":concat-map__files", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "brace-expansion__files", - srcs = glob( - include = ["node_modules/brace-expansion/**/*"], - exclude = [ - "node_modules/brace-expansion/test/**", - "node_modules/brace-expansion/docs/**", - "node_modules/brace-expansion/**/* */**", - "node_modules/brace-expansion/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "brace-expansion__typings", - srcs = glob( - include = ["node_modules/brace-expansion/**/*.d.ts"], - exclude = [ - "node_modules/brace-expansion/test/**", - "node_modules/brace-expansion/docs/**", - "node_modules/brace-expansion/**/* */**", - "node_modules/brace-expansion/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "concat-map", - srcs = [ - ":concat-map__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "concat-map__files", - srcs = glob( - include = ["node_modules/concat-map/**/*"], - exclude = [ - "node_modules/concat-map/test/**", - "node_modules/concat-map/docs/**", - "node_modules/concat-map/**/* */**", - "node_modules/concat-map/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "concat-map__typings", - srcs = glob( - include = ["node_modules/concat-map/**/*.d.ts"], - exclude = [ - "node_modules/concat-map/test/**", - "node_modules/concat-map/docs/**", - "node_modules/concat-map/**/* */**", - "node_modules/concat-map/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "diff", - srcs = [ - ":diff__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "diff__files", - srcs = glob( - include = ["node_modules/diff/**/*"], - exclude = [ - "node_modules/diff/test/**", - "node_modules/diff/docs/**", - "node_modules/diff/**/* */**", - "node_modules/diff/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "diff__typings", - srcs = glob( - include = ["node_modules/diff/**/*.d.ts"], - exclude = [ - "node_modules/diff/test/**", - "node_modules/diff/docs/**", - "node_modules/diff/**/* */**", - "node_modules/diff/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "fs.realpath", - srcs = [ - ":fs.realpath__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "fs.realpath__files", - srcs = glob( - include = ["node_modules/fs.realpath/**/*"], - exclude = [ - "node_modules/fs.realpath/test/**", - "node_modules/fs.realpath/docs/**", - "node_modules/fs.realpath/**/* */**", - "node_modules/fs.realpath/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "fs.realpath__typings", - srcs = glob( - include = ["node_modules/fs.realpath/**/*.d.ts"], - exclude = [ - "node_modules/fs.realpath/test/**", - "node_modules/fs.realpath/docs/**", - "node_modules/fs.realpath/**/* */**", - "node_modules/fs.realpath/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "glob", - srcs = [ - ":glob__files", - ":fs.realpath__files", - ":inflight__files", - ":once__files", - ":wrappy__files", - ":inherits__files", - ":minimatch__files", - ":brace-expansion__files", - ":balanced-match__files", - ":concat-map__files", - ":path-is-absolute__files", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "glob__files", - srcs = glob( - include = ["node_modules/glob/**/*"], - exclude = [ - "node_modules/glob/test/**", - "node_modules/glob/docs/**", - "node_modules/glob/**/* */**", - "node_modules/glob/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "glob__typings", - srcs = glob( - include = ["node_modules/glob/**/*.d.ts"], - exclude = [ - "node_modules/glob/test/**", - "node_modules/glob/docs/**", - "node_modules/glob/**/* */**", - "node_modules/glob/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "inflight", - srcs = [ - ":inflight__files", - ":once__files", - ":wrappy__files", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "inflight__files", - srcs = glob( - include = ["node_modules/inflight/**/*"], - exclude = [ - "node_modules/inflight/test/**", - "node_modules/inflight/docs/**", - "node_modules/inflight/**/* */**", - "node_modules/inflight/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "inflight__typings", - srcs = glob( - include = ["node_modules/inflight/**/*.d.ts"], - exclude = [ - "node_modules/inflight/test/**", - "node_modules/inflight/docs/**", - "node_modules/inflight/**/* */**", - "node_modules/inflight/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "inherits", - srcs = [ - ":inherits__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "inherits__files", - srcs = glob( - include = ["node_modules/inherits/**/*"], - exclude = [ - "node_modules/inherits/test/**", - "node_modules/inherits/docs/**", - "node_modules/inherits/**/* */**", - "node_modules/inherits/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "inherits__typings", - srcs = glob( - include = ["node_modules/inherits/**/*.d.ts"], - exclude = [ - "node_modules/inherits/test/**", - "node_modules/inherits/docs/**", - "node_modules/inherits/**/* */**", - "node_modules/inherits/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "jasmine", - srcs = [ - ":jasmine__files", - ":glob__files", - ":fs.realpath__files", - ":inflight__files", - ":once__files", - ":wrappy__files", - ":inherits__files", - ":minimatch__files", - ":brace-expansion__files", - ":balanced-match__files", - ":concat-map__files", - ":path-is-absolute__files", - ":jasmine-core__files", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "jasmine__files", - srcs = glob( - include = ["node_modules/jasmine/**/*"], - exclude = [ - "node_modules/jasmine/test/**", - "node_modules/jasmine/docs/**", - "node_modules/jasmine/**/* */**", - "node_modules/jasmine/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "jasmine__typings", - srcs = glob( - include = ["node_modules/jasmine/**/*.d.ts"], - exclude = [ - "node_modules/jasmine/test/**", - "node_modules/jasmine/docs/**", - "node_modules/jasmine/**/* */**", - "node_modules/jasmine/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -nodejs_binary( - name = "jasmine/jasmine", - entry_point = "jasmine/bin/jasmine.js", - install_source_map_support = False, - data = [":jasmine"], -) -filegroup( - name = "jasmine-core", - srcs = [ - ":jasmine-core__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "jasmine-core__files", - srcs = glob( - include = ["node_modules/jasmine-core/**/*"], - exclude = [ - "node_modules/jasmine-core/test/**", - "node_modules/jasmine-core/docs/**", - "node_modules/jasmine-core/**/* */**", - "node_modules/jasmine-core/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "jasmine-core__typings", - srcs = glob( - include = ["node_modules/jasmine-core/**/*.d.ts"], - exclude = [ - "node_modules/jasmine-core/test/**", - "node_modules/jasmine-core/docs/**", - "node_modules/jasmine-core/**/* */**", - "node_modules/jasmine-core/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "minimatch", - srcs = [ - ":minimatch__files", - ":brace-expansion__files", - ":balanced-match__files", - ":concat-map__files", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "minimatch__files", - srcs = glob( - include = ["node_modules/minimatch/**/*"], - exclude = [ - "node_modules/minimatch/test/**", - "node_modules/minimatch/docs/**", - "node_modules/minimatch/**/* */**", - "node_modules/minimatch/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "minimatch__typings", - srcs = glob( - include = ["node_modules/minimatch/**/*.d.ts"], - exclude = [ - "node_modules/minimatch/test/**", - "node_modules/minimatch/docs/**", - "node_modules/minimatch/**/* */**", - "node_modules/minimatch/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "once", - srcs = [ - ":once__files", - ":wrappy__files", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "once__files", - srcs = glob( - include = ["node_modules/once/**/*"], - exclude = [ - "node_modules/once/test/**", - "node_modules/once/docs/**", - "node_modules/once/**/* */**", - "node_modules/once/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "once__typings", - srcs = glob( - include = ["node_modules/once/**/*.d.ts"], - exclude = [ - "node_modules/once/test/**", - "node_modules/once/docs/**", - "node_modules/once/**/* */**", - "node_modules/once/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "path-is-absolute", - srcs = [ - ":path-is-absolute__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "path-is-absolute__files", - srcs = glob( - include = ["node_modules/path-is-absolute/**/*"], - exclude = [ - "node_modules/path-is-absolute/test/**", - "node_modules/path-is-absolute/docs/**", - "node_modules/path-is-absolute/**/* */**", - "node_modules/path-is-absolute/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "path-is-absolute__typings", - srcs = glob( - include = ["node_modules/path-is-absolute/**/*.d.ts"], - exclude = [ - "node_modules/path-is-absolute/test/**", - "node_modules/path-is-absolute/docs/**", - "node_modules/path-is-absolute/**/* */**", - "node_modules/path-is-absolute/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "unidiff", - srcs = [ - ":unidiff__files", - ":diff__files", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "unidiff__files", - srcs = glob( - include = ["node_modules/unidiff/**/*"], - exclude = [ - "node_modules/unidiff/test/**", - "node_modules/unidiff/docs/**", - "node_modules/unidiff/**/* */**", - "node_modules/unidiff/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "unidiff__typings", - srcs = glob( - include = ["node_modules/unidiff/**/*.d.ts"], - exclude = [ - "node_modules/unidiff/test/**", - "node_modules/unidiff/docs/**", - "node_modules/unidiff/**/* */**", - "node_modules/unidiff/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "wrappy", - srcs = [ - ":wrappy__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "wrappy__files", - srcs = glob( - include = ["node_modules/wrappy/**/*"], - exclude = [ - "node_modules/wrappy/test/**", - "node_modules/wrappy/docs/**", - "node_modules/wrappy/**/* */**", - "node_modules/wrappy/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "wrappy__typings", - srcs = glob( - include = ["node_modules/wrappy/**/*.d.ts"], - exclude = [ - "node_modules/wrappy/test/**", - "node_modules/wrappy/docs/**", - "node_modules/wrappy/**/* */**", - "node_modules/wrappy/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@gregmagolan/test-a", - srcs = [ - ":@gregmagolan/test-a__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@gregmagolan/test-a__files", - srcs = glob( - include = ["node_modules/@gregmagolan/test-a/**/*"], - exclude = [ - "node_modules/@gregmagolan/test-a/test/**", - "node_modules/@gregmagolan/test-a/docs/**", - "node_modules/@gregmagolan/test-a/**/* */**", - "node_modules/@gregmagolan/test-a/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@gregmagolan/test-a__typings", - srcs = glob( - include = ["node_modules/@gregmagolan/test-a/**/*.d.ts"], - exclude = [ - "node_modules/@gregmagolan/test-a/test/**", - "node_modules/@gregmagolan/test-a/docs/**", - "node_modules/@gregmagolan/test-a/**/* */**", - "node_modules/@gregmagolan/test-a/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@gregmagolan/test-b", - srcs = [ - ":@gregmagolan/test-b__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@gregmagolan/test-b__files", - srcs = glob( - include = ["node_modules/@gregmagolan/test-b/**/*"], - exclude = [ - "node_modules/@gregmagolan/test-b/test/**", - "node_modules/@gregmagolan/test-b/docs/**", - "node_modules/@gregmagolan/test-b/**/* */**", - "node_modules/@gregmagolan/test-b/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@gregmagolan/test-b__typings", - srcs = glob( - include = ["node_modules/@gregmagolan/test-b/**/*.d.ts"], - exclude = [ - "node_modules/@gregmagolan/test-b/test/**", - "node_modules/@gregmagolan/test-b/docs/**", - "node_modules/@gregmagolan/test-b/**/* */**", - "node_modules/@gregmagolan/test-b/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@yarnpkg/lockfile", - srcs = [ - ":@yarnpkg/lockfile__files", - - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@yarnpkg/lockfile__files", - srcs = glob( - include = ["node_modules/@yarnpkg/lockfile/**/*"], - exclude = [ - "node_modules/@yarnpkg/lockfile/test/**", - "node_modules/@yarnpkg/lockfile/docs/**", - "node_modules/@yarnpkg/lockfile/**/* */**", - "node_modules/@yarnpkg/lockfile/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@yarnpkg/lockfile__typings", - srcs = glob( - include = ["node_modules/@yarnpkg/lockfile/**/*.d.ts"], - exclude = [ - "node_modules/@yarnpkg/lockfile/test/**", - "node_modules/@yarnpkg/lockfile/docs/**", - "node_modules/@yarnpkg/lockfile/**/* */**", - "node_modules/@yarnpkg/lockfile/**/* *", - ], - ), - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@gregmagolan", - srcs = [ - ":@gregmagolan/test-a", - ":@gregmagolan/test-b", - ], - tags = ["NODE_MODULE_MARKER"], -) -filegroup( - name = "@yarnpkg", - srcs = [ - ":@yarnpkg/lockfile", - ], - tags = ["NODE_MODULE_MARKER"], -) diff --git a/internal/npm_install/test/check.js b/internal/npm_install/test/check.js index 9dd8629b18..1f787de37a 100644 --- a/internal/npm_install/test/check.js +++ b/internal/npm_install/test/check.js @@ -3,10 +3,7 @@ const fs = require('fs'); const path = require('path'); const unidiff = require('unidiff') -const actual = 'BUILD.bazel'; -const golden = 'BUILD.bazel.golden'; - -function check(updateGolden = false) { +function check(actual, updateGolden = false) { // We must change the directory to the BUILD file path // so the generator is able to run process.chdir(path.dirname(__filename)); @@ -24,6 +21,7 @@ function check(updateGolden = false) { .replace(/[\n]+/g, '\n'); // Load the golden file for comparison + const golden = path.posix.join('golden', actual + '.golden'); const goldenContents = fs.readFileSync(golden, {encoding: 'utf-8'}).replace(/\r\n/g, '\n'); // Check if actualContents matches golden file @@ -48,4 +46,13 @@ Update the golden file: } } -module.exports = check; \ No newline at end of file +module.exports = { + check, + files: [ + 'BUILD.bazel', '@gregmagolan/BUILD.bazel', '@gregmagolan/test-a/BUILD.bazel', + '@gregmagolan/test-b/BUILD.bazel', 'jasmine/BUILD.bazel', 'unidiff/BUILD.bazel', + 'node_modules/@gregmagolan/BUILD.bazel', 'node_modules/@gregmagolan/test-a/BUILD.bazel', + 'node_modules/@gregmagolan/test-b/BUILD.bazel', 'node_modules/jasmine/BUILD.bazel', + 'node_modules/unidiff/BUILD.bazel' + ], +}; \ No newline at end of file diff --git a/internal/npm_install/test/generate_build_file.spec.js b/internal/npm_install/test/generate_build_file.spec.js index dd1fa56e9b..9653ca1b64 100644 --- a/internal/npm_install/test/generate_build_file.spec.js +++ b/internal/npm_install/test/generate_build_file.spec.js @@ -1,7 +1,7 @@ -const check = require('./check'); +const {check, files} = require('./check'); describe('build file generator', () => { - it('should produce a BUILD file from the node_modules file structure', () => { - check(); + it('should produce BUILD files from the node_modules file structure', () => { + files.forEach(file => check(file)); }); }); diff --git a/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden b/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden new file mode 100644 index 0000000000..050cd0a460 --- /dev/null +++ b/internal/npm_install/test/golden/@gregmagolan/BUILD.bazel.golden @@ -0,0 +1,6 @@ + +package(default_visibility = ["//visibility:public"]) +alias( + name = "@gregmagolan", + actual = "//node_modules/@gregmagolan", +) 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 new file mode 100644 index 0000000000..fabb32eba4 --- /dev/null +++ b/internal/npm_install/test/golden/@gregmagolan/test-a/BUILD.bazel.golden @@ -0,0 +1,6 @@ + +package(default_visibility = ["//visibility:public"]) +alias( + name = "test-a", + actual = "//node_modules/@gregmagolan/test-a", +) 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 new file mode 100644 index 0000000000..7d439251a3 --- /dev/null +++ b/internal/npm_install/test/golden/@gregmagolan/test-b/BUILD.bazel.golden @@ -0,0 +1,6 @@ + +package(default_visibility = ["//visibility:public"]) +alias( + name = "test-b", + actual = "//node_modules/@gregmagolan/test-b", +) diff --git a/internal/npm_install/test/golden/BUILD.bazel.golden b/internal/npm_install/test/golden/BUILD.bazel.golden new file mode 100644 index 0000000000..bd8f7fc964 --- /dev/null +++ b/internal/npm_install/test/golden/BUILD.bazel.golden @@ -0,0 +1,52 @@ + +package(default_visibility = ["//visibility:public"]) +filegroup( + name = "node_modules", + srcs = glob(["node_modules/.bin/*"]) + [ + "//node_modules/balanced-match:balanced-match__files", + "//node_modules/brace-expansion:brace-expansion__files", + "//node_modules/concat-map:concat-map__files", + "//node_modules/diff:diff__files", + "//node_modules/fs.realpath:fs.realpath__files", + "//node_modules/glob:glob__files", + "//node_modules/inflight:inflight__files", + "//node_modules/inherits:inherits__files", + "//node_modules/jasmine:jasmine__files", + "//node_modules/jasmine-core:jasmine-core__files", + "//node_modules/minimatch:minimatch__files", + "//node_modules/once:once__files", + "//node_modules/path-is-absolute:path-is-absolute__files", + "//node_modules/unidiff:unidiff__files", + "//node_modules/wrappy:wrappy__files", + "//node_modules/@gregmagolan/test-a:test-a__files", + "//node_modules/@gregmagolan/test-b:test-b__files", + "//node_modules/@yarnpkg/lockfile:lockfile__files", + ], +) +filegroup( + name = "node_modules_lite", + srcs = glob(["node_modules/.bin/*"]) + [ + "//node_modules/balanced-match:balanced-match__lite", + "//node_modules/brace-expansion:brace-expansion__lite", + "//node_modules/concat-map:concat-map__lite", + "//node_modules/diff:diff__lite", + "//node_modules/fs.realpath:fs.realpath__lite", + "//node_modules/glob:glob__lite", + "//node_modules/inflight:inflight__lite", + "//node_modules/inherits:inherits__lite", + "//node_modules/jasmine:jasmine__lite", + "//node_modules/jasmine-core:jasmine-core__lite", + "//node_modules/minimatch:minimatch__lite", + "//node_modules/once:once__lite", + "//node_modules/path-is-absolute:path-is-absolute__lite", + "//node_modules/unidiff:unidiff__lite", + "//node_modules/wrappy:wrappy__lite", + "//node_modules/@gregmagolan/test-a:test-a__lite", + "//node_modules/@gregmagolan/test-b:test-b__lite", + "//node_modules/@yarnpkg/lockfile:lockfile__lite", + ], +) +filegroup( + name = "node_modules_bin", + srcs = glob(["node_modules/.bin/*"]), +) diff --git a/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden b/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden new file mode 100644 index 0000000000..fd12e6a86d --- /dev/null +++ b/internal/npm_install/test/golden/jasmine/BUILD.bazel.golden @@ -0,0 +1,10 @@ + +package(default_visibility = ["//visibility:public"]) +alias( + name = "jasmine", + actual = "//node_modules/jasmine", +) +alias( + name = "jasmine__bin", + actual = "//node_modules/jasmine:jasmine__bin", +) diff --git a/internal/npm_install/test/golden/node_modules/@gregmagolan/BUILD.bazel.golden b/internal/npm_install/test/golden/node_modules/@gregmagolan/BUILD.bazel.golden new file mode 100644 index 0000000000..f7142117e9 --- /dev/null +++ b/internal/npm_install/test/golden/node_modules/@gregmagolan/BUILD.bazel.golden @@ -0,0 +1,10 @@ + +package(default_visibility = ["//visibility:public"]) +filegroup( + name = "@gregmagolan", + srcs = [ + "//node_modules/@gregmagolan/test-a", + "//node_modules/@gregmagolan/test-b", + ], + tags = ["NODE_MODULE_MARKER"], +) diff --git a/internal/npm_install/test/golden/node_modules/@gregmagolan/test-a/BUILD.bazel.golden b/internal/npm_install/test/golden/node_modules/@gregmagolan/test-a/BUILD.bazel.golden new file mode 100644 index 0000000000..236246ae50 --- /dev/null +++ b/internal/npm_install/test/golden/node_modules/@gregmagolan/test-a/BUILD.bazel.golden @@ -0,0 +1,54 @@ + +package(default_visibility = ["//visibility:public"]) +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") +filegroup( + name = "test-a", + srcs = [ + ":test-a__files", + + ], + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "test-a__files", + srcs = glob( + include = ["**/*"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "test-a__lite", + srcs = glob( + include = [ + "**/*.js", + "**/*.d.ts", + "**/*.json", + ], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "test-a__typings", + srcs = glob( + include = ["**/*.d.ts"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) diff --git a/internal/npm_install/test/golden/node_modules/@gregmagolan/test-b/BUILD.bazel.golden b/internal/npm_install/test/golden/node_modules/@gregmagolan/test-b/BUILD.bazel.golden new file mode 100644 index 0000000000..c975e5db55 --- /dev/null +++ b/internal/npm_install/test/golden/node_modules/@gregmagolan/test-b/BUILD.bazel.golden @@ -0,0 +1,54 @@ + +package(default_visibility = ["//visibility:public"]) +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") +filegroup( + name = "test-b", + srcs = [ + ":test-b__files", + + ], + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "test-b__files", + srcs = glob( + include = ["**/*"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "test-b__lite", + srcs = glob( + include = [ + "**/*.js", + "**/*.d.ts", + "**/*.json", + ], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "test-b__typings", + srcs = glob( + include = ["**/*.d.ts"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) diff --git a/internal/npm_install/test/golden/node_modules/jasmine/BUILD.bazel.golden b/internal/npm_install/test/golden/node_modules/jasmine/BUILD.bazel.golden new file mode 100644 index 0000000000..16a1663941 --- /dev/null +++ b/internal/npm_install/test/golden/node_modules/jasmine/BUILD.bazel.golden @@ -0,0 +1,71 @@ + +package(default_visibility = ["//visibility:public"]) +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") +filegroup( + name = "jasmine", + srcs = [ + ":jasmine__files", + "//node_modules/glob:glob__files", + "//node_modules/fs.realpath:fs.realpath__files", + "//node_modules/inflight:inflight__files", + "//node_modules/once:once__files", + "//node_modules/wrappy:wrappy__files", + "//node_modules/inherits:inherits__files", + "//node_modules/minimatch:minimatch__files", + "//node_modules/brace-expansion:brace-expansion__files", + "//node_modules/balanced-match:balanced-match__files", + "//node_modules/concat-map:concat-map__files", + "//node_modules/path-is-absolute:path-is-absolute__files", + "//node_modules/jasmine-core:jasmine-core__files", + ], + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "jasmine__files", + srcs = glob( + include = ["**/*"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "jasmine__lite", + srcs = glob( + include = [ + "**/*.js", + "**/*.d.ts", + "**/*.json", + ], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "jasmine__typings", + srcs = glob( + include = ["**/*.d.ts"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +nodejs_binary( + name = "jasmine__bin", + entry_point = "jasmine/bin/jasmine.js", + install_source_map_support = False, + data = [":jasmine"], +) diff --git a/internal/npm_install/test/golden/node_modules/unidiff/BUILD.bazel.golden b/internal/npm_install/test/golden/node_modules/unidiff/BUILD.bazel.golden new file mode 100644 index 0000000000..dd94c4aef4 --- /dev/null +++ b/internal/npm_install/test/golden/node_modules/unidiff/BUILD.bazel.golden @@ -0,0 +1,54 @@ + +package(default_visibility = ["//visibility:public"]) +load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") +filegroup( + name = "unidiff", + srcs = [ + ":unidiff__files", + "//node_modules/diff:diff__files", + ], + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "unidiff__files", + srcs = glob( + include = ["**/*"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "unidiff__lite", + srcs = glob( + include = [ + "**/*.js", + "**/*.d.ts", + "**/*.json", + ], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) +filegroup( + name = "unidiff__typings", + srcs = glob( + include = ["**/*.d.ts"], + exclude = [ + "test/**", + "docs/**", + "**/* */**", + "**/* *", + ], + ), + tags = ["NODE_MODULE_MARKER"], +) diff --git a/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden b/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden new file mode 100644 index 0000000000..92fa71cb10 --- /dev/null +++ b/internal/npm_install/test/golden/unidiff/BUILD.bazel.golden @@ -0,0 +1,6 @@ + +package(default_visibility = ["//visibility:public"]) +alias( + name = "unidiff", + actual = "//node_modules/unidiff", +) diff --git a/internal/npm_install/test/update_golden.js b/internal/npm_install/test/update_golden.js index f2224532c4..ce22df4630 100644 --- a/internal/npm_install/test/update_golden.js +++ b/internal/npm_install/test/update_golden.js @@ -1,3 +1,3 @@ -const check = require('./check'); +const {check, files} = require('./check'); -check(true); +files.forEach(file => check(file, true)); diff --git a/internal/npm_install/test/yarn.lock b/internal/npm_install/test/yarn.lock index 1c91ad5093..4acacd1b8a 100644 --- a/internal/npm_install/test/yarn.lock +++ b/internal/npm_install/test/yarn.lock @@ -17,8 +17,8 @@ "@gregmagolan/test-a" "0.0.1" "@yarnpkg/lockfile@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.0.2.tgz#833d163680a151d2441a2489f5fe5fa87ac87726" + version "1.1.0" + resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" balanced-match@^1.0.0: version "1.0.0" @@ -44,8 +44,8 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" glob@^7.0.6: - version "7.1.2" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" + version "7.1.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" dependencies: fs.realpath "^1.0.0" inflight "^1.0.4" diff --git a/internal/rollup/rollup_bundle.bzl b/internal/rollup/rollup_bundle.bzl index aab5fc1702..8096d33c33 100644 --- a/internal/rollup/rollup_bundle.bzl +++ b/internal/rollup/rollup_bundle.bzl @@ -497,8 +497,8 @@ ROLLUP_ATTRS = { name = "bundle", ... deps = [ - "@npm//:foo", - "@npm//:bar", + "@npm//foo", + "@npm//bar", ... ], )