diff --git a/CHANGELOG.md b/CHANGELOG.md index b417d00ce..8429fd448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +Other improvements: +- Avoid writing a JS file when executing `spago run` (#845, #846) + ## [0.20.4] - 2022-01-29 Bugfixes: diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 68b37a858..597d1e621 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -330,12 +330,10 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe build (Just postBuild) where fromFilePath = Text.pack . Turtle.encodeString - runJsSource = fromFilePath (sourceDir Turtle. ".spago/run.js") nodeArgs = Text.intercalate " " $ map unBackendArg extraArgs nodeContents outputPath' = fold - [ "#!/usr/bin/env node\n\n" - , "require('" + [ "require('" , Text.replace "\\" "/" (fromFilePath sourceDir) , "/" , Text.pack outputPath' @@ -343,16 +341,14 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe , unModuleName moduleName , "').main()" ] - nodeCmd = "node " <> runJsSource <> " " <> nodeArgs + nodeCmd outputPath'= "node -e \"" <> nodeContents outputPath' <> "\" " <> nodeArgs nodeAction outputPath' = do - logDebug $ "Writing " <> displayShow @Text runJsSource - writeTextFile runJsSource (nodeContents outputPath') - void $ chmod executable $ pathFromText runJsSource -- cd to executeDir in case it isn't the same as sourceDir logDebug $ "Executing from: " <> displayShow @FilePath executeDir Turtle.cd executeDir -- We build a process by hand here because we need to forward the stdin to the backend process - let processWithStdin = (Process.shell (Text.unpack nodeCmd)) { Process.std_in = Process.Inherit } + logDebug $ "Running node command: `" <> (display $ nodeCmd outputPath') <> "`" + let processWithStdin = (Process.shell (Text.unpack $ nodeCmd outputPath')) { Process.std_in = Process.Inherit } Turtle.system processWithStdin empty >>= \case ExitSuccess -> maybe (pure ()) (logInfo . display) maybeSuccessMessage ExitFailure n -> die [ display failureMessage <> "exit code: " <> repr n ] diff --git a/test/fixtures/spago-run-args.purs b/test/fixtures/spago-run-args.purs index 447a70bc6..aaa57155b 100644 --- a/test/fixtures/spago-run-args.purs +++ b/test/fixtures/spago-run-args.purs @@ -10,5 +10,5 @@ import Data.Show (show) main :: Effect Unit main = do args <- argv - -- dropping the first two args, node path and script name, to make test stable - log $ show $ drop 2 args + -- dropping the first arg, node path to make test stable + log $ show $ drop 1 args