-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
feat: add prod
and dev
attributes to npm_link_targets
#2051
base: main
Are you sure you want to change the base?
feat: add prod
and dev
attributes to npm_link_targets
#2051
Conversation
TestFailed tests (2)//npm/private:_test_gendocs_0_0 [k8-fastbuild] 🔗 //npm/private:_test_gendocs_0_1 [k8-fastbuild] 🔗 💡 To reproduce the test failures, run
Teste2e/bzlmodAll tests were cache hits 5 tests (100.0%) were fully cached saving 857ms. Teste2e/gyp_no_install_scriptAll tests were cache hits 2 tests (100.0%) were fully cached saving 503ms. Teste2e/js_image_ociAll tests were cache hits 1 test (100.0%) was fully cached saving 7s. Teste2e/npm_link_packageAll tests were cache hits 3 tests (100.0%) were fully cached saving 820ms. Teste2e/npm_link_package-esmAll tests were cache hits 3 tests (100.0%) were fully cached saving 1s. Teste2e/npm_translate_lockAll tests were cache hits 1 test (100.0%) was fully cached saving 34ms. Teste2e/npm_translate_lock_emptyAll tests were cache hits 1 test (100.0%) was fully cached saving 34ms. Teste2e/npm_translate_lock_multiAll tests were cache hits 2 tests (100.0%) were fully cached saving 171ms. Teste2e/npm_translate_lock_partial_cloneAll tests were cache hits 1 test (100.0%) was fully cached saving 129ms. Teste2e/npm_translate_lock_replace_packagesFailed tests (1)//:write_npm_translate_lock_bzlmod_test [k8-fastbuild] 🔗 💡 To reproduce the test failures, run
Teste2e/npm_translate_lock_subdir_patchAll tests were cache hits 1 test (100.0%) was fully cached saving 222ms. Teste2e/npm_translate_package_lockAll tests were cache hits 1 test (100.0%) was fully cached saving 131ms. Teste2e/npm_translate_yarn_lockAll tests were cache hits 1 test (100.0%) was fully cached saving 131ms. Teste2e/package_json_moduleAll tests were cache hits 1 test (100.0%) was fully cached saving 590ms. Teste2e/pnpm_lockfilesFailed tests (4)//v54:repos_0_test [k8-fastbuild] 🔗 //v60:repos_0_test [k8-fastbuild] 🔗 //v61:repos_0_test [k8-fastbuild] 🔗 //v90:repos_0_test [k8-fastbuild] 🔗 💡 To reproduce the test failures, run
Teste2e/pnpm_workspaceAll tests were cache hits 10 tests (100.0%) were fully cached saving 3s. Teste2e/pnpm_workspace_rerootedAll tests were cache hits 12 tests (100.0%) were fully cached saving 2s. Teste2e/repo_mappingAll tests were cache hits 2 tests (100.0%) were fully cached saving 474ms. Teste2e/rules_fooAll tests were cache hits 2 tests (100.0%) were fully cached saving 470ms. Teste2e/runfilesAll tests were cache hits 1 test (100.0%) was fully cached saving 474ms. Teste2e/vendored_nodeAll tests were cache hits 1 test (100.0%) was fully cached saving 199ms. BuildifierFormat |
e0a193d
to
5ef2ba5
Compare
@@ -219,7 +222,7 @@ def npm_link_targets(name = "node_modules", package = None): | |||
npm_link_all_packages_bzl = [ | |||
"""\ | |||
# buildifier: disable=function-docstring | |||
def npm_link_all_packages(name = "node_modules", imported_links = []): | |||
def npm_link_all_packages(name = "node_modules", imported_links = [], prod = False, dev = False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other ideas for this API?
It might be nice if we didn't have this scenario where 1/4 of the states is basically invalid and has an odd non-intuitive default. Maybe just throw when false/false
and then the other 3 states are valid and understandable?
dev = True|False|None
or something like that is one alternative, although the word "dev" in the API without "prod" in the API is confusing imo. Or type = "dev"|"prod"|None
but I'd want a term better then "type".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually is this API simply a copy of npm_translate_lock
? In which case we should do exactly as you have and my suggestion can be considered in rules_js v3 or something like that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's just following the prod
/dev
API from npm_translate_lock
. I agree that an API that excludes invalid states by design would be better for v3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This current API does not allow a single BUILD to have a mix of these though, correct? If you wanted to include dev deps for some targets (such as tests) but not for others (such as libraries).
Would something such as :node_modules[__{dev,prod}]
as the API also solve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does allow a mix. You could write npm_link_targets()
and npm_link_targets(prod = True)
and npm_link_targets(dev = True)
in the same BUILD if you wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking you can't have multiple npm_link_all_packages()
targets though...?
@@ -134,6 +134,9 @@ WARNING: Cannot determine home directory in order to load home `.npmrc` file in | |||
system_tar = detect_system_tar(module_ctx) | |||
|
|||
for i in imports: | |||
link_packages = {} | |||
for link_package, link_names in i.link_packages.items(): | |||
link_packages[link_package] = [link_name["pkg"] for link_name in link_names] | |||
npm_import( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this is probably beyond this scope of this PR, but I'd like to start the discussion here...)
I think the npm_import(dev)
flag is flawed and should actually be removed completely. The dev vs prod logic needs to be 100% at package link time based on the package.json dev vs non-dev dependencies, not the lockfile dev
flag which is currently misused in rules_js (and non-existent in pnpm9).
Does that sound right to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the behavior of lockfile dev
flag makes it unsuitable for really anything that rules_js wants to do with regard to dev dependencies.
@@ -2048,371 +2048,369 @@ def npm_link_all_packages(name = "node_modules", imported_links = []): | |||
if link: | |||
if bazel_package == "js/private/worker/src": | |||
link_2(name = "{}/abortcontroller-polyfill".format(name)) | |||
link_targets.append("//{}:{}/abortcontroller-polyfill".format(bazel_package, name)) | |||
link_targets.append("//{}:{}/abortcontroller-polyfill".format(bazel_package, name)) if (not prod and not dev) or (prod and not True) or (dev and True) else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generated if ...
is ugly and I'm pondering how else we can do it. I think we can generate something simpler.
Can't we just compute a few vars at the top of the method such as include_dev
and include_prod
? Then this will be if include_dev else None
or if include_prod else None
or blank (or if True else None
instead of blank).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, something like that should be possible I think.
IIUC this solves the issue where rules_js currently treats the lockfile |
This is my suggested solution for #1879. I think it's orthogonal to the lockfile |
Fixes #1879
Changes are visible to end-users: yes
Test plan