Skip to content

Commit 0e57c86

Browse files
committed
feat: migrate to spago@next
1 parent 0778ff9 commit 0e57c86

File tree

7 files changed

+41
-38
lines changed

7 files changed

+41
-38
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,17 @@ jobs:
2727
.spago
2828
output
2929
30+
- name: Setup node and npm
31+
uses: actions/setup-node@v4
32+
with:
33+
cache: npm
34+
cache-dependency-path: "**/package-lock.json"
35+
36+
- name: Install NPM dependencies
37+
run: npm install
38+
3039
- name: Build source
31-
run: spago build --censor-stats --strict --pedantic-packages
40+
run: spago build --censor-stats --strict --ensure-ranges --pedantic-packages
3241

3342
- name: Run tests
3443
run: spago test --offline --censor-stats --strict --pedantic-packages -- --censor-codes=UserDefinedWarning

bower.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,5 @@
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/purescript-contrib/purescript-affjax-node.git"
13-
},
14-
"ignore": [
15-
"**/.*",
16-
"bower_components",
17-
"node_modules",
18-
"output",
19-
"test",
20-
"tmp",
21-
"bower.json",
22-
"gulpfile.js",
23-
"package.json"
24-
]
13+
}
2514
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"scripts": {
4-
"build": "eslint src && spago build --censor-stats --strict --pedantic-packages",
4+
"build": "eslint src && spago build --censor-stats --strict --ensure-ranges --pedantic-packages",
55
"test": "spago test --offline"
66
},
77
"devDependencies": {

spago.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package:
22
name: affjax-node
3+
description: An asynchronous AJAX library built using Aff that runs on Node.js.
34
publish:
45
license: Apache-2.0
56
version: 1.0.0
67
location:
78
githubOwner: purescript-contrib
89
githubRepo: purescript-affjax-node
910
dependencies:
10-
- aff
11-
- affjax
12-
- either
13-
- maybe
14-
- prelude
11+
- aff: ">=8.0.0 <9.0.0"
12+
- affjax: ">=13.0.0 <14.0.0"
13+
- either: ">=6.1.0 <7.0.0"
14+
- maybe: ">=6.0.0 <7.0.0"
15+
- prelude: ">=6.0.1 <7.0.0"
1516
test:
1617
main: Test.Main
1718
dependencies:

src/Affjax/Node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import XHR from "xhr2";
2-
import urllib from "url";
2+
import { URL, format } from "node:url";
33

44
export const driver = {
55
newXHR: function () {
66
return new XHR();
77
},
88
fixupUrl: function (url, xhr) {
99
if (xhr.nodejsBaseUrl === null) {
10-
var u = urllib.parse(url);
10+
var u = new URL(url);
1111
u.protocol = u.protocol || "http:";
1212
u.hostname = u.hostname || "localhost";
13-
return urllib.format(u);
13+
return format(u);
1414
} else {
1515
return url || "/";
1616
}

test/Test/Main.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import express from "express";
22
import bodyParser from "body-parser";
33

4-
import { fileURLToPath } from 'url'
5-
import { dirname } from 'path'
4+
import { fileURLToPath } from 'node:url'
5+
import { dirname } from 'node:path'
66
const __dirname = dirname(fileURLToPath(import.meta.url));
77

88
export function logAny(a) {
@@ -16,24 +16,24 @@ export function startServer(errback, callback) {
1616
var app = express();
1717

1818
// Always make req.body available as a String
19-
app.use(bodyParser.text(function() { return true; }));
19+
app.use(bodyParser.text(function () { return true; }));
2020

2121
app.use(express.static(__dirname));
2222

23-
app.get('/', function (req, res) {
23+
app.get('/', function (_req, res) {
2424
res.send('<html><script src="tmp/test.js"></script></html>');
2525
});
2626

27-
app.get('/arrayview', function(req, res) {
27+
app.get('/arrayview', function (_req, res) {
2828
res.send('TODO');
2929
});
3030

31-
app.get('/not-json', function(req, res) {
32-
res.header({'content-type': 'text/plain'});
31+
app.get('/not-json', function (_req, res) {
32+
res.header({ 'content-type': 'text/plain' });
3333
res.send('This is not JSON');
3434
});
3535

36-
app.all('/mirror', function(req, res) {
36+
app.all('/mirror', function (req, res) {
3737
res.json({
3838
headers: req.headers,
3939
body: req.body,
@@ -42,13 +42,13 @@ export function startServer(errback, callback) {
4242
});
4343
});
4444

45-
app.get('/slow', function(req, res) {
45+
app.get('/slow', function (_req, res) {
4646
var date = Date.now();
4747
var currentDate = null;
4848
do {
4949
currentDate = Date.now();
5050
} while (currentDate - date < 2000);
51-
res.header({'content-type': 'text/plain'});
51+
res.header({ 'content-type': 'text/plain' });
5252
res.send('I hope I am not late!');
5353
});
5454

@@ -59,7 +59,7 @@ export function startServer(errback, callback) {
5959
errback(error);
6060
});
6161

62-
return function (cancelError, onCancelerError, onCancelerSuccess) {
62+
return function (_cancelError, _onCancelerError, onCancelerSuccess) {
6363
onCancelerSuccess();
6464
};
6565
}
@@ -70,7 +70,7 @@ export function stopServer(server) {
7070
if (err) errback(err);
7171
else callback();
7272
});
73-
return function (cancelError, onCancelerError, onCancelerSuccess) {
73+
return function (_cancelError, _onCancelerError, onCancelerSuccess) {
7474
onCancelerSuccess();
7575
};
7676
};

test/Test/Main.purs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ main = void $ runAff (either (\e -> logShow e *> throwException e) (const $ log
100100
assertEq (Just "PUT") (J.toString =<< FO.lookup "method" =<< J.toObject res.body)
101101
assertEq (Just content) (J.toString =<< FO.lookup "body" =<< J.toObject res.body)
102102

103-
A.log "Testing CORS, HTTPS"
104-
AN.get ResponseFormat.json "https://cors-test.appspot.com/test" >>= assertRight >>= \res -> do
105-
assertEq ok200 res.status
106-
107103
A.log "Testing cancellation"
108104
forkAff (AN.post_ mirror (Just (RequestBody.string "do it now"))) >>= killFiber (error "Pull the cord!")
109105
assertMsg "Should have been canceled" true
106+
107+
A.log "Testing CORS, HTTPS"
108+
-- IF error `Unexpected token '<', "\n<html><hea"... is not valid JSON` THEN
109+
-- Error: Server Error
110+
-- The service you requested is not available yet.
111+
-- Please try again in 30 seconds.
112+
AN.get ResponseFormat.json "https://cors-test.appspot.com/test" >>= assertRight >>= \res -> do
113+
assertEq ok200 res.status

0 commit comments

Comments
 (0)