Skip to content

Commit

Permalink
refactor: remove package_json attribute from node_repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Jan 11, 2022
1 parent fa84c43 commit abdf05b
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 202 deletions.
3 changes: 0 additions & 3 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ tasks:
name: ubuntu1804
platform: ubuntu1804
run_targets:
- "@node16_linux_amd64//:yarn_node_repositories"
- "@node16_linux_amd64//:yarn"
# Regression test for #1493
- "//packages/create:npm_package.pack"
Expand Down Expand Up @@ -130,7 +129,6 @@ tasks:
name: macos
platform: macos
run_targets:
- "@node16_darwin_amd64//:yarn_node_repositories"
- "@node16_darwin_amd64//:yarn"
# Regression test for #1493
- "//packages/create:npm_package.pack"
Expand Down Expand Up @@ -221,7 +219,6 @@ tasks:
name: windows
platform: windows
run_targets:
- "@node16_windows_amd64//:yarn_node_repositories"
- "@node16_windows_amd64//:yarn"
- "//internal/node/test:no_deps"
- "//internal/node/test:has_deps_legacy"
Expand Down
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import %workspace%/common.bazelrc
# This lets us glob() up all the files inside the examples to make them inputs to tests
# To update these lines, just run `yarn bazel:update-deleted-packages`
# (Note, we cannot use common --deleted_packages because the bazel version command doesn't support it)
build --deleted_packages=e2e/bazel_managed_deps,e2e/concatjs_devserver,e2e/concatjs_devserver/genrule,e2e/concatjs_devserver/subpackage,e2e/concatjs_devserver_directory_artifacts,e2e/concatjs_devserver_directory_artifacts/genrule,e2e/concatjs_devserver_directory_artifacts/subpackage,examples/toolchain,e2e/coverage,e2e/fine_grained_symlinks,e2e/jasmine,e2e/node_loader_no_preserve_symlinks,e2e/node_loader_preserve_symlinks,e2e/nodejs_image,e2e/nodejs_image/foolib,e2e/nodejs_repository,e2e/packages,e2e/symlinked_node_modules_npm,e2e/symlinked_node_modules_yarn,e2e/typescript,e2e/webapp,examples/angular,examples/angular/e2e,examples/angular/src,examples/angular/src/app,examples/angular/src/app/hello-world,examples/angular/src/app/home,examples/angular/src/app/todos,examples/angular/src/app/todos/reducers,examples/angular/src/assets,examples/angular/src/lib/shorten,examples/angular/src/shared/material,examples/angular/tools,examples/angular_bazel_architect,examples/angular_bazel_architect/projects/frontend-lib,examples/app,examples/app/styles,examples/app/test,examples/closure,examples/create-react-app,examples/cypress,examples/esbuild,examples/esbuild/src,examples/from_source,examples/jest,examples/jest/ts,examples/jest/ts/src,examples/jest/ts/test,examples/kotlin,examples/nestjs,examples/nestjs/src,examples/parcel,examples/protobufjs,examples/protocol_buffers,examples/react_webpack,examples/user_managed_deps,examples/vendored_node,examples/vendored_node_and_yarn,examples/vue,examples/vue/src,examples/vue/src/components/HelloWorld,examples/web_testing,examples/webapp,examples/worker
query --deleted_packages=e2e/bazel_managed_deps,e2e/concatjs_devserver,e2e/concatjs_devserver/genrule,e2e/concatjs_devserver/subpackage,e2e/concatjs_devserver_directory_artifacts,e2e/concatjs_devserver_directory_artifacts/genrule,e2e/concatjs_devserver_directory_artifacts/subpackage,examples/toolchain,e2e/coverage,e2e/fine_grained_symlinks,e2e/jasmine,e2e/node_loader_no_preserve_symlinks,e2e/node_loader_preserve_symlinks,e2e/nodejs_image,e2e/nodejs_image/foolib,e2e/nodejs_repository,e2e/packages,e2e/symlinked_node_modules_npm,e2e/symlinked_node_modules_yarn,e2e/typescript,e2e/webapp,examples/angular,examples/angular/e2e,examples/angular/src,examples/angular/src/app,examples/angular/src/app/hello-world,examples/angular/src/app/home,examples/angular/src/app/todos,examples/angular/src/app/todos/reducers,examples/angular/src/assets,examples/angular/src/lib/shorten,examples/angular/src/shared/material,examples/angular/tools,examples/angular_bazel_architect,examples/angular_bazel_architect/projects/frontend-lib,examples/app,examples/app/styles,examples/app/test,examples/closure,examples/create-react-app,examples/cypress,examples/esbuild,examples/esbuild/src,examples/from_source,examples/jest,examples/jest/ts,examples/jest/ts/src,examples/jest/ts/test,examples/kotlin,examples/nestjs,examples/nestjs/src,examples/parcel,examples/protobufjs,examples/protocol_buffers,examples/react_webpack,examples/user_managed_deps,examples/vendored_node,examples/vendored_node_and_yarn,examples/vue,examples/vue/src,examples/vue/src/components/HelloWorld,examples/web_testing,examples/webapp,examples/worker
build --deleted_packages=e2e/bazel_managed_deps,e2e/concatjs_devserver,e2e/concatjs_devserver/genrule,e2e/concatjs_devserver/subpackage,e2e/coverage,e2e/fine_grained_symlinks,e2e/jasmine,e2e/node_loader_no_preserve_symlinks,e2e/node_loader_preserve_symlinks,e2e/nodejs_host,e2e/nodejs_image,e2e/nodejs_image/foolib,e2e/packages,e2e/symlinked_node_modules_npm,e2e/symlinked_node_modules_yarn,e2e/typescript,e2e/webapp,examples/angular,examples/angular/e2e,examples/angular/src,examples/angular/src/app,examples/angular/src/app/hello-world,examples/angular/src/app/home,examples/angular/src/app/todos,examples/angular/src/app/todos/reducers,examples/angular/src/assets,examples/angular/src/lib/shorten,examples/angular/src/shared/material,examples/angular/tools,examples/angular_bazel_architect,examples/angular_bazel_architect/projects/frontend-lib,examples/app,examples/app/styles,examples/app/test,examples/closure,examples/create-react-app,examples/cypress,examples/esbuild,examples/esbuild/src,examples/from_source,examples/jest,examples/jest/ts,examples/jest/ts/src,examples/jest/ts/test,examples/kotlin,examples/nestjs,examples/nestjs/src,examples/parcel,examples/protobufjs,examples/react_webpack,examples/toolchain,examples/user_managed_deps,examples/vendored_node,examples/vendored_node_and_yarn,examples/vue,examples/vue/src,examples/vue/src/components/HelloWorld,examples/web_testing,examples/webapp,examples/worker
query --deleted_packages=e2e/bazel_managed_deps,e2e/concatjs_devserver,e2e/concatjs_devserver/genrule,e2e/concatjs_devserver/subpackage,e2e/coverage,e2e/fine_grained_symlinks,e2e/jasmine,e2e/node_loader_no_preserve_symlinks,e2e/node_loader_preserve_symlinks,e2e/nodejs_host,e2e/nodejs_image,e2e/nodejs_image/foolib,e2e/packages,e2e/symlinked_node_modules_npm,e2e/symlinked_node_modules_yarn,e2e/typescript,e2e/webapp,examples/angular,examples/angular/e2e,examples/angular/src,examples/angular/src/app,examples/angular/src/app/hello-world,examples/angular/src/app/home,examples/angular/src/app/todos,examples/angular/src/app/todos/reducers,examples/angular/src/assets,examples/angular/src/lib/shorten,examples/angular/src/shared/material,examples/angular/tools,examples/angular_bazel_architect,examples/angular_bazel_architect/projects/frontend-lib,examples/app,examples/app/styles,examples/app/test,examples/closure,examples/create-react-app,examples/cypress,examples/esbuild,examples/esbuild/src,examples/from_source,examples/jest,examples/jest/ts,examples/jest/ts/src,examples/jest/ts/test,examples/kotlin,examples/nestjs,examples/nestjs/src,examples/parcel,examples/protobufjs,examples/react_webpack,examples/toolchain,examples/user_managed_deps,examples/vendored_node,examples/vendored_node_and_yarn,examples/vue,examples/vue/src,examples/vue/src/components/HelloWorld,examples/web_testing,examples/webapp,examples/worker

