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

Module Tree output #903

Closed
adamdbradley opened this issue Sep 7, 2016 · 4 comments · Fixed by #913
Closed

Module Tree output #903

adamdbradley opened this issue Sep 7, 2016 · 4 comments · Fixed by #913

Comments

@adamdbradley
Copy link

Would it be possible for rollup to print out a tree of all the modules used and how they are related? Reason for the request is that I have a project where certain dependencies are still getting included, but having difficulty tracking down "why", and thought a module graph or tree would help pinpoint the culprit. Thanks

@Rich-Harris
Copy link
Contributor

👍, we should do this – would just be a case of adding a dependencies property here which contained a list of module IDs:

rollup.rollup( options ).then( bundle => {
  bundle.modules.forEach( ({ id, dependencies }) => {
    console.log( `${id} has ${dependencies.length} dependencies:`, dependencies );
  });
});

This would only work via the JavaScript API, unless we added more logging to the CLI – #651.

Rich-Harris added a commit that referenced this issue Sep 10, 2016
include dependencies in bundle.modules
@Rich-Harris
Copy link
Contributor

Released in 0.35

@jharris4
Copy link

jharris4 commented Oct 1, 2019

In case it helps anyone, it looks like bundle.modules got replaced with bundle.cache.modules in version 1.x.

@DesignByOnyx
Copy link

For anybody who comes here for the same reason I did, here's a handy little function for listing all of the modules which depend on another module:

async function build() {
	const bundle = await rollup.rollup(config);
	const { modules } = bundle.cache;
	printModulesWhichDependOn(modules, 'lodash');
}

/**
 * Prints a list of modules which depend on `moduleName`, excluding the module itself.
 * This is useful if you need to see every module which depends on eg. "lodash".
 * 
 * @param {*} modules - a list of modules from the build (build.modules or build.cache.modules)
 * @param {*} moduleName 
 */
function printModulesWhichDependOn(modules, moduleName) {
	console.log(`MODULES WHICH DEPEND ON "${moduleName}":`);
	modules.forEach(({ id, dependencies }) => {
		if (
			id.indexOf(moduleName) === -1 &&
			dependencies.find(d => d.indexOf(moduleName) > -1)
		) {
			console.log(`  - ${id}`);
		}
	});
}

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.

4 participants