diff --git a/BUILD.bazel b/BUILD.bazel index 380b762687..63f354e9e9 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -14,7 +14,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") -load("@build_bazel_rules_nodejs//:index.bzl", "COMMON_REPLACEMENTS", "npm_package") +load("@build_bazel_rules_nodejs//:index.bzl", "COMMON_REPLACEMENTS", "pkg_npm") load("//:tools/defaults.bzl", "codeowners") package(default_visibility = ["//visibility:public"]) @@ -47,7 +47,7 @@ bzl_library( "//internal/common:bzl", "//internal/jasmine_node_test:bzl", "//internal/linker:bzl", - "//internal/npm_package:bzl", + "//internal/pkg_npm:bzl", "//internal/pkg_web:bzl", "//internal/providers:bzl", "//toolchains/node:bzl", @@ -61,7 +61,7 @@ filegroup( srcs = [], ) -npm_package( +pkg_npm( name = "rules_nodejs_package", srcs = glob(["*.bzl"]) + [ "BUILD.bazel", @@ -70,7 +70,7 @@ npm_package( # Don't rename BUILD files as this package is not published to npm # but is compressed in "release" below and published as a .tar.gz to GitHub rename_build_files = False, - # Don't replace the default 0.0.0-PLACEHOLDER for this npm_package since + # Don't replace the default 0.0.0-PLACEHOLDER for this pkg_npm since # we are packaging up the packager itself and this replacement will break it replace_with_version = "", replacements = COMMON_REPLACEMENTS, @@ -85,7 +85,7 @@ npm_package( "//internal/linker:package_contents", "//internal/node:package_contents", "//internal/npm_install:package_contents", - "//internal/npm_package:package_contents", + "//internal/pkg_npm:package_contents", "//internal/pkg_web:package_contents", "//internal/providers:package_contents", "//third_party/github.com/bazelbuild/bazel-skylib:package_contents", diff --git a/WORKSPACE b/WORKSPACE index 7fa7c23fef..703bded671 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -189,7 +189,7 @@ bazel_skylib_workspace() local_repository( name = "internal_npm_package_test_vendored_external", - path = "internal/npm_package/test/vendored_external", + path = "internal/pkg_npm/test/vendored_external", ) yarn_install( diff --git a/defs.bzl b/defs.bzl index 54824f7ad8..c6960e9f9b 100644 --- a/defs.bzl +++ b/defs.bzl @@ -21,25 +21,7 @@ ERROR: defs.bzl has been removed from build_bazel_rules_nodejs Please update your load statements to use index.bzl instead. -If you depend on another ruleset that still depends on defs.bzl, you must update: - -http_archive( - name = "io_bazel_rules_sass", - sha256 = "617e444f47a1f3e25eb1b6f8e88a2451d54a2afdc7c50518861d9f706fc8baaa", - urls = [ - "https://github.com/bazelbuild/rules_sass/archive/1.23.7.zip", - "https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/1.23.7.zip", - ], - strip_prefix = "rules_sass-1.23.7", -) - -http_archive( - name = "io_bazel_rules_docker", - sha256 = "c9b298ec18157fc8ada915bb958dfd1c3d98ec247b5aca29efb1d222b5f9e7df", - # TODO: update to next release after 17 December 2019 that includes this commit - strip_prefix = "rules_docker-8c28cb910f1b93d0fa3289a11ec62ef1710172d5", - urls = ["https://github.com/bazelbuild/rules_docker/archive/8c28cb910f1b93d0fa3289a11ec62ef1710172d5.zip"], -) +See https://github.com/bazelbuild/rules_nodejs/wiki#migrating-off-build_bazel_rules_nodejsdefsbzl for help. """) check_bazel_version = _error @@ -48,6 +30,7 @@ nodejs_test = _error node_repositories = _error jasmine_node_test = _error npm_package = _error +pkg_npm = _error npm_package_bin = _error # ANY RULES ADDED HERE SHOULD BE DOCUMENTED, see index.for_docs.bzl diff --git a/docs/Built-ins.md b/docs/Built-ins.md index 7df7bdd5e1..a1d5bf25b3 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -756,16 +756,16 @@ Defaults to `True` Defaults to `3600` -## npm_package +## pkg_npm -The npm_package rule creates a directory containing a publishable npm artifact. +The pkg_npm rule creates a directory containing a publishable npm artifact. Example: ```python -load("@build_bazel_rules_nodejs//:index.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") -npm_package( +pkg_npm( name = "my_package", srcs = ["package.json"], deps = [":my_typescript_lib"], @@ -787,7 +787,7 @@ function doThing() { Usage: -`npm_package` yields three labels. Build the package directory using the default label: +`pkg_npm` yields three labels. Build the package directory using the default label: ```sh $ bazel build :my_package @@ -821,7 +821,7 @@ You can pass arguments to npm by escaping them from Bazel using a double-hyphen ### Usage ``` -npm_package(name, deps, node_context_data, packages, rename_build_files, replace_with_version, replacements, srcs, vendor_external) +pkg_npm(name, deps, node_context_data, packages, rename_build_files, replace_with_version, replacements, srcs, vendor_external) ``` @@ -840,7 +840,7 @@ Defaults to `[]` Defaults to `@build_bazel_rules_nodejs//internal:node_context_data` #### `packages` -(*[labels]*): Other npm_package rules whose content is copied into this package. +(*[labels]*): Other pkg_npm rules whose content is copied into this package. Defaults to `[]` diff --git a/docs/index.md b/docs/index.md index 7d6ebfbba5..5f1ea489dc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -174,11 +174,11 @@ readonly BAZEL_BIN=./node_modules/.bin/bazel readonly TMP=$(mktemp -d -t bazel-release.XXXXXXX) readonly BAZEL="$BAZEL_BIN --output_base=$TMP" # Find all the npm packages in the repo -readonly NPM_PACKAGE_LABELS=`$BAZEL query --output=label 'kind("npm_package", //...)'` +readonly PKG_NPM_LABELS=`$BAZEL query --output=label 'kind("pkg_npm", //...)'` # Build them in one command to maximize parallelism -$BAZEL build --config=release $NPM_PACKAGE_LABELS +$BAZEL build --config=release $PKG_NPM_LABELS # publish one package at a time to make it easier to spot any errors or warnings -for pkg in $NPM_PACKAGE_LABELS ; do +for pkg in $PKG_NPM_LABELS ; do $BAZEL run -- ${pkg}.${NPM_COMMAND} --access public --tag latest done ``` diff --git a/examples/angular/package.json b/examples/angular/package.json index 8bef62104d..f9007edeb4 100644 --- a/examples/angular/package.json +++ b/examples/angular/package.json @@ -53,6 +53,7 @@ "karma-jasmine": "2.0.1", "karma-requirejs": "1.1.0", "karma-sourcemap-loader": "0.3.7", + "patch-package": "^6.2.0", "protractor": "^5.4.2", "requirejs": "2.3.6", "rollup": "^1.21.4", @@ -69,7 +70,7 @@ "e2e": "bazel test //e2e:all", "test": "bazel test //src/...", "benchmark": "ibazel-benchmark-runner //src:devserver src/app/hello-world/hello-world.component.ts --url=http://localhost:5432", - "postinstall": "ngcc", + "postinstall": "patch-package && ngcc", "generate": "node tools/generator/index.js", "generate:clean": "node tools/generator/index.js --clean" } diff --git a/examples/angular/patches/@angular+bazel+9.0.0-rc.2.patch b/examples/angular/patches/@angular+bazel+9.0.0-rc.2.patch new file mode 100644 index 0000000000..89fa345bed --- /dev/null +++ b/examples/angular/patches/@angular+bazel+9.0.0-rc.2.patch @@ -0,0 +1,51 @@ +diff --git a/node_modules/@angular/bazel/src/ng_package/ng_package.bzl b/node_modules/@angular/bazel/src/ng_package/ng_package.bzl +index ccda5a5..00f1624 100755 +--- a/node_modules/@angular/bazel/src/ng_package/ng_package.bzl ++++ b/node_modules/@angular/bazel/src/ng_package/ng_package.bzl +@@ -15,9 +15,9 @@ specification of this format at https://goo.gl/jB3GVv + + load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo", "JSNamedModuleInfo", "NpmPackageInfo", "node_modules_aspect") + load( +- "@build_bazel_rules_nodejs//internal/npm_package:npm_package.bzl", +- "NPM_PACKAGE_ATTRS", +- "NPM_PACKAGE_OUTPUTS", ++ "@build_bazel_rules_nodejs//internal/pkg_npm:pkg_npm.bzl", ++ "PKG_NPM_ATTRS", ++ "PKG_NPM_OUTPUTS", + "create_package", + ) + load("//src:external.bzl", "FLAT_DTS_FILE_SUFFIX") +@@ -619,7 +619,7 @@ def _ng_package_impl(ctx): + if JSNamedModuleInfo in dep: + devfiles = depset(transitive = [devfiles, dep[JSNamedModuleInfo].sources]) + +- # Re-use the create_package function from the nodejs npm_package rule. ++ # Re-use the create_package function from the nodejs pkg_npm rule. + package_dir = create_package( + ctx, + devfiles.to_list(), +@@ -631,7 +631,7 @@ def _ng_package_impl(ctx): + + _NG_PACKAGE_DEPS_ASPECTS = [esm5_outputs_aspect, ng_package_module_mappings_aspect, node_modules_aspect] + +-_NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **{ ++_NG_PACKAGE_ATTRS = dict(PKG_NPM_ATTRS, **{ + "srcs": attr.label_list( + doc = """JavaScript source files from the workspace. + These can use ES2015 syntax and ES Modules (import/export)""", +@@ -807,12 +807,12 @@ def _ng_package_outputs(name, entry_point, entry_point_name): + "umd": "%s.umd.js" % basename, + "umd_min": "%s.umd.min.js" % basename, + } +- for key in NPM_PACKAGE_OUTPUTS: +- # NPM_PACKAGE_OUTPUTS is a "normal" dict-valued outputs so it looks like ++ for key in PKG_NPM_OUTPUTS: ++ # PKG_NPM_OUTPUTS is a "normal" dict-valued outputs so it looks like + # "pack": "%{name}.pack", + # But this is a function-valued outputs. + # Bazel won't replace the %{name} token so we have to do it. +- outputs[key] = NPM_PACKAGE_OUTPUTS[key].replace("%{name}", name) ++ outputs[key] = PKG_NPM_OUTPUTS[key].replace("%{name}", name) + return outputs + + ng_package = rule( diff --git a/examples/angular/yarn.lock b/examples/angular/yarn.lock index 9a846a168b..a773b2ab04 100644 --- a/examples/angular/yarn.lock +++ b/examples/angular/yarn.lock @@ -1079,7 +1079,7 @@ resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.16.tgz#50a4755f8e33edacd9c406729e9b930d2451902a" integrity sha512-lMC2G0ItF2xv4UCiwbJGbnJlIuUixHrioOhNGHSCsYCJ8l4t9hMCUimCytvFv7qy6AfSzRxhRHoGa+UqaqwyeA== -"@yarnpkg/lockfile@1.1.0": +"@yarnpkg/lockfile@1.1.0", "@yarnpkg/lockfile@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== @@ -1820,6 +1820,11 @@ ci-info@^1.5.0: resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497" integrity sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A== +ci-info@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" + integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== + cjson@^0.3.1: version "0.3.3" resolved "https://registry.yarnpkg.com/cjson/-/cjson-0.3.3.tgz#a92d9c786e5bf9b930806329ee05d5d3261b4afa" @@ -2941,6 +2946,14 @@ find-up@^3.0.0: dependencies: locate-path "^3.0.0" +find-yarn-workspace-root@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db" + integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q== + dependencies: + fs-extra "^4.0.3" + micromatch "^3.1.4" + firebase-tools@7.1.0: version "7.1.0" resolved "https://registry.yarnpkg.com/firebase-tools/-/firebase-tools-7.1.0.tgz#dcde117e70d021d163616e8bcd02abead5d5c1e1" @@ -3091,6 +3104,15 @@ fs-extra@^0.30.0: path-is-absolute "^1.0.0" rimraf "^2.2.8" +fs-extra@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94" + integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg== + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + fs-extra@^7.0.1, fs-extra@~7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" @@ -3703,6 +3725,13 @@ is-ci@^1.0.10: dependencies: ci-info "^1.5.0" +is-ci@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" + integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w== + dependencies: + ci-info "^2.0.0" + is-data-descriptor@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56" @@ -4217,6 +4246,13 @@ kind-of@^6.0.0, kind-of@^6.0.2: resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051" integrity sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA== +klaw-sync@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" + integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== + dependencies: + graceful-fs "^4.1.11" + klaw@^1.0.0: version "1.3.1" resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439" @@ -5252,6 +5288,25 @@ pascalcase@^0.1.1: resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= +patch-package@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.2.0.tgz#677de858e352b6ca4e6cb48a6efde2cec9fde566" + integrity sha512-HWlQflaBBMjLBfOWomfolF8aqsFDeNbSNro1JDUgYqnVvPM5OILJ9DQdwIRiKmGaOsmHvhkl1FYkvv1I9r2ZJw== + dependencies: + "@yarnpkg/lockfile" "^1.1.0" + chalk "^2.4.2" + cross-spawn "^6.0.5" + find-yarn-workspace-root "^1.2.1" + fs-extra "^7.0.1" + is-ci "^2.0.0" + klaw-sync "^6.0.0" + minimist "^1.2.0" + rimraf "^2.6.3" + semver "^5.6.0" + slash "^2.0.0" + tmp "^0.0.33" + update-notifier "^2.5.0" + path-dirname@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/path-dirname/-/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0" diff --git a/examples/angular_view_engine/patches/@angular+bazel+9.0.0-rc.2.patch b/examples/angular_view_engine/patches/@angular+bazel+9.0.0-rc.2.patch new file mode 100644 index 0000000000..89fa345bed --- /dev/null +++ b/examples/angular_view_engine/patches/@angular+bazel+9.0.0-rc.2.patch @@ -0,0 +1,51 @@ +diff --git a/node_modules/@angular/bazel/src/ng_package/ng_package.bzl b/node_modules/@angular/bazel/src/ng_package/ng_package.bzl +index ccda5a5..00f1624 100755 +--- a/node_modules/@angular/bazel/src/ng_package/ng_package.bzl ++++ b/node_modules/@angular/bazel/src/ng_package/ng_package.bzl +@@ -15,9 +15,9 @@ specification of this format at https://goo.gl/jB3GVv + + load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo", "JSNamedModuleInfo", "NpmPackageInfo", "node_modules_aspect") + load( +- "@build_bazel_rules_nodejs//internal/npm_package:npm_package.bzl", +- "NPM_PACKAGE_ATTRS", +- "NPM_PACKAGE_OUTPUTS", ++ "@build_bazel_rules_nodejs//internal/pkg_npm:pkg_npm.bzl", ++ "PKG_NPM_ATTRS", ++ "PKG_NPM_OUTPUTS", + "create_package", + ) + load("//src:external.bzl", "FLAT_DTS_FILE_SUFFIX") +@@ -619,7 +619,7 @@ def _ng_package_impl(ctx): + if JSNamedModuleInfo in dep: + devfiles = depset(transitive = [devfiles, dep[JSNamedModuleInfo].sources]) + +- # Re-use the create_package function from the nodejs npm_package rule. ++ # Re-use the create_package function from the nodejs pkg_npm rule. + package_dir = create_package( + ctx, + devfiles.to_list(), +@@ -631,7 +631,7 @@ def _ng_package_impl(ctx): + + _NG_PACKAGE_DEPS_ASPECTS = [esm5_outputs_aspect, ng_package_module_mappings_aspect, node_modules_aspect] + +-_NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **{ ++_NG_PACKAGE_ATTRS = dict(PKG_NPM_ATTRS, **{ + "srcs": attr.label_list( + doc = """JavaScript source files from the workspace. + These can use ES2015 syntax and ES Modules (import/export)""", +@@ -807,12 +807,12 @@ def _ng_package_outputs(name, entry_point, entry_point_name): + "umd": "%s.umd.js" % basename, + "umd_min": "%s.umd.min.js" % basename, + } +- for key in NPM_PACKAGE_OUTPUTS: +- # NPM_PACKAGE_OUTPUTS is a "normal" dict-valued outputs so it looks like ++ for key in PKG_NPM_OUTPUTS: ++ # PKG_NPM_OUTPUTS is a "normal" dict-valued outputs so it looks like + # "pack": "%{name}.pack", + # But this is a function-valued outputs. + # Bazel won't replace the %{name} token so we have to do it. +- outputs[key] = NPM_PACKAGE_OUTPUTS[key].replace("%{name}", name) ++ outputs[key] = PKG_NPM_OUTPUTS[key].replace("%{name}", name) + return outputs + + ng_package = rule( diff --git a/index.bzl b/index.bzl index e36179b6fe..1097836363 100644 --- a/index.bzl +++ b/index.bzl @@ -29,7 +29,7 @@ load( load("//internal/node:node_repositories.bzl", _node_repositories = "node_repositories") load("//internal/node:npm_package_bin.bzl", _npm_bin = "npm_package_bin") load("//internal/npm_install:npm_install.bzl", _npm_install = "npm_install", _yarn_install = "yarn_install") -load("//internal/npm_package:npm_package.bzl", _npm_package = "npm_package") +load("//internal/pkg_npm:pkg_npm.bzl", _pkg_npm = "pkg_npm") load("//internal/pkg_web:pkg_web.bzl", _pkg_web = "pkg_web") check_bazel_version = _check_bazel_version @@ -37,7 +37,7 @@ nodejs_binary = _nodejs_binary nodejs_test = _nodejs_test node_repositories = _node_repositories jasmine_node_test = _jasmine_node_test -npm_package = _npm_package +pkg_npm = _pkg_npm npm_package_bin = _npm_bin pkg_web = _pkg_web copy_to_bin = _copy_to_bin diff --git a/index.for_docs.bzl b/index.for_docs.bzl index 5a35e6604c..4312ba4aa0 100644 --- a/index.for_docs.bzl +++ b/index.for_docs.bzl @@ -22,7 +22,7 @@ load("//internal/node:node.bzl", _nodejs_binary = "nodejs_binary", _nodejs_test load("//internal/node:node_repositories.bzl", _node_repositories = "node_repositories_rule") load("//internal/node:npm_package_bin.bzl", _npm_bin = "npm_package_bin") load("//internal/npm_install:npm_install.bzl", _npm_install = "npm_install", _yarn_install = "yarn_install") -load("//internal/npm_package:npm_package.bzl", _npm_package = "npm_package") +load("//internal/pkg_npm:pkg_npm.bzl", _pkg_npm = "pkg_npm") load("//internal/pkg_web:pkg_web.bzl", _pkg_web = "pkg_web") check_bazel_version = _check_bazel_version @@ -30,7 +30,7 @@ copy_to_bin = _copy_to_bin nodejs_binary = _nodejs_binary nodejs_test = _nodejs_test node_repositories = _node_repositories -npm_package = _npm_package +pkg_npm = _pkg_npm npm_install = _npm_install yarn_install = _yarn_install npm_package_bin = _npm_bin diff --git a/internal/bazel_integration_test/bazel_integration_test.bzl b/internal/bazel_integration_test/bazel_integration_test.bzl index 5704ce961d..a662515ba8 100644 --- a/internal/bazel_integration_test/bazel_integration_test.bzl +++ b/internal/bazel_integration_test/bazel_integration_test.bzl @@ -183,7 +183,7 @@ are missed for any one test. ), "npm_packages": attr.label_keyed_string_dict( doc = """A label keyed string dictionary of npm package replacements to make in the workspace-under-test's -package.json with generated npm package targets. The targets should be npm_package rules. +package.json with generated npm package targets. The targets should be pkg_npm rules. For example, ``` diff --git a/internal/bazel_integration_test/test_runner.js b/internal/bazel_integration_test/test_runner.js index 2370a45cd7..70276caf6e 100644 --- a/internal/bazel_integration_test/test_runner.js +++ b/internal/bazel_integration_test/test_runner.js @@ -270,7 +270,7 @@ if (isFile(packageJsonFile)) { if (packageJsonContents.includes(`"${packageJsonKey}"`) && !packageJsonContents.includes(`"${packageJsonKey}": "file:`)) { console.error(`bazel_integration_test: expected replacement of npm package ${ - packageJsonKey} for locally generated npm_package not found; add ${ + packageJsonKey} for locally generated npm package not found; add ${ packageJsonKey} to npm_packages attribute`); process.exit(1); } diff --git a/internal/node/context.bzl b/internal/node/context.bzl index 2397357beb..dfde3ac760 100644 --- a/internal/node/context.bzl +++ b/internal/node/context.bzl @@ -4,7 +4,7 @@ load("@build_bazel_rules_nodejs//:providers.bzl", "NodeContextInfo") _DOC = """node_context_data gathers information about the build configuration. It is a common dependency of all targets that are sensitive to configuration. -(currently npm_package and rollup_bundle)""" +(currently pkg_npm and rollup_bundle)""" def _impl(ctx): return [NodeContextInfo(stamp = ctx.attr.stamp)] diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index 8fbe08ef98..92881c8bff 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -333,7 +333,7 @@ def _prepare_node(repository_ctx): the BUILD file here. In addition, we create a bash script wrapper around NPM that passes a given NPM command to all package.json labels passed into here. - Finally, we create a reusable template bash script around NPM that is used by rules like npm_package to access + Finally, we create a reusable template bash script around NPM that is used by rules like pkg_npm to access NPM. Args: @@ -520,7 +520,7 @@ if %errorlevel% neq 0 exit /b %errorlevel% for package_json in repository_ctx.attr.package_json ]), executable = True) - # This template file is used by the packager tool and the npm_package rule. + # This template file is used by the packager tool and the pkg_npm rule. # `yarn publish` is not ready for use under Bazel, see https://github.com/yarnpkg/yarn/issues/610 repository_ctx.file("run_npm.sh.template", content = """ "{node}" "{script}" TMPL_args "$@" diff --git a/internal/npm_package/BUILD.bazel b/internal/pkg_npm/BUILD.bazel similarity index 95% rename from internal/npm_package/BUILD.bazel rename to internal/pkg_npm/BUILD.bazel index 5d44da157d..2a18670337 100644 --- a/internal/npm_package/BUILD.bazel +++ b/internal/pkg_npm/BUILD.bazel @@ -10,7 +10,7 @@ bzl_library( ) # Exported to be consumed for generating skydoc. -exports_files(["npm_package.bzl"]) +exports_files(["pkg_npm.bzl"]) nodejs_binary( name = "packager", diff --git a/internal/npm_package/packager.js b/internal/pkg_npm/packager.js similarity index 98% rename from internal/npm_package/packager.js rename to internal/pkg_npm/packager.js index 3c86b8e788..c5b8f8496e 100644 --- a/internal/npm_package/packager.js +++ b/internal/pkg_npm/packager.js @@ -179,7 +179,8 @@ function main(args) { const npmTemplate = fs.readFileSync(require.resolve(runNpmTemplatePath), {encoding: 'utf-8'}); // Resolve the outDir to an absolute path so it doesn't depend on Bazel's bazel-out symlink fs.writeFileSync(packPath, npmTemplate.replace('TMPL_args', `pack "${path.resolve(outDir)}"`)); - fs.writeFileSync(publishPath, npmTemplate.replace('TMPL_args', `publish "${path.resolve(outDir)}"`)); + fs.writeFileSync( + publishPath, npmTemplate.replace('TMPL_args', `publish "${path.resolve(outDir)}"`)); } if (require.main === module) { diff --git a/internal/npm_package/npm_package.bzl b/internal/pkg_npm/pkg_npm.bzl similarity index 93% rename from internal/npm_package/npm_package.bzl rename to internal/pkg_npm/pkg_npm.bzl index 37d117610f..23f833959d 100644 --- a/internal/npm_package/npm_package.bzl +++ b/internal/pkg_npm/pkg_npm.bzl @@ -89,7 +89,7 @@ def create_package(ctx, deps_sources, nested_packages): ) return package_dir -def _npm_package(ctx): +def _pkg_npm(ctx): sources_depsets = [] for dep in ctx.attr.deps: @@ -118,7 +118,7 @@ def _npm_package(ctx): runfiles = ctx.runfiles([package_dir]), )] -NPM_PACKAGE_ATTRS = { +PKG_NPM_ATTRS = { "srcs": attr.label_list( doc = """Files inside this directory which are simply copied into the package.""", allow_files = True, @@ -129,7 +129,7 @@ NPM_PACKAGE_ATTRS = { doc = "Internal use only", ), "packages": attr.label_list( - doc = """Other npm_package rules whose content is copied into this package.""", + doc = """Other pkg_npm rules whose content is copied into this package.""", allow_files = True, ), "rename_build_files": attr.bool( @@ -155,7 +155,7 @@ NPM_PACKAGE_ATTRS = { allow_files = True, ), "_packager": attr.label( - default = Label("//internal/npm_package:packager"), + default = Label("//internal/pkg_npm:packager"), cfg = "host", executable = True, ), @@ -165,22 +165,22 @@ NPM_PACKAGE_ATTRS = { ), } -NPM_PACKAGE_OUTPUTS = { +PKG_NPM_OUTPUTS = { "pack": "%{name}.pack", "publish": "%{name}.publish", } -npm_package = rule( - implementation = _npm_package, - attrs = NPM_PACKAGE_ATTRS, - doc = """The npm_package rule creates a directory containing a publishable npm artifact. +pkg_npm = rule( + implementation = _pkg_npm, + attrs = PKG_NPM_ATTRS, + doc = """The pkg_npm rule creates a directory containing a publishable npm artifact. Example: ```python -load("@build_bazel_rules_nodejs//:index.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") -npm_package( +pkg_npm( name = "my_package", srcs = ["package.json"], deps = [":my_typescript_lib"], @@ -202,7 +202,7 @@ function doThing() { Usage: -`npm_package` yields three labels. Build the package directory using the default label: +`pkg_npm` yields three labels. Build the package directory using the default label: ```sh $ bazel build :my_package @@ -231,5 +231,5 @@ $ bazel run :my_package.publish You can pass arguments to npm by escaping them from Bazel using a double-hyphen `bazel run my_package.publish -- --tag=next` """, - outputs = NPM_PACKAGE_OUTPUTS, + outputs = PKG_NPM_OUTPUTS, ) diff --git a/internal/npm_package/test/BUILD.bazel b/internal/pkg_npm/test/BUILD.bazel similarity index 91% rename from internal/npm_package/test/BUILD.bazel rename to internal/pkg_npm/test/BUILD.bazel index 323ebe0b3f..12fa8226ed 100644 --- a/internal/npm_package/test/BUILD.bazel +++ b/internal/pkg_npm/test/BUILD.bazel @@ -1,4 +1,4 @@ -load("@build_bazel_rules_nodejs//:index.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test") load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library") load("//internal/node:context.bzl", "node_context_data") @@ -16,7 +16,7 @@ ts_library( data = ["data.json"], ) -npm_package( +pkg_npm( name = "dependent_pkg", srcs = ["dependent_file"], ) @@ -28,7 +28,7 @@ node_context_data( stamp = True, ) -npm_package( +pkg_npm( name = "test_pkg", srcs = [ "package.json", @@ -51,7 +51,7 @@ npm_package( jasmine_node_test( name = "test", - srcs = ["npm_package.spec.js"], + srcs = ["pkg_npm.spec.js"], data = [":test_pkg"], ) diff --git a/internal/npm_package/test/data.json b/internal/pkg_npm/test/data.json similarity index 100% rename from internal/npm_package/test/data.json rename to internal/pkg_npm/test/data.json diff --git a/internal/npm_package/test/dependent_file b/internal/pkg_npm/test/dependent_file similarity index 100% rename from internal/npm_package/test/dependent_file rename to internal/pkg_npm/test/dependent_file diff --git a/internal/npm_package/test/foo.ts b/internal/pkg_npm/test/foo.ts similarity index 100% rename from internal/npm_package/test/foo.ts rename to internal/pkg_npm/test/foo.ts diff --git a/internal/npm_package/test/package.json b/internal/pkg_npm/test/package.json similarity index 100% rename from internal/npm_package/test/package.json rename to internal/pkg_npm/test/package.json diff --git a/internal/npm_package/test/npm_package.spec.js b/internal/pkg_npm/test/pkg_npm.spec.js similarity index 96% rename from internal/npm_package/test/npm_package.spec.js rename to internal/pkg_npm/test/pkg_npm.spec.js index 37a751b2e9..121011a009 100644 --- a/internal/npm_package/test/npm_package.spec.js +++ b/internal/pkg_npm/test/pkg_npm.spec.js @@ -11,7 +11,7 @@ function read(p) { return fs.readFileSync(path.join(dir, 'test_pkg', p), {encoding: 'utf-8'}).trim(); } -describe('npm_package srcs', () => { +describe('pkg_npm srcs', () => { it('copies srcs and replaces contents', () => { expect(read('some_file')).toEqual('replaced'); }); @@ -48,7 +48,7 @@ describe('npm_package srcs', () => { }); it('vendors external workspaces', () => { - // TODO(alexeagle): there isn't a way to test this yet, because the npm_package under test + // TODO(alexeagle): there isn't a way to test this yet, because the pkg_npm under test // has to live in the root of the repository in order for external/foo to appear inside it }); }); diff --git a/internal/npm_package/test/some_file b/internal/pkg_npm/test/some_file similarity index 100% rename from internal/npm_package/test/some_file rename to internal/pkg_npm/test/some_file diff --git a/internal/npm_package/test/vendored_external/BUILD.bazel b/internal/pkg_npm/test/vendored_external/BUILD.bazel similarity index 100% rename from internal/npm_package/test/vendored_external/BUILD.bazel rename to internal/pkg_npm/test/vendored_external/BUILD.bazel diff --git a/internal/npm_package/test/vendored_external/WORKSPACE b/internal/pkg_npm/test/vendored_external/WORKSPACE similarity index 100% rename from internal/npm_package/test/vendored_external/WORKSPACE rename to internal/pkg_npm/test/vendored_external/WORKSPACE diff --git a/internal/npm_package/test/vendored_external/external.ts b/internal/pkg_npm/test/vendored_external/external.ts similarity index 100% rename from internal/npm_package/test/vendored_external/external.ts rename to internal/pkg_npm/test/vendored_external/external.ts diff --git a/internal/npm_package/test/vendored_external/tsconfig.json b/internal/pkg_npm/test/vendored_external/tsconfig.json similarity index 100% rename from internal/npm_package/test/vendored_external/tsconfig.json rename to internal/pkg_npm/test/vendored_external/tsconfig.json diff --git a/internal/npm_package/test/vendored_external/vendored_external_file b/internal/pkg_npm/test/vendored_external/vendored_external_file similarity index 100% rename from internal/npm_package/test/vendored_external/vendored_external_file rename to internal/pkg_npm/test/vendored_external/vendored_external_file diff --git a/packages/create/BUILD.bazel b/packages/create/BUILD.bazel index c0d126cf3a..8c2d60cce6 100644 --- a/packages/create/BUILD.bazel +++ b/packages/create/BUILD.bazel @@ -1,4 +1,4 @@ -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "nodejs_test", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "nodejs_test", "pkg_npm") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") # Copy common bazelrc file to be included in this package @@ -8,7 +8,7 @@ copy_file( out = "common.bazelrc", ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "README.md", diff --git a/packages/hide-bazel-files/BUILD.bazel b/packages/hide-bazel-files/BUILD.bazel index c1651be7b7..d7bf48a4c9 100644 --- a/packages/hide-bazel-files/BUILD.bazel +++ b/packages/hide-bazel-files/BUILD.bazel @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") -npm_package( +pkg_npm( name = "npm_package", srcs = [ ":README.md", diff --git a/packages/jasmine/BUILD.bazel b/packages/jasmine/BUILD.bazel index 899402aa16..1e8f9a88e1 100644 --- a/packages/jasmine/BUILD.bazel +++ b/packages/jasmine/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") # Ugly genrule depending on local linux environment to build the README out of skylark doc generation. # Only referenced when we do a release. @@ -29,7 +29,7 @@ genrule( visibility = ["//docs:__pkg__"], ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "@npm_bazel_jasmine//:package_contents", diff --git a/packages/karma/BUILD.bazel b/packages/karma/BUILD.bazel index 2744af5be3..329027ca76 100644 --- a/packages/karma/BUILD.bazel +++ b/packages/karma/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") # Ugly genrule depending on local linux environment to build the README out of skylark doc generation. # Only referenced when we do a release. @@ -29,7 +29,7 @@ genrule( visibility = ["//docs:__pkg__"], ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "@npm_bazel_karma//:package_contents", diff --git a/packages/labs/BUILD.bazel b/packages/labs/BUILD.bazel index 074c7d3c7d..72c7568212 100644 --- a/packages/labs/BUILD.bazel +++ b/packages/labs/BUILD.bazel @@ -1,8 +1,8 @@ -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") exports_files(["tsconfig.json"]) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "@npm_bazel_labs//:package_contents", diff --git a/packages/protractor/BUILD.bazel b/packages/protractor/BUILD.bazel index a46a64f7b7..58c82fa134 100644 --- a/packages/protractor/BUILD.bazel +++ b/packages/protractor/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") # Ugly genrule depending on local linux environment to build the README out of skylark doc generation. # Only referenced when we do a release. @@ -29,7 +29,7 @@ genrule( visibility = ["//docs:__pkg__"], ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "@npm_bazel_protractor//:package_contents", diff --git a/packages/rollup/BUILD.bazel b/packages/rollup/BUILD.bazel index ddc5d74669..ec79881112 100644 --- a/packages/rollup/BUILD.bazel +++ b/packages/rollup/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") # Ugly genrule depending on local linux environment to build the README out of skylark doc generation. # Only referenced when we do a release. @@ -29,7 +29,7 @@ genrule( visibility = ["//docs:__pkg__"], ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "@npm_bazel_rollup//:package_contents", diff --git a/packages/terser/BUILD.bazel b/packages/terser/BUILD.bazel index f354f5ea55..375be7a7ef 100644 --- a/packages/terser/BUILD.bazel +++ b/packages/terser/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") # Ugly genrule depending on local linux environment to build the README out of skylark doc generation. # Only referenced when we do a release. @@ -29,7 +29,7 @@ genrule( visibility = ["//docs:__pkg__"], ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "@npm_bazel_terser//:package_contents", diff --git a/packages/typescript/BUILD.bazel b/packages/typescript/BUILD.bazel index d25255c951..2c635b5fd6 100644 --- a/packages/typescript/BUILD.bazel +++ b/packages/typescript/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") load(":replacements.bzl", "TYPESCRIPT_REPLACEMENTS") # Ugly genrule depending on local linux environment to build the README out of skylark doc generation. @@ -30,7 +30,7 @@ genrule( visibility = ["//docs:__pkg__"], ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "@npm_bazel_typescript//:package_contents", diff --git a/packages/worker/BUILD.bazel b/packages/worker/BUILD.bazel index 0a8676324f..6b232411e3 100644 --- a/packages/worker/BUILD.bazel +++ b/packages/worker/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") # We reach inside the @bazel/typescript npm package to grab this one .js file @@ -45,7 +45,7 @@ copy_file( out = "%s/worker_protocol.proto" % _worker_proto_dir, ) -npm_package( +pkg_npm( name = "npm_package", srcs = [ "README.md", diff --git a/rules_typescript.patch b/rules_typescript.patch index 99161d5aa9..3a253b5423 100644 --- a/rules_typescript.patch +++ b/rules_typescript.patch @@ -1,3 +1,25 @@ +diff --git a/BUILD.bazel b/BUILD.bazel +index b0a0051..3a519c5 100644 +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -19,7 +19,7 @@ + # https://github.com/bazelbuild/rules_go/blob/master/go/tools/gazelle/README.rst#directives + # gazelle:exclude node_modules + load("@bazel_gazelle//:def.bzl", "gazelle") +-load("@build_bazel_rules_nodejs//:index.bzl", "npm_package") ++load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") + + exports_files([ + "LICENSE", +@@ -32,7 +32,7 @@ gazelle( + ) + + # This package is included in the npm_bazel_typescript package in rules_nodejs/packages/typescript +-npm_package( ++pkg_npm( + name = "npm_bazel_typescript_package", + srcs = [ + "//internal:npm_package_assets", diff --git a/internal/common/compilation.bzl b/internal/common/compilation.bzl index e815f37..a2b6468 100644 --- a/internal/common/compilation.bzl diff --git a/scripts/clean_yarn_cache_selectively.sh b/scripts/clean_yarn_cache_selectively.sh index eec5f4d769..2e94cb0c7f 100755 --- a/scripts/clean_yarn_cache_selectively.sh +++ b/scripts/clean_yarn_cache_selectively.sh @@ -11,9 +11,9 @@ echo_and_run() { echo "+ $@" ; "$@" ; } echo "yarn cache root: ${YARN_CACHE_ROOT}" -readonly NPM_PACKAGE_LABELS=`bazel query --output=package 'kind("npm_package", //packages/...)'` +readonly PKG_NPM_LABELS=`bazel query --output=package 'kind("pkg_npm", //packages/...)'` -for npmPackageLabel in ${NPM_PACKAGE_LABELS[@]} ; do +for npmPackageLabel in ${PKG_NPM_LABELS[@]} ; do # Trim packages/foobar to foobar package=$(echo ${npmPackageLabel} | cut -c 10-) echo_and_run yarn cache clean @bazel/${package} diff --git a/scripts/publish_release.sh b/scripts/publish_release.sh index bd602cc0cc..deb2a6f3e1 100755 --- a/scripts/publish_release.sh +++ b/scripts/publish_release.sh @@ -17,10 +17,10 @@ readonly BAZEL_BIN=./node_modules/.bin/bazel # Bazel can't know if the git metadata changed readonly TMP=$(mktemp -d -t bazel-release.XXXXXXX) readonly BAZEL="$BAZEL_BIN --output_base=$TMP" -readonly NPM_PACKAGE_LABELS=`$BAZEL query --output=label 'kind("npm_package rule", //packages/...) - attr("tags", "\[.*do-not-publish.*\]", //packages/...)'` +readonly PKG_NPM_LABELS=`$BAZEL query --output=label 'kind("pkg_npm rule", //packages/...) - attr("tags", "\[.*do-not-publish.*\]", //packages/...)'` -$BAZEL build --config=release $NPM_PACKAGE_LABELS +$BAZEL build --config=release $PKG_NPM_LABELS # publish one package at a time to make it easier to spot any errors or warnings -for pkg in $NPM_PACKAGE_LABELS ; do +for pkg in $PKG_NPM_LABELS ; do $BAZEL run --config=release -- ${pkg}.${NPM_COMMAND} --access public --tag latest --registry https://wombat-dressing-room.appspot.com done diff --git a/tools/defaults.bzl b/tools/defaults.bzl index feed4843d7..00f8231c70 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -7,15 +7,15 @@ load( "@build_bazel_rules_nodejs//:index.bzl", _COMMON_REPLACEMENTS = "COMMON_REPLACEMENTS", _nodejs_test = "nodejs_test", - _npm_package = "npm_package", + _pkg_npm = "pkg_npm", ) load("@rules_codeowners//tools:codeowners.bzl", _codeowners = "codeowners") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") nodejs_test = _nodejs_test -def npm_package(**kwargs): - "Set some defaults for the npm_package rule" +def pkg_npm(**kwargs): + "Set some defaults for the pkg_npm rule" # Every package should have a copy of the root LICENSE file copy_file( @@ -47,7 +47,7 @@ def npm_package(**kwargs): replacements = kwargs.pop("replacements", _COMMON_REPLACEMENTS) # Finally call through to the rule with our defaults set - _npm_package( + _pkg_npm( deps = deps, replacements = replacements, visibility = visibility,