egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.49k stars 209 forks source link

Support building a dependency tree of packages #999

Open tale opened 9 months ago

tale commented 9 months ago

This is really just a suggestion based on a use case that I realized. I don't believe it's been asked before, but a system for supporting dependencies of packages in a workspace/monorepo being built with tsup would be useful.

Currently, I have packageA which uses packageB and packageC, these are all in a monorepo, and they are all built using tsup --watch. Because packageA will not rebuild/rerun its onSuccess hook when packageB or packageC have changes and recompile, we ended up writing a tool in that workspace which wraps the build() function and uses TCP to tell other instances of the tool to rebuild and rerun the onSuccess hook.

TCP isn't a great option, but maybe adding direct support for a "dependencies" array that take the directories of other projects, or their paths to tsup.config.ts/js/whatever. Maybe something like this (rough idea):

import { defineConfig } from 'tsup'

export default defineConfig({
  entry: ['./src/index.ts'],
  format: 'esm'
  platform: 'node',
  onSuccess: 'node --enable-source-maps --inspect=0.0.0.0 ./dist/index.js',
  dependencies: [{
    path: '/Users/tale/monorepo/projectB',
    configPath: '/Users/tale/monorepo/projectB/tsup.ts' // Optional but equivalent to --config
  }]
})

I haven't completely panned this out in my head, but I wanted to start the discussion to see if this is something that can be considered in-scope with the project, and if so, I'd be willing to contribute and implement this.

Upvote & Fund

Fund with Polar

koheiio commented 9 months ago

I think simply allowing us to monitor file changes in node_modules might be sufficient to trigger the build. Right now watch ignores the node_modules folder. Is there a way to ignore it?

tale commented 9 months ago

I don't think node_modules would suffice because in something like a PNPM repo, workspaces are linked directly from their source. Internally our tool is watching for something like this:

If projectA depends on projectB, I have chokidar watching /packages/projectB/dist to detect rebuilds of projectB and then it'll rerun (without rebuilding).

yairopro commented 6 months ago

Something like a notIgnoreWatching option should do the work.

Like

{
  "notIgnoreWatching": [
    "@myMonorepo/myPackage"
  ]
}
egoist commented 5 months ago

I don't think node_modules would suffice because in something like a PNPM repo, workspaces are linked directly from their source. Internally our tool is watching for something like this:

If projectA depends on projectB, I have chokidar watching /packages/projectB/dist to detect rebuilds of projectB and then it'll rerun (without rebuilding).

@tale I did some test and watching package-b/dist actually will trigger the rebuild of the package using it.

# in package a
tsup --watch . --watch "../package-b/dist/**"

so I think for now it could be a workaround until we automatically do that

ilijaNL commented 3 months ago

It would be nice to override the default ignore (node_modules)