Skip to content

Commit

Permalink
Merge pull request #32 from ocsigen/rescript-support
Browse files Browse the repository at this point in the history
ReScript support
  • Loading branch information
cannorin authored Feb 27, 2024
2 parents deafbdf + c81af8c commit a4a48b3
Show file tree
Hide file tree
Showing 45 changed files with 5,053 additions and 275 deletions.
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.
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

0 comments on commit a4a48b3

Please sign in to comment.