Skip to content

Commit

Permalink
refactor(builtin): renamed npm_package to pkg_npm to match naming con…
Browse files Browse the repository at this point in the history
…vention

It also frees up the name `npm_package` which may be useful in the future as a non-packaging representation of an npm package as an alternative to promoting js_library to the public API.

BREAKING CHANGE:
`npm_package` renamed to `pkg_npm`. This is to match the naming convention for package rules https://docs.bazel.build/versions/master/be/pkg.html.
  • Loading branch information
gregmagolan authored and alexeagle committed Dec 18, 2019
1 parent e04b268 commit 7df4109
Show file tree
Hide file tree
Showing 44 changed files with 260 additions and 96 deletions.
10 changes: 5 additions & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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",
Expand All @@ -61,7 +61,7 @@ filegroup(
srcs = [],
)

npm_package(
pkg_npm(
name = "rules_nodejs_package",
srcs = glob(["*.bzl"]) + [
"BUILD.bazel",
Expand All @@ -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,
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 2 additions & 19 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions docs/Built-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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
Expand Down Expand Up @@ -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)
```


Expand All @@ -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 `[]`

Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
3 changes: 2 additions & 1 deletion examples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand Down
51 changes: 51 additions & 0 deletions examples/angular/patches/@angular+bazel+9.0.0-rc.2.patch
Original file line number Diff line number Diff line change
@@ -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(
57 changes: 56 additions & 1 deletion examples/angular/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.16.tgz#50a4755f8e33edacd9c406729e9b930d2451902a"
integrity sha512-lMC2G0ItF2xv4UCiwbJGbnJlIuUixHrioOhNGHSCsYCJ8l4t9hMCUimCytvFv7qy6AfSzRxhRHoGa+UqaqwyeA==

"@yarnpkg/[email protected]":
"@yarnpkg/[email protected]", "@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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"

[email protected]:
version "7.1.0"
resolved "https://registry.yarnpkg.com/firebase-tools/-/firebase-tools-7.1.0.tgz#dcde117e70d021d163616e8bcd02abead5d5c1e1"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
4 changes: 2 additions & 2 deletions index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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
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
Expand Down
Loading

0 comments on commit 7df4109

Please sign in to comment.