Skip to content

feat: migrate to spago@next #6

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 0 additions & 30 deletions .eslintrc.json

This file was deleted.

43 changes: 18 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,29 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up PureScript toolchain
- name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
purescript: "latest"
purs-tidy: "latest"
spago: "unstable"

- name: Cache PureScript dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}
path: |
.spago
output

- name: Set up Node toolchain
uses: actions/setup-node@v2
with:
node-version: "12.x"
uses: actions/setup-node@v4

- name: Cache NPM dependencies
uses: actions/cache@v2
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
Expand All @@ -44,25 +42,20 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-

- uses: browser-actions/setup-chrome@v1
id: setup-chrome

- name: Install NPM dependencies
run: npm install

- name: Build the project
run: npm run build
- name: Build source
run: spago build --censor-stats --strict --ensure-ranges --pedantic-packages

- name: Run tests
run: npm run test

- name: Check formatting
run: |
npx eslint src
purs-tidy check src
${{ steps.setup-chrome.outputs.chrome-path }} --version
npm run build
npx mocha-headless-chrome --file dist/index.html --args disable-web-security --args no-sandbox --timeout 9999999 --executablePath ${{ steps.setup-chrome.outputs.chrome-path }}

- name: Verify Bower & Pulp
run: |
npm install bower [email protected]
npx bower install
npx pulp build -- --censor-lib --strict
if [ -d "test" ]; then
npx pulp test
fi
- name: Verify formatting
run: purs-tidy check src test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ bower_components
node_modules
package-lock.json
*.lock
dist/*
31 changes: 0 additions & 31 deletions bower.json

This file was deleted.

17 changes: 17 additions & 0 deletions browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mocha Tests</title>
<link rel="stylesheet" href="node_modules/mocha/mocha.css" />
<script type="module" src="node_modules/mocha/mocha.js"></script>
</head>

<body>
<div id="mocha"></div>
<script type="module" src="./index.js"></script>
</body>

</html>
14 changes: 14 additions & 0 deletions browser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* global mocha, describe, it */
//
// cannot import commonjs, added
// <script type="module" src="node_modules/mocha/mocha.js"></script>
//
// import mocha from "mocha"
// import mocha from "mocha/browser-entry.js"
// import "mocha"

import { main } from 'PureScript/Test.Main/index.js'

mocha.setup("bdd");
main();
mocha.run();
8 changes: 8 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import globals from "globals";
import pluginJs from "@eslint/js";


export default [
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
];
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
{
"private": true,
"browserslist": "defaults, not ie <= 11",
"scripts": {
"build": "eslint src && spago build --purs-args '--censor-lib --strict'"
"test:watch": "watchexec -e purs,js,yaml,rb -- spago bundle --outfile output/bundle.js --module Test.Main && mocha output/bundle.js",
"clean": "rm -rfd output output-es .spago dist",
"build": "rm -rdf dist && eslint src && spago build --censor-stats --strict --ensure-ranges --pedantic-packages && vite build",
"format": "purs-tidy format-in-place src test",
"check": "purs-tidy check src test",
"test": "spago test",
"update-docs": "spago docs --format markdown",
"production:build": "spago build && purs-backend-es build && vite build",
"production:preview": "vite preview --open",
"dev:vite": "vite dev --open",
"dev:spago": "watchexec -e purs,js,yaml -- spago build"
},
"devDependencies": {
"eslint": "^7.6.0"
"@eslint/js": "^9.12.0",
"eslint": "^9.12.0",
"globals": "^15.11.0",
"mocha": "^10.7.3",
"mocha-headless-chrome": "^4.0.0",
"vite": "^5.4.0"
}
}
4 changes: 0 additions & 4 deletions packages.dhall

This file was deleted.

11 changes: 11 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

npm run build

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

# or open to debug
#
# chromium --disable-web-security --no-sandbox --disable-gpu --args --allow-file-access-from-files --user-data-dir=/tmp/chrome_dev_test dist/index.html
5 changes: 0 additions & 5 deletions spago.dhall

This file was deleted.

26 changes: 26 additions & 0 deletions spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package:
name: affjax-web
description: An asynchronous AJAX library built using Aff that runs on the browser.
publish:
license: Apache-2.0
version: 2.0.0
location:
githubOwner: purescript-contrib
githubRepo: purescript-affjax-web
dependencies:
- aff: ">=8.0.0 <9.0.0"
- affjax: ">=13.0.0 <14.0.0"
- either: ">=6.1.0 <7.0.0"
- maybe: ">=6.0.0 <7.0.0"
- prelude: ">=6.0.1 <7.0.0"
test:
main: Test.Main
dependencies:
- console
- effect
- exceptions
- spec
- spec-mocha
- transformers
- unsafe-coerce
workspace: {}
38 changes: 38 additions & 0 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Test.Main where

import Prelude

import Affjax.ResponseFormat as ResponseFormat
import Affjax.Web as AX
import Control.Monad.Error.Class (throwError)
import Data.Either (Either(..))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (class MonadEffect)
import Effect.Class.Console (log)
import Effect.Exception (error)
import Test.Spec (it)
import Test.Spec.Assertions (fail)
import Test.Spec.Mocha (runMocha)
import Unsafe.Coerce (unsafeCoerce)

logAny' :: forall a m. MonadEffect m => a -> m Unit
logAny' = log <<< unsafeCoerce

assertRight :: forall a b. Either a b -> Aff b
assertRight = case _ of
Left y -> logAny' y *> throwError (error "Expected a Right value")
Right y -> pure y

assertLeft :: forall a b. Either a b -> Aff a
assertLeft x = case x of
Right y -> logAny' y *> throwError (error "Expected a Left value")
Left y -> pure y

main :: Effect Unit
main = runMocha do
it "Testing invalid url" do
res <- AX.get ResponseFormat.string "/фіва шхххх"
assertLeft res >>= case _ of
AX.RequestFailedError -> pure unit
other -> logAny' other *> fail "Expected a RequestFailedError"
41 changes: 41 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as path from "node:path";
// import * as fs from 'node:fs'
// import * as yaml from 'js-yaml'

// Read and parse the YAML file
// const spagoYamlFilePath = path.resolve(__dirname, 'spago.yaml');
// const spagoYamlFileContent = fs.readFileSync(spagoYamlFilePath, 'utf8');
// const data = yaml.load(spagoYamlFileContent);

export default {
// Why base is empty?
//
// if undefined - it outputs
//
// <script type="module" crossorigin src="/assets/index-gxVfuqPj.js"></script>
// <link rel="stylesheet" crossorigin href="/assets/index-CyNfkOrK.css" />
//
// if "" - changes to relative paths
//
// <script type="module" crossorigin src="./assets/index-gxVfuqPj.js"></script>
// <link rel="stylesheet" crossorigin href="./assets/index-CyNfkOrK.css" />
// base: `/${data.package.publish.location.githubRepo}/`,
base: ``,

root: path.resolve(__dirname, "browser"),
build: {
outDir: path.resolve(__dirname, "dist"),
minify: false, // for debug
emptyOutDir: true, // prevent `outDir .../dist is not inside project root and will not be emptied.`
},
// mode: 'development', // still be minimified, option used if You want to `vite dev` (with a watching)
resolve: {
alias: {
// PureScript: process.env.NODE_ENV === "production"
// ? path.resolve(__dirname, "output-es")
// : path.resolve(__dirname, "output"),
node_modules: path.resolve(__dirname, "node_modules"),
PureScript: path.resolve(__dirname, "output"),
},
}
};
Loading