-
Notifications
You must be signed in to change notification settings - Fork 2
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
Why is main
not set to dist/
in email-send-1
#1
Comments
Thank you for raising this issue! The reason why this is set to the TypeScript source as opposed to the compiled source is so that IntelliSense and the bundler always refer to the original TypeScript source. Providing more convenient look up (e.g. go to declaration will go to the source) and providing the bundler and other tooling access to the original source, which I think could potentially be used for better optimisation (e.g. I am still struggling to get tree shaking working off the compiled JS. Since this package should never be used outside the monorepo, this should not cause any problems here. If the package should be published to npm and imported in other workspaces, Yarn allows overriding the main in the Getting everything in the workspace to resolve correctly for local development, bundling and publishing was a bit of a delicate matter initially but the current set up has worked quite well for a while. However, if there is any new developments that I may have missed providing a different alternative hear, I will be very happy to learn about it! |
I thank you for the detailed answer!
I see.
Aah, I didn't know about this. Pretty cool.
I think the standard way to achieving your goal (IDE integration) is to use the approach popularized by Andrei Picus in his article How to set up a TypeScript monorepo and make Go to definition work, which involves using multiple TSConfig files. An example can be found here: https://github.com/NiGhTTraX/ts-monorepo One file, Nonetheless, I agree that there is little difference between the two approaches. Turborepo recommends doing what you have done in their article You might not need TypeScript project references. |
Thank you for sending through the article. Yes, I think that could also work! However, I think I prefer the current approach in this repo due to:
This monorepo already provides a tool to keep TypeScript references up to date. I think that alone is probably sufficient to have the go to declaration work: https://github.com/goldstack/goldstack/tree/master/workspaces/utils/packages/utils-typescript-references#readme TypeScript is quite optimised to avoid rebuilding modules references through TypeScript references (and this monorepo is configured for this), so I don't think the approach from the Turborepo article is required. Btw, in an earlier iteration of this monorepo it was configured to resolve all In any case, always happy to be convinced otherwise 😄 |
Thanks for the additional color. I am with you that Project References are the way to go for TypeScript-only monorepos, but they cannot be used with tools like Next.js, which use a different compiler (SWC). I've actually opened a discussion in the Next.js forum to ask for guidance on this situation: vercel/next.js#50866. My current thinking is that it is not possible to use project references with Next.js, and the only way to make Next.js work in a monorepo is to have multiple TSConfig files (OR do what Turborepo recommends, if all of your packages are meant to remain private forever).
Wait, this confuses me! aren't project references supposed to make TypeScript build the dependencies in a topological way, and thus have the compiler use the built files from 'dist` (the JS source)? |
That's a good question, will follow it as well! Note I have also a self-updating monorepo template specifically for Next.js related to this template here: https://github.com/goldstack/nextjs-bootstrap-boilerplate This works with But generally seems to work without any issues! |
Ah, I didn't see that - thanks for sharing. I'll have a look.
FYI that package is no longer needed since Next.js v13.1 |
That is great to know on |
Sorry to bug you again, @mxro, but I think that you missed my question above? This:
|
Oh yes, sorry for missing the question! I think generally the answer to this is yes! However, there are a few special circumstances to keep in mind:
e.g. see here
Thus I think generally it is best to hook up TypeScript files directly as opposed to going through the generate JS and d.ts files. |
Based on what I understand from ChatGPT,
main
should point to the built JavaScript files, not to the TypeScript source code. Or am I (and ChatGPT) wrong?typescript-monorepo-boilerplate/packages/email-send-1/package.json
Line 7 in 4cb5ad5
The text was updated successfully, but these errors were encountered: