Skip to content

Commit

Permalink
Merge pull request #166 from ocsigen/v2
Browse files Browse the repository at this point in the history
v2
  • Loading branch information
cannorin authored Jul 13, 2023
2 parents 3f169c9 + 9eb39cb commit 9d51cc4
Show file tree
Hide file tree
Showing 37 changed files with 5,280 additions and 3,041 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: bash 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 & test & publish the project
run: bash fake all

- name: Push js_of_ocaml standard library to jsoo-stdlib
if: success()
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.0-alpha.0]
- Upgrade TypeScript to v5.
- Added an explicit support of ambient modules.
- Topological sorting inside ambient modules now works as expected (#157).
- Perform various improvements over messages.
- Messages now come with color (warning: yellow, error: red).
- The error location is now shown with a code frame.
- Deprecate the `--safe-arity` option.
- Ts2ocaml now generates minimal arity-safe output by default.
- Perform massive internal refactoring.

## [1.4.6] - 2023-07-13
- Fix a bug which generated unnecessarily duplicated option type (#315).

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 ()
18 changes: 13 additions & 5 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 @@ -132,7 +131,7 @@ module Test =
"safe", !! "node_modules/@types/yargs-parser/index.d.ts", [];
"safe", !! "node_modules/@types/yargs/index.d.ts", ["--rec-module=off"];

"minimal", !! "node_modules/@types/vscode/index.d.ts", ["--safe-arity=full"; "--readable-names"];
"minimal", !! "node_modules/@types/vscode/index.d.ts", ["--readable-names"];
]

for preset, package, additionalOptions in packages do
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>
2 changes: 1 addition & 1 deletion dist_jsoo/dune-project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(lang dune 3.0)
(name ts2ocaml-jsoo-stdlib)
(version 1.4.6)
(version 2.0.0-alpha.0)

(maintainers "[email protected]")
(authors
Expand Down
2 changes: 1 addition & 1 deletion dist_jsoo/ts2ocaml-jsoo-stdlib.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "1.4.6"
version: "2.0.0-alpha.0"
synopsis:
"Standard library for ts2ocaml generated bindings (js_of_ocaml target)"
description:
Expand Down
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
Loading

0 comments on commit 9d51cc4

Please sign in to comment.