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

Simple fs -> js solution? #1369

Closed
matthid opened this issue Mar 19, 2018 · 6 comments
Closed

Simple fs -> js solution? #1369

matthid opened this issue Mar 19, 2018 · 6 comments

Comments

@matthid
Copy link
Contributor

matthid commented Mar 19, 2018

Description

Recently I wrote some VSTS-Build-Tasks with typescript (https://github.com/matthid/Paket.TeamBuildCredentials/blob/master/SetPaketCredentialProvider.dev/setCredentialManager.ts). The primary reason to use typescript was that it was so easy to get started:

Basically npm install <> && tsc file.js is everything you need to do in order to get out of the "javascript misery".
The problem especially for build-tasks is that it feels like using fable is more overhead than just writing the task in javascript/typescript.

My question now is: Can we already do the same for fable and I just missed it? What is currently the most minimal way to write such a build task in f#?

Feel free to point me to some existing samples/documentation maybe I have just missed them.

@bilkusg
Copy link
Contributor

bilkusg commented Mar 21, 2018

I'm pretty sure there's nothing quite that simple - mainly because Fable needs both dotnet and javascript infrastructures working in tandem. I've written a summary of how to create a minimal fable application here - https://medium.com/@bilkusg/fable-f-why-and-how-14e4d3702593 which works with the latest templates which (once you've dealt with the prerequisites ), can turn a basic F# file into javascript in about 4 lines.

@alfonsogarciacaro
Copy link
Member

That's right, there are two things right now that make it a bit difficult to compile a single F# file to JS with zero-configuration:

  • Fable 1.x only accepts .fsproj files. Until Fable 0.7 it was common to use single .fsx files, but then we moved Fable dependencies to Nuget and the new .fsproj and/or Paket made it much easier to handle them, instead of adding manual references to the .dll on top of the .fsx file. I'm not sure what's the current status of Paket references in .fsx files and whether they could work with Fable or not.

  • As @bilkusg, Fable runs two processes: dotnet and node.js. It was like this from the beginning, but Fable 1.x made it explicit to make it easier to connect Fable with different JS tools (Webpack, Rollup...).

None of the points above is unsolvable: we could add .fsx support again, and also make a more opinionated CLI tool available that compiles F# to JS with a single command and no configuration. But this has not been a common scenario so far as it's usually easier to simply write JS or TS for simple scripts like the one you pointed out (in fact the file you linked is valid -modern- JS, you can just add the // @ts-check comment to get Typescript checking). Take also into account that JS/TS tooling are usually better in handling external dependencies though ts2fable is getting better and better.

However, if someone is interested in building such a tool I will gladly provide support and guidance for it :)

@TheAngryByrd
Copy link

So I started some proof of concept of trying to do this based of @ncave's repl.

node fantasy.js ../examples/hello.fsx
Getting Checker...
Parsing Project...
Loading compiler...
Compiling To Babel Json Ast...
Compiling to codeES2015
"use strict";

var _String = require("fable-core/String");

(0, _String.toConsole)((0, _String.printf)("%s"))("hello world");

Still needs lots of love though.

@alfonsogarciacaro
Copy link
Member

That's great @TheAngryByrd! Where's your POC?

@TheAngryByrd
Copy link

Had to give it a good cleaning before I showed it to anyone 😸

https://github.com/TheAngryByrd/fantasy

can try it with

./build.sh
cd dist && node fantasy ../examples/hello.fsx

@alfonsogarciacaro
Copy link
Member

fable-splitter 2.1 (currently in beta, so you need to install it with npm i fable-splitter@next fable-compiler@next but the stable version will be released soon) it's close to this. You can just do npx fable-splitter src -o build. Please check the README for more information.

Note that .fsx scripts are not supported at the moment because there's no standard solution yet to add package references, so for now it's easier to use .fsproj. But we can revisit it when .fsx can contain nuget/paket references and we get them resolved by the F# compiler or Dotnet.ProjInfo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants