diff --git a/cli.js b/cli.js index a6536cf..9a6dd70 100755 --- a/cli.js +++ b/cli.js @@ -88,7 +88,28 @@ if (hasFlag('--clear')) { } }) replHistory(replServer, TRYMODULE_HISTORY_PATH) - replServer.context = Object.assign(replServer.context, contextPackages) + Object.keys(contextPackages).forEach(as => { + var pkg = contextPackages[as] + // special-case assignment to _ so that it returns + // the required package (e.g. lodash) rather than the + // value of the last expression + if (as === '_') { + Object.defineProperty(replServer.context, as, { + configurable: true, + enumerable: false, + get: function () { return pkg }, + // allow (temporary) assignment to _: + // + // > _ = 42 + // 42 + // > _.each + // [Function: forEach] + set: function (val) { return val } + }) + } else { + replServer.context[as] = pkg + } + }) } }) } diff --git a/readme.md b/readme.md index 0205ac6..0989727 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ Downloads the module colors if needed, and starts a nodejs REPL with colors load Same as above but with many packages in one go! -`trymodule colors=c lodash=l` +`trymodule colors=c lodash=_` Assign packages to custom variable names.