# Mock versioning command to test the --stamp behavior
build --workspace_status_command="echo BUILD_SCM_VERSION 1.2.3"
Expand Down
6 changes: 3 additions & 3 deletions docs/Built-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ Actually publish the package with `npm publish` (also builds first):

```sh
# Check login credentials
$ bazel run @nodejs//:npm_node_repositories who
$ bazel run @nodejs_host//:npm who
# Publishes the package
$ bazel run :my_package.publish
```
Expand Down Expand Up @@ -1321,8 +1321,8 @@ This flag enables an exact install of the version that is specified in the `yarn
file. This helps to have reproducible builds across builds.

To update a dependency or install a new one run the `yarn install` command with the
vendored yarn binary. `bazel run @nodejs//:yarn install`. You can pass the options like
`bazel run @nodejs//:yarn install -- -D <dep-name>`.
vendored yarn binary. `bazel run @nodejs_host//:yarn install`. You can pass the options like
`bazel run @nodejs_host//:yarn install -- -D <dep-name>`.

Defaults to `True`

Expand Down
24 changes: 3 additions & 21 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,38 +238,20 @@ To use the Yarn package manager, which we recommend for its built-in
verification command, you can run:

```sh
$ bazel run @nodejs//:yarn_node_repositories
$ bazel run @nodejs_host//:yarn -- <arguments passed to yarn>
```

