Code Monkey home page Code Monkey logo

cljs-noderepl's Introduction

cljs-noderepl

Provides a ClojureScript REPL running on Node.JS.

Requirements

You must have Node version 0.8.x or higher installed.

Leiningen Plugin

To setup the Leiningen plugin, add this to your project.clj or ~/.lein/profiles.clj:

:plugins [[org.bodil/lein-noderepl "0.1.11"]]

Then, start the REPL like this:

$ lein trampoline noderepl

In-Project Usage

Add the following dependency to your project.clj:

[org.bodil/cljs-noderepl "0.1.11"]

To launch the REPL the hard way, run lein repl and enter the following:

(require '[cljs.repl :as repl] '[cljs.repl.node :as node])
(repl/repl (node/repl-env))

Environment

The REPL is connected to a live Node process running a sandboxed environment, which provides all of Node's available global variables.

As an example, here's the standard Node hello world, in REPL ready ClojureScript:

(let [http (js/require "http")
      handler (fn [req res] (.end res "Hello sailor!"))
      server (.createServer http handler)]
  (.listen server 1337))

Readline Support

If you have rlwrap installed, the following provides basic readline and paren matching support:

rlwrap -r -m -q '\"' -b "(){}[],^%3@\";:'" lein trampoline noderepl

nREPL With Piggieback

You can get cljs-noderepl running on an nREPL server through Piggieback, though it's a bit fiddly. Here's how.

Add the cljs-noderepl dependency to your project.clj (it will bring in Piggieback transitively):

[org.bodil/cljs-noderepl "0.1.11"]

You may want to add this dependency to your :dev profile so it's not carried along when you deploy your library/application.

Then, add the Piggieback nREPL middleware, also in project.clj:

:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}

Now, launch nREPL through Leiningen as usual - lein repl - and connect to it from wherever you prefer. You'll need to start the ClojureScript REPL manually once you have a Clojure REPL prompt:

