Skip to content

Commit

Permalink
feat: add exclude patterns for npm packages (#2078)
Browse files Browse the repository at this point in the history
### Changes are visible to end-users: yes

- Searched for relevant documentation and updated as needed: yes
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: yes

Add `npm_translate_lock(exclude_package_contents)` and `npm_import(exclude_package_contents)` for excluding content when extracting packages.

### Test plan

- New test added: e2e/package_exclude_patterns

Resolves: #2042
  • Loading branch information
Mivr authored Feb 6, 2025
1 parent a365f47 commit ef8e187
Show file tree
Hide file tree
Showing 38 changed files with 285 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
e2e/npm_translate_lock_subdir_patch
e2e/npm_translate_package_lock
e2e/npm_translate_yarn_lock
e2e/npm_translate_lock_exclude_package_contents
e2e/package_json_module
e2e/patch_from_repo
e2e/pnpm_lockfiles
Expand Down
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ npm.npm_translate_lock(
"//npm/private/test/vendored/is-odd:package.json",
"//npm/private/test/vendored/semver-max:package.json",
],
exclude_package_contents = {
"chalk": ["**/README*"],
},
generate_bzl_library_targets = True,
lifecycle_hooks = {
# We fetch @kubernetes/client-node from source and it has a `prepare` lifecycle hook that needs to be run
Expand Down
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ npm_translate_lock(
"//npm/private/test/vendored/is-odd:package.json",
"//npm/private/test/vendored/semver-max:package.json",
],
exclude_package_contents = {
"chalk": ["**/README*"],
},
generate_bzl_library_targets = True,
lifecycle_hooks = {
# We fetch @kubernetes/client-node from source and it has a `prepare` lifecycle hook that needs to be run
Expand Down
4 changes: 3 additions & 1 deletion docs/npm_import.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions docs/npm_translate_lock.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions e2e/npm_translate_lock_exclude_package_contents/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Import Aspect bazelrc presets
try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc
import %workspace%/../../.aspect/bazelrc/convenience.bazelrc
import %workspace%/../../.aspect/bazelrc/correctness.bazelrc
import %workspace%/../../.aspect/bazelrc/debug.bazelrc
import %workspace%/../../.aspect/bazelrc/javascript.bazelrc
import %workspace%/../../.aspect/bazelrc/performance.bazelrc

### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###

# Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`.
# This file should appear in `.gitignore` so that settings are not shared with team members. This
# should be last statement in this config so the user configuration is able to overwrite flags from
# this file. See https://bazel.build/configure/best-practices#bazelrc-file.
try-import %workspace%/../../.aspect/bazelrc/user.bazelrc
4 changes: 4 additions & 0 deletions e2e/npm_translate_lock_exclude_package_contents/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
hoist=false
11 changes: 11 additions & 0 deletions e2e/npm_translate_lock_exclude_package_contents/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

sh_test(
name = "test_sh",
srcs = ["is-odd-exclude-test.sh"],
data = [
":node_modules/is-odd",
],
)
Loading

0 comments on commit ef8e187

Please sign in to comment.