jbenet / transformer

transformer - multiformat data conversion
transform.datadex.io
130 stars 7 forks source link

installing contributor modules #6

Open jbenet opened 10 years ago

jbenet commented 10 years ago

Transformer modules (which define Types, Codecs, or Conversions) are addressed with an id: <namespace>/<module name> (<module name> defaults to transformer/<module_name>).

Currently, transformer will require modules from NPM:

Loader.LoadFromNpm = function (id) {
  name = Loader.NpmName(id)
  return require(name);
}

Loader.NpmName = function(id) {
  return 'transformer-' + id.toLowerCase().replace('/', '-');
}

From https://github.com/jbenet/transformer/blob/master/js/loader.js#L37-L44

Meaning, id jbenet/custom-timestamp resolves to module transformer-jbenet-custom-timestamp. And is then loaded with require('transformer-jbenet-custom-timestamp').

This is all well and good, but when people use transformer they'll have to install the required modules. If run without the required modules, transformer should error out with an exception saying which modules need to be installed. This is fine in js development, but using the cli, transformer should lead the user to install things correctly.

Something like:

> npm install -g dat-transformer
> transform mafintosh/a maxogden/b < a_data > b_data
Error: transformer needs the following npm modules to perform this conversion:
- transformer-mafintosh-a
- transformer-maxogden-b

To install them in this directory, run: 

  npm install transformer-mafintosh-a transformer-maxogden-b

To install them globally, run (you may need to sudo): 

  npm install -g transformer-mafintosh-a transformer-maxogden-b

Or, if you want transformer to automatically install them for you, run:

  transform --install-deps mafintosh/a maxogden/b
  transform --install-deps-global mafintosh/a maxogden/b

@maxogden @mafintosh thoughts?

mafintosh commented 10 years ago

Would probably lose the --install-deps and just rely on npm. Other than that :+1:

mafintosh commented 10 years ago

Why do we need the username namespace?

jbenet commented 10 years ago

the target users of transformer are not necessarily programmers. They are people that may have to program, but the target audience is pretty general.

I spent a while reading https://github.com/npm/npm/issues/798 which has some of the best arguments for non-namespacing, and chatted with substack quite a bit.

Still unclear to me whether pkg mgrs should enforce namespacing. However, I think there is one major reason to use namespaces in transformer: i want the transformer stdlib (the core set of types) to be distinct (transformer/). Many people may be running that code all over the place and I want people to not have to wonder about the code being used. I.e. it's been merged into the main project, so it does not need to be installed. And you can trust it. (people have already asked me about security in this...).

Also, I think i have the answer to the main argument people use for not namespacing. That there should be "one canonical module" for a thing. And not many A ... Z/foo, which is unclear. IMO namespacing doesn't break this. One canonical namespace is used to "symlink" (require) modules into the canonical space. E.g. I publish jbenet/foo, but it's great so gets merged into transformer/foo.

jbenet commented 10 years ago

More relevant information and thoughts in #10