siddharthkp/cost-of-modules

Extract CLI from module

Opened this issue ยท 10 comments

Hi @siddharthkp, thank you for good package.
I think your package shouldn't be bound to command line interface and can be decomposed to API and CLI, to allow users write their own interfaces.
What do you think about this?

@RoM4iK Ooh, I like that idea.

It is easily achievable too. All the heavy lifting happens in helpers functions and the cli entry point reads the options and calls the helper functions

Would you like to have a go at this?

P.S. What is the application that you have in mind for this? It would probably make more sense the whole service is exposed as an http API that accepts the contents of package.json and a returns a json with size information.

@siddharthkp, I just thought about creating http API, as you said.
I will start working on core extraction.

Sorry man, but I can't agree with your code style and lint config. So I gave up on this. I won't close PR, since this idea still has sense.

Ah, don't give up because of that ๐Ÿ˜”

Can we use prettier?

Yes, we can, but this will make a lot of changes. If u want to go this way, I'll help you:)

I have added prettier, would you like to review #38?

Was there any progress made on this in the end? I'm pretty keen on tying this module in with my build system, but I'd like to use a custom reporter function. Something like:

const costOfModules = require('cost-of-modules')
const data = await costOfModules.scan('.')
/*
[
  {name: 'express', children: 112, size: '64.2M'}
]
*/
myReport(data)

@rgrannell1 Would you like to take a shot at it?

https://github.com/siddharthkp/cost-of-modules/blob/master/src/index.js contains the required flow

@siddharthkp Sure, thanks for pointing me to that file. I'm working on a forked copy at the moment, as soon as I get tests passing I'll send in a PR.

Do you have any objections to me adding prettier to a dev dependency, and rewiring package.json to look for local copies of babel, prettier instead of globally installed versions? It makes it a bit quicker for contributors to get set up ๐Ÿ˜„. E.g

node_modules/.bin/prettier --write --single-quote --no-semi --trailing-comma es5

Sure, go for it