-
Notifications
You must be signed in to change notification settings - Fork 301
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
Fable as a library #3552
Comments
I have a difficult time seeing what would be the separations in term of features/API between the packages. I suppose for
Still need to find where the
I don't get that part, if you keep the project cracking inside of Things would be different when thinking of the MSBuild integration because I believe inside of MSBuild, we can have access to the restored dependencies etc. |
Project cracking would still need to be solved for the Vite plugin. However, there are situations where you want to go with a hardcoded or custom project. I'm thinking about some serverless function that would convert F# into Fable AST or JS. The compilation should not need to care where the input information came from. There are multiple ways of solving the project cracking. The MSBuild route would probably get all the information first-hand, so you don't want to take any dependency on what As for the Vite Plugin, I was actually thinking about trying the new MSBuild capabilities announced in dotnet 8 rc 2. It could be convenient to run a design-time build from the dotnet cli and capture all the arguments from there. Similar to how FCS works, you also need to provide the |
@nojaf Just FYI, the JS-only I'm not saying it's a prime solution, since the JS-version of Fable is 3x slower than the .NET one, it's just somewhat relevant to the conversation of project cracking and using Fable as a library. |
Oh, that is interesting. On the topic of project cracking, in dotnet 8 RC 2 you can do the following:
This dumps everything as JSON: {
"Items": {
"FscCommandLineArgs": [
{
"Identity": "-o:obj\\Debug\\net7.0\\telplin.dll",
"FullPath": "C:\\Users\\nojaf\\Projects\\telplin\\src\\Telplin\\-o:obj\\Debug\\net7.0\\telplin.dll",
"RootDir": "C:\\",
"Filename": "telplin",
"Extension": ".dll",
"RelativeDir": "-o:obj\\Debug\\net7.0\\",
"Directory": "Users\\nojaf\\Projects\\telplin\\src\\Telplin\\-o:obj\\Debug\\net7.0\\",
"RecursiveDir": "",
"ModifiedTime": "",
"CreatedTime": "",
"AccessedTime": "",
"DefiningProjectFullPath": "C:\\Program Files\\dotnet\\sdk\\8.0.100-rc.2.23502.2\\FSharp\\Microsoft.FSharp.Targets",
"DefiningProjectDirectory": "C:\\Program Files\\dotnet\\sdk\\8.0.100-rc.2.23502.2\\FSharp\\",
"DefiningProjectName": "Microsoft.FSharp",
"DefiningProjectExtension": ".Targets"
},
{
"Identity": "-g",
"FullPath": "C:\\Users\\nojaf\\Projects\\telplin\\src\\Telplin\\-g",
"RootDir": "C:\\",
"Filename": "-g",
"Extension": "",
"RelativeDir": "",
"Directory": "Users\\nojaf\\Projects\\telplin\\src\\Telplin\\",
"RecursiveDir": "",
"ModifiedTime": "",
"CreatedTime": "",
"AccessedTime": "",
"DefiningProjectFullPath": "C:\\Program Files\\dotnet\\sdk\\8.0.100-rc.2.23502.2\\FSharp\\Microsoft.FSharp.Targets",
"DefiningProjectDirectory": "C:\\Program Files\\dotnet\\sdk\\8.0.100-rc.2.23502.2\\FSharp\\",
"DefiningProjectName": "Microsoft.FSharp",
"DefiningProjectExtension": ".Targets"
},
{
"Identity": "--debug:embedded",
"FullPath": "C:\\Users\\nojaf\\Projects\\telplin\\src\\Telplin\\--debug:embedded",
"RootDir": "C:\\",
"Filename": "--debug:embedded",
"Extension": "",
"RelativeDir": "",
"Directory": "Users\\nojaf\\Projects\\telplin\\src\\Telplin\\",
"RecursiveDir": "",
"ModifiedTime": "",
"CreatedTime": "",
"AccessedTime": "",
"DefiningProjectFullPath": "C:\\Program Files\\dotnet\\sdk\\8.0.100-rc.2.23502.2\\FSharp\\Microsoft.FSharp.Targets",
"DefiningProjectDirectory": "C:\\Program Files\\dotnet\\sdk\\8.0.100-rc.2.23502.2\\FSharp\\",
"DefiningProjectName": "Microsoft.FSharp",
"DefiningProjectExtension": ".Targets"
},
...
] That is another reason I want to de-couple project cracking from Fable compilation. |
@nojaf Yes, parsing projects with Regex works, but obviously only for simple F# projects (non-conditional, no multi-target, no pre/post build steps, etc.), unless you want to reimplement most of MSBuild machinery. The Fable CLI already has a robust project cracking using Buildalyzer, so why not use the Fable CLI as a library, just expose what additional API you need. Although if now MSBuild can export all we need as JSON, perhaps that's a good option too. |
This could remove the trick we do with creating a Does this means that the user needs to use .NET 8? What if the user has a |
I agree this was probably more robust than Anyway, my main ask is to extract core bits of |
Here is a summary of our discussion @nojaf @jwosty Please feel free to complete or correct me We want to continue the exploration of introducing "Fable as a library". Goals:
|
To also elaborate a bit more on my end-game for this: I basically see Fable as an alternative to TypeScript or Elm. When you create a front-end application these days, you would strongly consider Vite given its popularity. When using Vite TS works out of the box and Elm uses a plugin. In both cases, you start Vite. Currently, with Fable, you are forced to start To make this Vite plugin, I would like to spawn some dotnet process and talk to it from the JavaScript side. To pull this off, I want to carve out the basics that I'm after. I need a way to tell Fable to compile a single file and give the result in memory. And of course, I need to be able to do this over and over again as that dotnet process will live as long as Vite is running. Disclaimer: This sounds a bit ambitious and so far I have no evidence this will work out or even be efficient. All I have is a hunch right now and I'm scratching my own itch. You should really see this as an experiment and nothing more. On the flip side, if you are interested in this, do please reach out, I would love to collaborate with others on this! |
I believe ncave/fsharp#14 could be beneficial to tackle this case. |
@nojaf net6.0 would be fine for the SDK. In terms of naming, may I suggest simply Fable.Compiler or Fable.API |
Personally, I think Like that you have:
And I believe each name is self explanatory. I don't think the |
Description
It is related to #3549.
Could we compile F# code using Fable in a library scenario?
Similar to how FCS works today. The things I would be most interested in are getting Fable AST and compiling JS programmatically.
I envision this would be a carve-out of what
Fable.Cli
does today.Things like project cracking, the file watcher and writing files to disk should remain in
Fable.Cli
.The text was updated successfully, but these errors were encountered: