Skip to content
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

refactor: do not add JsInfo.types or js_library(types) to JsInfo.sources #2080

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jbedard
Copy link
Member

@jbedard jbedard commented Jan 30, 2025

No "types" should ever make it into runfiles or JsInfo.[transitive_]sources as it might trigger type-producing actions such as tsc.

I'm uncertain if packages in js_library(types) should be passed forward to JsInfo.{npm_sources,npm_package_store_infos} though.


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

Do not propagate js_library(types) or JsInfo.[transitive_]types to JsInfo.sources.

Test plan

  • Covered by existing test cases

@jbedard jbedard requested a review from gregmagolan January 30, 2025 01:47
Copy link

aspect-workflows bot commented Jan 30, 2025

Test

All tests were cache hits

213 tests (100.0%) were fully cached saving 37s.


Test

e2e/bzlmod

All tests were cache hits

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


Test

e2e/gyp_no_install_script

All tests were cache hits

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


Test

e2e/js_image_oci

All tests were cache hits

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


Test

e2e/npm_link_package

All tests were cache hits

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


Test

e2e/npm_link_package-esm

All tests were cache hits

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


Test

e2e/npm_translate_lock

All tests were cache hits

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


Test

e2e/npm_translate_lock_empty

All tests were cache hits

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


Test

e2e/npm_translate_lock_multi

All tests were cache hits

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


Test

e2e/npm_translate_lock_partial_clone

All tests were cache hits

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


Test

e2e/npm_translate_lock_replace_packages

All tests were cache hits

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


Test

e2e/npm_translate_lock_subdir_patch

All tests were cache hits

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


Test

e2e/npm_translate_package_lock

All tests were cache hits

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


Test

e2e/npm_translate_yarn_lock

All tests were cache hits

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


Test

e2e/package_json_module

All tests were cache hits

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


Test

e2e/pnpm_lockfiles

All tests were cache hits

42 tests (100.0%) were fully cached saving 3s.


Test

e2e/pnpm_workspace

All tests were cache hits

10 tests (100.0%) were fully cached saving 4s.


Test

e2e/pnpm_workspace_rerooted

All tests were cache hits

12 tests (100.0%) were fully cached saving 1s.


Test

e2e/repo_mapping

All tests were cache hits

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


Test

e2e/rules_foo

All tests were cache hits

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


Test

e2e/runfiles

All tests were cache hits

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


Test

e2e/vendored_node

All tests were cache hits

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


Buildifier      Format

@jbedard jbedard changed the title fix: do not add JsInfo.types or js_library(types) to JsInfo.sources refactor: do not add JsInfo.types or js_library(types) to JsInfo.sources Feb 6, 2025
@jbedard jbedard requested a review from dzbarsky February 6, 2025 22:39
@jbedard jbedard marked this pull request as ready for review February 6, 2025 22:39
@jbedard jbedard requested a review from alexeagle February 6, 2025 23:49
# Collect transitive sources, types and npm providers from srcs+types+deps
for target in srcs_types_deps:
# Collect transitive sources, types and npm providers from js_library(srcs+deps)
for target in srcs_deps:
if JsInfo in target:
jsinfo = target[JsInfo]
transitive_sources.append(jsinfo.transitive_sources)
transitive_types.append(jsinfo.transitive_types)
npm_sources.append(jsinfo.npm_sources)
Copy link
Member

Choose a reason for hiding this comment

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

Targets in types may have npm deps they depend on so I think it is correct to propagate the npm_package_store infos as well.

Technically, this PR is a breaking change as we're changing the contract for the types attribute:

"""Same as `srcs` except all files are also provided as "types" available to downstream rules for type checking.
For example, a js_library with only `.js` files that are intended to be imported as `.js` files by downstream type checking
rules such as `ts_project` would list those files in `types`:
js_library(
    name = "js_lib",
    types = ["index.js"],
)
"""

With this change it is no longer "Same as srcs" but instead deps added to types only propogate their types and not their sources. That does seem like a better pattern for that attribute... essentially if you wanted something that wouldn't be normally be a type to be included in types then you would put it in types. If you also wanted it in sources then you would put it in both types and sources. With this change you can pass a dep with both sources and types and intentionally strip out the sources.

However, the question is how breaking is this for users? My guess is that very few ppl are using the types attribute and this could be marked as a "fix" under the reasoning that the past behaviour was not correct.

Copy link
Member

Choose a reason for hiding this comment

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

Semver police might overlook this one :)

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.

2 participants