如何将 ClojureScript 节点 REPL 连接到我的 :node-library shadow-cljs 项目?

cus*_*der 6 node.js clojurescript shadow-cljs vscode-calva

语境

我正在使用 ClojureScript 和shadow-cljs构建一个 Node.js 库。
所有开发都是使用 ClojureScript 完成的,但构建工件是一个 NPM 包。例子:

(ns com.example.answer)

(defn answer [] 42)
Run Code Online (Sandbox Code Playgroud)

构建...发布...然后

const answer = require('answer');
answer(); //=> 42
Run Code Online (Sandbox Code Playgroud)

注意:我最近在这篇文章中贡献了我的构建设置的详细信息。

我的整个开发环境都在一个 Docker 容器中,我使用的是“Visual Studio Code Remote - Container”扩展。

问题”

我的构建设置工作正常(至少我认为是这样!)但我想实现更快的开发反馈周期。
换句话说:我不想为了测试几行更改而重建整个 NPM 包。

完美世界 又名“问题”

在一个完美的世界中,我应该能够打开 REPL 并能够始终评估我的 ClojureScript 代码。

无论我如何尝试到达那里,我似乎都被相同的潜在问题所阻止:

没有应用程序连接到 REPL 服务器。确保您的 JS 环境已加载您编译的 ClojureScript 代码。

我试过的

  1. shadow-cljs只:

    鉴于以下shadow-cljs.edn文件:

    const answer = require('answer');
    answer(); //=> 42
    
    Run Code Online (Sandbox Code Playgroud)

    第一次观看:

    root@97db64e5dfa3:/workspaces/citegen# cd packages/csl-processor/
    root@97db64e5dfa3:/workspaces/citegen/packages/csl-processor# yarn shadow-cljs cljs-repl lib
    yarn run v1.17.3
    $ /workspaces/citegen/node_modules/.bin/shadow-cljs cljs-repl lib
    shadow-cljs - config: /workspaces/citegen/packages/csl-processor/shadow-cljs.edn  cli version: 2.8.52  node: v12.10.0
    shadow-cljs - socket connect failed, server process dead?
    shadow-cljs - updating dependencies
    ...
    shadow-cljs - dependencies updated
    shadow-cljs - server version: 2.8.52 running at http://localhost:9630
    shadow-cljs - nREPL server started on port 36017
    [0:0]~cljs.user=>
    
    Run Code Online (Sandbox Code Playgroud)

    然后在另一个终端:(注意错误信息)

    root@97db64e5dfa3:/workspaces/citegen# cd packages/csl-processor/
    root@97db64e5dfa3:/workspaces/citegen/packages/csl-processor# yarn shadow-cljs cljs-repl lib
    yarn run v1.17.3
    $ /workspaces/citegen/node_modules/.bin/shadow-cljs cljs-repl lib
    shadow-cljs - config: /workspaces/citegen/packages/csl-processor/shadow-cljs.edn  cli version: 2.8.52  node: v12.10.0
    shadow-cljs - connected to server
    [1:1]~cljs.user=> (inc 41)
    No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用 VS Code Calva

    给定与shadow-cljs.edn上述相同的文件:

    在此处输入图片说明

    当我尝试使用 手动加载命名空间时Calva: Load current namespace in REPL window,出现相同的错误:

    没有应用程序连接到 REPL 服务器。确保您的 JS 环境已加载您编译的 ClojureScript 代码。

问题:我如何到达那个完美的世界?

cus*_*der 6

多亏了 Thomas Heller,我才设法让它发挥作用。

我没有意识到我需要运行一次构建工件才能连接到 REPL。

这将有效地摆脱这个错误:

没有应用程序连接到 REPL 服务器。确保您的 JS 环境已加载您编译的 ClojureScript 代码。

脚步

  1. 在 VS Code 中打开任何 ClojureScript 文件
  2. 按下CMDSHIFTp并选择Calva: Start a project REPL and connect (aka Jack-in)
  3. 等到 REPL 窗口打开
  4. 只有这样,打开一个新终端并需要您的构建工件,以便连接到 REPL。例如node -e "require('./dist')"
  5. 打开要在 REPL 中评估的任何 ClojureScript 文件,按下CMDSHIFTp并选择Calva: Load current namespace in the REPL window

我在下面附上了一个截屏视频。如你看到的:

  • 在CLJS REPL窗口中的命名空间没有设置为undefined
  • 对 ClojureScript 文件的任何更改都会自动重新编译并在 REPL 中可用

在此处输入图片说明