diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f33f26a8..9b2fed49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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' diff --git a/.gitignore b/.gitignore index eb1860a6..a7fcc9b6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ cabal.sandbox.config *.lksh* bundle/ client/public/js/output +client/client.js diff --git a/CHANGELOG.md b/CHANGELOG.md index ff1ae5d5..e9e5b019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/client/package.json b/client/package.json index c9cf67ad..ac057b9b 100644 --- a/client/package.json +++ b/client/package.json @@ -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" } } diff --git a/client/packages.dhall b/client/packages.dhall index 75331a36..c1888031 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.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 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/spago.dhall b/client/spago.dhall index d8c65090..44a9bbdf 100644 --- a/client/spago.dhall +++ b/client/spago.dhall @@ -3,14 +3,15 @@ [ "ace" , "aff" , "affjax" + , "affjax-web" , "argonaut-codecs" + , "argonaut-core" , "arrays" , "assert" , "bifunctors" , "console" - , "const" , "control" - , "debug" + , "datetime" , "effect" , "either" , "exceptions" @@ -18,26 +19,25 @@ , "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 diff --git a/client/src/Main.purs b/client/src/Main.purs index 8c3d781c..2ba63761 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 = void $ launchAff_ do body <- HA.awaitBody - runUI Container.component unit body + void $ runUI Container.component unit body diff --git a/client/src/Try/API.purs b/client/src/Try/API.purs index afe533c6..4de89e3d 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 $ "- Expected a value of `OtherError` or `CompilerErrors` but got '" <> 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 = $( + '