If you use npm instead, run:

```sh
$ bazel run @nodejs//:npm_node_repositories install
```

The `@nodejs//:yarn_node_repositories` and `@nodejs//:npm_node_repositories` targets will run yarn/npm on all of the
package.json contexts listed `package_json` attribute of the `node_repositories`
repository rule in your WORKSPACE file (`node_repositories(package_json = [...])`).

If there are multiple package.json contexts in this rule but you would like to
run the bazel managed yarn or npm on a single context this can be done
using the following targets:

```sh
$ bazel run @nodejs//:yarn -- <arguments passed to yarn>
```

If you use npm instead, run:

```sh
$ bazel run @nodejs//:npm -- <arguments passed to npm>
$ bazel run @nodejs_host//:npm -- <arguments passed to npm>
```

This will run yarn/npm in the current working directory. To add a package with the `yarn add` command,
for example, you would use:

```sh
$ bazel run @nodejs//:yarn -- add <package>
$ bazel run @nodejs_host//:yarn -- add <package>
```

Note: the arguments passed to `bazel run` after `--` are forwarded to the executable being run.
Expand Down
5 changes: 1 addition & 4 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Add this to your `WORKSPACE` file. It only tells Bazel how to find your
# NOTE: this rule installs nodejs, npm, and yarn, but does NOT install
# your npm dependencies into your node_modules folder.
# You must still run the package manager to do this.
node_repositories(package_json = ["//:package.json"])
node_repositories()
```
## Installation with a specific supported version of Node.js and Yarn

Expand All @@ -77,7 +77,6 @@ Add to `WORKSPACE`:
# your npm dependencies into your node_modules folder.
# You must still run the package manager to do this.
node_repositories(
package_json = ["//:package.json"],
node_version = "8.11.1",
yarn_version = "1.5.1",
)
Expand Down Expand Up @@ -106,7 +105,6 @@ node_repositories(
},
node_urls = ["https://nodejs.org/dist/v{version}/{filename}"],
yarn_urls = ["https://github.com/yarnpkg/yarn/releases/download/v{version}/{filename}"],
package_json = ["//:package.json"])
```

Specifying `node_urls` and `yarn_urls` is optional. If omitted, the default values will be used. You may also use a custom NodeJS version and the default Yarn version or vice-versa.
Expand All @@ -127,7 +125,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
node_repositories(
vendored_node = "@wksp//:third_party/node-v10.12.0-linux-x64",
vendored_yarn = "@wksp//:third_party/yarn-v1.10.0",
package_json = ["//:package.json"])
```

In this case, the locally installed Node.js and Yarn are located in the `wksp` workspace in
Expand Down
18 changes: 7 additions & 11 deletions docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,26 @@ rules_nodejs produces several repositories for you to reference.
Bazel represents your workspace as one repository, and code fetched or installed from outside your workspace lives in other repositories.
These are referenced with the `@repo//` syntax in your BUILD files.