user=> (require '[cljs.repl.node :as node])
user=> (node/run-node-nrepl)

License

Copyright ยฉ 2012 Bodil Stokke.

Distributed under the Eclipse Public License, the same as Clojure.

cljs-noderepl's People

Contributors

bodil avatar cemerick avatar danskarda avatar joakin avatar neatonk avatar olenhad 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cljs-noderepl's Issues

repl not working

i have noderepl in my project.clj, ran lein deps

if i run lein trampoline noderepl, i get

ClojureScript:cljs.user> (def http (js/require "http"))
"Error evaluating:" (def http (js/require "http")) :as "cljs.user.http = require(\"http\")"
Error: parsers,STATUS_CODES,IncomingMessage,OutgoingMessage,ServerResponse,Agent,globalAgent,ClientRequest,request,get,Server,createServer,_connectionListener,Client,createClient is not ISeqable

every time i try to load anything from node

if i try to load noderepl from the lein repl

user=> (require '[cljs.repl :as repl] '[cljs.repl.node :as node])

FileNotFoundException Could not locate cljs/repl/node__init.class or cljs/repl/node.clj on classpath:   clojure.lang.RT.load (RT.java:443)

any ideas?
thanks!

'lein trampoline noderepl' fails silently

Trying start a noderepl via "lein trampoline noderepl" yields "Building Clojurescript." and then returns to the shell without an error code. Starting the cljs repl manually via a clojure repl works as expected.

Using lein-cljsbuild 0.3.0, nodejs 0.8.20, lein-noderepl 0.1.6

js->clj returns argument when given a JavaScript object

noderepl:

$ lein trampoline noderepl
ClojureScript:cljs.user> (def o (clj->js {:foo 42}))
#<[object Object]>
ClojureScript:cljs.user> (js->clj o)
#<[object Object]>
ClojureScript:cljs.user> (identical? o (js->clj o))
#<true>

ClojureScript REPL:

$ script/repljs
ClojureScript:cljs.user> (def o (clj->js {:foo 42}))
#js {:foo 42}
ClojureScript:cljs.user> (js->clj o)
{"foo" 42}

Both REPLs handle arrays correctly:

ClojureScript:cljs.user> (-> [1 2 3] clj->js js->clj)
[1 2 3]

lein trampoline noderepl faill with IllegalArgumentException

When i tried to go through the readme instructions

Exception in thread "main" java.lang.IllegalArgumentException: No single method: _setup of interface: cljs.repl.IJavaScriptEnv found for function: -setup of protocol: IJavaScriptEnv, compiling:(cemerick/piggieback.clj:148:5)

nREPL support for Emacs

Is it possible to connect to noderepl via emacs nREPL client? If not, that would be a really useful feature ๐Ÿ˜„

PS: I'm well aware of the possibility that the author prefers Catnip over Emacs; so maybe a plugin for Catnip then?

nREPL Emacs integration

I could totally be missing something here, and forgive me if I am, but whenever I run the cljs repl from Emacs connected to nREPL it prompts me for input from Stdin:. Everything in my profile.clj looks good. Is that what you were hinting at when you said it was "a bit fiddly"?

Oh, FWIW, you might wanna bump the piggieback dependency's version too.

IO Exception: The pipe has been ended

When I start lein trampoline noderepl, I'm getting the following error.

Exception in thread "main" java.io.IOException: The pipe has been ended
        at java.io.FileOutputStream.writeBytes(Native Method)
        at java.io.FileOutputStream.write(Unknown Source)
        at java.io.BufferedOutputStream.write(Unknown Source)
        at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
        at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
        at sun.nio.cs.StreamEncoder.write(Unknown Source)
        at java.io.OutputStreamWriter.write(Unknown Source)
        at java.io.BufferedWriter.flushBuffer(Unknown Source)
        at java.io.BufferedWriter.write(Unknown Source)
        at java.io.Writer.write(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93)
        at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
        at cljs.repl.node$js_eval.invoke(node.clj:63)
        at cljs.repl.node$load_resource.invoke(node.clj:101)
        at cljs.repl.node$repl_env.doInvoke(node.clj:125)
        at clojure.lang.RestFn.invoke(RestFn.java:397)
        at cljs.repl.node$run_node_repl.invoke(node.clj:130)
        at G__428$eval2937$fn__2939.invoke(NO_SOURCE_FILE:1)
        at G__428$eval2937.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:6511)
        at clojure.lang.Compiler.eval(Compiler.java:6501)
        at clojure.lang.Compiler.eval(Compiler.java:6501)
        at clojure.lang.Compiler.eval(Compiler.java:6477)
        at clojure.core$eval.invoke(core.clj:2797)
        at clojure.main$eval_opt.invoke(main.clj:297)
        at clojure.main$initialize.invoke(main.clj:316)
        at clojure.main$null_opt.invoke(main.clj:349)
        at clojure.main$main.doInvoke(main.clj:427)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:419)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.Var.applyTo(Var.java:532)
        at clojure.main.main(main.java:37)

Here's my project.clj file.

(defproject hello "0.1.0-SNAPSHOT"
  :plugins [[org.bodil/lein-noderepl "0.1.6"]]
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [org.clojure/clojurescript "0.0-1586"]])

I'm running it with node 0.8.20 on Windows 8

IO Exception: Write end dead

When I start lein trampoline noderepl, I eventually (takes several seconds) get the following error (multiple times).

I checked that a node process was running and that the file in tmp/ exists and actually contains something -- both was the case.

Running with node 0.8.16, clojure 1.4.0 and cls-noderepl 0.1.3

java.io.IOException: Write end dead
at java.io.PipedReader.read(PipedReader.java:298)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:298)
at cljs.repl.node$js_eval.invoke(node.clj:67)
at cljs.repl.node$node_eval.invoke(node.clj:81)
at cljs.repl.node.NodeEnv._evaluate(node.clj:110)
at cljs.repl$evaluate_form.invoke(repl.clj:80)
at cljs.repl$evaluate_form.invoke(repl.clj:64)
at cljs.repl.node$node_setup.invoke(node.clj:77)
at cljs.repl.node.NodeEnv._setup(node.clj:108)
at cljs.repl$repl.doInvoke(repl.clj:172)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at cljs.repl.node$run_node_repl.invoke(node.clj:132)
at G__1212$eval1799$fn__1801.invoke(NO_SOURCE_FILE:1)
at G__1212$eval1799.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6511)
at clojure.lang.Compiler.eval(Compiler.java:6501)
at clojure.lang.Compiler.eval(Compiler.java:6501)
at clojure.lang.Compiler.eval(Compiler.java:6477)
at clojure.core$eval.invoke(core.clj:2797)
at clojure.main$eval_opt.invoke(main.clj:297)
at clojure.main$initialize.invoke(main.clj:316)
at clojure.main$null_opt.invoke(main.clj:349)
at clojure.main$main.doInvoke(main.clj:427)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:419)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)

