Skip to content

Commit faa95bb

Browse files
Update client to PureScript 0.15.2 (#278)
* Update package set to latest; drop globals/math * Update client code to PS 0.15.2 * Move jquery code to Container.js FFI * Bundle code via esm * Add changelog entry * Hack around JsonDecodeError issue using encodeJson
1 parent 18be3a0 commit faa95bb

19 files changed

+163
-176
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
npm run build
7373
npm run test
7474
npm run build:production
75+
npm run bundle
7576
7677
- name: Build client assets
7778
if: github.event_name == 'release'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ cabal.sandbox.config
1515
*.lksh*
1616
bundle/
1717
client/public/js/output
18+
client/client.js

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ New features:
1111
Bugfixes:
1212

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

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

client/package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
"clean": "rimraf output",
66
"test": "spago test --path config/dev/Try.Config.purs",
77
"build": "spago build --path config/dev/Try.Config.purs",
8-
"build:dev": "spago bundle-app --path config/dev/Try.Config.purs --to public/js/index.js",
9-
"build:production": "spago bundle-app --path config/prod/Try.Config.purs --purs-args '--censor-lib --strict' --to public/js/index.js",
8+
"build:dev": "spago bundle-app --path config/dev/Try.Config.purs --to client.js",
9+
"build:production": "spago bundle-app --path config/prod/Try.Config.purs --purs-args '--censor-lib --strict' --to client.js",
10+
"bundle": "esbuild --outfile=public/js/index.js --bundle --minify --platform=browser --format=iife --tree-shaking=true --footer:js=\"\n\nmain();\" client.js",
1011
"serve": "http-server public/ -o / --cors=\"Access-Control-Allow-Origin: *\" -c-1",
11-
"serve:dev": "npm run build:dev && npm run serve",
12-
"serve:production": "npm run build:production && npm run serve"
12+
"serve:dev": "npm run build:dev && npm run bundle && npm run serve",
13+
"serve:production": "npm run build:production && npm run bundle && npm run serve"
1314
},
1415
"devDependencies": {
16+
"esbuild": "^0.14.43",
1517
"http-server": "^14.1.0",
16-
"purescript": "^0.13.6",
17-
"purescript-psa": "^0.7.3",
18+
"purescript": "^0.15.2",
19+
"purescript-psa": "^0.8.2",
1820
"rimraf": "^2.5.4",
19-
"spago": "^0.14.0"
21+
"spago": "^0.20.9"
22+
},
23+
"dependencies": {
24+
"ace-builds": "^1.5.0",
25+
"jquery": "^1.12.4"
2026
}
2127
}

client/packages.dhall

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
let upstream =
2-
https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200404/packages.dhall sha256:f239f2e215d0cbd5c203307701748581938f74c4c78f4aeffa32c11c131ef7b6
2+
https://github.com/purescript/package-sets/releases/download/psc-0.15.2-20220609/packages.dhall
3+
sha256:2b15922dcc47143e5f271a75d4aa91b0379bc1bd7d880adfb428e287617210f7
34

4-
let additions =
5-
{ ace =
6-
{ repo = "https://github.com/purescript-contrib/purescript-ace.git"
7-
, version = "v7.0.0"
8-
, dependencies =
9-
[ "arrays"
10-
, "console"
11-
, "effect"
12-
, "foreign"
13-
, "nullable"
14-
, "prelude"
15-
, "refs"
16-
, "web-html"
17-
, "web-uievents"
18-
]
19-
}
20-
}
21-
22-
in upstream // additions
5+
in upstream

client/public/index.html

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,6 @@
1919
<link rel="stylesheet" type="text/css" href="css/index.css" />
2020
</head>
2121
<body>
22-
<script type="text/javascript">
23-
$.ajaxSetup({
24-
dataType: "text",
25-
});
26-
27-
function teardownIFrame() {
28-
var $ctr = $("iframe#output-iframe");
29-
$ctr.remove()
30-
}
31-
32-
function setupIFrame(data, loadCb, failCb) {
33-
var $ctr = $("#column2");
34-
var $iframe = $(
35-
'<iframe sandbox="allow-scripts allow-forms" id="output-iframe" src="frame.html">'
36-
);
37-
$ctr.empty().append($iframe);
38-
var tries = 0;
39-
40-
var sendSources = setInterval(function () {
41-
// Stop after 10 seconds
42-
if (tries >= 100) {
43-
return clearInterval(sendSources);
44-
}
45-
tries++;
46-
var iframe = $iframe.get(0).contentWindow;
47-
if (iframe) {
48-
iframe.postMessage(data, "*");
49-
loadCb();
50-
} else {
51-
failCb();
52-
console.warn("Frame is not available");
53-
}
54-
}, 100);
55-
56-
window.addEventListener(
57-
"message",
58-
function () {
59-
clearInterval(sendSources);
60-
},
61-
{ once: true }
62-
);
63-
64-
window.addEventListener("message", function (event) {
65-
if (
66-
event.data &&
67-
event.data.githubId
68-
) {
69-
window.location.search = "github=" + event.data.githubId;
70-
}
71-
if (
72-
event.data &&
73-
event.data.gistId &&
74-
/^[0-9a-f]+$/.test(event.data.gistId)
75-
) {
76-
window.location.search = "gist=" + event.data.gistId;
77-
}
78-
});
79-
80-
return $iframe;
81-
}
82-
</script>
8322
<script type="text/javascript" src="js/index.js"></script>
8423
</body>
8524
</html>

