Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bazel-contrib/rules_nodejs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ee5b9dfad0ea4c6f3f4ad01e2e8110e23166e105
Choose a base ref
..
head repository: bazel-contrib/rules_nodejs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1d187ff837df9827fec62e62148e819c896fee98
Choose a head ref
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ npm_install(
".json",
".proto",
],
npm_ci = False,
npm_command = "install",
package_json = "//:tools/fine_grained_deps_npm/package.json",
package_lock_json = "//:tools/fine_grained_deps_npm/package-lock.json",
symlink_node_modules = False,
4 changes: 2 additions & 2 deletions e2e/packages/WORKSPACE
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ npm_install(
name = "e2e_packages_npm_install",
args = ["--production"],
data = ["//:postinstall.js"],
npm_ci = False,
npm_command = "install",
package_json = "//:npm1/package.json",
package_lock_json = "//:npm1/package-lock.json",
symlink_node_modules = False,
@@ -29,7 +29,7 @@ npm_install(
name = "e2e_packages_npm_install_duplicate_for_determinism_testing",
args = ["--production"],
data = ["//:postinstall.js"],
npm_ci = False,
npm_command = "install",
package_json = "//:npm2/package.json",
package_lock_json = "//:npm2/package-lock.json",
symlink_node_modules = False,
2 changes: 1 addition & 1 deletion e2e/symlinked_node_modules_npm/WORKSPACE
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")

npm_install(
name = "npm",
npm_ci = False,
npm_command = "install",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
quiet = False,
6 changes: 1 addition & 5 deletions examples/kotlin/WORKSPACE
Original file line number Diff line number Diff line change
@@ -17,11 +17,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
npm_install(
# Name this npm so that Bazel Label references look like @npm//package
name = "npm",
# Set this to true in a real world example (the default value is true), to have hermetic
# builds and use npm ci in favour of npm install. We have to disable this here as the @bazel
# scoped packages are getting replaced in the package.json with a file url and the version
# won't match with the one in the lock file then.
npm_ci = False,
npm_command = "install",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
)
6 changes: 1 addition & 5 deletions examples/parcel/WORKSPACE
Original file line number Diff line number Diff line change
@@ -29,11 +29,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")

npm_install(
name = "npm",
# Set this to true in a real world example (the default value is true), to have hermetic
# builds and use npm ci in favour of npm install. We have to disable this here as the @bazel
# scoped packages are getting replaced in the package.json with a file url and the version
# won't match with the one in the lock file then.
npm_ci = False,
npm_command = "install",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
)
6 changes: 1 addition & 5 deletions examples/vendored_node/WORKSPACE
Original file line number Diff line number Diff line change
@@ -46,11 +46,7 @@ npm_install(
data = [
"@vendored_node_10_12_0//:node-v10.12.0-linux-x64/bin/node",
],
# Set this to true in a real world example (the default value is true), to have hermetic
# builds and use npm ci in favour of npm install. We have to disable this here as the @bazel
# scoped packages are getting replaced in the package.json with a file url and the version
# won't match with the one in the lock file then.
npm_ci = False,
npm_command = "install",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
)
6 changes: 1 addition & 5 deletions examples/vue/WORKSPACE
Original file line number Diff line number Diff line change
@@ -17,11 +17,7 @@ node_repositories(package_json = ["//:package.json"])

npm_install(
name = "npm",
# Set this to true in a real world example (the default value is true), to have hermetic
# builds and use npm ci in favour of npm install. We have to disable this here as the @bazel
# scoped packages are getting replaced in the package.json with a file url and the version
# won't match with the one in the lock file then.
npm_ci = False,
npm_command = "install",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
)
28 changes: 8 additions & 20 deletions internal/npm_install/npm_install.bzl
Original file line number Diff line number Diff line change
@@ -157,8 +157,8 @@ def _add_data_dependencies(repository_ctx):
for f in repository_ctx.attr.data:
to = []
if f.package:
to += [f.package]
to += [f.name]
to.append(f.package)
to.append(f.name)

# Make copies of the data files instead of symlinking
# as yarn under linux will have trouble using symlinked
@@ -207,13 +207,8 @@ def _npm_install_impl(repository_ctx):
node = repository_ctx.path(get_node_label(repository_ctx))
npm = get_npm_label(repository_ctx)

# Use npm ci to have hermetic installs that only install the exact version
# from the package-lock.json file. To update or install a different version
# use the bazel managed binary `bazel run @nodejs//:npm install`.
if repository_ctx.attr.npm_ci:
npm_args = ["ci"]
else:
npm_args = ["install"]
# Set the base command (install or ci)
npm_args = [repository_ctx.attr.npm_command]

npm_args.extend(repository_ctx.attr.args)

@@ -312,17 +307,10 @@ npm_install = repository_rule(
See npm CLI docs https://docs.npmjs.com/cli/install.html for complete list of supported arguments.""",
default = [],
),
"npm_ci": attr.bool(
default = True,
doc = """Use the `npm ci` command instead of `npm install.
Don’t generate a `package-lock.json` and fail if an update is needed.
This mode enables an exact install of the version that is specified in the `package-lock.json`
file. It will remove the node_modules before performing an install.
To update a dependency or install a new one run the `npm install` command with the
vendored npm binary. `bazel run @nodejs//:npm install`. You can pass the options like
`bazel run @nodejs//:npm install -- -D <dep-name>`.
""",
"npm_command": attr.string(
default = "ci",
doc = "The npm command to run, to install dependencies.",
values = ["ci", "install"],
),
"package_lock_json": attr.label(
mandatory = True,