Skip to content

Commit 9d51cc4

Browse files
authored
Merge pull request #166 from ocsigen/v2
v2
2 parents 3f169c9 + 9eb39cb commit 9d51cc4

37 files changed

+5280
-3041
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: bash 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 & test & publish the project
52+
run: bash fake all
5353

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

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.0.0-alpha.0]
10+
- Upgrade TypeScript to v5.
11+
- Added an explicit support of ambient modules.
12+
- Topological sorting inside ambient modules now works as expected (#157).
13+
- Perform various improvements over messages.
14+
- Messages now come with color (warning: yellow, error: red).
15+
- The error location is now shown with a code frame.
16+
- Deprecate the `--safe-arity` option.
17+
- Ts2ocaml now generates minimal arity-safe output by default.
18+
- Perform massive internal refactoring.
19+
920
## [1.4.6] - 2023-07-13
1021
- Fix a bug which generated unnecessarily duplicated option type (#315).
1122

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: 13 additions & 5 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

@@ -132,7 +131,7 @@ module Test =
132131
"safe", !! "node_modules/@types/yargs-parser/index.d.ts", [];
133132
"safe", !! "node_modules/@types/yargs/index.d.ts", ["--rec-module=off"];
134133

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

138137
for preset, package, additionalOptions in packages do
@@ -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>

dist_jsoo/dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(lang dune 3.0)
22
(name ts2ocaml-jsoo-stdlib)
3-
(version 1.4.6)
3+
(version 2.0.0-alpha.0)
44

55
(maintainers "[email protected]")
66
(authors

dist_jsoo/ts2ocaml-jsoo-stdlib.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is generated by dune, edit dune-project instead
22
opam-version: "2.0"
3-
version: "1.4.6"
3+
version: "2.0.0-alpha.0"
44
synopsis:
55
"Standard library for ts2ocaml generated bindings (js_of_ocaml target)"
66
description:

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

0 commit comments

Comments
 (0)