`:cljs/quit` throws `java.lang.NullPointerException`

Typing :cljs/quit at the repl throws the error below and then hangs.

ClojureScript:cljs.user> :cljs/quit
Exception in thread "main" java.lang.NullPointerException
        at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:296)
        at cljs.repl.node$node_tear_down.invoke(node.clj:95)
        at cljs.repl.node.NodeEnv._tear_down(node.clj:115)
        at cljs.repl$repl.doInvoke(repl.clj:189)
        at clojure.lang.RestFn.invoke(RestFn.java:410)
        at cljs.repl.node$run_node_repl.invoke(node.clj:133)
        at G__424$eval3049$fn__3051.invoke(NO_SOURCE_FILE:1)
        at G__424$eval3049.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:6511)
        at clojure.lang.Compiler.eval(Compiler.java:6501)
        at clojure.lang.Compiler.eval(Compiler.java:6501)
        at clojure.lang.Compiler.eval(Compiler.java:6477)
        at clojure.core$eval.invoke(core.clj:2797)
        at clojure.main$eval_opt.invoke(main.clj:297)
        at clojure.main$initialize.invoke(main.clj:316)
        at clojure.main$null_opt.invoke(main.clj:349)
        at clojure.main$main.doInvoke(main.clj:427)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:419)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.Var.applyTo(Var.java:532)
        at clojure.main.main(main.java:37)

evaluation error

cljs.user> (def http (js/require "http"))
"Error evaluating:" (def http (js/require "http")) :as "cljs.user.http = require("http");\r\n"

Error: parsers,STATUS_CODES,IncomingMessage,OutgoingMessage,ServerResponse,Agent,globalAgent,ClientRequest,request,get,Server,createServer,_connectionListener,Client,createClient is not ISeqable
at seq (cljs/core.cljs:39:9)
at cljs.core.map.map__2 (cljs/core.cljs:11:120)
at cljs.core.LazySeq.sval (cljs/core.cljs:43:23)
at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (cljs/core.cljs:55:30)
at _seq (cljs/core.cljs:9:11)
at seq (cljs/core.cljs:19:24)
at print_map (cljs/core.cljs:4:36)
at pr_writer (cljs/core.cljs:64:28)
at pr_seq_writer (cljs/core.cljs:1:89)
at pr_sb_with_opts (cljs/core.cljs:1:184)

Clojure 1.5.1, Node.js 0.10.33, Austin 0.1.5, Leiningen 2.2.0, Java 1.7.0_71 Java HotSpot(TM) Client VM, Windows 7 64bit

lein trampoline noderepl fails (loudly)

Hi hi! I just hit the following:

(core-dev)[venantius@ziz:circleci] 15:57:23 $ lein trampoline noderepl
Retrieving org/bodil/lein-noderepl/0.1.11/lein-noderepl-0.1.11.pom from clojars
Retrieving leinjacker/leinjacker/0.4.2/leinjacker-0.4.2.pom from clojars
Retrieving leinjacker/leinjacker/0.4.2/leinjacker-0.4.2.jar from clojars
Retrieving org/bodil/lein-noderepl/0.1.11/lein-noderepl-0.1.11.jar from clojars
Retrieving org/bodil/cljs-noderepl/0.1.11/cljs-noderepl-0.1.11.pom from clojars
Retrieving com/cemerick/piggieback/0.1.2/piggieback-0.1.2.pom from central
Retrieving com/cemerick/piggieback/0.1.2/piggieback-0.1.2.jar from central
Retrieving org/bodil/cljs-noderepl/0.1.11/cljs-noderepl-0.1.11.jar from clojars
Compiling ClojureScript.
Exception in thread "main" java.io.FileNotFoundException: Could not locate cljsbuild/compiler__init.class or cljsbuild/compiler.clj on classpath:
    at clojure.lang.RT.load(RT.java:443)
    at clojure.lang.RT.load(RT.java:411)
    at clojure.core$load$fn__5018.invoke(core.clj:5530)
    at clojure.core$load.doInvoke(core.clj:5529)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5336)
    at clojure.core$load_lib$fn__4967.invoke(core.clj:5375)
    at clojure.core$load_lib.doInvoke(core.clj:5374)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:619)
    at clojure.core$load_libs.doInvoke(core.clj:5413)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:619)
    at clojure.core$require.doInvoke(core.clj:5496)
    at clojure.lang.RestFn.invoke(RestFn.java:436)
    at user$eval7.invoke(form-init9205719152844321130.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6619)
    at clojure.lang.Compiler.eval(Compiler.java:6608)
    at clojure.lang.Compiler.load(Compiler.java:7064)
    at clojure.lang.Compiler.loadFile(Compiler.java:7020)
    at clojure.main$load_script.invoke(main.clj:294)
    at clojure.main$init_opt.invoke(main.clj:299)
    at clojure.main$initialize.invoke(main.clj:327)
    at clojure.main$null_opt.invoke(main.clj:362)
    at clojure.main$main.doInvoke(main.clj:440)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:419)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:532)
    at clojure.main.main(main.java:37)

Which was curious because I had no problem loading stuff in from the REPL directly

(core-dev)[davidjarvis@ziz:circleci] 15:57:43 $ lein repl
Compiling ClojureScript.
Compiling "out/circleci.js" from ["src/cljs"]...
Successfully compiled "out/circleci.js" in 7.706 seconds.
nREPL server started on port 6005 on host 127.0.0.1
REPL-y 0.3.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (require '[cljs.repl :as repl] '[cljs.repl.node :as node])
nil
user=> (repl/repl (node/repl-env))
To quit, type: :cljs/quit
ClojureScript:cljs.user> (+ 2 2)
4
ClojureScript:cljs.user> (+ 1 1)
2

For reference, my project.clj currently looks like this:

(defproject circleci-cli "0.0.1"
  :description "A Command-Line Interface (CLI) for CircleCI"
  :url "http://www.circleci.com"
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [org.clojure/clojurescript "0.0-2197"]
                 ;; [com.cemerick/piggieback "0.1.3"]
                 [com.cemerick/clojurescript.test "0.3.1"]
                 [org.bodil/cljs-noderepl "0.1.11"]
                 ]

  :plugins [[lein-cljsbuild "1.0.3"]
            [lein-npm "0.4.0"]
            [org.bodil/lein-noderepl "0.1.11"]]
  :hooks [leiningen.cljsbuild]
  :node-dependencies [[request "2.36.0"]
                      [docopt "0.4.0"]]

  ;; :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}

  :source-paths ["src/cljs" "src/clj"]
  :cljsbuild {:builds [{:id "main"
                        :source-paths ["src/cljs"]
                        :compiler {:output-to "out/circleci.js"
                                   :optimizations :simple
                                   :target :nodejs
                                   :pretty-print true}}]})

Any thoughts as to why it's not happy launching from trampoline?

ReferenceError: require is not defined

Hey, I got the following error upon starting:

"Error evaluating:" (set! cljs.core/*print-fn* (.-print (js/require "util"))) :as "cljs.core._STAR_print_fn_STAR_ = require(\"util\").print;\n"
ReferenceError: require is not defined
    at <cljs repl>:1:34
    at Socket.<anonymous> (eval at <anonymous> (eval at <anonymous> (eval:1:82)))
    at Socket.emit (events.js:67:17)
    at Pipe.onread (net.js:347:14)

Do I need to add specific cljsbuild directives. I suspect thats the issue. Here's my project.clj for reference sake:

(defproject noderepl "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.4.0"]
                 ]
  :plugins [[org.bodil/lein-noderepl "0.1.5"]])

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.