Skip to content

Commit 6733a6a

Browse files
committed
Update TypeScript to 5.1
1 parent ac55e8f commit 6733a6a

File tree

16 files changed

+2548
-1791
lines changed

16 files changed

+2548
-1791
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ jobs:
5555
- name: Install OCaml Dependencies
5656
run: opam install . --deps-only
5757

58-
- name: Run build.fs
59-
run: dotnet run target Test
58+
- name: Build and test the project
59+
run: ./fake test
6060

6161
auto-merge:
6262
name: Auto-Merge PRs by Dependabot

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ jobs:
4848
- name: Install OCaml Dependencies
4949
run: opam install . --deps-only
5050

51-
- name: Run build.fs
52-
run: dotnet run target All
51+
- name: Build the project
52+
run: ./fake
5353

5454
- name: Push js_of_ocaml standard library to jsoo-stdlib
5555
if: success()

build/BindingUpdater.fs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module BindingUpdater
2+
3+
open Fake.Core
4+
open Fake.IO
5+
open System.Text.RegularExpressions
6+
7+
let commonOptions = "--noresizearray --convertpropfns --tagged-union --remove-obsolete"
8+
let ts2fable (srcs: string list) (dest: string) =
9+
let src = srcs |> String.concat " "
10+
Shell.Exec(
11+
"yarn",
12+
$"ts2fable {src} {dest} {commonOptions}"
13+
)
14+
15+
let typeParamConstraints =
16+
new Regex("""when '\w+ :> \w+(?: and '\w+ :> \w+)*""", RegexOptions.Compiled)
17+
18+
let erasedCast =
19+
new Regex("""static member inline op_ErasedCast.+$""", RegexOptions.Compiled ||| RegexOptions.Multiline)
20+
21+
let replace (regex: Regex) (replacement: string) (s: string) =
22+
printfn $"{regex.ToString()} ==> {replacement}"
23+
regex.Replace(s, replacement)
24+
25+
let typescript () =
26+
let dest = "lib/Bindings/TypeScript.fs"
27+
ts2fable ["node_modules/typescript/lib/typescript.d.ts"] dest |> ignore
28+
File.readAsString dest
29+
|> replace typeParamConstraints ""
30+
|> replace erasedCast "// $&"
31+
|> File.writeString false dest
32+
33+
let run () =
34+
typescript ()

build.fs renamed to build/build.fs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ let setup () =
5555

5656
Target.create "Restore" <| fun _ ->
5757
DotNet.restore
58-
(DotNet.Options.withWorkingDirectory __SOURCE_DIRECTORY__)
58+
id
5959
"ts2ocaml.sln"
6060

6161
Target.create "YarnInstall" <| fun _ ->
62-
Yarn.installFrozenLockFile (fun ``params`` ->
63-
{ ``params`` with WorkingDirectory = "./" })
62+
Yarn.installFrozenLockFile id
6463

6564
Target.create "Prepare" ignore
6665

@@ -234,9 +233,17 @@ module Publish =
234233

235234
"Build" ?=> "Test" ?=> "Publish"
236235

236+
// Utility targets
237+
238+
module Utility =
239+
let setup () =
240+
Target.create "UpdateBindings" <| fun _ -> BindingUpdater.run ()
241+
"Prepare" ==> "UpdateBindings"
242+
237243
[<EntryPoint>]
238244
let main argv =
239-
Shell.cd __SOURCE_DIRECTORY__
245+
// ensure working at the repository root
246+
Shell.cd (Path.combine __SOURCE_DIRECTORY__ "..")
240247

241248
argv
242249
|> Array.toList
@@ -247,6 +254,7 @@ let main argv =
247254
setup ()
248255
Test.setup ()
249256
Publish.setup ()
257+
Utility.setup ()
250258

251259
Target.create "All" ignore
252260
"Prepare"
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
6-
</PropertyGroup>
7-
8-
<ItemGroup>
9-
<Compile Include="build.fs" />
10-
</ItemGroup>
11-
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="BindingUpdater.fs" />
8+
<Compile Include="build.fs" />
9+
</ItemGroup>
1210
<ItemGroup>
1311
<PackageReference Include="Fake.Core.Process" Version="6.0.0" />
1412
<PackageReference Include="Fake.Core.ReleaseNotes" Version="6.0.0" />
@@ -18,6 +16,5 @@
1816
<PackageReference Include="Fake.IO.FileSystem" Version="6.0.0" />
1917
<PackageReference Include="Fake.JavaScript.Yarn" Version="6.0.0" />
2018
<PackageReference Include="Fake.Tools.Git" Version="6.0.0" />
21-
</ItemGroup>
22-
23-
</Project>
19+
</ItemGroup>
20+
</Project>

docs/development.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Modules with **\[\<AutoOpen\>\]** does not require `open` to use.
4242

4343
- [.NET SDK 6.0](https://dotnet.microsoft.com/download/dotnet/6.0)
4444
- [Fable](https://fable.io/) is required to build this tool.
45-
- Run `dotnet tool restore` in the root directory of this repo to install them.
45+
- Run `dotnet tool restore` in the root directory of this repo to install it.
4646

4747
- OCaml 4.08 or higher
4848
- [js_of_ocaml](https://github.com/ocsigen/js_of_ocaml) should be installed to your opam switch.
@@ -54,13 +54,13 @@ Modules with **\[\<AutoOpen\>\]** does not require `open` to use.
5454

5555
## Debugging
5656

57-
`dotnet run -t Watch` to live update `dist/ts2ocaml.js`.
57+
`./fake watch` to live update `dist/ts2ocaml.js`.
5858

5959
It will be bundled by Webpack with the `development` mode.
6060

6161
## Building
6262

63-
`dotnet run -t Build` performs the followings:
63+
`./fake build` performs the followings:
6464
- `yarn install` to populate `node_modules`
6565
- `dotnet restore ts2ocaml.sln` to install required F# libraries
6666
- Compile F# source files into JS source files (through Fable)
@@ -70,7 +70,7 @@ The resulting `dist/ts2ocaml.js` is then ready to run through `node`.
7070

7171
## Testing
7272

73-
`dotnet run -t Test` builds the tool and then performs the followings:
73+
`./fake test` builds the tool and then performs the followings:
7474

7575
### Test the tool for [`js_of_ocaml` target](js_of_ocaml.md)
7676

@@ -92,7 +92,7 @@ The resulting `dist/ts2ocaml.js` is then ready to run through `node`.
9292
9393
## Publishing
9494

95-
`dotnet run -t Publish` builds the tool, runs the tests, and then performs the followings:
95+
`./fake publish` builds the tool, runs the tests, and then performs the followings:
9696

9797
### Prepare for publishing the standard library for [`js_of_ocaml` target](js_of_ocaml.md) to the `jsoo-stdlib` branch
9898

fake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
echo "Restoring dotnet tools..."
7+
dotnet tool restore
8+
9+
if [ -z "$@"]; then
10+
FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj
11+
else
12+
FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@"
13+
fi

fake.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo Restoring dotnet tools...
2+
dotnet tool restore
3+
4+
dotnet run --project ./build/build.fsproj -- -t %*

0 commit comments

Comments
 (0)