Skip to content

Commit a4a48b3

Browse files
authored
Merge pull request #32 from ocsigen/rescript-support
ReScript support
2 parents deafbdf + c81af8c commit a4a48b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5053
-275
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: CI
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [main,v2]
66
pull_request:
7-
branches: [main]
7+
branches: [main,v2]
88
workflow_dispatch:
99

1010
jobs:
11-
build:
11+
build-jsoo:
1212
strategy:
1313
fail-fast: false
1414
matrix:
@@ -56,12 +56,49 @@ jobs:
5656
run: opam install . --deps-only
5757

5858
- name: Build and test the project
59-
run: bash fake test
59+
run: bash fake TestJsoo
60+
61+
build-res:
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
os:
66+
- ubuntu-latest
67+
dotnet:
68+
- 6.0.x
69+
node-version:
70+
- 20.x
71+
72+
runs-on: ${{ matrix.os }}
73+
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v2
77+
78+
- name: Use .NET ${{ matrix.dotnet }}
79+
uses: actions/setup-dotnet@v1
80+
with:
81+
dotnet-version: ${{ matrix.dotnet }}
82+
83+
- name: Use Node.js ${{ matrix.node-version }}
84+
uses: actions/setup-node@v2
85+
with:
86+
node-version: ${{ matrix.node-version }}
87+
cache: yarn
88+
89+
- name: Install .NET Dependencies
90+
run: |
91+
dotnet restore
92+
dotnet tool restore
93+
94+
- name: Run FAKE
95+
run: bash fake TestRes
6096

