Skip to content

Commit bff7cd5

Browse files
committed
feat: upgrade to spago@next
1 parent f53a865 commit bff7cd5

14 files changed

+197
-74
lines changed

.eslintrc.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,53 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12-
1312
steps:
14-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1514

16-
- name: Set up PureScript toolchain
15+
- name: Set up a PureScript toolchain
1716
uses: purescript-contrib/setup-purescript@main
1817
with:
19-
purescript: "unstable"
18+
purescript: "latest"
2019
purs-tidy: "latest"
20+
spago: "unstable"
2121

2222
- name: Cache PureScript dependencies
23-
uses: actions/cache@v2
23+
uses: actions/cache@v4
2424
with:
25-
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
25+
key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}
2626
path: |
2727
.spago
2828
output
2929
3030
- name: Set up Node toolchain
31-
uses: actions/setup-node@v2
32-
with:
33-
node-version: "12.x"
31+
uses: actions/setup-node@v4
3432

3533
- name: Cache NPM dependencies
36-
uses: actions/cache@v2
34+
uses: actions/cache@v4
3735
env:
3836
cache-name: cache-node-modules
3937
with:
4038
path: ~/.npm
41-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
39+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
4240
restore-keys: |
4341
${{ runner.os }}-build-${{ env.cache-name }}-
4442
${{ runner.os }}-build-
4543
${{ runner.os }}-
4644
45+
- uses: browser-actions/setup-chrome@v1
46+
id: setup-chrome
47+
4748
- name: Install NPM dependencies
4849
run: npm install
4950

50-
- name: Build the project
51-
run: npm run build
51+
- name: Build source
52+
run: spago build --censor-stats --strict --pedantic-packages
5253

5354
- name: Run tests
54-
run: npm run test
55-
56-
- name: Check formatting
5755
run: |
58-
npx eslint src
59-
purs-tidy check src
56+
${{ steps.setup-chrome.outputs.chrome-path }} --version
57+
npm run build
58+
mocha-headless-chrome --file dist/index.html --args disable-web-security --args no-sandbox --timeout 9999999 --executablePath ${{ steps.setup-chrome.outputs.chrome-path }}
6059
61-
- name: Verify Bower & Pulp
62-
run: |
63-
npm install bower [email protected]
64-
npx bower install
65-
npx pulp build -- --censor-lib --strict
66-
if [ -d "test" ]; then
67-
npx pulp test
68-
fi
60+
- name: Verify formatting
61+
run: purs-tidy check src test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ bower_components
1212
node_modules
1313
package-lock.json
1414
*.lock
15+
dist/*

bower.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,5 @@
2121
"bower.json",
2222
"gulpfile.js",
2323
"package.json"
24-
],
25-
"dependencies": {
26-
"purescript-affjax": "^13.0.0"
27-
},
28-
"devDependencies": {
29-
"purescript-psci-support": "^6.0.0"
30-
}
24+
]
3125
}

browser/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Mocha Tests</title>
8+
<link rel="stylesheet" href="node_modules/mocha/mocha.css" />
9+
<script type="module" src="node_modules/mocha/mocha.js"></script>
10+
</head>
11+
12+
<body>
13+
<div id="mocha"></div>
14+
<script type="module" src="./index.js"></script>
15+
</body>
16+
17+
</html>

browser/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* global mocha, describe, it */
2+
//
3+
// cannot import commonjs, added
4+
// <script type="module" src="node_modules/mocha/mocha.js"></script>
5+
//
6+
// import mocha from "mocha"
7+
// import mocha from "mocha/browser-entry.js"
8+
// import "mocha"
9+
10+
import { main } from 'PureScript/Test.Main/index.js'
11+
12+
mocha.setup("bdd");
13+
main();
14+
mocha.run();

eslint.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
4+
5+
export default [
6+
{languageOptions: { globals: globals.browser }},
7+
pluginJs.configs.recommended,
8+
];

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
{
22
"private": true,
3+
"browserslist": "defaults, not ie <= 11",
34
"scripts": {
4-
"build": "eslint src && spago build --purs-args '--censor-lib --strict'"
5+
"test:watch": "watchexec -e purs,js,yaml,rb -- spago bundle --outfile output/bundle.js --module Test.Main && mocha output/bundle.js",
6+
"clean": "rm -rfd output output-es .spago dist",
7+
"build": "rm -rdf dist && eslint src && spago build --censor-stats --strict --pedantic-packages && vite build",
8+
"format": "purs-tidy format-in-place src test",
9+
"check": "purs-tidy check src test",
10+
"test": "spago test",
11+
"update-docs": "spago docs --format markdown",
12+
"production:build": "spago build && purs-backend-es build && vite build",
13+
"production:preview": "vite preview --open",
14+
"dev:vite": "vite dev --open",
15+
"dev:spago": "watchexec -e purs,js,yaml -- spago build"
516
},
617
"devDependencies": {
7-
"eslint": "^7.6.0"
18+
"@eslint/js": "^9.12.0",
19+
"eslint": "^9.12.0",
20+
"globals": "^15.11.0",
21+
"mocha": "^10.7.3",
22+
"mocha-headless-chrome": "^4.0.0",
23+
"parcel": "^2.12.0",
24+
"vite": "^5.4.0"
825
}
926
}

packages.dhall

Lines changed: 0 additions & 4 deletions
This file was deleted.

run_tests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
npm run build
6+
7+
mocha-headless-chrome --file dist/index.html --out output/test-output-headless.txt --args disable-web-security --args no-sandbox --executablePath chromium --visible --timeout 9999999
8+
9+
# or open to debug
10+
#
11+
# chromium --disable-web-security --no-sandbox --disable-gpu --args --allow-file-access-from-files --user-data-dir=/tmp/chrome_dev_test dist/index.html

spago.dhall

Lines changed: 0 additions & 5 deletions
This file was deleted.

spago.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package:
2+
name: affjax-web
3+
publish:
4+
license: Apache-2.0
5+
version: 1.0.0
6+
location:
7+
githubOwner: purescript-contrib
8+
githubRepo: purescript-affjax-web
9+
dependencies:
10+
- aff
11+
- affjax
12+
- either
13+
- maybe
14+
- prelude
15+
test:
16+
main: Test.Main
17+
dependencies:
18+
- console
19+
- effect
20+
- exceptions
21+
- spec
22+
- spec-mocha
23+
- transformers
24+
- unsafe-coerce
25+
workspace:
26+
extraPackages: {}
27+
packageSet:
28+
registry: 60.5.0

test/Test/Main.purs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module Test.Main where
2+
3+
import Prelude
4+
5+
import Affjax.ResponseFormat as ResponseFormat
6+
import Affjax.Web as AX
7+
import Control.Monad.Error.Class (throwError)
8+
import Data.Either (Either(..))
9+
import Effect (Effect)
10+
import Effect.Aff (Aff)
11+
import Effect.Class (class MonadEffect)
12+
import Effect.Class.Console (log)
13+
import Effect.Exception (error)
14+
import Test.Spec (it)
15+
import Test.Spec.Assertions (fail)
16+
import Test.Spec.Mocha (runMocha)
17+
import Unsafe.Coerce (unsafeCoerce)
18+
19+
logAny' :: forall a m. MonadEffect m => a -> m Unit
20+
logAny' = log <<< unsafeCoerce
21+
22+
assertRight :: forall a b. Either a b -> Aff b
23+
assertRight = case _ of
24+
Left y -> logAny' y *> throwError (error "Expected a Right value")
25+
Right y -> pure y
26+
27+
assertLeft :: forall a b. Either a b -> Aff a
28+
assertLeft x = case x of
29+
Right y -> logAny' y *> throwError (error "Expected a Left value")
30+
Left y -> pure y
31+
32+
main :: Effect Unit
33+
main = runMocha do
34+
it "Testing invalid url" do
35+
res <- AX.get ResponseFormat.string "/фіва шхххх"
36+
assertLeft res >>= case _ of
37+
AX.RequestFailedError -> pure unit
38+
other -> logAny' other *> fail "Expected a RequestFailedError"

vite.config.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as path from "node:path";
2+
// import * as fs from 'node:fs'
3+
// import * as yaml from 'js-yaml'
4+
5+
// Read and parse the YAML file
6+
// const spagoYamlFilePath = path.resolve(__dirname, 'spago.yaml');
7+
// const spagoYamlFileContent = fs.readFileSync(spagoYamlFilePath, 'utf8');
8+
// const data = yaml.load(spagoYamlFileContent);
9+
10+
export default {
11+
// Why base is empty?
12+
//
13+
// if undefined - it outputs
14+
//
15+
// <script type="module" crossorigin src="/assets/index-gxVfuqPj.js"></script>
16+
// <link rel="stylesheet" crossorigin href="/assets/index-CyNfkOrK.css" />
17+
//
18+
// if "" - changes to relative paths
19+
//
20+
// <script type="module" crossorigin src="./assets/index-gxVfuqPj.js"></script>
21+
// <link rel="stylesheet" crossorigin href="./assets/index-CyNfkOrK.css" />
22+
// base: `/${data.package.publish.location.githubRepo}/`,
23+
base: ``,
24+
25+
root: path.resolve(__dirname, "browser"),
26+
build: {
27+
outDir: path.resolve(__dirname, "dist"),
28+
minify: false, // for debug
29+
emptyOutDir: true, // prevent `outDir .../dist is not inside project root and will not be emptied.`
30+
},
31+
// mode: 'development', // still be minimified, option used if You want to `vite dev` (with a watching)
32+
resolve: {
33+
alias: {
34+
// PureScript: process.env.NODE_ENV === "production"
35+
// ? path.resolve(__dirname, "output-es")
36+
// : path.resolve(__dirname, "output"),
37+
node_modules: path.resolve(__dirname, "node_modules"),
38+
PureScript: path.resolve(__dirname, "output"),
39+
},
40+
}
41+
};

0 commit comments

Comments
 (0)