Skip to content

Update client to PureScript 0.15.2 #278

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

Merged
merged 9 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
npm run build
npm run test
npm run build:production
npm run bundle

- name: Build client assets
if: github.event_name == 'release'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ cabal.sandbox.config
*.lksh*
bundle/
client/public/js/output
client/client.js
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New features:
Bugfixes:

Other improvements:
- Update client to 0.15.2; bundle via esbuild (#278 by @JordanMartinez)

## [v2022-06-10.1](https://github.com/purescript/trypurescript/releases/tag/v2022-06-10.1)

Expand Down
20 changes: 13 additions & 7 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
"clean": "rimraf output",
"test": "spago test --path config/dev/Try.Config.purs",
"build": "spago build --path config/dev/Try.Config.purs",
"build:dev": "spago bundle-app --path config/dev/Try.Config.purs --to public/js/index.js",
"build:production": "spago bundle-app --path config/prod/Try.Config.purs --purs-args '--censor-lib --strict' --to public/js/index.js",
"build:dev": "spago bundle-app --path config/dev/Try.Config.purs --to client.js",
"build:production": "spago bundle-app --path config/prod/Try.Config.purs --purs-args '--censor-lib --strict' --to client.js",
"bundle": "esbuild --outfile=public/js/index.js --bundle --minify --platform=browser --format=iife --tree-shaking=true --footer:js=\"\n\nmain();\" client.js",
"serve": "http-server public/ -o / --cors=\"Access-Control-Allow-Origin: *\" -c-1",
"serve:dev": "npm run build:dev && npm run serve",
"serve:production": "npm run build:production && npm run serve"
"serve:dev": "npm run build:dev && npm run bundle && npm run serve",
"serve:production": "npm run build:production && npm run bundle && npm run serve"
},
"devDependencies": {
"esbuild": "^0.14.43",
"http-server": "^14.1.0",
"purescript": "^0.13.6",
"purescript-psa": "^0.7.3",
"purescript": "^0.15.2",
"purescript-psa": "^0.8.2",
"rimraf": "^2.5.4",
"spago": "^0.14.0"
"spago": "^0.20.9"
},
"dependencies": {
"ace-builds": "^1.5.0",
"jquery": "^1.12.4"
}
}
23 changes: 3 additions & 20 deletions client/packages.dhall
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200404/packages.dhall sha256:f239f2e215d0cbd5c203307701748581938f74c4c78f4aeffa32c11c131ef7b6
https://github.com/purescript/package-sets/releases/download/psc-0.15.2-20220609/packages.dhall
sha256:2b15922dcc47143e5f271a75d4aa91b0379bc1bd7d880adfb428e287617210f7

let additions =
{ ace =
{ repo = "https://github.com/purescript-contrib/purescript-ace.git"
, version = "v7.0.0"
, dependencies =
[ "arrays"
, "console"
, "effect"
, "foreign"
, "nullable"
, "prelude"
, "refs"
, "web-html"
, "web-uievents"
]
}
}

in upstream // additions
in upstream
61 changes: 0 additions & 61 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,6 @@
<link rel="stylesheet" type="text/css" href="css/index.css" />
</head>
<body>
<script type="text/javascript">
$.ajaxSetup({
dataType: "text",
});

function teardownIFrame() {
var $ctr = $("iframe#output-iframe");
$ctr.remove()
}

