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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Add `exec-args` as alias to `node-args`, to clarify that the args are
forwarded to whichever backend is being targeted (go, js, etc), not
exclusively node.

## [0.18.0] - 2020-12-07

Breaking changes (😱!!!):
Expand Down
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and respect and do not harass or belittle others.

## What is the correct way to ask a question?

It's ok to ask questions by [opening an issue][spago-issues]!
It's ok to ask questions by [opening an issue][spago-issues]!
I ([@f-f][f-f]) am also on the [Functional Programming Slack][fp-slack], so you can also ask
questions in the `#purescript` and `#purescript-beginners` channels.

Expand Down Expand Up @@ -81,6 +81,9 @@ $ npm install -g bower

# This runs the tests which make use of the `spago` executable
$ stack test

# A single test can be running by providing a pattern to the 'match' flag
$ stack test --test-arguments='--match "/Spago/spago run/Spago should use exec-args"'
```


Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,12 @@ $ spago run --main ModulePath.To.Main
# And pass arguments through to `purs compile`
$ spago run --main ModulePath.To.Main --purs-args "--verbose-errors"

# Or pass arguments to node
# Or pass arguments to the backend, in this case node
$ spago run --exec-args "arg1 arg2"

# For versions 18 and below, use `node-args` instead:
$ spago run --node-args "arg1 arg2"

```


Expand Down
8 changes: 5 additions & 3 deletions src/Spago/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ parser = do
docsFormat = CLI.optional $ CLI.opt Purs.parseDocsFormat "format" 'f' "Docs output format (markdown | html | etags | ctags)"
jobsLimit = CLI.optional (CLI.optInt "jobs" 'j' "Limit the amount of jobs that can run concurrently")
nodeArgs = many $ CLI.opt (Just . BackendArg) "node-args" 'a' "Argument to pass to node (run/test only)"
backendArgs = many $ CLI.opt (Just . BackendArg) "exec-args" 'b' "Argument to pass to the backend (run/test only)"
replPackageNames = many $ CLI.opt (Just . PackageName) "dependency" 'D' "Package name to add to the REPL as dependency"
sourcePaths = many $ CLI.opt (Just . SourcePath) "path" 'p' "Source path to include"

Expand All @@ -174,7 +175,6 @@ parser = do
globalOptions = GlobalOptions <$> quiet <*> verbose <*> veryVerbose <*> (not <$> noColor) <*> usePsa
<*> jobsLimit <*> configPath <*> cacheFlag


initProject =
( "init"
, "Initialize a new sample project, or migrate a psc-package one"
Expand All @@ -193,16 +193,18 @@ parser = do
, Repl <$> replPackageNames <*> sourcePaths <*> pursArgs <*> depsOnly
)

execArgs = (++) <$> backendArgs <*> nodeArgs

test =
( "test"
, "Test the project with some module, default Test.Main"
, Test <$> mainModule <*> buildOptions <*> nodeArgs
, Test <$> mainModule <*> buildOptions <*> execArgs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now wondering if we should now call the new flag --exec-args or --run-args rather than --backend-args? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I like exec-args better. I guess my variable names betray that.

)

run =
( "run"
, "Runs the project with some module, default Main"
, Run <$> mainModule <*> buildOptions <*> nodeArgs
, Run <$> mainModule <*> buildOptions <*> execArgs
)

bundleApp =
Expand Down
28 changes: 26 additions & 2 deletions test/SpagoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ spec = around_ setup $ do

shell "psa --version" empty >>= \case
ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"
ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"
ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"

it "Spago should be able to not use `psa`" $ do

Expand All @@ -668,6 +668,30 @@ spec = around_ setup $ do
spago ["build"] >>= shouldBeSuccess
shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt"

it "Spago should use exec-args" $ do

spago ["init"] >>= shouldBeSuccess
cp "../fixtures/spago-run-args.purs" "src/Main.purs"
spago ["install", "node-process"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt"

it "Spago should use node-args" $ do

spago ["init"] >>= shouldBeSuccess
cp "../fixtures/spago-run-args.purs" "src/Main.purs"
spago ["install", "node-process"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt"

it "Spago should prefer exec-args" $ do

spago ["init"] >>= shouldBeSuccess
cp "../fixtures/spago-run-args.purs" "src/Main.purs"
spago ["install", "node-process"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt"

describe "spago bundle" $ do

it "Spago should fail but should point to the replacement command" $ do
Expand All @@ -689,7 +713,7 @@ spec = around_ setup $ do
spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess
checkFixture "bundle-app-src-map.js"
checkFileExist "bundle-app-src-map.js.map"

describe "spago make-module" $ do

it "Spago should fail but should point to the replacement command" $ do
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/run-args-combined-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["hello","world","hallo","welt"]
1 change: 1 addition & 0 deletions test/fixtures/run-args-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["hello","world"]
14 changes: 14 additions & 0 deletions test/fixtures/spago-run-args.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Main where

import Effect (Effect)
import Effect.Console (log)
import Node.Process (argv)
import Prelude (Unit, ($), bind)
import Data.Array (drop)
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