Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 4 additions & 8 deletions src/Spago/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -330,29 +330,25 @@ 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'
, "/"
, 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 ]
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/spago-run-args.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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