Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spago run does not call Node correctly #295

Closed
justinwoo opened this issue Jun 26, 2019 · 2 comments

Comments

@justinwoo
Copy link
Collaborator

commented Jun 26, 2019

this is probably some carry over from porting something from purp and whatever

foreign import argv :: Array String -- from Node process.argv

main :: Effect Unit
main = do
  log $ "argv length:" <> show (Array.length argv)
  log $ "argv: " <> show argv

See how spago run ends with 3 args, because it doesn't evaluate a script. This makes writing programs that need to use argv not work with Spago run.

$ spago run --node-args "hello world"
Installation complete.
Build succeeded.
argv length:3
argv: ["/nix/store/shit-nodejs-10.16.0/bin/node","hello","world"]
$ ./index.js hello world
argv length:4
argv: ["/nix/store/shit-nodejs-10.16.0/bin/node","/path/to/spago-run-behavior/index.js","hello","world"]

Compare pulp and psc-package:

$ pulp --psc-package run -- hello world
* Building project in /home/justin/Code/spago-run-behavior
           Src   Lib   All
Warnings   0     0     0
Errors     0     0     0
* Build successful.
argv length:4
argv: ["/nix/store/shit-nodejs-10.16.0/bin/node","/tmp/pulp-run2019526-3727-tm0ixi.8zxop.js","hello","world"]

repo:

https://github.com/justinwoo/spago-run-behavior

@justinwoo

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 26, 2019

I would prefer if Spago run just wrote a small JS file to .spago/run.js with the contents:

#!/usr/bin/env node

require('./output/Main').main()

With executable mode (Main needs to be replaced when -m is set)

@justinwoo

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 26, 2019

cmd = "node -e \"require('./output/" <> Purs.unModuleName moduleName <> "').main()\" " <> args

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.