Skip to content

feat: add default npm package excludes from yarn #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/npm_import.md

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

2 changes: 1 addition & 1 deletion js/private/test/image/checksum_test.bzlmod.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
c603eafdacc184f3df28ef966704cd580bf5f53c7d599f77132abaac45c110fc js/private/test/image/cksum_node.tar
eec022801c54978ece38859f525f6f7114dcf743ea5e4564ef2a8a522d51aeab js/private/test/image/cksum_package_store_3p.tar
8126c8b88906969911c519f4df5e6ee4a51361595703ce98c17f821dda788ee9 js/private/test/image/cksum_package_store_3p.tar
9395e137de4767edfdd663bc6010a597844bdb68663f8b3ecb036175122bcb2f js/private/test/image/cksum_package_store_1p.tar
fbd40000f29527fb494ba83172bf55ecb01e01b29a8ff4727ead46e4ebf745f1 js/private/test/image/cksum_node_modules.tar
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.ru
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn
-r-xr-xr-x 0 100 0 22267 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/CHANGELOG.md
-r-xr-xr-x 0 100 0 1099 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/LICENSE
-r-xr-xr-x 0 100 0 10799 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/README.md
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin
-r-xr-xr-x 0 100 0 60 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin/acorn
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/dist
Expand All @@ -25,9 +23,7 @@ drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.ru
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn
-r-xr-xr-x 0 100 0 19126 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/CHANGELOG.md
-r-xr-xr-x 0 100 0 1099 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/LICENSE
-r-xr-xr-x 0 100 0 10341 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/README.md
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin
-r-xr-xr-x 0 100 0 60 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin/acorn
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/dist
Expand All @@ -40,10 +36,6 @@ drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.ru
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid
-r-xr-xr-x 0 100 0 12680 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/CHANGELOG.md
-r-xr-xr-x 0 100 0 513 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/CONTRIBUTING.md
-r-xr-xr-x 0 100 0 1109 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/LICENSE.md
-r-xr-xr-x 0 100 0 16564 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/README.md
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/dist
drwxr-xr-x 0 100 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/dist/bin
-r-xr-xr-x 0 100 0 44 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/dist/bin/uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.ru
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn
-r-xr-xr-x 0 0 0 22267 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/CHANGELOG.md
-r-xr-xr-x 0 0 0 1099 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/LICENSE
-r-xr-xr-x 0 0 0 10799 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/README.md
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin
-r-xr-xr-x 0 0 0 60 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin/acorn
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/dist
Expand All @@ -25,9 +23,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.ru
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn
-r-xr-xr-x 0 0 0 19126 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/CHANGELOG.md
-r-xr-xr-x 0 0 0 1099 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/LICENSE
-r-xr-xr-x 0 0 0 10341 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/README.md
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin
-r-xr-xr-x 0 0 0 60 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/bin/acorn
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/acorn/dist
Expand All @@ -40,10 +36,6 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.ru
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid
-r-xr-xr-x 0 0 0 12680 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/CHANGELOG.md
-r-xr-xr-x 0 0 0 513 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/CONTRIBUTING.md
-r-xr-xr-x 0 0 0 1109 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/LICENSE.md
-r-xr-xr-x 0 0 0 16564 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/README.md
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/dist
drwxr-xr-x 0 0 0 0 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/dist/bin
-r-xr-xr-x 0 0 0 44 Jan 1 1970 app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/[email protected]/node_modules/uuid/dist/bin/uuid
Expand Down
2 changes: 2 additions & 0 deletions npm/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ bzl_library(
"//npm:__subpackages__",
],
deps = [
":exclude_package_contents_default.bzl",
":npm_package_info",
":npm_package_store_info",
":utils",
Expand All @@ -113,6 +114,7 @@ bzl_library(
"//npm:__subpackages__",
],
deps = [
":exclude_package_contents_default.bzl",
":starlark_codegen_utils",
":tar",
":utils",
Expand Down
53 changes: 53 additions & 0 deletions npm/private/exclude_package_contents_default.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""A default files exclude list for common packages.

Based on Yarn autoclean; see
https://github.com/yarnpkg/yarn/blob/7cafa512a777048ce0b666080a24e80aae3d66a9/src/cli/commands/autoclean.js#L16
"""

exclude_package_contents_default = [
# test directories
"**/__tests__/**",
"**/test/**",
"**/tests/**",
"**/powered-test/**",

# asset directories
"**/docs/**",
"**/doc/**",
"**/website/**",
"**/images/**",
"**/assets/**",

# examples
"**/example/**",
"**/examples/**",

# code coverage directories
"**/coverage/**",
"**/.nyc_output/**",

# build scripts (files)
"Makefile",
"Gulpfile.js",
"Gruntfile.js",

# configs (files)
"appveyor.yml",
"circle.yml",
"codeship-services.yml",
"codeship-steps.yml",
"wercker.yml",
".tern-project",
".gitattributes",
".editorconfig",
".*ignore",
".eslintrc",
".jshintrc",
".flowconfig",
".documentup.json",
".yarn-metadata.json",
".travis.yml",

# misc (files)
"*.md",
]
9 changes: 5 additions & 4 deletions npm/private/npm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ load(
_git_reset = "reset",
)
load("//npm/private:tar.bzl", "detect_system_tar")
load(":exclude_package_contents_default.bzl", "exclude_package_contents_default")
load(":starlark_codegen_utils.bzl", "starlark_codegen_utils")
load(":utils.bzl", "utils")

Expand Down Expand Up @@ -757,7 +758,7 @@ def _npm_import_links_rule_impl(rctx):
public_visibility = ("//visibility:public" in rctx.attr.package_visibility)

maybe_exclude_package_contents = ""
if rctx.attr.exclude_package_contents == []:
if rctx.attr.exclude_package_contents == exclude_package_contents_default:
maybe_exclude_package_contents = ""
elif rctx.attr.exclude_package_contents != None:
maybe_exclude_package_contents = "\n exclude_package_contents = " + starlark_codegen_utils.to_list_attr(rctx.attr.exclude_package_contents) + ","
Expand Down Expand Up @@ -827,15 +828,15 @@ _ATTRS_LINKS = dicts.add(_COMMON_ATTRS, {
"transitive_closure": attr.string_list_dict(),
"package_visibility": attr.string_list(),
"replace_package": attr.string(),
"exclude_package_contents": attr.string_list(default = []),
"exclude_package_contents": attr.string_list(default = exclude_package_contents_default),
})

_ATTRS = dicts.add(_COMMON_ATTRS, {
"commit": attr.string(),
"custom_postinstall": attr.string(),
"extra_build_content": attr.string(),
"extract_full_archive": attr.bool(),
"exclude_package_contents": attr.string_list(default = []),
"exclude_package_contents": attr.string_list(default = exclude_package_contents_default),
"generate_bzl_library_targets": attr.bool(),
"integrity": attr.string(),
"lifecycle_hooks": attr.string_list(),
Expand Down Expand Up @@ -919,7 +920,7 @@ def npm_import(
npm_auth_password = "",
bins = {},
dev = False,
exclude_package_contents = [],
exclude_package_contents = exclude_package_contents_default,
**kwargs):
"""Import a single npm package into Bazel.

Expand Down
3 changes: 2 additions & 1 deletion npm/private/npm_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@aspect_bazel_lib//lib:copy_directory.bzl", "copy_directory_bin_action")

# buildifier: disable=bzl-visibility
load("//js/private:js_info.bzl", "JsInfo", "js_info")
load(":exclude_package_contents_default.bzl", "exclude_package_contents_default")
load(":npm_package_info.bzl", "NpmPackageInfo")
load(":npm_package_store_info.bzl", "NpmPackageStoreInfo")
load(":utils.bzl", "utils")
Expand Down Expand Up @@ -112,7 +113,7 @@ _ATTRS = {

The exclude patterns are relative to the package store directory.
""",
default = [],
default = exclude_package_contents_default,
),
"package": attr.string(
doc = """The package name to link to.
Expand Down