trymodule icon indicating copy to clipboard operation
trymodule copied to clipboard

Be able to use a specific version of a module

Open codingmatty opened this issue 9 years ago • 7 comments

Currently, this tool always uses @latest, but it'd be nice to be able to specify a specific version to try out. It helps when you are trying to identify problems after upgrading. I don't know if you'd want to allow 2 versions in the same session, that might be overkill.

codingmatty avatar Mar 21 '16 19:03 codingmatty

This is a good feature suggestion and something I would love to add. Also, being able to run two different versions of the same package sounds like a good feature as well, as long as the code written to support this can be simple.

If anyone want to try to implement it (my time is limited right now), https://github.com/VictorBjelkholm/trymodule/blob/master/index.js#L30 would be the part where version is necessary to add (npmi docs here: https://github.com/maxleiko/npmi#optionsversion ). The multiple version packages thing I see as an extra addition that would simply resolve [email protected] to be lodash in global context by default, but if the user provides [email protected] and [email protected] to be lodash_v0_1_0 and lodash_v0_2_0 in the global context (which is kind of ugly, if someone has a better idea of variable naming, please step forward :) )

victorb avatar Mar 21 '16 19:03 victorb

What if the user could set an alias for a module ? Like trymodule "[email protected] as l1" "[email protected] as l2". Or shorter like trymodule [email protected]=l1 [email protected]=l2 But it's only a suggestion maybe too much work involved here ;).

jlebras avatar Mar 23 '16 00:03 jlebras

@jlebras I've opened a issue for that here: https://github.com/VictorBjelkholm/trymodule/issues/17

victorb avatar Apr 01 '16 23:04 victorb

Once #19 is merged this should be pretty straightforward 😃

shockey avatar Jun 07 '16 20:06 shockey

I'm thinking how we can actually implement this. I did some quick hacking today, trying to just setting the version when calling npmi but it's not enough since npm has no feature for handling multiple versions of the same package.

      var version = 'latest'
      if (moduleName.indexOf('@')) {
        version = moduleName.split('@')[1]
        moduleName = moduleName.split('@')[0]
      }
      npmi({name: moduleName, path: install_path, version}, (err, result) => {

So even with the change above, I'm not sure how to do this... If anyone have any ideas, please speak up! :)

victorb avatar Jun 11 '16 08:06 victorb

Say you want to load [email protected] and [email protected].

We'll say the command looks like trymodule [email protected]=lodash1 [email protected]=lodash2

Something that flows sequentially like this could work.

  1. npmi [email protected]
  2. require('lodash') and assign the result to the REPL scope as lodash1
  3. npmi [email protected]
  4. require('lodash') and assign the result to the REPL scope as lodash2

In doing this, we must be careful to work around require's module caching.

shockey avatar Jun 11 '16 22:06 shockey