Skip to content

Commit

Permalink
Update TypeScript to 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cannorin committed Jul 13, 2023
1 parent ac55e8f commit 6733a6a
Show file tree
Hide file tree
Showing 16 changed files with 2,548 additions and 1,791 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ jobs:
- name: Install OCaml Dependencies
run: opam install . --deps-only

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

auto-merge:
name: Auto-Merge PRs by Dependabot
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
- name: Install OCaml Dependencies
run: opam install . --deps-only

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

- name: Push js_of_ocaml standard library to jsoo-stdlib
if: success()
Expand Down
34 changes: 34 additions & 0 deletions build/BindingUpdater.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module BindingUpdater

open Fake.Core
open Fake.IO
open System.Text.RegularExpressions

let commonOptions = "--noresizearray --convertpropfns --tagged-union --remove-obsolete"
let ts2fable (srcs: string list) (dest: string) =
let src = srcs |> String.concat " "
Shell.Exec(
"yarn",
$"ts2fable {src} {dest} {commonOptions}"
)

let typeParamConstraints =
new Regex("""when '\w+ :> \w+(?: and '\w+ :> \w+)*""", RegexOptions.Compiled)

let erasedCast =
new Regex("""static member inline op_ErasedCast.+$""", RegexOptions.Compiled ||| RegexOptions.Multiline)

let replace (regex: Regex) (replacement: string) (s: string) =
printfn $"{regex.ToString()} ==> {replacement}"
regex.Replace(s, replacement)

let typescript () =
let dest = "lib/Bindings/TypeScript.fs"
ts2fable ["node_modules/typescript/lib/typescript.d.ts"] dest |> ignore
File.readAsString dest
|> replace typeParamConstraints ""
|> replace erasedCast "// $&"
|> File.writeString false dest

let run () =
typescript ()
16 changes: 12 additions & 4 deletions build.fs → build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ let setup () =

Target.create "Restore" <| fun _ ->
DotNet.restore
(DotNet.Options.withWorkingDirectory __SOURCE_DIRECTORY__)
id
"ts2ocaml.sln"

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

Target.create "Prepare" ignore

Expand Down Expand Up @@ -234,9 +233,17 @@ module Publish =

"Build" ?=> "Test" ?=> "Publish"

// Utility targets

module Utility =
let setup () =
Target.create "UpdateBindings" <| fun _ -> BindingUpdater.run ()
"Prepare" ==> "UpdateBindings"

[<EntryPoint>]
let main argv =
Shell.cd __SOURCE_DIRECTORY__
// ensure working at the repository root
Shell.cd (Path.combine __SOURCE_DIRECTORY__ "..")

argv
|> Array.toList
Expand All @@ -247,6 +254,7 @@ let main argv =
setup ()
Test.setup ()
Publish.setup ()
Utility.setup ()

Target.create "All" ignore
"Prepare"
Expand Down
25 changes: 11 additions & 14 deletions build.fsproj → build/build.fsproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="build.fs" />
</ItemGroup>

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="BindingUpdater.fs" />
<Compile Include="build.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fake.Core.Process" Version="6.0.0" />
<PackageReference Include="Fake.Core.ReleaseNotes" Version="6.0.0" />
Expand All @@ -18,6 +16,5 @@
<PackageReference Include="Fake.IO.FileSystem" Version="6.0.0" />
<PackageReference Include="Fake.JavaScript.Yarn" Version="6.0.0" />
<PackageReference Include="Fake.Tools.Git" Version="6.0.0" />
</ItemGroup>

</Project>
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Modules with **\[\<AutoOpen\>\]** does not require `open` to use.

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

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

## Debugging

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

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

## Building

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

## Testing

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

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

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

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

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

Expand Down
13 changes: 13 additions & 0 deletions fake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

echo "Restoring dotnet tools..."
dotnet tool restore

if [ -z "$@"]; then
FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj
else
FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@"
fi
4 changes: 4 additions & 0 deletions fake.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo Restoring dotnet tools...
dotnet tool restore

dotnet run --project ./build/build.fsproj -- -t %*
Loading

0 comments on commit 6733a6a

Please sign in to comment.