Skip to content

Conversation

@Mivr
Copy link
Collaborator

@Mivr Mivr commented Mar 19, 2025

Closes #2110

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): yes
  • Suggested release notes appear below: yes

Added option to use default package content exclusions similar to yarn autoclean.

With bzlmod extensions:

npm.npm_package_content_excludes(
    package = "*",
    use_defaults = True,
)

# Override for `my-pkg@1.2.3`
npm.npm_package_content_excludes(
    package = "my-pkg@1.2.3",
    excludes = ["README.md", "*.spec.js"]
)

For legacy WORKSPACE:

npm_translate_lock(
    package_content_excludes = {
        "*": True,
        "my-pkg@1.2.3": ["README.md", "*.spec.js"]
    )
)

Test plan

  • Covered by existing test cases

@aspect-workflows
Copy link

aspect-workflows bot commented Mar 19, 2025

Test

All tests were cache hits

223 tests (100.0%) were fully cached saving 34s.


Test

e2e/bzlmod

All tests were cache hits

5 tests (100.0%) were fully cached saving 539ms.


Test

e2e/gyp_no_install_script

All tests were cache hits

2 tests (100.0%) were fully cached saving 184ms.


Test

e2e/js_image_oci

All tests were cache hits

1 test (100.0%) was fully cached saving 6s.


Test

e2e/npm_link_package

All tests were cache hits

3 tests (100.0%) were fully cached saving 533ms.


Test

e2e/npm_link_package-esm

All tests were cache hits

3 tests (100.0%) were fully cached saving 630ms.


Test

e2e/npm_translate_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/npm_translate_lock_empty

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/npm_translate_lock_multi

All tests were cache hits

2 tests (100.0%) were fully cached saving 268ms.


Test

e2e/npm_translate_lock_partial_clone

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/npm_translate_lock_replace_packages

All tests were cache hits

3 tests (100.0%) were fully cached saving 269ms.


Test

e2e/npm_translate_lock_subdir_patch

All tests were cache hits

1 test (100.0%) was fully cached saving 73ms.


Test

e2e/npm_translate_package_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/npm_translate_yarn_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/package_json_module

All tests were cache hits

1 test (100.0%) was fully cached saving 324ms.


Test

e2e/pnpm_lockfiles

All tests were cache hits

52 tests (100.0%) were fully cached saving 6s.


Test

e2e/pnpm_workspace

All tests were cache hits

15 tests (100.0%) were fully cached saving 2s.


Test

e2e/pnpm_workspace_rerooted

All tests were cache hits

15 tests (100.0%) were fully cached saving 2s.


Test

e2e/repo_mapping

All tests were cache hits

3 tests (100.0%) were fully cached saving 410ms.


Test

e2e/rules_foo

All tests were cache hits

2 tests (100.0%) were fully cached saving 137ms.


Test

e2e/runfiles

All tests were cache hits

1 test (100.0%) was fully cached saving 107ms.


Test

e2e/vendored_node

All tests were cache hits

1 test (100.0%) was fully cached saving 114ms.


Buildifier      Format

@jbedard jbedard requested review from alexeagle and jbedard March 19, 2025 19:00
@jbedard jbedard changed the title [FR]: Add default npm package excludes from yarn feat: add default npm package excludes from yarn Apr 4, 2025
@jbedard jbedard mentioned this pull request Apr 22, 2025
33 tasks
Copy link
Collaborator

@dzbarsky dzbarsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I love this idea (and in fact I implemented the same thing last time I worked on a big JS monorepo), but I'm a bit worried about the perf of all these globs. Alternately, we could drop these tiles as part of the extraction step. @jbedard WDYT?

@jbedard
Copy link
Member

jbedard commented Jun 16, 2025

These are globs evaluated by tar which I would think is the best place to do it. What do you mean "we could drop these tiles as part of the extraction step"?

@dzbarsky
Copy link
Collaborator

These are globs evaluated by tar which I would think is the best place to do it. What do you mean "we could drop these tiles as part of the extraction step"?

Oh right we invoke tar directly. In my fork we had a script action around the tar so I was thinking to put the expansion there and hide it from analysis.

Disregard me this approach is probably fine

@jbedard
Copy link
Member

jbedard commented Jun 25, 2025

@Mivr can you confirm if these are actually enabled by default in yarn? Or is it only when you explicitly call yarn autoclean? That makes me wonder if this should be opt-in.

If it is opt-in, maybe should also make this feature opt-in and then we can merge this now (without waiting for rules_js v3). Can we do something like replacing True with the default list? So users can do exclude_package_contents = {"*": True} then it replaces True with this default list...

@Mivr Mivr force-pushed the add-package-exclude-defaults-from-yarn branch from 4b23f46 to 3569a09 Compare July 8, 2025 16:53
@CLAassistant
Copy link

CLAassistant commented Jul 8, 2025

CLA assistant check
All committers have signed the CLA.

@Mivr Mivr force-pushed the add-package-exclude-defaults-from-yarn branch from ea34f10 to d1a3c2b Compare July 9, 2025 08:41
@Mivr
Copy link
Collaborator Author

Mivr commented Jul 9, 2025

So in yarn it has to be enabled. It is disabled by default.

I added a magic string for now, not sure it will work with a Boolean and the string does allow for more flexibility like extending the defaults further for some packages.

It's interesting to discuss which option will be more user friendly.

I tried also with a constant but Module.Bazel does not work with a constant as it does not allow for load statements.

It can also be a rule, which by syntax for the user is a close to the magic string.

@Mivr
Copy link
Collaborator Author

Mivr commented Jul 16, 2025

The closest I could get this is:
In Module bazel the users will need to migrate to a string that contains a complex object:
'{ "*": True, "some-package": "pattern" }'
Instead of the current syntax with a dictionary.

For WORKSPACE it will just work both ways.

I am open to other approaches for this, for now this was was least intrusive way I could find for the users.

@Mivr Mivr force-pushed the add-package-exclude-defaults-from-yarn branch 2 times, most recently from c5f9792 to 6510b84 Compare July 16, 2025 22:45
@Mivr Mivr force-pushed the add-package-exclude-defaults-from-yarn branch from 6510b84 to 0a64355 Compare July 16, 2025 22:46
@Mivr Mivr force-pushed the add-package-exclude-defaults-from-yarn branch from 0a64355 to bd88476 Compare July 16, 2025 22:52
@jbedard jbedard changed the title feat: add default npm package excludes from yarn feat: add opt-in default npm package excludes from yarn Jul 21, 2025
@jbedard jbedard enabled auto-merge (squash) July 21, 2025 17:46
@jbedard jbedard merged commit f3d0c94 into aspect-build:main Jul 21, 2025
99 checks passed
@Mivr Mivr deleted the add-package-exclude-defaults-from-yarn branch July 21, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: provide default exclude_package_contents similar to yarn autoclean

5 participants