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

Use custom transformer when building solution references #1550

Conversation

feosuna1
Copy link
Contributor

This PR adds support for custom transformers in project references.

While attempting to use custom transformers, I realized that the transformers were only being applied to the main target and not to any of my referenced projects. After a bit of spelunking, I found that #1025 was a similar issue to my own. #1274 attempted to solve the problem, but some changes needed to be made in Typescript to allow for custom transformers in project references. All the necessary changes to support are available in Typescript v4.3+.

I've modeled my changes after @gasnier's original PR (#1025). This change set:

  1. Moves the getCustomTransformers logic out of initializeInstance and into a dedicated function, so that it can be shared.
  2. Refactors makeSolutionBuilderHost to include the new getCustomTransformer field in the solutionBuilderHost and have it return the transformers made available in the loader options.

Fixes #1025

This allows us to share the function between `initializeInstance` and
`makeSolutionBuilderHost`. `makeSolutionBuilderHost` is called as a part
of `buildSolutionReferences`.  `buildSolutionReferences` is called before
`initializeInstance` where the custom transformers are initialized.
This allows us to pass on the custom transformer while the project
references are built.
@johnnyreilly
Copy link
Member

Thanks for this - little snowed right now. Will look when I can

if (options) {
// The `configFilePath` is the same value that is used as the `project` parameter of
// `getCustomtransformers` below.
const project = options.configFilePath?.toString();
Copy link
Member

Choose a reason for hiding this comment

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

is the toString necessary?

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 always a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I don't know what I was thinking. It's a string.

@johnnyreilly
Copy link
Member

Have updated your branch - it's possible you might need to do some repairs

`options.configFilePath` is always a string, there's no reason we need `toString()` too.
@johnnyreilly
Copy link
Member

Failing tests following merge I'm afraid - could you take a look please?

@feosuna1
Copy link
Contributor Author

Failing tests following merge I'm afraid - could you take a look please?

It started failing because the typescript compiler is complaining that options can be a bunch of different types.

CleanShot 2022-11-26 at 09 24 22@2x

In a previous commit, I removed `.toString()` without validating what
the Typescript compiler would say. This change does a runtime check
that the project variable is an actual string.
@feosuna1 feosuna1 force-pushed the feo/bugfix/custom-transformer-in-build-solution branch from 71a8d37 to ed3f70f Compare November 26, 2022 14:46
@johnnyreilly
Copy link
Member

I think we might be nearly there. Could you update the version in the package.json and put an entry in the changeling.md please?

@johnnyreilly johnnyreilly merged commit 5e7220b into TypeStrong:main Nov 30, 2022
@johnnyreilly
Copy link
Member

Thanks!

@johnnyreilly
Copy link
Member

@feosuna1 feosuna1 deleted the feo/bugfix/custom-transformer-in-build-solution branch December 1, 2022 20:26
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.

Custom transformers not working for referenced projects
2 participants