Skip to content

Update to 0.15.0 PureScript #274

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
00ed3da
Update changelog for last release
JordanMartinez Mar 31, 2022
098fb42
Update purescript deps for 0.15.0; drop cst dep
JordanMartinez Apr 30, 2022
905d54d
Upgrade to latest pkg set; install entire set
JordanMartinez Apr 30, 2022
3880074
Get server code to compile
JordanMartinez Apr 30, 2022
37cf79a
Migrated FFI to ES modules via 'lebab'
JordanMartinez Apr 30, 2022
db55540
Removed '"use strict";' in FFI files
JordanMartinez Apr 30, 2022
479619b
Remove redundant import
JordanMartinez Apr 30, 2022
52dc624
Update to 0.15.0 for client
JordanMartinez Apr 30, 2022
473ca20
Migrate FFI in client to ES modules
JordanMartinez Apr 30, 2022
b8debc4
Account for breaking changes
JordanMartinez Apr 30, 2022
32c52a7
Fix spago transitive deps error
JordanMartinez Apr 30, 2022
c534443
Add changelog entry
JordanMartinez Apr 30, 2022
7c2b46e
Update spago to 0.20.9
JordanMartinez May 14, 2022
683e658
Support shims via es-module-shims
JordanMartinez May 14, 2022
c6d0300
Update package set to latest one; drop debug override
JordanMartinez May 14, 2022
958b736
Move setup/teardown iframe fns to FFI file
JordanMartinez May 14, 2022
b3f5009
Add jquery a dependency
JordanMartinez May 14, 2022
173330b
Just send JS code to iframe
JordanMartinez May 14, 2022
a431f57
Add http-server as dev dep
JordanMartinez May 14, 2022
0074fbd
Update package set to latest version
JordanMartinez May 17, 2022
022095c
Refactor scripts; include ace-builds as dev dep
JordanMartinez May 17, 2022
ee85437
Ignore vscode settings
JordanMartinez May 17, 2022
8c35d23
Fix API decoder
JordanMartinez May 17, 2022
7d599d9
Fix import sort
JordanMartinez May 17, 2022
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Notable changes to this project are documented in this file. The format is based

## [Unreleased]