## @nodejs
## @nodejs_host

This repository is created by calling the `node_repositories` function in your `WORKSPACE` file.
It contains the node, npm, and yarn programs.

As always, `bazel query` is useful for learning about what targets are available.

```sh
$ bazel query @nodejs//...
@nodejs//:node
$ bazel query @nodejs_host//...
@nodejs_host//:node
...
```

You don't typically need to reference the `@nodejs` repository from your BUILD files because it's used behind the scenes
to run node and fetch dependencies.
You don't typically need to reference the `@nodejs_host` repository from your BUILD files because it's used behind the scenes to run node and fetch dependencies.

Some ways you can use this:

- Run the Bazel-managed version of node: `bazel run @nodejs//:node path/to/program.js`
- Run the Bazel-managed version of npm: `bazel run @nodejs//:npm`
- Run the Bazel-managed version of yarn: `bazel run @nodejs//:yarn`
- Install dependencies from nested package.json file(s) which were passed to `node_repositories#package.json`
- using npm: `bazel run @nodejs//:npm_node_repositories install`
- using yarn: `bazel run @nodejs//:yarn_node_repositories`
- Run the Bazel-managed version of node: `bazel run @nodejs_host//:node path/to/program.js`
- Run the Bazel-managed version of npm: `bazel run @nodejs_host//:npm`
- Run the Bazel-managed version of yarn: `bazel run @nodejs_host//:yarn`

## @npm

Expand Down
8 changes: 1 addition & 7 deletions e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ e2e_integration_test(
)

e2e_integration_test(
name = "e2e_nodejs_repository",
# Only run on buildkite linux as we hard-coded the platform in the test
tags = [
"no-bazelci-mac",
"no-bazelci-windows",
"no-circleci",
],
name = "e2e_nodejs_host",
)

