如何将 ClojureScript 节点 REPL 连接到我的 :node-library shadow-cljs 项目?
How to connect a ClojureScript node REPL to my :node-library shadow-cljs project?
上下文
我正在使用 ClojureScript 和 构建一个 Node.js 库。
所有开发都是使用 ClojureScript 完成的,但构建工件是一个 NPM 包。示例:
(ns com.example.answer)
(defn answer [] 42)
构建...发布...然后
const answer = require('answer');
answer(); //=> 42
注意:我最近向贡献了我的构建设置的细节。
我的整个开发环境都在 Docker 容器中,我正在使用 "Visual Studio Code Remote - Container" 扩展。
- ClojureScript v1.10
- Node.js v12
- shadow-cljs v2.8.55
- Visual Studio代码Calva extension (running in a VS Code remote container)
"Problem"
我的构建设置工作正常(至少我这么认为!)但我想实施更快的开发反馈周期。
换句话说:我不想重建整个 NPM 包只是为了测试几行更改。
完美世界 又名"the question"
在理想情况下,我应该能够打开 REPL 并且能够随时评估我的 ClojureScript 代码。
无论我如何尝试到达那里,我似乎都被同样的潜在问题所阻碍:
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
我试过的
仅 shadow-cljs
:
给定以下 shadow-cljs.edn
文件:
;; shadow-cljs configuration
{:source-paths
["src"]
:builds
{:lib {:target :node-library
:output-to "dist/index.js"
:exports {:citation citegen.processor.main/citation}}}}
第一次观看:
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=>
然后在另一个终端:(注意错误信息)
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.
使用 VS Code Calva:
给定与上面相同的 shadow-cljs.edn
文件:
当我尝试使用 Calva: Load current namespace in REPL window
手动加载命名空间时,我得到了同样的错误:
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
问题:如何到达那个完美的世界?
我建议阅读有关 REPL Troubleshooting 的手册部分。
您很可能想要 运行 shadow-cljs node-repl
。这将启动一个 REPL,其中包含一个连接的托管 运行time。否则你需要一些 运行ning 节点来加载由 :node-library
生成的代码,如手册中所述。
如果您愿意,可以手动执行此操作 运行 宁 node
然后 require("./dist/index.js")
。一旦完成,cljs-repl
将能够评估。
多亏了 Thomas Heller,我才得以成功。
我没有意识到我需要 运行 一次构建工件才能连接到 REPL。
这将有效地消除此错误:
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
步骤
- 在 VS Code 中打开任何 ClojureScript 文件
- 按CMDSHIFTp和select
Calva: Start a project REPL and connect (aka Jack-in)
- 等到 REPL window 打开
- 只有这样,才能打开一个新终端并需要您的构建工件,以便连接到 REPL。例如
node -e "require('./dist')"
- 打开任何你想在 REPL 中评估的 ClojureScript 文件,按 CMDSHIFTp 和 select
Calva: Load current namespace in the REPL window
我在下面附上了截屏视频。如您所见:
- CLJS REPL window 中的命名空间不再设置为
undefined
- 对 ClojureScript 文件的任何更改都会自动重新编译并在 REPL 中可用
上下文
我正在使用 ClojureScript 和
所有开发都是使用 ClojureScript 完成的,但构建工件是一个 NPM 包。示例:
(ns com.example.answer)
(defn answer [] 42)
构建...发布...然后
const answer = require('answer');
answer(); //=> 42
注意:我最近向
我的整个开发环境都在 Docker 容器中,我正在使用 "Visual Studio Code Remote - Container" 扩展。
- ClojureScript v1.10
- Node.js v12
- shadow-cljs v2.8.55
- Visual Studio代码Calva extension (running in a VS Code remote container)
"Problem"
我的构建设置工作正常(至少我这么认为!)但我想实施更快的开发反馈周期。
换句话说:我不想重建整个 NPM 包只是为了测试几行更改。
完美世界 又名"the question"
在理想情况下,我应该能够打开 REPL 并且能够随时评估我的 ClojureScript 代码。
无论我如何尝试到达那里,我似乎都被同样的潜在问题所阻碍:
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
我试过的
仅
shadow-cljs
:给定以下
shadow-cljs.edn
文件:;; shadow-cljs configuration {:source-paths ["src"] :builds {:lib {:target :node-library :output-to "dist/index.js" :exports {:citation citegen.processor.main/citation}}}}
第一次观看:
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=>
然后在另一个终端:(注意错误信息)
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.
使用 VS Code Calva:
给定与上面相同的
shadow-cljs.edn
文件:当我尝试使用
Calva: Load current namespace in REPL window
手动加载命名空间时,我得到了同样的错误:No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
问题:如何到达那个完美的世界?
我建议阅读有关 REPL Troubleshooting 的手册部分。
您很可能想要 运行 shadow-cljs node-repl
。这将启动一个 REPL,其中包含一个连接的托管 运行time。否则你需要一些 运行ning 节点来加载由 :node-library
生成的代码,如手册中所述。
如果您愿意,可以手动执行此操作 运行 宁 node
然后 require("./dist/index.js")
。一旦完成,cljs-repl
将能够评估。
多亏了 Thomas Heller,我才得以成功。
我没有意识到我需要 运行 一次构建工件才能连接到 REPL。
这将有效地消除此错误:
No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
步骤
- 在 VS Code 中打开任何 ClojureScript 文件
- 按CMDSHIFTp和select
Calva: Start a project REPL and connect (aka Jack-in)
- 等到 REPL window 打开
- 只有这样,才能打开一个新终端并需要您的构建工件,以便连接到 REPL。例如
node -e "require('./dist')"
- 打开任何你想在 REPL 中评估的 ClojureScript 文件,按 CMDSHIFTp 和 select
Calva: Load current namespace in the REPL window
我在下面附上了截屏视频。如您所见:
- CLJS REPL window 中的命名空间不再设置为
undefined
- 对 ClojureScript 文件的任何更改都会自动重新编译并在 REPL 中可用