Git Product home page Git Product logo

trymodule's Introduction

trymodule Circle CI

A simple cli tool for trying out different nodejs modules.

trymodule demo

Installation

npm install -g trymodule

Usage

trymodule colors

Downloads the module colors if needed, and starts a nodejs REPL with colors loaded in the current scope, ready for you to use.

trymodule colors lodash

Same as above but with many packages in one go!

trymodule colors=c lodash=l

Assign packages to custom variable names.

trymodule --clear

Removes the directory where trymodules stores the node modules. Removes TRYMODULE_PATH + '/node_modules'

Configuration

There are a couple of environment variables you can use to customize trymodule.

TRYMODULE_PATH for setting the path of where modules are stored. By default this is $HOME/.trymodule or $USERPROFILE/.trymodule

TRYMODULE_NONINTERACTIVE for making trymodule not fire up the repl in the end. This is useful if you want to just install some packages for future use. By default this is undefined. Setting it to any value would make trymodule non-interactive.

TRYMODULE_HISTORY_PATH for changing where to save the repl history. Should be pointing to a user write-able file. Defaults to $TRYMODULE_PATH/repl_history

You can set the environment variables for one session with export TRYMODULE_PATH=/usr/bin/trymodule or for just one time by doing TRYMOUDLE_PATH=/usr/bin/trymodule trymodule colors.

Support / Help

If you have any questions, open a Github issue here: github.com/VictorBjelkholm/trymodule/issues/new

or feel free to contact me on Twitter here: @VictorBjelkholm

Inspiration

Inspiration comes from a leiningen plugin called lein-try that allows you to try out clojure libraries without having to declare them in an existing project. Thanks to @rkneufeld for the inspiration!

License

The MIT License (MIT)

Copyright (c) 2016 Victor Bjelkholm

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

trymodule's People

Contributors

gblazex avatar philschatz avatar shockey avatar victorb avatar zeke avatar zzarcon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

trymodule's Issues

REPL cannot start due to error with loading history

I get this error when I try to run anything e.g. trymodule lodash:

Gonna start a REPL with packages installed and loaded for you
Couldn't find 'lodash' locally, gonna download it now
[email protected] .trymodule/node_modules/lodash
Package 'lodash' was loaded and assigned to 'l' in the current scope
REPL started...
  /usr/local/lib/node_modules/trymodule/node_modules/repl.history/index.js:19
  repl.rli.addListener('line', function(code) {
           ^

TypeError: Cannot read property 'addListener' of undefined
    at module.exports (/usr/local/lib/node_modules/trymodule/node_modules/repl.history/index.js:19:12)
    at /usr/local/lib/node_modules/trymodule/cli.js:72:7
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

I've done basic clean up steps i.e. uninstall trymodule and delete the ~/.trymodule/ folder (or trymodule --clear).

I don't understand why it fails here.

Allow for default session values to be specified

So I had the same idea for this module a while ago (great job btw!) and one of the things I wanted to do was allow for packages to allow a default session, meaning they could pre-define a few variables in their package.json file or somewhere else and that JSON would also be attached to the global object in the REPL section.

So say you have something like selectn and you want to test it. Instead of having to manually type in dummy data the package manager could add something to their package.json (or something) like:

...
"try": {
  "addresses":  [
  {"first": "blah blah blah"},
  {"second": "blah blah blah" }
 ]
}

And that would be parsed and loaded in just like the module itself.

How do I get specific functions of a module?

hi! I want to try out node-jira module which requires me to import the module like this JiraApi = require('jira').JiraApi;

I am unable to figure out how to run the same in trymodule node-jira.

Error installing specific version

Trying to install a specific version of a package, I get an error:

❯ try [email protected]
Gonna start a REPL with packages installed and loaded for you
Couldn't find '[email protected]' locally, gonna download it now
No compatible version found: electron-api-docs@'1.4.2@latest'
Valid install targets:
["1.4.1","1.4.2"]

/usr/local/lib/node_modules/trymodule/index.js:29
            throw new Error('npm install error')
            ^

Error: npm install error
    at npmi (/usr/local/lib/node_modules/trymodule/index.js:29:19)
    at installCallback (/usr/local/lib/node_modules/trymodule/node_modules/npmi/npmi.js:102:9)
    at cb (/usr/local/lib/node_modules/trymodule/node_modules/npm/lib/install.js:119:20)
    at cb (/usr/local/lib/node_modules/trymodule/node_modules/npm/lib/install.js:599:40)
    at /usr/local/lib/node_modules/trymodule/node_modules/npm/lib/install.js:707:22
    at cb (/usr/local/lib/node_modules/trymodule/node_modules/npm/node_modules/slide/lib/async-map.js:47:24)
    at /usr/local/lib/node_modules/trymodule/node_modules/npm/lib/install.js:912:14
    at /usr/local/lib/node_modules/trymodule/node_modules/npm/lib/cache.js:335:58
    at cb (/usr/local/lib/node_modules/trymodule/node_modules/npm/lib/cache/add-named.js:53:5)
    at next (/usr/local/lib/node_modules/trymodule/node_modules/npm/lib/cache/add-named.js:95:12)

Be able to set a specific variable name

Maybe someone is used to calling lodash as _ in their code, we should allow them to specify this when starting trymodule.

Example

# trymodule [email protected]=_ [email protected]=underscorejs
Package 'lodash' was loaded and assigned to '_' in the current scope
Package 'underscorejs' was loaded and assigned to 'underscorejs' in the current scope

This was first brought up in #13

Defining an empty variable name makes a module inaccessible

Example:

→ trymodule js-yaml=
Gonna start a REPL with packages installed and loaded for you
Couldn't find 'js-yaml' locally, gonna download it now
[email protected] .trymodule/node_modules/js-yaml
├── [email protected]
└── [email protected] ([email protected])
Package 'js-yaml' was loaded and assigned to '' in the current scope
REPL started...
>

This was a typo on my part, and strictly speaking, it isn't a bug... but it definitely would have been a nice user experience for trymodule to have picked up on my mistake and defaulted to the module's name.

Thoughts?

Support babel-node as options?

Nowadays most node.js use babel to work with their js env. Are there any such kind of support for trymodule? Thanks a lot!

Losing reference to module when using `lodash=_`

[email protected] on node 4.2.1.

→ trymodule lodash=_
Gonna start a REPL with packages installed and loaded for you
'lodash' was already installed since before!
Package 'lodash' was loaded and assigned to '_' in the current scope
REPL started...
> _.each
[Function: forEach]
> _.each
undefined
> _
undefined
> 

It may have something to do with using _ as the local variable.

Can someone try to reproduce this?

Multiple vulnerabilities in outdated packages

Currently trymodule contains 41 vulnerabilities (35 moderate, 6 high) due to not updated packages. @victorb please update packages.

List of outdated packages with vulnerabilities:

Severity: Moderate
Type: ReDoS
Package brace-expansion
Patched in >=1.1.7
Dependency of trymodule
Path trymodule > npmi > npm > fs-vacuum > rimraf > glob > minimatch > brace-expansion
Path trymodule > npmi > npm > fstream-npm > fstream-ignore > minimatch > brace-expansion
Path trymodule > npmi > npm > node-gyp > fstream > rimraf > glob > minimatch > brace-expansion
More info https://nodesecurity.io/advisories/338

Severity: Moderate
Type: Prototype pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of trymodule
Path trymodule > npmi > npm > node-gyp > request > hawk > boom > hoek
Path trymodule > npmi > npm > node-gyp > request > hawk > cryptiles > boom > hoek
Path trymodule > npmi > npm > node-gyp > request > hawk > hoek
Path trymodule > npmi > npm > node-gyp > request > hawk > sntp > hoek
Path trymodule > npmi > npm > npm-registry-client > request > hawk > boom > hoek
Path trymodule > npmi > npm > npm-registry-client > request > hawk > cryptiles > boom > hoek
Path trymodule > npmi > npm > npm-registry-client > request > hawk > hoek
Path trymodule > npmi > npm > npm-registry-client > request > hawk > sntp > hoek
Path trymodule > npmi > npm > request > hawk > boom > hoek
Path trymodule > npmi > npm > request > hawk > cryptiles > boom > hoek
Path trymodule > npmi > npm > request > hawk > hoek
Path trymodule > npmi > npm > request > hawk > sntp > hoek
More info https://nodesecurity.io/advisories/566

Severity: High
Type: Regular Expression Denial of Service
Package sshpk
Patched in >=1.13.2 < 1.14.0 || >=1.14.1
Dependency of trymodule
Path trymodule > npmi > npm > node-gyp > request > http-signature > sshpk
Path trymodule > npmi > npm > npm-registry-client > request > http-signature > sshpk
Path trymodule > npmi > npm > request > http-signature > sshpk
More info https://nodesecurity.io/advisories/606

Severity: High
Type: Regular Expression Denial of Service
Package tough-cookie
Patched in >=2.3.3
Dependency of trymodule
Path trymodule > npmi > npm > node-gyp > request > tough-cookie
Path trymodule > npmi > npm > npm-registry-client > request > tough-cookie
Path trymodule > npmi > npm > request > tough-cookie
More info https://nodesecurity.io/advisories/525

Severity: Moderate
Type: Memory Exposure
Package tunnel-agent
Patched in >=0.6.0
Dependency of trymodule
Path trymodule > npmi > npm > node-gyp > request > tunnel-agent
Path trymodule > npmi > npm > npm-registry-client > request > tunnel-agent
Path trymodule > npmi > npm > request > tunnel-agent
More info https://nodesecurity.io/advisories/598

Severity: Moderate
Type: Out-of-bounds Read
Package stringstream
Patched in >=0.0.6
Dependency of trymodule
Path trymodule > npmi > npm > node-gyp > request > stringstream
Path trymodule > npmi > npm > npm-registry-client > request > stringstream
Path trymodule > npmi > npm > request > stringstream
More info https://nodesecurity.io/advisories/664

Idea: trymodule .

Hey @victorbjelkholm. I love this module!

It would be cool to be able to run trymodule . or trymodule some/dir to load a REPL for a given directory, using the name of the directory as the name of required module:

cd projects/foo
trymodule .

Then in the repl, foo would be set to the value of require('.')

Save/Restore session

Something that would be useful to have is a save/restore functionality, where previous entered code and state can be restored in a future session.

  1. User enters trymodule lodash and repl opens with lodash installed
  2. User enters var something = lodash.repeat('WIN', 5)
  3. User enters save()
  4. User closes repl and opens it again with trymodule colors
  5. User enters restore()

And now something and lodash is available in the repl again.

Can't try private modules

Hi,

Is it possible to try a module, but import it into a specific variable name?

This would be particularly use for private modules, as it has a slash and @ in the name e.g. @org/myModule.

I can't seem to access the variable in the way it loads currently.

Thanks

Be able to use a specific version of a module

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.