Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing karma, eslint, etc. files across multiple codebases

I have several repositories that share so much of the same sorts of configuration files (e.g. .eslintrc, .babelrc, karma.conf.js) along with other sorts of utility files. I'd love to be able to extract these out and be able to leverage them across all repos. What are some of the best ways for achieving this?

  1. Create a new repo and publish it as an npm module. Then, import it and use it as needed?
  2. Create a CLI tool that basically generates the needed files?
  3. Symlinking?
  4. Others?

I feel that option 1 would be ideal, however, I'm not sure how one would be able to reference a file that is not exported. For example, how would one repo make use of the .eslintrc file within this npm module?

like image 992
Detuned Avatar asked Oct 24 '25 21:10

Detuned


1 Answers

Symlinking won't work well when you need to run builds and tests on a CI server, but it might be worth checking out lerna which wraps multiple packages in a monorepo.

I've tried the CLI approach, but ended up going with private npm "micro" modules, that I just drop in the package.json as needed.

What went wrong with the CLI:

  • it introduces a global dependency that every team member must install on their machine
  • you need to build some mechanism to let the CLI update itself
  • it adds an abstraction layer to your project

To use a specific .eslintrc from within an npm module, you can pass eslint a --config arg with your .eslintrc path.

Bear in mind that these tools (eslint, babel, karma, mocha, etc) are sometimes a pain to configure and update, so it is a good idea to keep your codebase self-contained, and duplicate the config files instead of having abstraction layers.

like image 155
Philippe Avatar answered Oct 26 '25 09:10

Philippe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!