6197
auto-merge:
6298
name: Auto-Merge PRs by Dependabot
6399
needs:
64-
- build
100+
- build-jsoo
101+
- build-res
65102
runs-on: ubuntu-latest
66103
permissions:
67104
pull-requests: write

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
env:
5858
REPO: self
5959
BRANCH: jsoo-stdlib
60-
FOLDER: dist_jsoo
60+
FOLDER: dist/jsoo
6161
TAG: jsoo-stdlib-${{ github.event.release.tag_name }}
6262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6363
MESSAGE: "Build ({sha}) {msg}"

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,5 @@ test/jsoo/src/*.mli
307307
test/jsoo/src/stub.js
308308

309309
# Dist artifacts
310-
dist
311-
dist_jsoo/src/ts2ocaml_*.ml*
310+
dist/js/
311+
dist/jsoo/src/ts2ocaml_*.ml*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ An in-browser version may be available in future.
4545
For users:
4646
- [Common options](docs/common_options.md) among all the targets
4747
- [ts2ocaml for js_of_ocaml](docs/js_of_ocaml.md)
48-
- ts2ocaml for ReScript [(ongoing)](https://github.com/ocsigen/ts2ocaml/pull/32)
48+
- [ts2ocaml for ReScript](docs/rescript.md)
4949

5050
For developers and contributors:
5151
- [Overview for developers](docs/development.md)

build/build.fs

Lines changed: 84 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,26 @@ let run cmd dir args =
2727
failwithf "Error while running '%s' with args: %s " cmd args
2828

2929
let platformTool tool =
30-
ProcessUtils.tryFindFileOnPath tool
31-
|> function Some t -> t | _ -> failwithf "%s not found" tool
30+
lazy
31+
ProcessUtils.tryFindFileOnPath tool
32+
|> function Some t -> t | _ -> failwithf "%s not found" tool
3233

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

3839
let opamTool = platformTool "opam"
39-
let opam args = run opamTool "./" args
40-
let dune args = run opamTool "./" (sprintf "exec -- dune %s" args)
40+
let opam args = run opamTool.Value "./" args
41+
let dune args = run opamTool.Value "./" (sprintf "exec -- dune %s" args)
4142

4243
// Build targets
4344

4445
let setup () =
4546
Target.create "Clean" <| fun _ ->
4647
!! "src/bin"
4748
++ "src/obj"
48-
++ distDir
49+
++ (distDir </> "js") // clean ts2ocaml.js
4950
++ "src/.fable"
5051
|> Seq.iter Shell.cleanDir
5152

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

77-
Target.create "TestComplete" ignore
78+
Target.create "Test" ignore
7879

79-
"Clean" ?=> "Build"
80+
Target.create "Publish" ignore
8081

81-
"Clean"
82-
?=> "YarnInstall"
82+
"YarnInstall"
8383
==> "Restore"
8484
==> "Prepare"
85-
?=> "Build"
8685

8786
"Prepare"
88-
?=> "BuildForTest"
89-
?=> "TestComplete"
90-
?=> "BuildForPublish"
87+
==> "BuildForTest"
9188
==> "Build"
9289

9390
"Prepare"
94-
?=> "Watch"
91+
==> "BuildForPublish"
92+
93+
"Prepare"
94+
==> "Watch"
95+
96+
"Clean"
97+
?=> "BuildForTest" ?=> "Build" ?=> "Test"
98+
?=> "BuildForPublish" ?=> "Publish"
9599

96100
// Test targets
97101

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

152+
module Res =
153+
let testDir = testDir </> "res"
154+
let outputDir = outputDir </> "test_res"
155+
let srcDir = testDir </> "src"
156+
let srcGeneratedDir = srcDir </> "generated"
157+
158+
let clean () =
159+
!! $"{outputDir}/*"
160+
++ $"{srcGeneratedDir}/*.res"
161+
++ $"{srcGeneratedDir}/*.resi"
162+
++ $"{srcGeneratedDir}/*.bs.js"
163+
|> Seq.iter Shell.rm
164+
165+
let generateBindings () =
166+
Directory.create outputDir
167+
168+
let ts2res args files =
169+
Yarn.exec (sprintf "ts2ocaml res %s" (String.concat " " (Seq.append args files))) id
170+
171+
ts2res ["--create-stdlib"; $"-o {outputDir}"] []
172+
173+
let packages = [
174+
// "full" package involving a lot of inheritance
175+
"full", !! "node_modules/typescript/lib/typescript.d.ts", ["--experimental-tagged-union"];
176+
177+
// "full" packages involving a lot of dependencies (which includes some "safe" packages)
178+
"safe", !! "node_modules/@types/scheduler/tracing.d.ts", [];
179+
"full", !! "node_modules/csstype/index.d.ts", [];
180+
"safe", !! "node_modules/@types/prop-types/index.d.ts", [];
181+
"full", !! "node_modules/@types/react/index.d.ts" ++ "node_modules/@types/react/global.d.ts", ["--readable-names"];
182+
"full", !! "node_modules/@types/react-modal/index.d.ts", ["--readable-names"];
183+
184+
// "safe" package which depends on another "safe" package
185+
"safe", !! "node_modules/@types/yargs-parser/index.d.ts", [];
186+
"safe", !! "node_modules/@types/yargs/index.d.ts", [];
187+
188+
"minimal", !! "node_modules/@types/vscode/index.d.ts", ["--readable-names"];
189+
]
190+
191+
for preset, package, additionalOptions in packages do
192+
ts2res
193+
(["--verbose"; "--nowarn"; "--follow-relative-references";
194+
$"--preset {preset}"; $"-o {outputDir}"] @ additionalOptions)
195+
package
196+
197+
let build () =
198+
Shell.mkdir srcGeneratedDir
199+
for file in outputDir |> Shell.copyRecursiveTo true srcGeneratedDir do
200+
printfn "* copied to %s" file
201+
inDirectory testDir <| fun () ->
202+
Yarn.install id
203+
Yarn.exec "rescript" id
204+
148205
let setup () =
149206
Target.create "TestJsooClean" <| fun _ -> Jsoo.clean ()
150207
Target.create "TestJsooGenerateBindings" <| fun _ -> Jsoo.generateBindings ()
@@ -156,13 +213,18 @@ module Test =
156213
==> "TestJsooGenerateBindings"
157214
==> "TestJsooBuild"
158215
==> "TestJsoo"
216+
==> "Test"
159217

160-
Target.create "Test" ignore
161-
Target.create "TestOnly" ignore
218+
Target.create "TestResClean" <| fun _ -> Res.clean ()
219+
Target.create "TestResGenerateBindings" <| fun _ -> Res.generateBindings ()
220+
Target.create "TestResBuild" <| fun _ -> Res.build ()
221+
Target.create "TestRes" ignore
162222

163-
"TestJsoo"
164-
==> "TestOnly"
165-
==> "TestComplete"
223+
"BuildForTest"
224+
==> "TestResClean"
225+
==> "TestResGenerateBindings"
226+
==> "TestResBuild"
227+
==> "TestRes"
166228
==> "Test"
167229

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

179241
module Jsoo =
180-
let targetDir = "./dist_jsoo"
242+
let targetDir = distDir </> "jsoo"
181243
let duneProject = targetDir </> "dune-project"
182244

183245
let copyArtifacts () =
@@ -200,10 +262,10 @@ module Publish =
200262
if result.Success then
201263
let oldVersion = result.Groups.[1].Value
202264
if oldVersion <> newVersion then
203-
printfn $"* updating version in dist_jsoo/dune-project from '{oldVersion}' to '{newVersion}'."
265+
printfn $"* updating version in dist/jsoo/dune-project from '{oldVersion}' to '{newVersion}'."
204266
content |> String.replace result.Value $"(version {newVersion})"
205267
else
206-
printfn $"* version in dist_jsoo/dune-project not updated ('{newVersion}')."
268+
printfn $"* version in dist/jsoo/dune-project not updated ('{newVersion}')."
207269
content
208270
else content
209271
)
@@ -212,9 +274,6 @@ module Publish =
212274
inDirectory targetDir <| fun () -> dune "build"
213275

214276
let setup () =
215-
Target.create "Publish" <| fun _ -> ()
216-
Target.create "PublishOnly" <| fun _ -> ()
217-
218277
Target.create "PublishNpm" <| fun _ ->
219278
Npm.updateVersion ()
220279

@@ -226,13 +285,8 @@ module Publish =
226285
"BuildForPublish"
227286
==> "PublishNpm"
228287
==> "PublishJsoo"
229-
==> "PublishOnly"
230288
==> "Publish"
231289

232-
"TestJsoo" ==> "PublishJsoo"
233-
234-
"Build" ?=> "Test" ?=> "Publish"
235-
236290
// Utility targets
237291

238292
module Utility =
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

dist/res/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/node_modules/
3+
/lib/
4+
.bsb.lock
5+
.merlin
6+
7+
*.bs.js
8+
Demo.res

dist/res/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "ts2ocaml-rescript-stdlib",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"build": "rescript",
6+
"clean": "rescript clean -with-deps",
7+
"start": "rescript build -w"
8+
},
9+
"keywords": [
10+
"rescript"
11+
],
12+
"author": "",
13+
"license": "Apache-2.0",
14+
"devDependencies": {
15+
"rescript": "11.0.1"
16+
},
17+
"peerDependencies": {
18+
"rescript": "^11.0.1"
19+
}
20+
}

dist/res/rescript.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "ts2ocaml-rescript-stdlib",
3+
"version": "0.0.0",
4+
"sources": {
5+
"dir" : "src",
6+
"subdirs" : true
7+
},
8+
"package-specs": {
9+
"module": "commonjs",
10+
"in-source": true
11+
},
12+
"suffix": ".bs.js",
13+
"bs-dependencies": [
14+
],
15+
"warnings": {
16+
"error" : "+101"
17+
}
18+
}

0 commit comments

Comments
 (0)