From 8bd765c8e4bad7ce427bc187d7345ba1460f595b Mon Sep 17 00:00:00 2001 From: Patrick Stapfer Date: Tue, 10 Nov 2020 23:18:22 +0100 Subject: [PATCH 1/4] Upgrade to rescript 8.3.3-dev.2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 561540ab7..a08806458 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "devDependencies": { "autoprefixer": "^9.5.1", - "bs-platform": "8.3.2", + "bs-platform": "8.3.3-dev.2", "cssnano": "^4.1.10", "postcss-cli": "^7.1.1", "reanalyze": "^2.5.0", diff --git a/yarn.lock b/yarn.lock index 198b47fbe..ed20de9b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2161,10 +2161,10 @@ bs-fetch@^0.3.1: resolved "https://registry.yarnpkg.com/bs-fetch/-/bs-fetch-0.3.1.tgz#9c7d074b27e6bb2b9f2ec985964f32bcac49f79e" integrity sha512-MxwnuuXPldXnoCtlpeN5JNbbmb1tVgsqpLfVunvuMLAIQNyP0TqoImHiQRTz38PBSN8/iX+2yVlm+PFJfnHHiA== -bs-platform@8.3.2: - version "8.3.2" - resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-8.3.2.tgz#c307f1cc2d2397c3d088c7f3b62e9f493283cdcf" - integrity sha512-iOTi5JIlNPoCPq31NS9ET79FLyCpwTL2JZbgHz35LzY9Bch1iDtbBR3FVGhRbjphxelAP4fLlFONfUNp5Y3a5g== +bs-platform@8.3.3-dev.2: + version "8.3.3-dev.2" + resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-8.3.3-dev.2.tgz#af94cf48708899b02af76095d4197e20e6d12e97" + integrity sha512-2G2PPIFhUBoN1tzZW9PurjWgvCg+Lx/gIqkAjPaDIIA6S8GFPs/UcTyl4ZwJNvQdKv33Qgih2eYTiBp4hCM3MQ== buffer-from@^1.0.0, buffer-from@^1.1.1: version "1.1.1" From c59af37e1ae05576eb8893513ef918c79075fde6 Mon Sep 17 00:00:00 2001 From: Patrick Stapfer Date: Tue, 10 Nov 2020 23:18:28 +0100 Subject: [PATCH 2/4] Fix all warnings --- common/Mdx.res | 5 +-- common/MetaFrontmatter.js | 16 -------- common/MetaFrontmatter.res | 10 ----- components/ApiMarkdown.res | 4 -- components/Button.res | 2 - components/CodeMirror.js | 4 +- components/CodeMirror.res | 27 ++++++------- components/DocSearch.js | 8 ++-- components/DocSearch.res | 23 ++++++----- components/Navigation.res | 16 ++++---- layouts/SidebarLayout.res | 4 +- re_pages/Blog.res | 2 +- re_pages/Playground.js | 19 +--------- re_pages/Playground.res | 78 +++++++++++++++----------------------- 14 files changed, 77 insertions(+), 141 deletions(-) delete mode 100644 common/MetaFrontmatter.js delete mode 100644 common/MetaFrontmatter.res diff --git a/common/Mdx.res b/common/Mdx.res index 3eceec600..f0db0d61d 100644 --- a/common/Mdx.res +++ b/common/Mdx.res @@ -48,8 +48,7 @@ module MdxChildren: { } = { type unknown - @unboxed - type rec t = Any('a): t + type t type case = | String(string) @@ -57,7 +56,7 @@ module MdxChildren: { | Array(array) | Unknown(unknown) - let classify = (Any(v): t): case => + let classify = (v: t): case => if %raw(`function (a) { return a instanceof Array}`)(v) { Array((Obj.magic(v): array)) } else if Js.typeof(v) == "string" { diff --git a/common/MetaFrontmatter.js b/common/MetaFrontmatter.js deleted file mode 100644 index 2de49633d..000000000 --- a/common/MetaFrontmatter.js +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - - -function decode(json) { - return { - TAG: 1, - _0: "Not implemented", - [Symbol.for("name")]: "Error" - }; -} - -export { - decode , - -} -/* No side effect */ diff --git a/common/MetaFrontmatter.res b/common/MetaFrontmatter.res deleted file mode 100644 index ad4f147c3..000000000 --- a/common/MetaFrontmatter.res +++ /dev/null @@ -1,10 +0,0 @@ -// This module is used for accessing meta data from MDX frontmatter -// It's mostly used in conjunction with the component - -// Note: Every optional value in here must be encoded -// as Js.Null.t, since it will be used for JSON serialization -// within Next's static generation - -type t - -let decode = (json: Js.Json.t): result => Error("Not implemented") diff --git a/components/ApiMarkdown.res b/components/ApiMarkdown.res index 78e8f884b..fa48b4f0b 100644 --- a/components/ApiMarkdown.res +++ b/components/ApiMarkdown.res @@ -1,7 +1,3 @@ -// This file was automatically converted to ReScript from 'ApiMarkdown.re' -// Check the output and make sure to delete the original file -open Util.ReactStuff - /* This module is intended for the ODOC like documentation layout. It hides the h2 tags and does diff --git a/components/Button.res b/components/Button.res index f3fa964fb..9f71c0399 100644 --- a/components/Button.res +++ b/components/Button.res @@ -1,5 +1,3 @@ -open Util.ReactStuff - @react.component let make = (~children) => }) - let body = switch Belt.Array.get(tabs, current) { - | Some(tab) => tab.content - | None => React.null - } - let body = Belt.Array.mapWithIndex(tabs, (i, tab) => { let className = current === i ? "block h-full" : "hidden" @@ -511,7 +506,7 @@ module ResultPane = { } module WarningFlagsWidget = { - @bs.set external scrollTop: (Dom.element, int) => unit = "scrollTop" + @bs.set external _scrollTop: (Dom.element, int) => unit = "scrollTop" @bs.send external focus: Dom.element => unit = "focus" @bs.send external scrollIntoView: (Dom.element, @bs.as(json`false`) _) => unit = "scrollIntoView" @@ -693,10 +688,10 @@ module WarningFlagsWidget = { let inputRef = React.useRef(Js.Nullable.null) let focusInput = () => - React.Ref.current(inputRef)->Js.Nullable.toOption->Belt.Option.forEach(el => el->focus) + inputRef.current->Js.Nullable.toOption->Belt.Option.forEach(el => el->focus) let blurInput = () => - React.Ref.current(inputRef)->Js.Nullable.toOption->Belt.Option.forEach(el => el->blur) + inputRef.current->Js.Nullable.toOption->Belt.Option.forEach(el => el->blur) let chips = Belt.Array.mapWithIndex(flags, (i, token) => { let {WarningFlagDescription.Parser.flag: flag, enabled} = token @@ -766,7 +761,7 @@ module WarningFlagsWidget = { let key = ReactEvent.Keyboard.key(evt) let ctrlKey = ReactEvent.Keyboard.ctrlKey(evt) - let caretPosition = ReactEvent.Keyboard.target(evt)["selectionStart"] + /* let caretPosition = ReactEvent.Keyboard.target(evt)["selectionStart"] */ /* Js.log2("caretPosition", caretPosition); */ let full = (ctrlKey ? "CTRL+" : "") ++ key @@ -856,7 +851,7 @@ module WarningFlagsWidget = { let ref = if selected === i { ReactDOMRe.Ref.callbackDomRef(dom => { let el = Js.Nullable.toOption(dom) - let parent = React.Ref.current(listboxRef)->Js.Nullable.toOption + let parent = listboxRef.current->Js.Nullable.toOption switch (parent, el) { | (Some(parent), Some(el)) => scrollToElement(~parent, el) @@ -969,7 +964,7 @@ module WarningFlagsWidget = { "border-night-light" } - let areaOnFocus = evt => + let areaOnFocus = _evt => if !isActive { focusInput() } @@ -1018,21 +1013,15 @@ module Settings = { ~readyState: CompilerManagerHook.ready, ~dispatch: CompilerManagerHook.action => unit, ~setConfig: Api.Config.t => unit, - ~editorCode: React.Ref.t, + ~editorCode: React.ref, ~config: Api.Config.t, ) => { let {Api.Config.warn_flags: warn_flags} = config - let targetLangVersion = switch readyState.targetLang { - | Res => (Api.Lang.Res, readyState.selected.compilerVersion) - | Reason => (Reason, readyState.selected.reasonVersion) - | OCaml => (OCaml, readyState.selected.ocamlVersion) - } - let availableTargetLangs = Api.Version.availableLanguages(readyState.selected.apiVersion) let onTargetLangSelect = lang => - dispatch(SwitchLanguage({lang: lang, code: React.Ref.current(editorCode)})) + dispatch(SwitchLanguage({lang: lang, code: editorCode.current})) let onWarningFlagsUpdate = flags => { let normalizeEmptyFlags = flags => @@ -1211,7 +1200,7 @@ module ControlPanel = { ~actionIndicatorKey: string, ~state: CompilerManagerHook.state, ~dispatch: CompilerManagerHook.action => unit, - ~editorCode: React.Ref.t, + ~editorCode: React.ref, ) => { let router = Next.Router.useRouter() let children = switch state { @@ -1221,7 +1210,7 @@ module ControlPanel = { | Ready(ready) => let onFormatClick = evt => { ReactEvent.Mouse.preventDefault(evt) - dispatch(Format(React.Ref.current(editorCode))) + dispatch(Format(editorCode.current)) } let createShareLink = () => { @@ -1232,7 +1221,7 @@ module ControlPanel = { Js.Array2.push( params, - ("code", editorCode->React.Ref.current->LzString.compressToEncodedURIComponent), + ("code", editorCode.current->LzString.compressToEncodedURIComponent), )->ignore let querystring = Belt.Array.reduce(params, "", (acc, next) => { @@ -1288,10 +1277,9 @@ module OutputPanel = { @react.component let make = ( - ~actionIndicatorKey, ~compilerDispatch, ~compilerState: CompilerManagerHook.state, - ~editorCode: React.Ref.t, + ~editorCode: React.ref, ) => { /* We need the prevState to understand different @@ -1303,7 +1291,7 @@ module OutputPanel = { */ let prevState = React.useRef(None) - let cmCode = switch React.Ref.current(prevState) { + let cmCode = switch prevState.current { | Some(prev) => switch (prev, compilerState) { | (_, Ready({result: Nothing})) => None @@ -1324,7 +1312,7 @@ module OutputPanel = { } } - React.Ref.setCurrent(prevState, Some(compilerState)) + prevState.current = Some(compilerState) let resultPane = switch compilerState { | Compiling(ready, _) @@ -1390,7 +1378,7 @@ module OutputPanel = { let prevSelected = React.useRef(0) let selected = switch compilerState { - | Compiling(_, _) => React.Ref.current(prevSelected) + | Compiling(_, _) => prevSelected.current | Ready(ready) => switch ready.result { | Comp(Success(_)) @@ -1400,7 +1388,7 @@ module OutputPanel = { | _ => 0 } - React.Ref.setCurrent(prevSelected, selected) + prevSelected.current = selected let tabs = [ {Pane.title: "JavaScript", content: output}, @@ -1499,7 +1487,7 @@ let default = () => { // The user can focus an error / warning on a specific line & column // which is stored in this ref and triggered by hover / click states // in the CodeMirror editor - let (focusedRowCol, setFocusedRowCol) = React.useState(_ => None) + let (_focusedRowCol, setFocusedRowCol) = React.useState(_ => None) let editorCode = React.useRef(initialContent) @@ -1507,9 +1495,9 @@ let default = () => { we take any success results and set the editor code to the new formatted code */ switch compilerState { | Ready({result: FinalResult.Nothing} as ready) => - compilerDispatch(CompileCode(ready.targetLang, React.Ref.current(editorCode))) + compilerDispatch(CompileCode(ready.targetLang, editorCode.current)) | Ready({result: FinalResult.Conv(Api.ConversionResult.Success({code}))}) => - React.Ref.setCurrent(editorCode, code) + editorCode.current = code | _ => () } @@ -1525,13 +1513,12 @@ let default = () => { let timeoutCompile = React.useRef(() => ()) React.useEffect1(() => { - React.Ref.setCurrent(timeoutCompile, () => + timeoutCompile.current = () => switch compilerState { - | Ready(ready) => - compilerDispatch(CompileCode(ready.targetLang, React.Ref.current(editorCode))) + | Ready(ready) => compilerDispatch(CompileCode(ready.targetLang, editorCode.current)) | _ => () } - ) + None }, [compilerState]) @@ -1598,21 +1585,21 @@ let default = () => { maxHeight="calc(100vh - 10rem)" mode="reason" errors=cmErrors - value={React.Ref.current(editorCode)} + value={editorCode.current} onChange={value => { - React.Ref.setCurrent(editorCode, value) + editorCode.current = value - switch React.Ref.current(typingTimer) { + switch typingTimer.current { | None => () | Some(timer) => Js.Global.clearTimeout(timer) } let timer = Js.Global.setTimeout(() => { - React.Ref.current(timeoutCompile)() - React.Ref.setCurrent(typingTimer, None) + timeoutCompile.current() + typingTimer.current = None }, 100) - React.Ref.setCurrent(typingTimer, Some(timer)) + typingTimer.current = Some(timer) }} - onMarkerFocus={rowCol => setFocusedRowCol(prev => Some(rowCol))} + onMarkerFocus={rowCol => setFocusedRowCol(_prev => Some(rowCol))} onMarkerFocusLeave={_ => setFocusedRowCol(_ => None)} /> @@ -1620,12 +1607,7 @@ let default = () => {
1024 ? "56rem" : "100%", ())}> - +
Date: Wed, 11 Nov 2020 11:05:44 +0100 Subject: [PATCH 3/4] Add bs-platform@8.2.0 as rescript-820 package, run tests with that instead --- package.json | 1 + scripts/test-examples.js | 5 ++++- yarn.lock | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a08806458..e26c61363 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "react-dom": "^16.12.0", "reason-promise": "^1.0.2", "reason-react": "^0.9.1", + "rescript-820": "npm:bs-platform@^8.2.0", "remark-parse": "^7.0.1", "remark-slug": "^5.1.2", "remark-stringify": "^7.0.3", diff --git a/scripts/test-examples.js b/scripts/test-examples.js index d903db522..94bd2dcf0 100644 --- a/scripts/test-examples.js +++ b/scripts/test-examples.js @@ -5,7 +5,10 @@ const path = require("path"); let tempFileName = path.join(__dirname, '..', '_tempFile.res') let tempFileNameRegex = /_tempFile\.res/g -let bsc = path.join(__dirname, '..', 'node_modules', 'bs-platform', process.platform, 'bsc.exe') + +// TODO: In the future we need to use the appropriate rescript version for each doc version variant +// see the package.json on how to define another rescript version +let bsc = path.join(__dirname, '..', 'node_modules', 'rescript-820', process.platform, 'bsc.exe') let parseFile = content => { if (!/```res (example|prelude|sig)/.test(content)) { diff --git a/yarn.lock b/yarn.lock index ed20de9b2..96f4ff363 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6853,6 +6853,11 @@ require-main-filename@^2.0.0: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== +"rescript-820@npm:bs-platform@^8.2.0": + version "8.3.2" + resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-8.3.2.tgz#c307f1cc2d2397c3d088c7f3b62e9f493283cdcf" + integrity sha512-iOTi5JIlNPoCPq31NS9ET79FLyCpwTL2JZbgHz35LzY9Bch1iDtbBR3FVGhRbjphxelAP4fLlFONfUNp5Y3a5g== + resolve-from@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748" From 6bd974a689b6acb118f94559d3eef75f59429ba6 Mon Sep 17 00:00:00 2001 From: Patrick Stapfer Date: Wed, 11 Nov 2020 11:46:32 +0100 Subject: [PATCH 4/4] Decouple compiler versions for testing with the actual rescript installation --- compilers/README.md | 5 +++++ compilers/package-lock.json | 13 +++++++++++++ compilers/package.json | 10 ++++++++++ package.json | 1 - scripts/test-examples.js | 15 ++++++++++++++- yarn.lock | 5 ----- 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 compilers/README.md create mode 100644 compilers/package-lock.json create mode 100644 compilers/package.json diff --git a/compilers/README.md b/compilers/README.md new file mode 100644 index 000000000..37503ac3b --- /dev/null +++ b/compilers/README.md @@ -0,0 +1,5 @@ +# compilers + +This folder is needed to install additional rescript compiler versions for testing our documented source code on multiple compiler versions. + +Our `scripts/test-examples.js` script will automatically install all package.json dependencies if it cannot find any compiler versions. diff --git a/compilers/package-lock.json b/compilers/package-lock.json new file mode 100644 index 000000000..0edc863f2 --- /dev/null +++ b/compilers/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "compilers", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "rescript-820": { + "version": "npm:bs-platform@8.2.0", + "resolved": "https://registry.npmjs.org/bs-platform/-/bs-platform-8.2.0.tgz", + "integrity": "sha512-quvmUac/ZxGDsT7L5+6RNXrLPvLHkWFownacaqlwVoyAm770bPyupTRU49ALPGk3HpjfD5eE+lpGdOSPtuwJiA==" + } + } +} diff --git a/compilers/package.json b/compilers/package.json new file mode 100644 index 000000000..4d308f493 --- /dev/null +++ b/compilers/package.json @@ -0,0 +1,10 @@ +{ + "name": "compilers", + "private": true, + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "dependencies": { + "rescript-820": "npm:bs-platform@8.2.0" + } +} diff --git a/package.json b/package.json index e26c61363..a08806458 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "react-dom": "^16.12.0", "reason-promise": "^1.0.2", "reason-react": "^0.9.1", - "rescript-820": "npm:bs-platform@^8.2.0", "remark-parse": "^7.0.1", "remark-slug": "^5.1.2", "remark-stringify": "^7.0.3", diff --git a/scripts/test-examples.js b/scripts/test-examples.js index 94bd2dcf0..ca23a9f37 100644 --- a/scripts/test-examples.js +++ b/scripts/test-examples.js @@ -8,7 +8,16 @@ let tempFileNameRegex = /_tempFile\.res/g // TODO: In the future we need to use the appropriate rescript version for each doc version variant // see the package.json on how to define another rescript version -let bsc = path.join(__dirname, '..', 'node_modules', 'rescript-820', process.platform, 'bsc.exe') +let compilersDir = path.join(__dirname, "..", "compilers") +let bsc = path.join(compilersDir, 'node_modules', 'rescript-820', process.platform, 'bsc.exe') + +const prepareCompilers = () => { + if (fs.existsSync(bsc)) { + return; + } + console.log("compilers not installed. Installing compilers..."); + child_process.execFileSync("npm", ['install'], {cwd: compilersDir}) +} let parseFile = content => { if (!/```res (example|prelude|sig)/.test(content)) { @@ -53,6 +62,10 @@ let postprocessOutput = (file, error) => { }) } + +prepareCompilers(); + +console.log("Running tests...") fs.writeFileSync(tempFileName, '') let success = true diff --git a/yarn.lock b/yarn.lock index 96f4ff363..ed20de9b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6853,11 +6853,6 @@ require-main-filename@^2.0.0: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== -"rescript-820@npm:bs-platform@^8.2.0": - version "8.3.2" - resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-8.3.2.tgz#c307f1cc2d2397c3d088c7f3b62e9f493283cdcf" - integrity sha512-iOTi5JIlNPoCPq31NS9ET79FLyCpwTL2JZbgHz35LzY9Bch1iDtbBR3FVGhRbjphxelAP4fLlFONfUNp5Y3a5g== - resolve-from@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"