'Node module as Typescript source only without build

I have written a small utility function in Typescript that I use in other projects. Currently, I have two different ways to share this, both with pros and cons. I would like to know if there is a way that I can have the best things from each method.

  1. Build my TS code into a CJS/ESM module in a directory like dist and check it into the repo each time I make a change. Install it in my projects with yarn install https://github.com/me/my-util
  2. Keep only TS source files in my utility repo, add it to each project as a submodule. When I build the project the files from this repo are built along with it as if they are part of the project.

If I yarn install a repo that has only TS source files. Is there a way I can configure my project to import those files without expecting them to be already compiled to JS? I understand that if someone tried to yarn install my utility in a 'normal' project it would not work but that's ok for this use case.

Bonus points if this could be done under Yarn PnP where there is no node_modules folder.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source