microsoft / rushstack

Monorepo for tools developed by the Rush Stack community
https://rushstack.io/
Other
5.81k stars 592 forks source link

[heft] Building non-source files #3089

Open Faithfinder opened 2 years ago

Faithfinder commented 2 years ago

Summary

Sometimes, building non-source files is needed, and heft's support for that is poor.

Details

While heft's model of "Use the same code you build" works quite well for library/application code, sometimes that's not the only typescript files in the package that you want to use.

The main use case that I have in mind and is sort of a blocker is jest setup files. They are extremely useful for integration/system level testing, and I want to use typescript to write them. With ts-jest/babel approach it's not a problem since transformers are applied to setup files as well, however with heft you need to link actual JS files. This creates two problems.

1) jest.config needs to reference the built file instead of the source file, which can be unintuitive. 2) You're unable to keep you setup files in a separate folder from src (e.g scripts) (and I don't want thing like that in src).

This is the case that I've actually hit and hinders me from using heft test in one of the apps - I need a setup file. I'll probably end up putting the setup script in src after all (when Jest 27 gets merged since I also need that), but my soul will ache when I do this.

However, I also have theoretical reservation about similar cases:

octogonz commented 2 years ago

With ts-jest/babel approach it's not a problem since transformers are applied to setup files as well, however with heft you need to link actual JS files.

Is the problem that Heft's Jest plugin tries to load the .js file /before/ TypeScript has compiled it? We could probably change that.

Gchahm commented 1 year ago

I think I have the same problem mentioned here. If you create a file /config/jest/setup.ts and you try to run tests you'll get this error.

jest-build-transform: The input path is not under the "src" folder:

/config/jest/setup.ts Which comes from the transformer here. https://github.com/microsoft/rushstack/blob/f558eea5cc67c51dec9cc12b1d258122b985c911/heft-plugins/heft-jest-plugin/src/transformers/BuildTransformer.ts#L388 There should be a way to allow the setup file to be processed without having to move it to /src.