Skip to content

Commit 1eaa825

Browse files
authored
Avoid writing a JS file when executing spago run (#846)
1 parent fc23817 commit 1eaa825

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
Other improvements:
11+
- Avoid writing a JS file when executing `spago run` (#845, #846)
12+
1013
## [0.20.4] - 2022-01-29
1114

1215
Bugfixes:

src/Spago/Build.hs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,29 +330,25 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe
330330
build (Just postBuild)
331331
where
332332
fromFilePath = Text.pack . Turtle.encodeString
333-
runJsSource = fromFilePath (sourceDir Turtle.</> ".spago/run.js")
334333
nodeArgs = Text.intercalate " " $ map unBackendArg extraArgs
335334
nodeContents outputPath' =
336335
fold
337-
[ "#!/usr/bin/env node\n\n"
338-
, "require('"
336+
[ "require('"
339337
, Text.replace "\\" "/" (fromFilePath sourceDir)
340338
, "/"
341339
, Text.pack outputPath'
342340
, "/"
343341
, unModuleName moduleName
344342
, "').main()"
345343
]
346-
nodeCmd = "node " <> runJsSource <> " " <> nodeArgs
344+
nodeCmd outputPath'= "node -e \"" <> nodeContents outputPath' <> "\" " <> nodeArgs
347345
nodeAction outputPath' = do
348-
logDebug $ "Writing " <> displayShow @Text runJsSource
349-
writeTextFile runJsSource (nodeContents outputPath')
350-
void $ chmod executable $ pathFromText runJsSource
351346
-- cd to executeDir in case it isn't the same as sourceDir
352347
logDebug $ "Executing from: " <> displayShow @FilePath executeDir
353348
Turtle.cd executeDir
354349
-- We build a process by hand here because we need to forward the stdin to the backend process
355-
let processWithStdin = (Process.shell (Text.unpack nodeCmd)) { Process.std_in = Process.Inherit }
350+
logDebug $ "Running node command: `" <> (display $ nodeCmd outputPath') <> "`"
351+
let processWithStdin = (Process.shell (Text.unpack $ nodeCmd outputPath')) { Process.std_in = Process.Inherit }
356352
Turtle.system processWithStdin empty >>= \case
357353
ExitSuccess -> maybe (pure ()) (logInfo . display) maybeSuccessMessage
358354
ExitFailure n -> die [ display failureMessage <> "exit code: " <> repr n ]

test/fixtures/spago-run-args.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ import Data.Show (show)
1010
main :: Effect Unit
1111
main = do
1212
args <- argv
13-
-- dropping the first two args, node path and script name, to make test stable
14-
log $ show $ drop 2 args
13+
-- dropping the first arg, node path to make test stable
14+
log $ show $ drop 1 args

0 commit comments

Comments
 (0)