Skip to content

Commit 3eaf663

Browse files
committed
CI rehab
* Tests terminate. Use __spec__ for tests. Upgrade `ci.yml`. * Add `spago.dhall` and `spago.dev.dhall`. * New function `HTTP.onRequest`.
1 parent 9baab9d commit 3eaf663

File tree

14 files changed

+335
-188
lines changed

14 files changed

+335
-188
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,34 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v2
1414

15-
- uses: purescript-contrib/setup-purescript@main
15+
- name: Set up a PureScript toolchain
16+
uses: purescript-contrib/setup-purescript@main
1617
with:
1718
purescript: "unstable"
19+
purs-tidy: "0.9.0"
1820

19-
- uses: actions/setup-node@v2
21+
- name: Cache PureScript dependencies
22+
uses: actions/cache@v2
2023
with:
21-
node-version: "14"
22-
24+
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
25+
path: |
26+
.spago
27+
output
2328
- name: Install dependencies
24-
run: |
25-
npm install -g bower
26-
npm install
27-
bower install --production
29+
run: spago install
2830

2931
- name: Build source
30-
run: npm run-script build
32+
run: spago build --no-install --purs-args '--censor-lib --strict'
33+
34+
- name: Install test dependencies
35+
run: spago -x spago.dev.dhall install
36+
37+
- name: Build tests
38+
run: spago -x spago.dev.dhall build --no-install --purs-args '--censor-lib --strict'
3139

3240
- name: Run tests
33-
run: |
34-
bower install
35-
npm run-script test --if-present
41+
run: spago -x spago.dev.dhall test --no-install
42+
43+
- name: Check formatting
44+
run: purs-tidy check src test
45+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/node_modules/
77
/output/
88
package-lock.json
9+
generated-docs/

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Breaking changes:
88

99
New features:
1010

11+
- Use __spec__ for tests. Upgraded `ci.yml`. Solves #35. (#47 by @jamesdbrock)
12+
- New function `HTTP.onRequest`. Solves #46. (#47 by @jamesdbrock)
13+
1114
Bugfixes:
1215

