purescript / spago

🍝 PureScript package manager and build tool
BSD 3-Clause "New" or "Revised" License
787 stars 132 forks source link

Reinstate `spago script` #1000

Open f-f opened 1 year ago

f-f commented 1 year ago

Still needs to be ported from the Haskell implementation, see here

JordanMartinez commented 1 year ago

This may require changes in node-execa first as I don't think it'll handle multi-line shebangs properly right now (or this might only be the case on Windows). See https://github.com/JordanMartinez/purescript-node-execa/blob/master/src/Node/Library/Execa/CrossSpawn.purs#L181-L188

f-f commented 9 months ago

This should now be unblocked?

JordanMartinez commented 9 months ago

Yes and no. For Linux/Mac, this is unblocked. For Windows, this is unblocked but may not work correctly in all cases. In node-execa (as noted above), we only read the first 150 bytes of a file. If there are multi-line shebangs that make up the entire command, we'll drop some of that on Windows.

f-f commented 9 months ago

Do we know why that 150? Is that just a number that is deemed "good enough" to read all the shebang lines?

JordanMartinez commented 9 months ago

Is that just a number that is deemed "good enough" to read all the shebang lines?

AFAICT, yes. That's what was in the original code. I can't recall whether there was a comment explaining why.

f-f commented 9 months ago

150 chars should be quite enough for the majority of cases, we can try shipping this and come back to bump it if we ever figure out it's not enough

JordanMartinez commented 9 months ago

It's your call.

f-f commented 9 months ago

Let's

fsoikin commented 1 month ago

A question/proposal: instead of (or in addition to) specifying package set and dependencies on the command line, how about supporting them via pragmas in the file itself? Haskell Stack does that to an extent, but I don't like the command-line syntax, I think F# does it much better.

And speaking of F#: it has another pragma #load that allows to have multi-module scripts, and could be trivially implemented in Spago - just copy all those #loaded files to the same temp dir.

f-f commented 1 month ago

I don't have a strong opinion on this, except for the fact that whatever we add in .purs files needs to be supported by the parser. E.g. when we introduced spago script for the Haskell implementation we had to patch the parser

fsoikin commented 1 month ago

Yes, of course, the pragmas would look like comments to the compiler.

The Haskell patch was for shebang lines, not the pragmas. Pragmas in Haskell files are also just comments, no patch would be needed for them.

And while I wasn't actually proposing to support shebangs as well, it can also be easily done: as long as we're copying the files to a different location anyway, we can just cut off the shebang lines along the way.