client/spago.dhall

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@
33
[ "ace"
44
, "aff"
55
, "affjax"
6+
, "affjax-web"
67
, "argonaut-codecs"
8+
, "argonaut-core"
79
, "arrays"
810
, "assert"
911
, "bifunctors"
1012
, "console"
11-
, "const"
1213
, "control"
13-
, "debug"
14+
, "datetime"
1415
, "effect"
1516
, "either"
1617
, "exceptions"
1718
, "foldable-traversable"
1819
, "foreign-object"
1920
, "functions"
2021
, "functors"
21-
, "globals"
2222
, "halogen"
23-
, "identity"
23+
, "halogen-subscriptions"
2424
, "integers"
2525
, "js-timers"
26-
, "math"
26+
, "js-uri"
27+
, "lists"
2728
, "maybe"
29+
, "newtype"
30+
, "node-buffer"
2831
, "node-fs"
29-
, "ordered-collections"
30-
, "parallel"
32+
, "nullable"
33+
, "partial"
3134
, "prelude"
32-
, "profunctor"
33-
, "psci-support"
3435
, "random"
3536
, "refs"
36-
, "semirings"
3737
, "strings"
3838
, "transformers"
3939
, "tuples"
40-
, "unfoldable"
40+
, "unsafe-coerce"
4141
, "web-html"
4242
]
4343
, packages = ./packages.dhall

client/src/Main.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import Halogen.VDom.Driver (runUI)
99
import Try.Container as Container
1010

1111
main :: Effect Unit
12-
main = launchAff_ do
12+
main = void $ launchAff_ do
1313
body <- HA.awaitBody
14-
runUI Container.component unit body
14+
void $ runUI Container.component unit body

client/src/Try/API.purs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ module Try.API
1414
import Prelude
1515

1616
import Affjax (URL, printError)
17-
import Affjax as AX
1817
import Affjax.RequestBody as AXRB
1918
import Affjax.ResponseFormat as AXRF
2019
import Affjax.StatusCode (StatusCode(..))
20+
import Affjax.Web as AX
2121
import Control.Alt ((<|>))
2222
import Control.Monad.Except (ExceptT(..))
23-
import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:))
23+
import Data.Argonaut.Decode (class DecodeJson, JsonDecodeError(..), decodeJson, printJsonDecodeError, (.:))
24+
import Data.Argonaut.Encode (encodeJson)
25+
import Data.Bifunctor (lmap)
2426
import Data.Either (Either(..))
2527
import Data.Maybe (Maybe(..))
2628
import Data.Traversable (traverse)
@@ -53,8 +55,8 @@ instance decodeJsonCompileError :: DecodeJson CompileError where
5355
map OtherError $ decodeJson contents
5456
"CompilerErrors" ->
5557
map CompilerErrors $ traverse decodeJson =<< decodeJson contents
56-
_ ->
57-
Left "Tag must be one of: OtherError, CompilerErrors"
58+
j ->
59+
Left $ AtKey "tag" $ UnexpectedValue $ encodeJson $ "- Expected a value of `OtherError` or `CompilerErrors` but got '" <> j <> "'"
5860

5961
type Suggestion =
6062
{ replacement :: String
@@ -105,6 +107,6 @@ compile endpoint code = ExceptT $ liftAff $ AX.post AXRF.json (endpoint <> "/com
105107
Right { status } | status >= StatusCode 400 ->
106108
pure $ Left $ "Received error status code: " <> show status
107109
Right { body } ->
108-
pure $ Right $ decodeJson body
110+
pure $ Right $ lmap printJsonDecodeError $ decodeJson body
109111
where
110112
requestBody = Just $ AXRB.string code

client/src/Try/Container.js

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
1-
"use strict";
1+
$.ajaxSetup({
2+
dataType: "text",
3+
});
24

3-
exports.setupIFrame = setupIFrame;
4-
exports.teardownIFrame = teardownIFrame;
5+
export function teardownIFrame() {
6+
var $ctr = $("iframe#output-iframe");
7+
$ctr.remove()
8+
}
9+
10+
export function setupIFrame(data, loadCb, failCb) {
11+
var $ctr = $("#column2");
12+
var $iframe = $(
13+
'<iframe sandbox="allow-scripts allow-forms" id="output-iframe" src="frame.html">'
14+
);
15+
$ctr.empty().append($iframe);
16+
var tries = 0;
17+
18+
var sendSources = setInterval(function () {
19+
// Stop after 10 seconds
20+
if (tries >= 100) {
21+
return clearInterval(sendSources);
22+
}
23+
tries++;
24+
var iframe = $iframe.get(0).contentWindow;
25+
if (iframe) {
26+
iframe.postMessage(data, "*");
27+
loadCb();
28+
} else {
29+
failCb();
30+
console.warn("Frame is not available");
31+
}
32+
}, 100);
33+
34+
window.addEventListener(
35+
"message",
36+
function () {
37+
clearInterval(sendSources);
38+
},
39+
{ once: true }
40+
);
41+
42+
window.addEventListener("message", function (event) {
43+
if (
44+
event.data &&
45+
event.data.githubId
46+
) {
47+
window.location.search = "github=" + event.data.githubId;
48+
}
49+
if (
50+
event.data &&
51+
event.data.gistId &&
52+
/^[0-9a-f]+$/.test(event.data.gistId)
53+
) {
54+
window.location.search = "gist=" + event.data.gistId;
55+
}
56+
});
57+
58+
return $iframe;
59+
}

0 commit comments

Comments
 (0)