1316
Other improvements:
@@ -32,7 +35,7 @@ New features:
3235
Other improvements:
3336
- Migrated CI to GitHub Actions, updated installation instructions to use Spago, and migrated from `jshint` to `eslint` (#30)
3437
- Added a changelog and pull request template (#34)
35-
38+
3639
## [v5.0.2](https://github.com/purescript-node/purescript-node-http/releases/tag/v5.0.2) - 2019-07-24
3740

3841
- Relaxed upper bounds on `node-buffer`

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@
44
[![Build status](https://github.com/purescript-node/purescript-node-http/workflows/CI/badge.svg?branch=master)](https://github.com/purescript-node/purescript-node-http/actions?query=workflow%3ACI+branch%3Amaster)
55
[![Pursuit](https://pursuit.purescript.org/packages/purescript-node-http/badge)](https://pursuit.purescript.org/packages/purescript-node-http)
66

7-
A wrapper for Node's HTTP APIs.
7+
A wrapper for Node’s [HTTP](https://nodejs.org/docs/latest/api/http.html) API.
88

99
## Installation
1010

1111
```
1212
spago install node-http
1313
```
1414

15+
16+
## Test
17+
18+
```
19+
spago -x spago.dev.dhall test
20+
```
21+
1522
## Documentation
1623

1724
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-node-http).
25+

bower.json

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
{
2-
"name": "purescript-node-http",
3-
"license": "MIT",
4-
"ignore": [
5-
"**/.*",
6-
"node_modules",
7-
"bower_components",
8-
"output"
9-
],
10-
"repository": {
11-
"type": "git",
12-
"url": "https://github.com/purescript-node/purescript-node-http.git"
13-
},
14-
"devDependencies": {
15-
"purescript-console": "^6.0.0"
16-
},
17-
"dependencies": {
18-
"purescript-arraybuffer-types": "^3.0.2",
19-
"purescript-contravariant": "^6.0.0",
20-
"purescript-effect": "^4.0.0",
21-
"purescript-foreign": "^7.0.0",
22-
"purescript-foreign-object": "^4.0.0",
23-
"purescript-maybe": "^6.0.0",
24-
"purescript-node-buffer": "^8.0.0",
25-
"purescript-node-net": "^4.0.0",
26-
"purescript-node-streams": "^7.0.0",
27-
"purescript-node-url": "^6.0.0",
28-
"purescript-nullable": "^6.0.0",
29-
"purescript-options": "^7.0.0",
30-
"purescript-prelude": "^6.0.0",
31-
"purescript-unsafe-coerce": "^6.0.0"
32-
}
2+
"name": "purescript-node-http",
3+
"license": [
4+
"MIT"
5+
],
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/purescript-node/purescript-node-http"
9+
},
10+
"ignore": [
11+
"**/.*",
12+
"node_modules",
13+
"bower_components",
14+
"output"
15+
],
16+
"dependencies": {
17+
"purescript-arraybuffer-types": "^v3.0.2",
18+
"purescript-contravariant": "^v6.0.0",
19+
"purescript-effect": "^v4.0.0",
20+
"purescript-foreign": "^v7.0.0",
21+
"purescript-foreign-object": "^v4.1.0",
22+
"purescript-maybe": "^v6.0.0",
23+
"purescript-node-buffer": "^v8.0.0",
24+
"purescript-node-net": "^v4.0.0",
25+
"purescript-node-streams": "^v7.0.0",
26+
"purescript-node-url": "^v6.0.0",
27+
"purescript-nullable": "^v6.0.0",
28+
"purescript-options": "^v7.0.0",
29+
"purescript-prelude": "^v6.0.1",
30+
"purescript-unsafe-coerce": "^v6.0.0"
31+
}
3332
}

packages.dhall

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let upstream =
2+
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221102/packages.dhall
3+
sha256:8628e413718876ce26983db1d0ce9d9e1588129117fa3bb8ed9f618db6914127
4+
5+
in upstream

spago.dev.dhall

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Spago configuration for testing.
2+
3+
let conf = ./spago.dhall
4+
5+
in conf //
6+
{ sources = [ "src/**/*.purs", "test/**/*.purs" ]
7+
, dependencies = conf.dependencies #
8+
[ "aff"
9+
, "console"
10+
, "either"
11+
, "exceptions"
12+
, "foldable-traversable"
13+
, "node-process"
14+
, "parallel"
15+
, "partial"
16+
, "spec"
17+
, "tuples"
18+
]
19+
}

spago.dhall

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ name = "node-http"
2+
, dependencies =
3+
[ "arraybuffer-types"
4+
, "contravariant"
5+
, "effect"
6+
, "foreign"
7+
, "foreign-object"
8+
, "maybe"
9+
, "node-buffer"
10+
, "node-net"
11+
, "node-streams"
12+
, "node-url"
13+
, "nullable"
14+
, "options"
15+
, "prelude"
16+
, "unsafe-coerce"
17+
]
18+
, packages = ./packages.dhall
19+
, sources = [ "src/**/*.purs" ]
20+
, license = "MIT"
21+
, repository = "https://github.com/purescript-node/purescript-node-http"
22+
}

src/Node/HTTP.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ export function onUpgrade(server) {
6464
};
6565
}
6666

67+
export function onRequest(server) {
68+
return function (cb) {
69+
return function () {
70+
server.on("request", function (req, res) {
71+
return cb(req)(res)();
72+
});
73+
};
74+
};
75+
}
76+
6777
export function setHeader(res) {
6878
return function (key) {
6979
return function (value) {

src/Node/HTTP.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Node.HTTP
1212
, listenSocket
1313
, onConnect
1414
, onUpgrade
15+
, onRequest
1516

1617
, httpVersion
1718
, requestHeaders
@@ -77,6 +78,9 @@ foreign import onConnect :: Server -> (Request -> Socket -> Buffer -> Effect Uni
7778
-- | Listen to `upgrade` events on the server
7879
foreign import onUpgrade :: Server -> (Request -> Socket -> Buffer -> Effect Unit) -> Effect Unit
7980

81+
-- | Listen to `request` events on the server
82+
foreign import onRequest :: Server -> (Request -> Response -> Effect Unit) -> Effect Unit
83+
8084
-- | Get the request HTTP version
8185
httpVersion :: Request -> String
8286
httpVersion = _.httpVersion <<< unsafeCoerce

0 commit comments

Comments
 (0)