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

fix: do not rely on @npm_typescript if custom tsc is provided #693

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

gzm0
Copy link
Contributor

@gzm0 gzm0 commented Sep 13, 2024

This is a follow-up to #675 which made the @npm_typescript repository less special.

This replaces the (hopefully) last occurrence of this special name that cannot be changed by configuration.

Alternatives I considered:

  • Expose the is_typescript_5_or_greater flag on the ts_project macro: Simplest option at first, but since it is only used for config validation, that would become nonsensical.
  • Add a npm_typescript_package or npm_typescript_repository parameter that would allow overriding all places where @npm_typescript// is used by default: Would offer more functionality (e.g. worker config checking), but would also be more invasive.

Changes are visible to end-users: yes

The change might make an incorrect warning disappear.

  • 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: no (no suggested additional release notes)

Test plan

  • Covered by existing test cases

This is a follow-up to aspect-build#675 which made the `@npm_typescript`
repository less special.

This replaces the (hopefully) last occurrence of this special name
that cannot be changed by configuration.

Alternatives I considered:

- Expose the `is_typescript_5_or_greater` flag on the `ts_project`
  macro:
  Simplest option at first, but since it is only used for config
  validation, that would become nonsensical.
- Add a `npm_typescript_package` or `npm_typescript_repository`
  parameter that would allow overriding all places where
  `@npm_typescript//` is used by default:
  Would offer more functionality (e.g. worker config checking), but
  would also be more invasive.
Copy link

aspect-workflows bot commented Sep 13, 2024

Test

All tests were cache hits

84 tests (100.0%) were fully cached saving 8s.


Buildifier      Format

@gzm0 gzm0 marked this pull request as ready for review September 13, 2024 13:04
@jbedard
Copy link
Member

jbedard commented Sep 13, 2024

The primary goal is to avoid any use of npm_typescript unless required?

Would it be possible to move any of the supports_workers / is_typescript_5_or_greater logic into the macro here so it's not split throughout the macro+rule as much? I'm not sure if it's possible or worth it but something to think about.

# - it would be wrong anyways
# - it is only used to warn if worker support is configured incorrectly.
if tsc != _tsc:
is_typescript_5_or_greater = None
Copy link
Member

Choose a reason for hiding this comment

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

I guess it would be here that we can potentially set supports_worker = False and maybe remove some code from within the rule? Does that simplify anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this would be correct: It is possible to supply a custom that has worker support. But if we set supports_worker = 0 here, workers would be disabled.

They way I think about this is: is_typescript_5_or_greater is a best effort configuration fix: If we can "prove" the config is wrong, we correct it and warn. If we cannot "prove" the config is wrong, we do what it says (and it might fail).

@gzm0
Copy link
Contributor Author

gzm0 commented Sep 16, 2024

The primary goal is to avoid any use of npm_typescript unless required?

Yes. We'd like to be able to use ts_project without the default npm_typescript repository. The use-case is that downstream modules can defined their own npm_typescript easily without collision (repositories generated by module extensions are not namespaced by the defining module).

Would it be possible to move any of the supports_workers / is_typescript_5_or_greater logic into the macro here so it's not split throughout the macro+rule as much? I'm not sure if it's possible or worth it but something to think about.

I don't think this is feasible unfortunately:

  • Due to the use of configurations, the actual values of supports_workers / is_typescript_5_or_greater are only available inside the ts_project rule --> we have to do the check inside the rule.
  • Retrieving is_typescript_5_or_greater requires "label-mangling" --> we have to do it in the macro.

One option to unmess the logic a bit would be to introduce a provider for tsc that holds the individual parts (tsc, watcher, validator, version).

  • The generated typescript repositories then could expose a target with this provider.
  • If manual overrides are provided in the macro, we could generate a glue-rule that puts them into the provider.
  • We could allow providing a target with this provider directly in the ts_project macro (and deprecate tsc, tsc_worker and validator).

gzm0 added a commit to gzm0/rules_ts that referenced this pull request Sep 16, 2024
Idea that came up in aspect-build#693
@gzm0 gzm0 mentioned this pull request Sep 16, 2024
@gzm0
Copy link
Contributor Author

gzm0 commented Sep 16, 2024

Extremely minimal outline on how a provider could look: https://github.com/aspect-build/rules_ts/pull/695/files

@jbedard
Copy link
Member

jbedard commented Sep 17, 2024

Awesome, thanks for the explanations and RFC! 👍

Switching to the RFC would be a future change, and this PR is great as-is so I'm going to merge this one.

@jbedard jbedard merged commit 4f26edc into aspect-build:main Sep 17, 2024
23 checks passed
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