Skip to content

Commit

Permalink
Upgrade ReScript to v11 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
cannorin committed Jul 17, 2023
1 parent 1cc321a commit 5c86226
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 53 deletions.
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*
10 changes: 5 additions & 5 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ 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 @@ -122,7 +122,7 @@ module Test =

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

// "full" packages involving a lot of dependencies (which includes some "safe" packages)
"safe", !! "node_modules/@types/scheduler/tracing.d.ts", [];
Expand Down Expand Up @@ -239,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 @@ -262,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 Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dist_rescript/package.json → dist/res/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"rescript": "*"
"rescript": "^11.0.0-beta.3"
}
}
File renamed without changes.
8 changes: 8 additions & 0 deletions dist/res/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


rescript@^11.0.0-beta.3:
version "11.0.0-beta.3"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-11.0.0-beta.3.tgz#f883a19aa8cb2ab162fd2c9f3d46d2c05cc5710b"
integrity sha512-j3YT3VdWMoHgwL4RydKJm9O/VIpN3NTI6keP18rZVJ8ansRKgkHYGLaIwoG6iVqSYYwBjb6d8l8oZ1Jz0fmTeQ==
13 changes: 0 additions & 13 deletions dist_rescript/package-lock.json

This file was deleted.

21 changes: 11 additions & 10 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Modules with **\[\<AutoOpen\>\]** does not require `open` to use.
- `Main.fs` ... entry point
- `test/`
- `jsoo/` ... test for `js_of_ocaml` target
- `dist/` ... output directory for NPM packaging
- `dist_jsoo/` ... output directory for OPAM packaging
- `dist/`
- `js/ `... output directory for NPM packaging
- `jsoo/` ... output directory for OPAM packaging
- `output/` ... temporary output directory for automated testing, etc

## Requirements
Expand All @@ -54,7 +55,7 @@ Modules with **\[\<AutoOpen\>\]** does not require `open` to use.

## Debugging

`./fake watch` to live update `dist/ts2ocaml.js`.
`./fake watch` to live update `dist/js/ts2ocaml.js`.

It will be bundled by Webpack with the `development` mode.

