diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c246b03e..f33f26a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,12 +72,6 @@ jobs: npm run build npm run test npm run build:production - if [ "/output/ignored/" != "$(cat public/frame.html | grep '/\1/;')" ]; then - echo "client/public/frame.html's 'base' element refers to the wrong path" - echo "Run 'npm run base:production' in the 'client' dir, and push the update as a commit" - echo "CI will fail until then" - exit 1 - fi - name: Build client assets if: github.event_name == 'release' diff --git a/README.md b/README.md index 6dfe478c..feee89b0 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,6 @@ npm install # Use `build:production` and `base:production` if you would like # to test the client against the production Try PureScript server. npm run build:(dev|production) -npm run base:(dev|production) npm run serve # Try PureScript is now available on localhost:8080 ``` diff --git a/client/config/dev/Try.Config.purs b/client/config/dev/Try.Config.purs index 598d3358..b3551a5c 100644 --- a/client/config/dev/Try.Config.purs +++ b/client/config/dev/Try.Config.purs @@ -2,6 +2,9 @@ module Try.Config where import Prelude +loaderUrl :: String +loaderUrl = "/js/output" + compileUrl :: String compileUrl = "http://localhost:8081" diff --git a/client/config/prod/Try.Config.purs b/client/config/prod/Try.Config.purs index 9a353f08..936b4b10 100644 --- a/client/config/prod/Try.Config.purs +++ b/client/config/prod/Try.Config.purs @@ -2,6 +2,9 @@ module Try.Config where import Prelude +loaderUrl :: String +loaderUrl = "https://compile.purescript.org/output" + compileUrl :: String compileUrl = "https://compile.purescript.org" diff --git a/client/package.json b/client/package.json index 7a325df7..c9cf67ad 100644 --- a/client/package.json +++ b/client/package.json @@ -3,15 +3,13 @@ "private": true, "scripts": { "clean": "rimraf output", - "base:dev": "node setBase.mjs \"dev\"", - "base:production": "node setBase.mjs \"prod\"", "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", "serve": "http-server public/ -o / --cors=\"Access-Control-Allow-Origin: *\" -c-1", - "serve:dev": "npm run build:dev && npm run base:dev && npm run serve", - "serve:production": "npm run build:production && npm run base:production && npm run serve" + "serve:dev": "npm run build:dev && npm run serve", + "serve:production": "npm run build:production && npm run serve" }, "devDependencies": { "http-server": "^14.1.0", diff --git a/client/public/frame.html b/client/public/frame.html index 6b91dc85..86297e67 100644 --- a/client/public/frame.html +++ b/client/public/frame.html @@ -5,8 +5,6 @@ - - - +
diff --git a/client/public/js/frame.js b/client/public/js/frame.js index 0efe6dfe..2f277b67 100644 --- a/client/public/js/frame.js +++ b/client/public/js/frame.js @@ -5,10 +5,7 @@ window.addEventListener("message", function(event) { parent = event.source; parent.postMessage("trypurescript", "*"); - const code = ` - ${event.data.code} - main(); - `; + const code = event.data.code; const scriptEl = document.createElement("script"); scriptEl.type = "module"; scriptEl.appendChild(document.createTextNode(code)); diff --git a/client/setBase.mjs b/client/setBase.mjs deleted file mode 100644 index 25583195..00000000 --- a/client/setBase.mjs +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node - -import path from "path"; -import fs from "fs"; -import process from "process"; - -const filePath = path.join("public", "frame.html"); - -// PureScript generates JS with the following import lines: -// `import * as Data_Foo from "../Data.Foo/index.js" -// To remap `../Data.Foo/index.js` to `output/Data.Foo/index.js` -// we append `/ignored/`. -// -// This: `/output/ignored/../Data.Foo/index.js` -// becomes: `/output/Data.Foo/index.js` -const prodPath = "/output/ignored/" -const devPath = "/js/output/ignored/" - -const environment = process.argv[2] || "dev"; -const baseHref = environment === "prod" ? prodPath : devPath; - -const frameHtml = fs.readFileSync(filePath, "utf-8"); -const newHtml = frameHtml - .split("\n") - .map((line) => line.replace(/^( * unsafeCrashWith "Invalid regex") identity + $ Regex.regex """^import (.+) from "../([^"]+)";$""" RegexFlags.noFlags + replacement = "import $1 from \"" <> Config.loaderUrl <> "/$2\";" + codeWithRemappedImports = js + # String.split (Pattern "\n") + # map (Regex.replace importRegex replacement) + # String.joinWith "\n" + + -- Actually call the `main` function + eventData = { code: codeWithRemappedImports <> "\n\n" <> "main();" } H.liftEffect teardownIFrame H.liftAff $ makeAff \f -> do runEffectFn3 setupIFrame eventData (f (Right unit)) (f (Left $ Aff.error "Could not load iframe")) diff --git a/deploy/nginx.conf b/deploy/nginx.conf index 5e9d0265..606f317e 100644 --- a/deploy/nginx.conf +++ b/deploy/nginx.conf @@ -86,6 +86,6 @@ server { # match to ensure that we only serve JS files. location ~ ^/output/(.+\.js)$ { add_header Access-Control-Allow-Origin *; - alias /var/www/trypurescript/staging/.psci_modules/node_modules/$1; + alias /var/www/trypurescript/staging/.psci_modules/$1; } }