Skip to content
Merged
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
49 changes: 31 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,66 @@
name: CI

# Run CI when a PR is opened against the branch `main`
# and when one pushes a commit to `main`.
# Run CI when a PR is opened against the branch `master`
# and when one pushes a commit to `master`.
on:
push:
branches: [master]
pull_request:
branches: [master]

# Run CI on all 3 latest OSes
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

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

- uses: purescript-contrib/setup-purescript@main
- name: Set up Node toolchain
uses: actions/setup-node@v3
with:
purescript: "0.15.7"
purs-tidy: "0.9.2"
psa: "0.8.2"
spago: "0.20.9"
psa: "0.7.2"
node-version: "16"

- name: Cache NPM dependencies
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Setup PureScript tooling
run:
npm i -g purescript@latest purs-tidy@latest purescript-psa@latest spago@latest

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

- name: Set up Node toolchain
uses: actions/setup-node@v2
with:
node-version: "16"

# Compile the library/project
# censor-lib: ignore warnings emitted by dependencies
# strict: convert warnings into errors
# Note: `purs-args` actually forwards these args to `psa`
- name: Build the project
run: |
spago build --purs-args "--censor-lib --strict"
npx spago build --purs-args "--censor-lib --strict"

- name: Run tests
run: |
spago test
npx spago -x test.dhall test

- name: Check Formatting
if: runner.os == 'Linux'
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 @@ -8,3 +8,4 @@
/.purs*
/.psa*
/.spago
/.vscode
4 changes: 2 additions & 2 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ name = "node-event-emitters"
, dependencies =
[ "effect"
, "either"
, "functions"
, "prelude"
, "safe-coerce"
, "unsafe-coerce"
, "unsafe-coerce"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
Expand Down
47 changes: 18 additions & 29 deletions src/Node/EventEmitter.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
import events from "node:events";
import EventEmitter from "node:events";

const newImpl = function () {
return new events.EventEmitter();
return new EventEmitter();
}
export { newImpl as new };

export function listenersLengthImpl(emitter, event) {
return emitter.listeners(event).length;
}

export function setMaxListenersImpl(emitter, max) {
emitter.setMaxListeners(max);
}

export function onImpl(emitter, eventName, cb) {
emitter.on(eventName, cb);
return cb;
}
// addEventListener - not implemented; alias to `on`
export const unsafeEmitFn = (emitter) => emitter.emit.bind(emitter);
export const eventNamesImpl = (emitter) => emitter.eventNames();
export const symbolOrStr = (left, right, sym) => typeof sym == "symbol" ? left(sym) : right(sym);
export const getMaxListenersImpl = (emitter) => emitter.getMaxListeners();
export const listenerCountImpl = (emitter, eventName) => emitter.listenerCount(eventName);
// listeners - not implemented; returned functions cannot be used in type-safe way.
export const unsafeOff = (emitter, eventName, cb) => emitter.off(eventName, cb);
export const unsafeOn = (emitter, eventName, cb) => emitter.on(eventName, cb);
export const unsafeOnce = (emitter, eventName, cb) => emitter.once(eventName, cb);
export const unsafePrependListener = (emitter, eventName, cb) => emitter.prependListener(eventName, cb);
export const unsafePrependOnceListener = (emitter, eventName, cb) => emitter.prependOnceListener(eventName, cb);
// removeAllListeners - not implemented; bad practice
// removeEventListener - not implemented; alias to `off`
export const setMaxListenersImpl = (emitter, max) => emitter.setMaxListeners(max);
// rawListeners - not implemented; returned functions cannot be used in type-safe way.

export function offImpl(emitter, eventName, cb) {
emitter.off(eventName, cb);
}

export function onceEventListener(emitter, eventName, cb) {
emitter.once(eventName, cb);
}

export function emitImpl(emitter, eventName) {
return function (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
emitter.emit(eventName, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
};
}
const undefined_ = undefined
export { undefined_ as undefined }
Loading