Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReScript support #32

Merged
merged 57 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e7c28e4
Initial commit for ReScript support
cannorin Nov 9, 2021
bcfa7ce
Scaffolding, add minimal stdlib
cannorin Nov 9, 2021
157dcfd
Merge main
cannorin Jan 21, 2022
5c699fc
Allow arbitrary type for name of poly variant
cannorin Jan 21, 2022
43d4ec6
Rewrite stdlib
cannorin Feb 15, 2022
17773fe
More helpers
cannorin Feb 15, 2022
9cab6e6
Add type emitter
cannorin Feb 21, 2022
ba4d353
[WIP] emit members
cannorin Feb 24, 2022
7849bc1
Emit members, load rescript/lib/ocaml/dom.ml
cannorin Feb 25, 2022
459957a
Better stdlib
cannorin Feb 25, 2022
f227848
Embed stdlib
cannorin Feb 25, 2022
50b3731
Emit StructuredText
cannorin Feb 28, 2022
f2842ad
Lock the package version of ReScript
smorimoto Feb 28, 2022
410b1f9
Emit enum definition
cannorin Mar 1, 2022
eca3350
Emit StructuredText
cannorin Mar 2, 2022
f8dc729
Implement ReScript target
cannorin Mar 7, 2022
27e0543
[WIP] try to generate compilable stdlib
cannorin Mar 9, 2022
8bcbd32
[WIP] try to generate compilable stdlib (2)
cannorin Mar 9, 2022
e397f45
Make typescript.res/resi compilable
cannorin Mar 18, 2022
fc203b1
Make stdlib compilable
cannorin Mar 23, 2022
e54cb12
Add all inherited members to class
cannorin Mar 23, 2022
3e27d07
Implement emitExportModule
cannorin Mar 30, 2022
33b0dd9
Fix a bug when emitting exports for enum types
cannorin Apr 5, 2022
eca05e4
Update yarn.lock
cannorin May 9, 2022
800ad35
Rebase to v2
cannorin May 26, 2022
bb60b80
Upgrade to rescript 10.0
cannorin Aug 29, 2022
682595b
Make it compile
cannorin Aug 29, 2022
2676402
Add rescript compile test
cannorin Aug 29, 2022
d36fb01
Split CI
cannorin Aug 29, 2022
53061b8
Fix property parsing (for res)
cannorin Aug 30, 2022
de4a2f7
Improve QoL (1)
cannorin Aug 30, 2022
6d54734
Improve QoL (2)
cannorin Sep 1, 2022
a6f6124
Smart safe arity
cannorin Sep 2, 2022
01eefd1
Reintroduce SCC sorting
cannorin Sep 15, 2022
77b664c
Mark recursive modules in DependencyTrie
cannorin Oct 3, 2022
d914cf2
Separate TypeDefText and TypeAliasText
cannorin Oct 13, 2022
2ec5158
Add DependencyTrie.isLinear
cannorin Oct 13, 2022
6ba4e7b
Fix fable build
cannorin Nov 8, 2022
60ae343
Remove unwanted extends clauses
cannorin Nov 8, 2022
c69a582
Fix getKnownTypes
cannorin Nov 9, 2022
fe0623c
Do not use Types module if linear
cannorin Nov 9, 2022
f8aeb9f
Add --no-types-module option
cannorin Nov 9, 2022
1d5b70f
Proper union type optimization
cannorin Nov 14, 2022
759108b
Proper union type optimization (2)
cannorin Nov 14, 2022
1cc321a
Rebase to main
cannorin Jul 17, 2023
5c86226
Upgrade ReScript to v11 beta
cannorin Jul 17, 2023
ca305ea
Adopt ReScript v11 enum representation
cannorin Jul 17, 2023
e4213e6
Emit unboxed variant if appropriate
cannorin Sep 3, 2023
872f277
Merge branch 'main' into rescript-support
cannorin Jan 30, 2024
2e7116c
Update ReScript to v11.0.1
cannorin Jan 30, 2024
ea996cf
Update ReScript to v11 in dist/res and test/res
cannorin Jan 30, 2024
ba4db66
Use uncurried mode
cannorin Jan 31, 2024
05c11a1
Do not generated duplicate types for union with enum type
cannorin Jan 31, 2024
6c0a164
Emit comments except for recursive modules
cannorin Feb 1, 2024
72d0193
Add docs for ReScript
cannorin Feb 26, 2024
956b3ed
Implement --experimental-tagged-union
cannorin Feb 27, 2024
c81af8c
Edit docs/development.md
cannorin Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: CI

on:
push:
branches: [main]
branches: [main,v2]
pull_request:
branches: [main]
branches: [main,v2]
workflow_dispatch:

jobs:
build:
build-jsoo:
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -56,12 +56,49 @@ jobs:
run: opam install . --deps-only

- name: Build and test the project
run: bash fake test
run: bash fake TestJsoo

build-res:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
dotnet:
- 6.0.x
node-version:
- 20.x

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use .NET ${{ matrix.dotnet }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet }}

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: yarn

- name: Install .NET Dependencies
run: |
dotnet restore
dotnet tool restore

- name: Run FAKE
run: bash fake TestRes

auto-merge:
name: Auto-Merge PRs by Dependabot
needs:
- build
- build-jsoo
- build-res
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
env:
REPO: self
BRANCH: jsoo-stdlib
FOLDER: dist_jsoo
FOLDER: dist/jsoo
TAG: jsoo-stdlib-${{ github.event.release.tag_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: "Build ({sha}) {msg}"
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,5 @@ test/jsoo/src/*.mli
test/jsoo/src/stub.js

# Dist artifacts
dist
dist_jsoo/src/ts2ocaml_*.ml*
dist/js/
dist/jsoo/src/ts2ocaml_*.ml*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ An in-browser version may be available in future.
For users:
- [Common options](docs/common_options.md) among all the targets
- [ts2ocaml for js_of_ocaml](docs/js_of_ocaml.md)
- ts2ocaml for ReScript [(ongoing)](https://github.com/ocsigen/ts2ocaml/pull/32)
- [ts2ocaml for ReScript](docs/rescript.md)

For developers and contributors:
- [Overview for developers](docs/development.md)
Expand Down
114 changes: 84 additions & 30 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ let run cmd dir args =
failwithf "Error while running '%s' with args: %s " cmd args

let platformTool tool =
ProcessUtils.tryFindFileOnPath tool
|> function Some t -> t | _ -> failwithf "%s not found" tool
lazy
ProcessUtils.tryFindFileOnPath tool
|> function Some t -> t | _ -> failwithf "%s not found" tool

let dotnetExec cmd args =
let result = DotNet.exec id cmd args
if not result.OK then
failwithf "Error while running 'dotnet %s %s'" cmd args

let opamTool = platformTool "opam"
let opam args = run opamTool "./" args
let dune args = run opamTool "./" (sprintf "exec -- dune %s" args)
let opam args = run opamTool.Value "./" args
let dune args = run opamTool.Value "./" (sprintf "exec -- dune %s" args)

// Build targets

let setup () =
Target.create "Clean" <| fun _ ->
!! "src/bin"
++ "src/obj"
++ distDir
++ (distDir </> "js") // clean ts2ocaml.js
++ "src/.fable"
|> Seq.iter Shell.cleanDir

Expand Down Expand Up @@ -74,24 +75,27 @@ let setup () =
Target.create "Watch" <| fun _ ->
dotnetExec "fable" $"watch {srcDir} --sourceMaps --define DEBUG --run webpack -w --mode=development"

Target.create "TestComplete" ignore
Target.create "Test" ignore

"Clean" ?=> "Build"
Target.create "Publish" ignore

"Clean"
?=> "YarnInstall"
"YarnInstall"
==> "Restore"
==> "Prepare"
?=> "Build"

"Prepare"
?=> "BuildForTest"
?=> "TestComplete"
?=> "BuildForPublish"
==> "BuildForTest"
==> "Build"

"Prepare"
?=> "Watch"
==> "BuildForPublish"

"Prepare"
==> "Watch"

"Clean"
?=> "BuildForTest" ?=> "Build" ?=> "Test"
?=> "BuildForPublish" ?=> "Publish"

// Test targets

Expand Down Expand Up @@ -145,6 +149,59 @@ module Test =
printfn "* copied to %s" file
inDirectory testDir <| fun () -> dune "build"

module Res =
let testDir = testDir </> "res"
let outputDir = outputDir </> "test_res"
let srcDir = testDir </> "src"
let srcGeneratedDir = srcDir </> "generated"

let clean () =
!! $"{outputDir}/*"
++ $"{srcGeneratedDir}/*.res"
++ $"{srcGeneratedDir}/*.resi"
++ $"{srcGeneratedDir}/*.bs.js"
|> Seq.iter Shell.rm

let generateBindings () =
Directory.create outputDir

let ts2res args files =
Yarn.exec (sprintf "ts2ocaml res %s" (String.concat " " (Seq.append args files))) id

ts2res ["--create-stdlib"; $"-o {outputDir}"] []

let packages = [
// "full" package involving a lot of inheritance
"full", !! "node_modules/typescript/lib/typescript.d.ts", ["--experimental-tagged-union"];

// "full" packages involving a lot of dependencies (which includes some "safe" packages)
"safe", !! "node_modules/@types/scheduler/tracing.d.ts", [];
"full", !! "node_modules/csstype/index.d.ts", [];
"safe", !! "node_modules/@types/prop-types/index.d.ts", [];
"full", !! "node_modules/@types/react/index.d.ts" ++ "node_modules/@types/react/global.d.ts", ["--readable-names"];
"full", !! "node_modules/@types/react-modal/index.d.ts", ["--readable-names"];

// "safe" package which depends on another "safe" package
"safe", !! "node_modules/@types/yargs-parser/index.d.ts", [];
"safe", !! "node_modules/@types/yargs/index.d.ts", [];

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

for preset, package, additionalOptions in packages do
ts2res
(["--verbose"; "--nowarn"; "--follow-relative-references";
$"--preset {preset}"; $"-o {outputDir}"] @ additionalOptions)
package

let build () =
Shell.mkdir srcGeneratedDir
for file in outputDir |> Shell.copyRecursiveTo true srcGeneratedDir do
printfn "* copied to %s" file
inDirectory testDir <| fun () ->
Yarn.install id
Yarn.exec "rescript" id

let setup () =
Target.create "TestJsooClean" <| fun _ -> Jsoo.clean ()
Target.create "TestJsooGenerateBindings" <| fun _ -> Jsoo.generateBindings ()
Expand All @@ -156,13 +213,18 @@ module Test =
==> "TestJsooGenerateBindings"
==> "TestJsooBuild"
==> "TestJsoo"
==> "Test"

Target.create "Test" ignore
Target.create "TestOnly" ignore
Target.create "TestResClean" <| fun _ -> Res.clean ()
Target.create "TestResGenerateBindings" <| fun _ -> Res.generateBindings ()
Target.create "TestResBuild" <| fun _ -> Res.build ()
Target.create "TestRes" ignore

"TestJsoo"
==> "TestOnly"
==> "TestComplete"
"BuildForTest"
==> "TestResClean"
==> "TestResGenerateBindings"
==> "TestResBuild"
==> "TestRes"
==> "Test"

// Publish targets
Expand All @@ -177,7 +239,7 @@ module Publish =
Yarn.exec $"version --new-version {newVersion} --no-git-tag-version" id

module Jsoo =
let targetDir = "./dist_jsoo"
let targetDir = distDir </> "jsoo"
let duneProject = targetDir </> "dune-project"

let copyArtifacts () =
Expand All @@ -200,10 +262,10 @@ module Publish =
if result.Success then
let oldVersion = result.Groups.[1].Value
if oldVersion <> newVersion then
printfn $"* updating version in dist_jsoo/dune-project from '{oldVersion}' to '{newVersion}'."
printfn $"* updating version in dist/jsoo/dune-project from '{oldVersion}' to '{newVersion}'."
content |> String.replace result.Value $"(version {newVersion})"
else
printfn $"* version in dist_jsoo/dune-project not updated ('{newVersion}')."
printfn $"* version in dist/jsoo/dune-project not updated ('{newVersion}')."
content
else content
)
Expand All @@ -212,9 +274,6 @@ module Publish =
inDirectory targetDir <| fun () -> dune "build"

let setup () =
Target.create "Publish" <| fun _ -> ()
Target.create "PublishOnly" <| fun _ -> ()

Target.create "PublishNpm" <| fun _ ->
Npm.updateVersion ()

Expand All @@ -226,13 +285,8 @@ module Publish =
"BuildForPublish"
==> "PublishNpm"
==> "PublishJsoo"
==> "PublishOnly"
==> "Publish"

"TestJsoo" ==> "PublishJsoo"

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

// Utility targets

module Utility =
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions dist/res/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/node_modules/
/lib/
.bsb.lock
.merlin

*.bs.js
Demo.res
20 changes: 20 additions & 0 deletions dist/res/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "ts2ocaml-rescript-stdlib",
"version": "0.0.0",
"scripts": {
"build": "rescript",
"clean": "rescript clean -with-deps",
"start": "rescript build -w"
},
"keywords": [
"rescript"
],
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"rescript": "11.0.1"
},
"peerDependencies": {
"rescript": "^11.0.1"
}
}
18 changes: 18 additions & 0 deletions dist/res/rescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "ts2ocaml-rescript-stdlib",
"version": "0.0.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
],
"warnings": {
"error" : "+101"
}
}
Loading
Loading