Skip to content
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

Expose JS API to combine multiple outputs into one #188

Open
aklinker1 opened this issue Jan 19, 2024 · 3 comments · May be fixed by #189
Open

Expose JS API to combine multiple outputs into one #188

aklinker1 opened this issue Jan 19, 2024 · 3 comments · May be fixed by #189

Comments

@aklinker1
Copy link

I'm working on a framework for building chrome extensions, WXT, that includes this plugin when running wxt build --analyze. Chrome extensions contain multiple bulid steps, so each step outputs a separate stats JSON file, and then the rollup-plugin-visualizer CLI is used to combine them.

However, this doesn't work out of the box when using pnpm and shamefully-hoist=true (the default). This is because the binary isn't included in node_modules/.bin, so it's not in the path. Instead, the binary is stored at node_modules/wxt/node_modules/.bin/rollup-plugin-visualizer. There might be a similar problem for yarn PnP, haven't tested it.

See wxt-dev/wxt#360 for more details.

I could add node_modules/wxt/node_modules/.bin to the path while calling spawn("rollup-plugin-visualizer") (and I likely will do that as a workaround for now), but I'd also like to just call a function instead of spawning a new process, something like this:

import { mergeStats } from 'rollup-plugin-visualizer';

await mergeStats({
  files: ["stats1.json", "stats2.json", ...],
  // other options...
});

After looking at the code, I think this is a pretty simple change. Just involves exporting runForPluginJson from plugin/index.ts, or another entrypoint if that doesn't make sense.

const runForPluginJson = async ({ title, template, filename, open }: CliArgs, files: string[]) => {

If that sounds OK, I'm willing to work on this and open a PR!

@btd
Copy link
Owner

btd commented Jan 20, 2024

There is a CLI tool for this https://github.com/btd/rollup-plugin-visualizer#cli already. Not sure if i want to support merge as API

@btd
Copy link
Owner

btd commented Jan 20, 2024

Basically merge happen there https://github.com/btd/rollup-plugin-visualizer/blob/master/bin/cli.ts#L70C3-L102C5
I can extract this to the function, if it works for you

@aklinker1
Copy link
Author

I would prefer the entire runForPluginJson function be exported. Or else please include the call to renderTemplate, since that's not exported either.

const fileContent = await renderTemplate(template, {
title,
data: JSON.stringify(data),
});

@aklinker1 aklinker1 linked a pull request Jan 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants