Skip to content

Instantly share code, notes, and snippets.

@jeroenvandijk
Created March 30, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenvandijk/ec0bfd56cd8cda5eec13f07a95378bb3 to your computer and use it in GitHub Desktop.
Save jeroenvandijk/ec0bfd56cd8cda5eec13f07a95378bb3 to your computer and use it in GitHub Desktop.
Alternative dependencies

External dependencies: a different approach?

Libraries like https://github.com/danielsz/system offer a way to share reusable components/namespaces. The downside is that it is impossible to customize (without weird hacks or code). Often it is easier to copy-paste the code in your repo.

What if we could automate the copy-pasting in these cases? I would like to propose an idea for a (leiningen) plugin to share code without the pains of normal dependencies. No (Leftpad)[http://www.haneycodes.net/npm-left-pad-have-we-forgotten-how-to-program/] issues.

Requirements

  • No external dependencies (no risk of losing a remote dependency e.g. read about left-pad issues [1])
  • Less work than copy-pasting
  • No conflicts between dependencies
  • Allow customizability

Proposal (in the case of Clojure)

  • Create a Leiningen plugin that can scan a code base for dependency information
  • Dependencies start with a file header, e.g. `::snippet {:uri "https://github.com/danielsz/system/blob/master/src/system/components/elasticsearch.clj"}
  • When running the tool this will be replaced with the appropriate headers.
  • We can re-run this command to check for updates. The tool can show us the diff and can ask us to appy it. And if we want commit the changes too.
  • When we made local changes. The tool should be able to show us, the difference
  • With the right credentials, we can also do this for private repositories.
  • Maybe we can also do it for more than one file if we added a bit of extra meta-information to the source repository (or we should make smart use of namespaces)

References: [1] Leftpad http://www.haneycodes.net/npm-left-pad-have-we-forgotten-how-to-program/ [2] Semantic versioning critics http://blog.scottlogic.com/2016/12/15/semantic-versioning-is-not-enough.html

@ChrisBlom
Copy link

How would the local changes work? Say I import some component foo, at version 1, make some changes, and then import foo again, which now has version 2, and the changes between foo 1 and 2 are incompatible with my changes?

@ChrisBlom
Copy link

How would you handle dependencies?
Most component collections libraries i've seen are monolithic repos with a lot of dependencies, so you don't want to import all of them in your project.clj, would you declare which libs are needed to import a component?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment