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: support non-file transpiler srcs #236

Merged
merged 3 commits into from
Nov 13, 2022

Conversation

jbedard
Copy link
Member

@jbedard jbedard commented Nov 9, 2022

The current transpiler which takes 3 arrays with aligning indexes is a bad API, and to fix #219 one of those arrays will no longer align with the other 2 making it unusable.

Proposed solution in this PR: #219 (comment)

This change makes the transpiler API simply transpiler(srcs). Any additional information required should be added via partial.make such as out_dir, source_map etc. Often these extra params will be required in order to align with the ts_project attributes. A macro will almost always be ideal to configure the transpiler including things like aligning these attributes.

swc change to do its own output declarations: aspect-build/rules_swc@f716962

ts/test/mock_transpiler.bzl is an example implementing a full rule including support for non-file srcs and predeclaring the .js and .js.map outputs.

examples/transpiler/babel.bzl is an example of a macro keeping the same functionality as today where it only supports file inputs. This also predeclares the .js and .js.map outputs as part of the babel invocation.

Alternatives:

  • changing js/map_outs to maps is a lot nicer then 3 arrays where the indexes align, especially since fixing targets (non-files) in srcs breaks the index-aligning. See 17a80d5

@jbedard jbedard requested review from alexeagle and thesayyn November 9, 2022 05:44
Copy link
Member

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

Could you add the documentation change as well, anywhere that the transpiler function signature is referenced? (the transpiler attribute and the separate transpiler.md file)

will help to understand if it's the right shape based on how we explain to users.

examples/transpiler/babel.bzl Outdated Show resolved Hide resolved
ts/private/ts_lib.bzl Outdated Show resolved Hide resolved
@alexeagle alexeagle added this to the 1.0 milestone Nov 9, 2022
@thesayyn
Copy link
Member

thesayyn commented Nov 9, 2022

i wonder how would this work when the build is;

filegroup(name = "filegroup", srcs = ["1.ts", "2.ts"])

ts_project(
 srcs = [":filegroup"]
)

@jbedard jbedard marked this pull request as ready for review November 10, 2022 03:56
@alexeagle alexeagle changed the title fix: support non-file transipler srcs fix: support non-file transpiler srcs Nov 10, 2022
Copy link
Member

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

Nice, I think you made a good case for this and the changes look right to me.

examples/transpiler/babel.bzl Outdated Show resolved Hide resolved
docs/transpiler.md Outdated Show resolved Hide resolved
@jbedard jbedard force-pushed the transpiler-api branch 3 times, most recently from d489fd7 to f50e781 Compare November 11, 2022 00:41
@jbedard jbedard requested a review from alexeagle November 11, 2022 00:43
ts/test/mock_transpiler.bzl Outdated Show resolved Hide resolved
Copy link
Member

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

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

looks good but we may need more tests. It would be great to have a test with filegroup select, and target with multiple files in it.

ts/test/BUILD.bazel Show resolved Hide resolved
The js_outs and map_outs attributes have been removed and all sources are passed including non .ts files.

Transpilers should produce .js files for each inputted .ts file. Additional features such as generation
of source maps (.js.map) may be implemented and should respect the the ts_project(source_map) attribute.

Transpilers may optionally pre-declare output files similar to ts_project().

Fixes aspect-build#219
@jbedard
Copy link
Member Author

jbedard commented Nov 12, 2022

@thesayyn I've added a filegroup test (see ts/test/BUILD.bazel). Adding a select would require #220 and can be done there if we decide to do it.

examples/transpiler/babel.bzl Show resolved Hide resolved
ts/test/mock_transpiler.bzl Outdated Show resolved Hide resolved
@jbedard
Copy link
Member Author

jbedard commented Nov 13, 2022

Good to merge then?

@alexeagle alexeagle enabled auto-merge (squash) November 13, 2022 00:49
@alexeagle alexeagle merged commit c2a9e1e into aspect-build:main Nov 13, 2022
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.

[Bug]: can't pass srcs to ts_project via another rule when transpiler is used
3 participants