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

feat: add JsInfo provider to ts_config rule #315

Merged
merged 1 commit into from
Feb 11, 2023
Merged

Conversation

gregmagolan
Copy link
Member

@gregmagolan gregmagolan commented Feb 11, 2023

Fixes #271 although it looks like there is additional speed bump that tsc doesn't follow the symlinked to the virtual store location of its extends so transitive npm deps of an extends can't be resolved. I suspect this is easily reproducible outside of Bazel when hoist = False in .npmrc.

See comment left in examples/linked_tsconfig_consumer/tsconfig.json for more info:

{
    "//": "the hacky path below is required because while @lib/tsconfig/tsconfig.json _will_ resolve, tsc won't follow the symlink into the virtual store so the transitive npm dep of @lib/tsconfig on @tsconfig/node18/tsconfig.json won't be resolvable",
    "extends": "../node_modules/.aspect_rules_js/@[email protected]/node_modules/@lib/tsconfig/tsconfig.json"
}

There are other way this could be worked around including manually propagating the dependency to downstream ts_project targets but the hacky virtual store path work-around above seems the simplest; here we just abandon the standard node_modules resolution algorithm that would incorrectly resolve to node_modules/@lib/tsconfig/tsconfig.json from where transitive npm deps of @lib/tsconfig would not be resolvable unless they were elsewhere on the node_modules resolution path such as node_modules/my_transitive_dep. The downside of this work-around is that would not work outside of Bazel with the same tsconfig file since under pnpm the virtual store path would be different.

@Toxaris There is a follow-up task here of reproducing the issue with tsc outside of Bazel and filing an issue to the typescript repo but I've got too many other things on my plate atm so I'm going to punt on that. If you wanted to make the repro and file an issue upstream I bet the fix is a relatively straight forward one in typescript.

@gregmagolan gregmagolan force-pushed the tsconfig_jsinfo branch 2 times, most recently from 90c7be5 to 9a25c4d Compare February 11, 2023 21:40
@gregmagolan gregmagolan merged commit ce5df51 into main Feb 11, 2023
@gregmagolan gregmagolan deleted the tsconfig_jsinfo branch February 11, 2023 22:09
@@ -218,7 +218,7 @@ This is an error because Bazel does not run actions unless their outputs are nee
if len(outputs) > 0:
inputs_depset = depset(
copy_files_to_bin_actions(ctx, inputs),
transitive = transitive_inputs + [_gather_declarations_from_js_providers(ctx.attr.srcs + ctx.attr.deps)],
transitive = transitive_inputs + [_gather_declarations_from_js_providers(ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps)],
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it possible there will be no tsconfig so [None] will be passed to _gather_declarations_from_js_providers? Is that ok?

Copy link
Member Author

@gregmagolan gregmagolan Feb 11, 2023

Choose a reason for hiding this comment

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

I checked the same thing. Not possible as the attribute is "tsconfig": attr.label(mandatory = True, allow_single_file = [".json"]), in the rule. You either get the user tsconfig or an auto-generated one that is done in the ts_project macro

Copy link
Member

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Bug]: ts_config doesn't provide a JsInfo
3 participants