From 217271a6234dbe0d8d89da53e85f2f0408532392 Mon Sep 17 00:00:00 2001 From: Zoe Stafford <36511192+Z-snails@users.noreply.github.com> Date: Thu, 22 Dec 2022 14:56:44 +0000 Subject: [PATCH] Js shebang (#2830) * add shebang to outputted node file after `chmod`ing the file, it can be run directly ie `./build/exec/test` rather than `node ./build/exec/test`` * update CHANGELOG.md * [ linter ] * [ linter ] again... --- CHANGELOG.md | 4 ++++ src/Compiler/ES/Node.idr | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3526d9c1d..38bdb5a82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ * Non-recursive top-level constants are compiled to eagerly evaluated constants in Chez Scheme. +#### Node.js + +* Generated JavaScript files now include a shebang when using the Node.js backend + ### Compiler changes * If `IAlternative` expression with `FirstSuccess` rule fails to typecheck, diff --git a/src/Compiler/ES/Node.idr b/src/Compiler/ES/Node.idr index 3e7b71147..3d67689be 100644 --- a/src/Compiler/ES/Node.idr +++ b/src/Compiler/ES/Node.idr @@ -31,7 +31,12 @@ compileToNode : Ref Ctxt Defs -> Ref Syn SyntaxInfo -> ClosedTerm -> Core String -compileToNode c s tm = compileToES c s Node tm ["node", "javascript"] +compileToNode c s tm = do + js <- compileToES c s Node tm ["node", "javascript"] + pure $ shebang ++ js + where + shebang : String + shebang = "#!/usr/bin/env node\n" ||| Node implementation of the `compileExpr` interface. compileExpr :