diff --git a/CHANGELOG.md b/CHANGELOG.md index 36d46714..64f8aeb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/client/.gitignore b/client/.gitignore index d4779c13..e6a2ff7e 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -8,3 +8,4 @@ /.stack* /public/js/index.js .spago/ +.vscode/ diff --git a/client/entry.js b/client/entry.js new file mode 100644 index 00000000..98d6e0fa --- /dev/null +++ b/client/entry.js @@ -0,0 +1,3 @@ +import { main } from "./public/js/output/Main/index.js"; + +main(); diff --git a/client/package.json b/client/package.json index fc071535..c53ca98c 100644 --- a/client/package.json +++ b/client/package.json @@ -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" } } diff --git a/client/packages.dhall b/client/packages.dhall index 75331a36..e51832b0 100644 --- a/client/packages.dhall +++ b/client/packages.dhall @@ -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 diff --git a/client/public/frame.html b/client/public/frame.html index ba347939..2642e0e1 100644 --- a/client/public/frame.html +++ b/client/public/frame.html @@ -5,7 +5,59 @@ - + + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/public/index.html b/client/public/index.html index 44a29b24..2cdc56ce 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -19,67 +19,6 @@ - diff --git a/client/public/js/frame.js b/client/public/js/frame.js index f0d0a6ff..a39e0a94 100644 --- a/client/public/js/frame.js +++ b/client/public/js/frame.js @@ -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)(""); - 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 }); diff --git a/client/spago.dhall b/client/spago.dhall index d8c65090..fd915d6b 100644 --- a/client/spago.dhall +++ b/client/spago.dhall @@ -3,13 +3,16 @@ [ "ace" , "aff" , "affjax" + , "affjax-web" , "argonaut-codecs" + , "argonaut-core" , "arrays" , "assert" , "bifunctors" , "console" , "const" , "control" + , "datetime" , "debug" , "effect" , "either" @@ -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" @@ -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" ] } diff --git a/client/src/Main.purs b/client/src/Main.purs index 8c3d781c..1749c9cb 100644 --- a/client/src/Main.purs +++ b/client/src/Main.purs @@ -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 diff --git a/client/src/Try/API.purs b/client/src/Try/API.purs index afe533c6..a4660254 100644 --- a/client/src/Try/API.purs +++ b/client/src/Try/API.purs @@ -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) @@ -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 @@ -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 diff --git a/client/src/Try/Container.js b/client/src/Try/Container.js index 8c26089e..72550304 100644 --- a/client/src/Try/Container.js +++ b/client/src/Try/Container.js @@ -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 = $( + '