Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ npm.npm_translate_lock(
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
)
npm.npm_import(
name = "npm__meaning-of-life__1.0.0",
integrity = "sha512-fVA4xSydqtK9owabGcYw1r4EKEsMOVVeYQLeCXPu77Z+8Y2j2B2I16UqZlKIOHnYkJ4RSvpJ00ywy9IWjmuxYw==",
package = "meaning-of-life",
patch_args = ["-p1"],
# A custom patch tool must be a pre-built binary or source file since repository
# rules cannot depend on the output of a build target.
patch_tool = "//npm/private/test:patch_tool.sh",
patches = ["//npm/private/test:meaning-of-life@1.0.0.patch"],
root_package = "npm/private/test",
version = "1.0.0",
)
use_repo(
npm,
"npm",
Expand All @@ -278,6 +290,8 @@ use_repo(
"npm__es5-ext__0.10.64__links",
"npm__fsevents__2.3.3__links",
"npm__google-closure-compiler__20251111.0.0__links",
"npm__meaning-of-life__1.0.0",
"npm__meaning-of-life__1.0.0__links",
"npm__rollup__4.55.2",
"npm__rollup__4.55.2__links",
"npm__unused__0.2.2__links",
Expand Down
10 changes: 10 additions & 0 deletions npm/private/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ load("@aspect_rules_js//js:defs.bzl", "js_test")
load("@bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm__meaning-of-life__1.0.0__links//:defs.bzl", "npm_link_imported_package")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load(":generated_pkg_json_test.bzl", "generated_pkg_json_test")
load(":npm_auth_test.bzl", "npm_auth_failure_test_suite", "npm_auth_test_suite")
Expand All @@ -15,6 +16,15 @@ load(":utils_tests.bzl", "utils_tests")

npm_link_all_packages()

# Links the /MODULE npm_import() of meaning-of-life, patched with a custom `patch_tool`
npm_link_imported_package()

js_test(
name = "patch_tool_test",
data = [":node_modules/meaning-of-life"],
entry_point = "patch_tool_test.js",
)

# Unit tests
utils_tests(name = "test_utils")

Expand Down
7 changes: 7 additions & 0 deletions npm/private/test/meaning-of-life@1.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff --git a/index.js b/index.js
index a8653a9c9264ca1ac9fd2acb6c523a321912ab33..ae967de93c7c12074a686e1e8437b7b2344108be 100644
--- a/index.js
+++ b/index.js
@@ -1 +1 @@
-module.exports = 42
+module.exports = "forty two"
8 changes: 8 additions & 0 deletions npm/private/test/patch_tool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail

patch "$@"

# Leave a trace only this custom tool would produce so the test can
# distinguish it from the default `patch` from PATH.
echo 'module.exports += " (custom patch_tool)"' >>index.js
7 changes: 7 additions & 0 deletions npm/private/test/patch_tool_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const assert = require('node:assert')

const meaningOfLife = require('meaning-of-life')

// `meaning-of-life@1.0.0.patch` changes 42 to "forty two" and the custom
// `patch_tool.sh` appends the " (custom patch_tool)" suffix.
assert.strictEqual(meaningOfLife, 'forty two (custom patch_tool)')
Loading