e2e_integration_test(
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions e2e/nodejs_host/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

# Dummy test target that imports various targets from the
# "@nodejs" repository. If a target of the repository is
# misconfigured, Bazel will complain about missing input files.
nodejs_test(
name = "test",
data = [
"index.spec.js",
"@nodejs_host//:node",
"@nodejs_host//:node_bin",
"@nodejs_host//:node_files",
"@nodejs_host//:npm",
"@nodejs_host//:npm_bin",
"@nodejs_host//:npm_files",
"@nodejs_host//:npx_bin",
"@nodejs_host//:yarn",
"@nodejs_host//:yarn_bin",
"@nodejs_host//:yarn_files",
],
entry_point = ":index.spec.js",
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
workspace(
name = "nodejs_repository",
name = "e2e_nodejs_host",
managed_directories = {"@npm": ["node_modules"]},
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 0 additions & 24 deletions e2e/nodejs_repository/BUILD.bazel

This file was deleted.

1 change: 0 additions & 1 deletion examples/from_source/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install

node_repositories(
node_version = "12.13.0",
package_json = ["//:package.json"],
yarn_version = "1.19.1",
)

Expand Down
15 changes: 4 additions & 11 deletions examples/user_managed_deps/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,12 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
# Install a hermetic version of node.
# After this is run, these labels will be available:
# - NodeJS:
# @nodejs//:node
# @nodejs_host//:node
# - NPM:
# @nodejs//:npm_node_repositories
# @nodejs_host//:npm
# - The yarn package manager:
# @nodejs//:yarn_node_repositories
#
# To install the node_modules of all the listed package_json files run:
# bazel run @nodejs//:yarn_node_repositories
# or
# bazel run @nodejs//:npm_node_repositories
node_repositories(
package_json = ["//:package.json"],
)
# @nodejs_host//:yarn
node_repositories()

# We have a source dependency on rules_typescript
# so we must repeat its transitive toolchain deps
Expand Down
2 changes: 1 addition & 1 deletion examples/user_managed_deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lodash": "4.17.20"
},
"scripts": {
"pretest": "bazel run @nodejs//:yarn_node_repositories",
"pretest": "bazel run @nodejs_host//:yarn -- install",
"test": "bazel test ..."
}
}
2 changes: 1 addition & 1 deletion internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fi
expected_exit_code = ctx.attr.expected_exit_code

# Add both the node executable for the user's local machine which is in ctx.files._node and comes
# from @nodejs//:node_bin and the node executable from the selected node --platform which comes from
# from @nodejs_host//:node_bin and the node executable from the selected node --platform which comes from
# ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo.
# In most cases these are the same files but for RBE and when explitely setting --platform for cross-compilation
# any given nodejs_binary should be able to run on both the user's local machine and on the RBE or selected
Expand Down
5 changes: 1 addition & 4 deletions internal/node/node_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Helper functions to get node and npm labels in @nodejs repository.
"""Helper functions to get node and npm labels in @nodejs_host and @nodejs_<platform> repositories.
Labels are different on windows and linux/OSX.
"""
Expand All @@ -29,8 +29,5 @@ def get_node_label(rctx):
def get_npm_label(rctx):
return _get_label(rctx, "bin/npm")

def get_npm_node_repositories_label(rctx):
return _get_label(rctx, "bin/npm_node_repositories")

def get_yarn_label(rctx):
return _get_label(rctx, "bin/yarn")
6 changes: 3 additions & 3 deletions internal/npm_install/npm_install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def _yarn_install_impl(repository_ctx):

# Set frozen lockfile as default install to install the exact version from the yarn.lock
# file. To perform an yarn install use the vendord yarn binary with:
# `bazel run @nodejs//:yarn install` or `bazel run @nodejs//:yarn install -- -D <dep-name>`
# `bazel run @nodejs_host//:yarn install` or `bazel run @nodejs_host//:yarn install -- -D <dep-name>`
if repository_ctx.attr.frozen_lockfile:
if yarn_version == "classic":
yarn_args.append("--frozen-lockfile")
Expand Down Expand Up @@ -975,8 +975,8 @@ This flag enables an exact install of the version that is specified in the `yarn
file. This helps to have reproducible builds across builds.
To update a dependency or install a new one run the `yarn install` command with the
vendored yarn binary. `bazel run @nodejs//:yarn install`. You can pass the options like
`bazel run @nodejs//:yarn install -- -D <dep-name>`.
vendored yarn binary. `bazel run @nodejs_host//:yarn install`. You can pass the options like
`bazel run @nodejs_host//:yarn install -- -D <dep-name>`.
""",
),
"use_global_yarn_cache": attr.bool(
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg_npm/pkg_npm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Actually publish the package with `npm publish` (also builds first):
```sh
# Check login credentials
$ bazel run @nodejs//:npm_node_repositories who
$ bazel run @nodejs_host//:npm who
# Publishes the package
$ bazel run :my_package.publish
```
Expand Down
4 changes: 1 addition & 3 deletions nodejs/private/nodejs_repo_host_os_alias.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"Provide convenience repository for the host platform like @nodejs"
"Provide convenience repository for the host platform"

load("//nodejs/private:os_name.bzl", "os_name")

Expand All @@ -18,8 +18,6 @@ alias(name = "yarn_bin", actual = "@{node_repository}_{os_name}//
alias(name = "node", actual = "@{node_repository}_{os_name}//:node")
alias(name = "npm", actual = "@{node_repository}_{os_name}//:npm")
alias(name = "yarn", actual = "@{node_repository}_{os_name}//:yarn")
alias(name = "npm_node_repositories", actual = "@{node_repository}_{os_name}//:npm_node_repositories")
alias(name = "yarn_node_repositories", actual = "@{node_repository}_{os_name}//:yarn_node_repositories")
alias(name = "node_files", actual = "@{node_repository}_{os_name}//:node_files")
alias(name = "yarn_files", actual = "@{node_repository}_{os_name}//:yarn_files")
alias(name = "npm_files", actual = "@{node_repository}_{os_name}//:npm_files")
Expand Down
Loading

0 comments on commit abdf05b

Please sign in to comment.