Expand All @@ -64,9 +65,9 @@ It will be bundled by Webpack with the `development` mode.
- `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)
- Bundle the JS files into `dist/ts2ocaml.js` (through Webpack)
- Bundle the JS files into `dist/js/ts2ocaml.js` (through Webpack)

The resulting `dist/ts2ocaml.js` is then ready to run through `node`.
The resulting `dist/js/ts2ocaml.js` is then ready to run through `node`.

## Testing

Expand Down Expand Up @@ -96,12 +97,12 @@ The resulting `dist/ts2ocaml.js` is then ready to run through `node`.

### Prepare for publishing the standard library for [`js_of_ocaml` target](js_of_ocaml.md) to the `jsoo-stdlib` branch

- Copy `ts2ocaml_*.mli` from `output/test_jsoo/` to `dist_jsoo/src/`
- Copy `ts2ocaml_*.ml` from `test/jsoo/_build/default/src/` to `dist_jsoo/src/`
- Set the correct `version` in `dist_jsoo/dune-project`
- Perform `dune build` in `dist_jsoo/` to generate `.opam` file and check if it compiles
- Copy `ts2ocaml_*.mli` from `output/test_jsoo/` to `dist/jsoo/src/`
- Copy `ts2ocaml_*.ml` from `test/jsoo/_build/default/src/` to `dist/jsoo/src/`
- Set the correct `version` in `dist/jsoo/dune-project`
- Perform `dune build` in `dist/jsoo/` to generate `.opam` file and check if it compiles

GitHub Action `publish.yml` is configured to push the `dist_jsoo` directory to the `jsoo-stdlib` branch.
GitHub Action `publish.yml` is configured to push the `dist/jsoo` directory to the `jsoo-stdlib` branch.

### Prepare for publishing the tool to NPM

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
},
"homepage": "https://github.com/ocsigen/ts2ocaml",
"scripts": {
"ts2ocaml": "node ./dist/ts2ocaml.js"
"ts2ocaml": "node ./dist/js/ts2ocaml.js"
},
"files": [
"dist/"
"dist/js/"
],
"main": "./dist/ts2ocaml.js",
"bin": "./dist/ts2ocaml.js",
"main": "./dist/js/ts2ocaml.js",
"bin": "./dist/js/ts2ocaml.js",
"dependencies": {
"@babel/code-frame": "^7.18.6",
"browser-or-node": "^2.0.0",
Expand All @@ -43,7 +43,7 @@
"cdk8s": "^2.2.41",
"monaco-editor": "0.40.0",
"react-player": "2.12.0",
"rescript": "^10.0.0",
"rescript": "^11.0.0-beta.3",
"ts2fable": "0.8.0-build.723",
"webpack": "5.88.0",
"webpack-cli": "5.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Targets/ReScript/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,4 @@ type Output = {
res: text
}

let [<ImportDefault("../../../dist_rescript/src/ts2ocaml.res?raw")>] stdlib: string = jsNative
let [<ImportDefault("../../../dist/res/src/ts2ocaml.res?raw")>] stdlib: string = jsNative
4 changes: 2 additions & 2 deletions src/Targets/ReScript/ReScriptHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open DataTypes.Text

module Source =
open Fable.Core
let [<ImportDefault("rescript/lib/ocaml/dom.ml?raw")>] dom: string = jsNative
let [<ImportDefault("rescript/lib/ocaml/dom.res?raw")>] dom: string = jsNative

let comment text =
if text = empty then empty
Expand Down Expand Up @@ -240,7 +240,7 @@ module Type =
Source.dom
|> String.splitManyThenRemoveEmptyEntries ["\n"; "\r"]
|> Array.filter (fun s -> s.StartsWith("type "))
|> Array.choose (fun s -> s |> String.replace "type " "" |> String.splitMany [" = "; " (*"] |> Array.tryHead)
|> Array.choose (fun s -> s |> String.replace "type " "" |> String.splitMany [" = "; " /*"] |> Array.tryHead)
|> Array.filter (fun s -> s.Length > 0 && s.ToCharArray() |> Array.forall Char.isAlphabet)
|> Array.map (fun s -> Naming.upperFirst s, "Dom." + s)
let ignoreCase =
Expand Down
6 changes: 3 additions & 3 deletions src/Targets/ReScript/Writer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,10 @@ let rec emitMembers flags overrideFunc ctx (selfTy: Type) (isExportDefaultClass:
| Choice2Of2 _ :: rest ->
let name = sprintf "arg%d" index |> rename
go (index+1) false ({| ml = str name; js = name; used = true |} :: acc) rest
| Choice1Of2 { name = name; isOptional = isOptional } :: rest ->
let ml = if isOptional then sprintf "~%s=?" name else "~" + name
| Choice1Of2 { name = name; isOptional = isOptional' } :: rest ->
let ml = if isOptional' then sprintf "~%s=?" name else "~" + name
let js = name |> String.replace "'" "$p"
go (index+1) isOptional ({| ml = str ml; js = js; used = true |} :: acc) rest
go (index+1) (isOptional || isOptional') ({| ml = str ml; js = js; used = true |} :: acc) rest
go 1 false [] args
let body =
let args =
Expand Down
2 changes: 1 addition & 1 deletion test/res/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"@ocsigen/ts2ocaml": "link:../../"
},
"dependencies": {
"rescript": "^10.0.0"
"rescript": "^11.0.0-beta.3"
}
}
8 changes: 4 additions & 4 deletions test/res/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ require-directory@^2.1.1:
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==

rescript@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-10.0.0.tgz#8460bc6f7d94bc580eac02d7c7efdf0a470916b8"
integrity sha512-LhNg/4+0j8NvoFeslgAeYLlzUwkq6kR6l6v8BnZ61VDTxopK2l96uT1lq5lv1aMxzMDynvE2qnX0zalre+6XxA==
rescript@^11.0.0-beta.3:
version "11.0.0-beta.3"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-11.0.0-beta.3.tgz#f883a19aa8cb2ab162fd2c9f3d46d2c05cc5710b"
integrity sha512-j3YT3VdWMoHgwL4RydKJm9O/VIpN3NTI6keP18rZVJ8ansRKgkHYGLaIwoG6iVqSYYwBjb6d8l8oZ1Jz0fmTeQ==

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const webpack = require('webpack');

var CONFIG = {
fsharpEntry: './src/Main.fs.js',
outputDir: './dist',
outputDir: './dist/js',
}

var path = require("path");
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2732,10 +2732,10 @@ requires-port@^1.0.0:
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=

rescript@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-10.0.0.tgz#8460bc6f7d94bc580eac02d7c7efdf0a470916b8"
integrity sha512-LhNg/4+0j8NvoFeslgAeYLlzUwkq6kR6l6v8BnZ61VDTxopK2l96uT1lq5lv1aMxzMDynvE2qnX0zalre+6XxA==
rescript@^11.0.0-beta.3:
version "11.0.0-beta.3"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-11.0.0-beta.3.tgz#f883a19aa8cb2ab162fd2c9f3d46d2c05cc5710b"
integrity sha512-j3YT3VdWMoHgwL4RydKJm9O/VIpN3NTI6keP18rZVJ8ansRKgkHYGLaIwoG6iVqSYYwBjb6d8l8oZ1Jz0fmTeQ==

resolve-cwd@^3.0.0:
version "3.0.0"
Expand Down

0 comments on commit 5c86226

Please sign in to comment.