Breaking changes:
- Update compiler to v0.15.0 (#274 by @JordanMartinez)

New features:

Bugfixes:

Other improvements:

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

Breaking changes:
- Update compiler to v0.14.7 (#271 by @JordanMartinez)

Expand Down
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/.stack*
/public/js/index.js
.spago/
.vscode/
3 changes: 3 additions & 0 deletions client/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { main } from "./public/js/output/Main/index.js";

main();
19 changes: 13 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
"scripts": {
"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"
"bundle": "esbuild --outfile=public/js/index.js --bundle entry.js --platform=browser --format=iife",
"build:dev": "spago build --path config/dev/Try.Config.purs --purs-args \"--output public/js/output\"",
"build:production": "spago bundle-app --path config/prod/Try.Config.purs --purs-args '--censor-lib --strict' --to public/js/index.js",
"serve:dev": "npm run build:dev && npm run bundle && http-server public/ -o / -c-1 --port 8100",
"serve:prod": "npm run build:prod && npm run bundle && http-server public/ -o / -c-1"
},
"devDependencies": {
"purescript": "^0.13.6",
"purescript-psa": "^0.7.3",
"http-server": "^14.1.0",
"purescript": "^0.15.0",
"purescript-psa": "^0.8.2",
"rimraf": "^2.5.4",
"spago": "^0.14.0"
"spago": "^0.20.9"
},
"dependencies": {
"jquery": "^1.12.4",
"ace-builds": "^1.5.0"
}
}
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.0-20220513/packages.dhall
sha256:1ed784f37ae6131d99acd542d058d5ce39954ccaacc3adba5cc7cf1549d2bffa

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
54 changes: 53 additions & 1 deletion client/public/frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,59 @@
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/frame.js"></script>
<script>
window.esmsInitOptions = {
// -- Hooks --
// Module load error
onerror: (e) => {
console.log("Error while loading module: ");
console.log(e);
throw e;
},
};
</script>
<!--
JSPM Generator Import Map
Edit URL: https://generator.jspm.io/#Y2NnYGCzD80rySzJSU1hSMpM183MK0lNTy1yMNQz0zM1ZEhJTc7MTczRyyp2MDTQM9YzZChKTUwu0U3Jz3UwNNMzxCqiX5xaVJZaBJGAKystzUxxsACaYQQAoBlP83cA
-->
<script type="importmap">
{
"imports": {
"big-integer": "https://ga.jspm.io/npm:[email protected]/BigInteger.js",
"decimal.js": "https://ga.jspm.io/npm:[email protected]/decimal.js",
"react": "https://ga.jspm.io/npm:[email protected]/index.js",
"react-dom": "https://ga.jspm.io/npm:[email protected]/index.js",
"react-dom/server": "https://ga.jspm.io/npm:[email protected]/server.browser.js",
"uuid": "https://ga.jspm.io/npm:[email protected]/dist/esm-browser/index.js"
},
"scopes": {
"https://ga.jspm.io/": {
"object-assign": "https://ga.jspm.io/npm:[email protected]/index.js",
"react": "https://ga.jspm.io/npm:[email protected]/index.js",
"scheduler": "https://ga.jspm.io/npm:[email protected]/index.js"
}
}
}
</script>

<!-- ES Module Shims: Import maps polyfill for modules browsers without import maps support (all except Chrome 89+) -->
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js" integrity="sha384-ZGtUNdKMtA2sSrO9dN9d2TOeiSlXlDSrOrasgO9YoKR4LsDV7RLdUvvX1M0gCkl2" crossorigin="anonymous"></script>

<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/BigInteger.js" integrity="sha384-Lxn1K4ox8//F5O+uihYrTIJvbfM+UJaRL2SdFA2s/z0v6i5TrWg9B8RzfjM60R9y"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/decimal.js" integrity="sha384-camBDJB1KoavtyRdQfdzzR4mj+uAKnNlvseJIwqKYOaHWnjZmnXR+1vyBP1WlZd0"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/index.js" integrity="sha384-iQp1zoaqIhfUYyYkz3UNk1QeFfmBGgt1Ojq0kZD5Prql1g7fgJVzVgsjDoR65lv8"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/cjs/react-dom-server.browser.production.min.js" integrity="sha384-XL5bjsaJ5UPjTIPsyzUfscq41OFbVXsLojl53DCgFfdzKNNUL2MOSd0WM/upjd53"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/cjs/react-dom.production.min.js" integrity="sha384-HDQjgsF+F2j5XuiiDtCiuLA1vgyHr9ONiNrBhKmJEVa43KqIZdAB7VN2+QjUGwvq"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/index.js" integrity="sha384-zAu0L7n/xnRAG7+D/qd1K4E1/2tYK4hL3puH/5YEliHNnO3OOt5jUhnnemFTHmIG"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/server.browser.js" integrity="sha384-dsW+4a3rjWELxqtR1rVEIeLNHGyMjRFwdBVz6OG30oBLs8tO2/dYUIxEvc515PSZ"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/index.js" integrity="sha384-T0mNrKFgmKBye+m7XrpShrh+7kfix2zQd9qrR8xytnppcxESpgzrb4IJXvE+uJcl"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/cjs/react.production.min.js" integrity="sha384-pTMZhybzHZ+1G029kWUmoGvTrBp1C+2oJAkZV48BBq7+e6Hk3bGuXtvxT2vQfBqj"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/index.js" integrity="sha384-jVagjV+2YtlseazU2byX6gMLPHaA5Ps2c6HhvsGDlWjn45YCCoU1q+QtQTOb1MjT"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/index.js" integrity="sha384-HIW1B3OQdGPkUEgh29MiYoUKQp+mFTjw50hRVvGhZgUaNYrUFYN07a+3CqC0/I7L"/>
<link rel="modulepreload" href="https://ga.jspm.io/npm:[email protected]/dist/esm-browser/index.js" integrity="sha384-y7UmGnwe+/V/S4AD5T6MLU9dHjA3PLvuVGNhrqZApiNbq9Lf8s3aNRrcnzOa+qtR"/>


<script type="module" src="js/frame.js"></script>
</head>
<body>
<main id="main"></main>
Expand Down
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>
41 changes: 10 additions & 31 deletions client/public/js/frame.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
(function() {
function evalSources(sources) {
var modules = {};
function dirname(str) {
var ix = str.lastIndexOf("/");
return ix < 0 ? "" : str.slice(0, ix);
}
function resolvePath(a, b) {
if (b[0] === "." && b[1] === "/") {
return dirname(a) + b.slice(1);
}
if (b[0] === "." && b[1] === "." && b[2] === "/") {
return dirname(dirname(a)) + b.slice(2);
}
return b;
}
return function load(name) {
if (modules[name]) {
return modules[name].exports;
}
function require(path) {
return load(resolvePath(name, path));
}
var module = modules[name] = { exports: {} };
new Function("module", "exports", "require", sources[name])(module, module.exports, require);
return module.exports;
};
}

var parent;

document.addEventListener("DOMContentLoaded", function() {
window.addEventListener("message", function(event) {
parent = event.source;
parent.postMessage("trypurescript", "*");
var file = evalSources(event.data)("<file>");
if (file.main && typeof file.main === "function") {
file.main();
const scriptEl = document.createElement("script");
scriptEl.type = "module";
const code = event.data;
// See https://stackoverflow.com/a/6433770
try {
scriptEl.appendChild(document.createTextNode(code));
} catch (e) {
scriptEl.text = code;
} finally {
document.body.appendChild(scriptEl);
}
}, { once: true });
}, { once: true });
Expand Down
15 changes: 12 additions & 3 deletions client/spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
[ "ace"
, "aff"
, "affjax"
, "affjax-web"
, "argonaut-codecs"
, "argonaut-core"
, "arrays"
, "assert"
, "bifunctors"
, "console"
, "const"
, "control"
, "datetime"
, "debug"
, "effect"
, "either"
Expand All @@ -18,16 +21,21 @@
, "foreign-object"
, "functions"
, "functors"
, "globals"
, "halogen"
, "halogen-subscriptions"
, "identity"
, "integers"
, "js-timers"
, "math"
, "js-uri"
, "lists"
, "maybe"
, "newtype"
, "node-buffer"
, "node-fs"
, "nullable"
, "ordered-collections"
, "parallel"
, "partial"
, "prelude"
, "profunctor"
, "psci-support"
Expand All @@ -38,8 +46,9 @@
, "transformers"
, "tuples"
, "unfoldable"
, "unsafe-coerce"
, "web-html"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
, sources = [ "src/**/*.purs", "config/dev/**/*.purs", "test/**/*.purs" ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps we should use 3 spago.dhall files: a shared one, one for dev and one for prod?

}
2 changes: 1 addition & 1 deletion 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 = launchAff_ $ void do
body <- HA.awaitBody
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 j

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
Loading