pkgroll icon indicating copy to clipboard operation
pkgroll copied to clipboard

Pkgroll API

Open finom opened this issue 2 months ago • 2 comments

Feature request

I'm working on a code generator that is also going to include a built in TypeScript bundler. The bundling process is multi-step, it includes bundling of different modules, and a post-bundle process that creates package.json with hard-coded "exports" and auto-generated README.md. Pkgroll looks promising, but as I explored the project's README and the source code, I haven't found an API that I can use as part of my own project.

Motivations

A few months ago I've already implemented, tested and documented the built-in bundler powered by tsdown. But at some point I started receiving compilation errors that completely blocked my further work on my codegen project. I've created 2 issues: one for rolldown, another for tsdown, but I received zero reaction from the authors after more than 2 weeks. Unfortunately, I'm starting to consider tsdown as a low quality open source project, and I was hoping to find an alternative that will help me to move forward. I use tsx tool for long time and never got any problems with it, so I'm sure pkgroll can offer similar level of quality and stability. Would be great if it's going to offer an API, besides the CLI interface.

Alternatives

No response

Additional context

No response

Bugs are expected to be fixed by those affected by it

  • [ ] I'm interested in working on this issue

Compensating engineering work financially will speed up resolution

  • [ ] I'm willing to offer financial support

finom avatar Oct 20 '25 14:10 finom

What would be useful here is a concrete proposal for the API you'd like to see.

If you think pkgroll should expose a programmatic API, could you outline:

  • The minimal API surface you'd expect (build(config), return shape, etc.).
  • How it would differ from / overlap with the CLI options.
  • Example code of how you'd want to use it inside your project.

A focused starting point will help us evaluate whether it's a good fit for pkgroll.

privatenumber avatar Oct 22 '25 03:10 privatenumber

@privatenumber thank you for the reply.

While I worked on the build-in bundler, I went across multiple approaches:

  • Webpack, Rollup, Rolldown - too bulky to set up internally and maintain loaders and plugins, requiring a lot of time and application.
  • ncc - not maintained, has no type defs for the API.
  • tsdown - relies on loose version of Rolldown, the dependency is set to "latest", where "latest" tag serves unstable beta versions.
  • tsup - not maintained.
  • esbuild - honestly, just don't remember the problematics of it, but I faced some issues that I couldn't fix to make it universally work.
  • pkgroll - doesn't have API, requires setting up package.json as a config.

The perfect API for me would be setting up entry, out dir and an optional tsconfig.json path:

// creates index.mjs, index.cjs, index.d.mts, index.d.cts files at dist folder 
await pkgroll.build({
  entry: ['./src/index.ts'],
  outDir: './dist',
  tsconfig: './tsconfig.build.json',
});

The perfect CLI would look similar:

# can have multiple --entry flags
npx pkgroll --entry index.ts --out dist --tsconfig tsconfig.build.json

In other words, it would "just work" as well as tsx.

I understand that it interferes the original idea of pkgroll and not likely will be implemented. I just hope that I wouldn't need to implement a bundler by my own as I realize what I would sign for 😬

Update: Looks like tsdown fixed the version problem https://github.com/rolldown/tsdown/issues/500#issuecomment-3421796799 after about a month of the issue was created. Update2: They still stick it to the beta/unstable version of Rolldown, no change.

finom avatar Oct 22 '25 11:10 finom