Skip to content

Commit 146254b

Browse files
author
Maxime Mangel
committed
Small improvements of the Fable library usage section
1 parent 69c1970 commit 146254b

File tree

2 files changed

+63
-18
lines changed

2 files changed

+63
-18
lines changed

docs/docs/your-fable-project/author-a-fable-library.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,39 @@ If your package is a library which targets JavaScript and Python you need to wri
105105
</PropertyGroup>
106106
```
107107

108+
## Native dependencies
109+
110+
When authoring a binding you often need your user to install a native dependency.
111+
112+
For example, if you create a binding for React, your user need to install `react` npm package.
113+
114+
[Femto](https://github.com/Zaid-Ajaj/Femto) is a tool that can help with that,
115+
but it needs some metadata in your `.fsproj` file.
116+
117+
Example:
118+
119+
For JavaScript/TypeScript packages via NPM:
120+
121+
```xml
122+
<PropertyGroup>
123+
<NpmDependencies>
124+
<NpmPackage Name="date-fns" Version="gt 1.30.0 lt 2.0.0" ResolutionStrategy="Max" />
125+
</NpmDependencies>
126+
</PropertyGroup>
127+
```
128+
129+
For Python packages via poetry:
130+
131+
```xml
132+
<PropertyGroup>
133+
<PythonDependencies>
134+
<Package Name="requests" Version="&gt;= 2.28.1 &lt; 3.0.0" ResolutionStrategy="Max" />
135+
</PythonDependencies>
136+
</PropertyGroup>
137+
```
138+
139+
Please refer to [Femto documentation](https://github.com/Zaid-Ajaj/Femto) for more information.
140+
108141
## Testing
109142

110143
It's a good idea to write unit tests for your library to make sure everything works as expected before publishing. The simplest way for that is to use a JS test runner like [Mocha](https://mochajs.org/), as in [this sample](https://github.com/fable-compiler/fable2-samples/tree/master/mocha). Or you can also use a library like [Fable.Mocha](https://github.com/Zaid-Ajaj/Fable.Mocha) containing more tools for Fable projects.

docs/docs/your-fable-project/use-a-fable-library.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Use a Fable library
33
layout: standard
44
---
55

6+
## Introduction
7+
68
We often use libraries using [NuGet](https://www.nuget.org/), which is the defacto .NET package manager.
79

810
So we do need libraries. And Fable proposes a great variety of libraries ready for you to use like:
@@ -19,38 +21,48 @@ There are 2 ways to call Fable libraries:
1921
1. Reference them directly in your project file
2022
2. Use [Paket](https://fsprojects.github.io/Paket/)
2123

22-
## Option 1: reference a library manually in your project file
24+
## Install a Fable library
25+
26+
Fable libraries are usually published on [Nuget](https://www.nuget.org/), which is the defacto .NET package manager.
2327

24-
Just like `.fs` files, we can reference libraries directly in the `.fsproj` file.
28+
You can use you favorite Nuget package manager to install them, like Nuget CLI, Paket, Visual Studio, Rider, etc.
2529

26-
We need to tell what library we need and what version we'd like to use. For instance for `Fable.Browser.Dom` version `1.0.0` we'll add the following node in the `.fsproj` file:
30+
Nuget CLI:
2731

28-
```xml
29-
<PackageReference Include="Fable.Browser.Dom" Version="1.0.0" />
32+
```bash
33+
dotnet add package <package name>
3034
```
3135

32-
Hence the standard format for a library:
36+
Paket:
3337

34-
```xml
35-
<PackageReference Include="[PACKAGE_ID]" Version="[PACKAGE_VERSION]" />
38+
```bash
39+
dotnet paket add <package name>
3640
```
3741

38-
The dotnet SDK offers a CLI command to do this operation without manually editing the .fsproj. Also if you omit the version number, it will automatically pick the most recent stable version for you. For instance:
42+
Please, refer to your Nuget package manager documentation to learn more about how to use it.
3943

40-
`dotnet add package Fable.Elmish.React [-v 3.0.1]`
44+
Depending on the type of library, it can happen that you also need to install a native dependency.
4145

42-
> Some IDEs like Visual Studio or Rider also include options in their Graphic Interface to manage Nuget packages.
46+
For example, if you are using a project that use React, you will need to install the `react` and `react-dom` from NPM packages.
4347

44-
That's basically all you need to do. The build process will then automatically download the libraries for you and compile your code against them.
48+
You need to refer to your library documentation to know if you need to install a native dependency.
4549

46-
> If you need to download the packages before the build (for example, to remove errors in the IDE), run the `dotnet restore` command in the folder containing the .fsproj file.
50+
### Femto
4751

48-
## Option 2: use Paket!
52+
[Femto](https://github.com/Zaid-Ajaj/Femto) is a tool that can help you install
53+
native dependencies if the library contains Femto metadata.
4954

50-
The second way of adding libraries is to use the [Paket](https://fsprojects.github.io/Paket/) library manager. While it's not compulsory, it's in most cases a good choice for large projects.
55+
Use `dotnet femto yourProject.fsproj` to check if your Fable dependencies
56+
requirements are met.
5157

52-
Using Paket is clearly straightforward if you follow the [official documentation](https://fsprojects.github.io/Paket/get-started.html).
58+
Use `dotnet femto --resolve yourProject.fsproj` to let Femto try to install
59+
the native dependencies for you.
5360

54-
But in order to make things easier for you, we created a [sample](https://github.com/fable-compiler/fable2-samples/tree/master/withpaket). This is a good companion while you read the paket doc.
61+
At the time of writing, Femto supports:
5562

56-
Usually getting started with Paket takes only a few minutes.
63+
- JavaScript/TypeScript
64+
- `npm` (default)
65+
- `yarn` when `yarn.lock` is found
66+
- `pnpm` when `pnpm-lock.yaml` is detected
67+
- Python
68+
- `poetry` when `pyproject.toml` is detected

0 commit comments

Comments
 (0)