Wai development server and cabal sandbox - haskell

I'm writing a small Scotty app and have decided after using yesod that I cannot live without wai-handler-devel to live-reload code for me. I'm using cabal sandbox like a good little boy, but every time I run my development executable (through cabal run), I get the error Could not find module Web.Scotty. However, when I build the application executable (not the development executable), it all runs fine.
The two executables have identical dependencies in the cabal file. The app executable has a main that uses wai's run handler, while the development executable uses runQuit from wai-handler-devel.
I assume this is a sandboxing issue, because the usual setup seems to be to use runhaskell to execute the development server script - but since my application is sandboxed, it doesn't even find the DevelServer import.

Related

How can I create a Rust Clippy binary to use as part of a separate standalone application?

I am trying to build a standalone application through which I can run Rust Clippy without needing to install it locally. Essentially, I want to run a command like cargo-clippy -- --message-format=json through my application when a Rust project is uploaded to it.
What I've tried:
I installed cargo locally using the instructions here
I forked the Clippy repo locally into a folder called clippy_local
I ran cargo build on the repo which created some exe binary files including cargo-clippy under clippy_local/target/debug/ (contents of the target folder attached in screenshot below)
I copied this cargo-clippy exe into the tool binaries folder for my application
After this, the project compiles, but when I try to run Clippy through my tool, I get an error like below:
dyld[14510]: Library not loaded: '#rpath/librustc_driver-6ca1b5240144bf0b.dylib'
Referenced from: '/Users/<redacted>/repos/<redacted>/target/webapp/WEB-INF/classes/tools/clippy/cargo-clippy'
Reason: tried: '/usr/local/lib/librustc_driver-6ca1b5240144bf0b.dylib' (no such file), '/usr/lib/librustc_driver-6ca1b5240144bf0b.dylib' (no such file)
My app is running the following command internally to invoke Clippy:
/Users/<redacted>/repos/<redacted>/target/webapp/WEB-INF/classes/tools/clippy/cargo-clippy -- --message-format=json
I was guessing from the error that it has something to do with missing libraries/dependencies (apart from the cargo-clippy exe). I have tried to copy all the contents of the target/debug folder into my app as well, but the same error still persists.
So, I want to know what's going wrong and how I can build a Rust Clippy binary which I can then use to run Clippy from other applications?

How to make a Nodejs distributable command line application

I'm making a command line application with commander, inquirer and nightwatch as top dependencies. The main purpose of the app is for automation and testing.. Is there any way i can make this distributable instead of publishing it as npm package. I want the same functionality as those cli made with python, where it can be setup, and run on a target machine. is this possible? Thank you
Here are two open source projects (PKG and Nexe) that enable you to package your Node.js project into an executable:
https://github.com/zeit/pkg/blob/master/README.md
Or
https://github.com/nexe/nexe/blob/dev/README.md
You can use either one to make an executable of your project.

how to build keter bundle for yesod web app that is one package of many in a stack build

I have a project that contains several packages that are specified in one stack.yaml file. One of these packages is the yesod application. It depends on the other packages. stack build handles dependencies nicely, but how do I build the keter bundle for the web app?
When I do stack exec -- yesod keter from inside the app package, it does happily re-compile all of the other packages (starts by unregistering all, then configure, build, copy/register). That takes much too long.
In the top level directory, I don't see how to yesod keter so I can only create the keter bundle manually (by calling tar cvfz ...)
This does not feel right because I have to provide redundant information (e.g., location of the executable needs to be listed in keter.yml, and is also needed as argument for tar), and I need to manually copy files (app/{config,static}/*)

How can I run a single test in my Yesod app?

Yesod provides the yesod test tool. A test is a value of type Spec which can be executed by hspec.
The scaffolding comes with a predefined spec in tests/HomeTest.hs which is explicitly called in tests/main.hs, the file that is apparently compiled and executed when you run yesod test. I assume you are supposed to manually add all your specs to main.hs as you create them, although perhaps there is a way to use hspec's automated test discovery.
This is great for regression testing, but what about test-driven development? What is the proper way to write a single test and then run it repeatedly during development? The help text for yesod test suggests that there is no way to do this:
$ yesod test --help
Usage: yesod test
Build and run the integration tests
Running a spec file directly doesn't work (and I suppose you wouldn't expect it to, since it doesn't contain a main definition):
$ runhaskell tests/HomeTest.hs
tests/HomeTest.hs:4:8:
Could not find module ‘TestImport’
Use -v to see a list of the files searched for.
$ cabal run tests/HomeTest.hs
cabal: Cannot build the executable 'myproject' because the component is marked as disabled in the .cabal file.
I'm not sure why my project's executable is disabled. Should I change that? Or should I create a temporary copy of main.hs and comment out all the other tests? What's the cleanest solution?

How to compile several Yesod projects quickly?

As far as I know to make new projects yosog and yosog2 I do the following
$ yesod init
$ cd yosog
yosog$ cabal sandbox init
yosog$ cabal install
$ yesod init
$ cd yosog2
yosog2$ cabal sandbox init
yosog2$ cabal install
But each cabal install takes forever. How am I suppose to make a bunch of Yesod projects if each takes forever to compile?
It sounds like what you're really trying to do is have multiple separate projects reuse the same cabal sandbox. You can do this by specifying a shared --sandbox option to the cabal sandbox command. Note, however, that by sharing a sandbox, you're giving up on some of the protection that sandboxes are intended to provide.
It is kind of unusual to run multiple projects Yesod at the same time. Each would need their own tcp port, and run a completely separate server. Two Yesod projects would usually indicate completely different websites that have nothing to do with each other.
You can put multiple handlers and routes in one single project, so if you have related web pages/APIs you would install them with a single command. If you have pieces that are truly modular and reusable, you could put those handlers in library packages, but the main project will still build and install under a single Yesod program.

Resources