turbo icon indicating copy to clipboard operation
turbo copied to clipboard

Add `tsup.noExternals` to handbook

Open mikevercoelen opened this issue 3 years ago • 4 comments

Which project is this feature idea for?

Turborepo

Describe the feature you'd like to request

As described here: https://turbo.build/repo/docs/handbook/sharing-code/internal-packages#6-configuring-your-app (and on a blog post that I can't find

The idea is that you don't define main: "./dist/index.js" in your files, because IDE's don't like autocompleting that etc.

The problem that I stumble up on is, for my usecase, I'm building a mono repo for pure Node.js serverside microservices.

We have an api and gateway app that share a lib and database (prisma) package.

The problem is: if we for example build our API with tsup ./src/index.ts while having your main and types configured to src instead of dist it won't actually compile, so you need another transpile step.

The solution is this:

Create a tsup.config.ts file and add:

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['./src/index.ts'],
  noExternal: [
    '@my-workspace/database',
    '@my-workspace/lib'
  ],
  sourcemap: true
})

The noExternals do the trick.

Another thing we could add to the docs is using ts-node for dev mode, and the above solution for build.

ts-node does all of this out of the box, no additional configure.

Describe the solution you'd like

Add noExternals to the docs here https://turbo.build/repo/docs/handbook/sharing-code/internal-packages#6-configuring-your-app

Example usage:

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['./src/index.ts'],
  noExternal: [
    '@my-workspace/database',
    '@my-workspace/lib'
  ],
  sourcemap: true
})

Describe alternatives you've considered

nope.

mikevercoelen avatar Dec 01 '22 21:12 mikevercoelen

If you are building your packages, I would recommend just pointing main and types to dist (or whereever your build output may be). Then mark your apps as depending on the build step of those packages in your turbo.json and turbo will ensure they are always built when you need them.

Just make sure you're generating types in your tsup build step (example) and your IDE should be happy.

tknickman avatar Dec 01 '22 21:12 tknickman

@tknickman there's a big downside to that i.e. editor don't like that, and you would need to re-compile your internal packages all the time.

As mentioned in my post, please read: https://turbo.build/blog/you-might-not-need-typescript-project-references

mikevercoelen avatar Dec 01 '22 23:12 mikevercoelen

This, turborepo is awesome but once you live the next.js environment it has it's issues

irg1008 avatar Jan 31 '23 16:01 irg1008

https://turbo.build/repo/docs/handbook/sharing-code/internal-packages documentation should be updated to reflect that in order to use Internal Packages in a Node.js application (as opposed to Next.js, etc), you have to bundle your Node.js codebase (e.g. using tsup). That is far from obvious.

gajus avatar May 10 '23 23:05 gajus

To address the top-level issue here, using options like these is highly circumstantial and contextual and should be documented in each of the respective tooling's docs. noExternals is likely "a bridge too far" so I'll close this issue.

Also, re: @gajus's comment, we've now done that here: https://turbo.build/repo/docs/crafting-your-repository/creating-an-internal-package

anthonyshew avatar Jun 05 '24 19:06 anthonyshew

Also, re: @gajus's comment, we've now done that here: https://turbo.build/repo/docs/crafting-your-repository/creating-an-internal-package

Can you quote the relevant bit? I fail to find it in the linked document.

gajus avatar Jun 05 '24 20:06 gajus

Sorry, pulled the wrong link off my clipboard: https://turbo.build/repo/docs/core-concepts/internal-packages#compiled-packages

anthonyshew avatar Jun 05 '24 23:06 anthonyshew