function setupIFrame(data, loadCb, failCb) {
var $ctr = $("#column2");
var $iframe = $(
'<iframe sandbox="allow-scripts allow-forms" id="output-iframe" src="frame.html">'
);
$ctr.empty().append($iframe);
var tries = 0;

var sendSources = setInterval(function () {
// Stop after 10 seconds
if (tries >= 100) {
return clearInterval(sendSources);
}
tries++;
var iframe = $iframe.get(0).contentWindow;
if (iframe) {
iframe.postMessage(data, "*");
loadCb();
} else {
failCb();
console.warn("Frame is not available");
}
}, 100);

window.addEventListener(
"message",
function () {
clearInterval(sendSources);
},
{ once: true }
);

window.addEventListener("message", function (event) {
if (
event.data &&
event.data.githubId
) {
window.location.search = "github=" + event.data.githubId;
}
if (
event.data &&
event.data.gistId &&
/^[0-9a-f]+$/.test(event.data.gistId)
) {
window.location.search = "gist=" + event.data.gistId;
}
});

return $iframe;
}
</script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
22 changes: 11 additions & 11 deletions client/spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@
[ "ace"
, "aff"
, "affjax"
, "affjax-web"
, "argonaut-codecs"
, "argonaut-core"
, "arrays"
, "assert"
, "bifunctors"
, "console"
, "const"
, "control"
, "debug"
, "datetime"
, "effect"
, "either"
, "exceptions"
, "foldable-traversable"
, "foreign-object"
, "functions"
, "functors"
, "globals"
, "halogen"
, "identity"
, "halogen-subscriptions"
, "integers"
, "js-timers"
, "math"
, "js-uri"
, "lists"
, "maybe"
, "newtype"
, "node-buffer"
, "node-fs"
, "ordered-collections"
, "parallel"
, "nullable"
, "partial"
, "prelude"
, "profunctor"
, "psci-support"
, "random"
, "refs"
, "semirings"
, "strings"
, "transformers"
, "tuples"
, "unfoldable"
, "unsafe-coerce"
, "web-html"
]
, packages = ./packages.dhall
Expand Down
4 changes: 2 additions & 2 deletions client/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import Halogen.VDom.Driver (runUI)
import Try.Container as Container

main :: Effect Unit
main = launchAff_ do
main = void $ launchAff_ do
body <- HA.awaitBody
runUI Container.component unit body
void $ runUI Container.component unit body
12 changes: 7 additions & 5 deletions client/src/Try/API.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ module Try.API
import Prelude

import Affjax (URL, printError)
import Affjax as AX
import Affjax.RequestBody as AXRB
import Affjax.ResponseFormat as AXRF
import Affjax.StatusCode (StatusCode(..))
import Affjax.Web as AX
import Control.Alt ((<|>))
import Control.Monad.Except (ExceptT(..))
import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:))
import Data.Argonaut.Decode (class DecodeJson, JsonDecodeError(..), decodeJson, printJsonDecodeError, (.:))
import Data.Argonaut.Encode (encodeJson)
import Data.Bifunctor (lmap)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.Traversable (traverse)
Expand Down Expand Up @@ -53,8 +55,8 @@ instance decodeJsonCompileError :: DecodeJson CompileError where
map OtherError $ decodeJson contents
"CompilerErrors" ->
map CompilerErrors $ traverse decodeJson =<< decodeJson contents
_ ->
Left "Tag must be one of: OtherError, CompilerErrors"
j ->
Left $ AtKey "tag" $ UnexpectedValue $ encodeJson $ "- Expected a value of `OtherError` or `CompilerErrors` but got '" <> j <> "'"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeJson FTW! 😄


type Suggestion =
{ replacement :: String
Expand Down Expand Up @@ -105,6 +107,6 @@ compile endpoint code = ExceptT $ liftAff $ AX.post AXRF.json (endpoint <> "/com
Right { status } | status >= StatusCode 400 ->
pure $ Left $ "Received error status code: " <> show status
Right { body } ->
pure $ Right $ decodeJson body
pure $ Right $ lmap printJsonDecodeError $ decodeJson body
where
requestBody = Just $ AXRB.string code
61 changes: 58 additions & 3 deletions client/src/Try/Container.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
"use strict";
$.ajaxSetup({
dataType: "text",
});

exports.setupIFrame = setupIFrame;
exports.teardownIFrame = teardownIFrame;
export function teardownIFrame() {
var $ctr = $("iframe#output-iframe");
$ctr.remove()
}

export function setupIFrame(data, loadCb, failCb) {
var $ctr = $("#column2");
var $iframe = $(
'<iframe sandbox="allow-scripts allow-forms" id="output-iframe" src="frame.html">'
);
$ctr.empty().append($iframe);
var tries = 0;

var sendSources = setInterval(function () {
// Stop after 10 seconds
if (tries >= 100) {
return clearInterval(sendSources);
}
tries++;
var iframe = $iframe.get(0).contentWindow;
if (iframe) {
iframe.postMessage(data, "*");
loadCb();
} else {
failCb();
console.warn("Frame is not available");
}
}, 100);

window.addEventListener(
"message",
function () {
clearInterval(sendSources);
},
{ once: true }
);

window.addEventListener("message", function (event) {
if (
event.data &&
event.data.githubId
) {
window.location.search = "github=" + event.data.githubId;
}
if (
event.data &&
event.data.gistId &&
/^[0-9a-f]+$/.test(event.data.gistId)
) {
window.location.search = "gist=" + event.data.gistId;
}
});

return $iframe;
}
Loading