My Elm build commands produce a versioned/checksummed JS file, which looks like main.[checksum].js
. How do I handle this with shake
(specifically, I can't figure out how to write the want
declaration for this, as the filename would change every time).
Asked
Active
Viewed 33 times
1

Saurabh Nanda
- 6,373
- 5
- 31
- 60
1 Answers
0
It's a little fiddly to model, but an intermediate file works well. When generating main.[checksum].js
you also generate main.txt
which contains the checksum within it. Depending looks like:
wantElm x = do
src <- readFile' (x </> "main.txt)
want [src]
And generating looks like:
generateElm = do
"**/main.txt" %> \out -> do
Stdout hash <- cmd "elm build" out
writeFile' out hash
That assumes Elm tells you the hash on stdout, but easily adapts to however you do find the hash.

Neil Mitchell
- 9,090
- 1
- 27
- 85
-
I'm still stuck wit this one (and the scope of the original question has expanded). Here's what I'm trying to do: If my `elm-src//*` folder has changed, it should trigger N elm builds to produce N checksummed JS files. However, these N builds **must be run serially** (irrespective of `shakeThreads`) due to a subtle bug in the Elm compiler. – Saurabh Nanda Jun 05 '20 at 06:43
-
I've gotten the following to work - https://gist.github.com/saurabhnanda/835b359f7996a9459ac9101c1d087f4f - but it's very brittle. It does not re-run if the checksummed file is deleted from the `dist` folder, because shake doesn't know about its existence. – Saurabh Nanda Jun 05 '20 at 06:51
-
To avoid running serially, use Resources in Shake. I'd still go for a pattern where each rule is a separate rule, more like the answer above than like the gist you linked to. – Neil Mitchell Jun 06 '20 at 15:23