From b40025a07f427df8fc47847aeae919a778c0b33d Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Tue, 22 Mar 2022 17:41:14 +0000 Subject: [PATCH] Update to PureScript v0.15.0 (#39) * ESM conversion * ES6 transformations * Removed '"use strict";' in FFI files * Update to CI to use 'unstable' purescript * Update Bower dependencies to master or main * Update pulp to 16.0.0-0 * Update psa to 0.8.2 * Update Bower dependencies to master or main * Update ci.yml to v2 * Add changelog entry Co-authored-by: Nicholas Wolverson --- .github/workflows/ci.yml | 6 +- CHANGELOG.md | 1 + bower.json | 16 +-- package.json | 4 +- src/Node/Stream.js | 285 +++++++++++++++------------------------ test/Main.js | 47 +++---- 6 files changed, 145 insertions(+), 214 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 063845e..06ed895 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,10 +13,12 @@ jobs: - uses: actions/checkout@v2 - uses: purescript-contrib/setup-purescript@main + with: + purescript: "unstable" - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: "10" + node-version: "14" - name: Install dependencies run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index fa592c0..a9b6757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: +- Update project and deps to PureScript v0.15.0 (#39 by @nwolverson, @JordanMartinez, @sigma-andex) New features: diff --git a/bower.json b/bower.json index e9a420c..42d9e4c 100644 --- a/bower.json +++ b/bower.json @@ -12,15 +12,15 @@ "url": "https://github.com/purescript-node/purescript-node-streams.git" }, "devDependencies": { - "purescript-assert": "^5.0.0", - "purescript-console": "^5.0.0", - "purescript-partial": "^3.0.0" + "purescript-assert": "master", + "purescript-console": "master", + "purescript-partial": "master" }, "dependencies": { - "purescript-effect": "^3.0.0", - "purescript-either": "^5.0.0", - "purescript-exceptions": "^5.0.0", - "purescript-node-buffer": "^7.0.0", - "purescript-prelude": "^5.0.0" + "purescript-effect": "master", + "purescript-either": "master", + "purescript-exceptions": "master", + "purescript-node-buffer": "master", + "purescript-prelude": "master" } } diff --git a/package.json b/package.json index 901476d..0672c6f 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ }, "devDependencies": { "eslint": "^7.15.0", - "pulp": "^15.0.0", - "purescript-psa": "^0.8.0", + "pulp": "16.0.0-0", + "purescript-psa": "^0.8.2", "rimraf": "^3.0.2", "stream-buffers": "^3.0.2" } diff --git a/src/Node/Stream.js b/src/Node/Stream.js index d4fb2b1..4900bf6 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -1,208 +1,145 @@ -"use strict"; +const _undefined = undefined; +export { _undefined as undefined }; -exports.undefined = undefined; - -exports.setEncodingImpl = function (s) { - return function (enc) { - return function () { - s.setEncoding(enc); - }; +export function setEncodingImpl(s) { + return enc => () => { + s.setEncoding(enc); }; -}; - -exports.readChunkImpl = function (Left) { - return function (Right) { - return function (chunk) { - if (chunk instanceof Buffer) { - return Right(chunk); - } else if (typeof chunk === "string") { - return Left(chunk); - } else { - throw new Error( - "Node.Stream.readChunkImpl: Unrecognised " + - "chunk type; expected String or Buffer, got: " + - chunk - ); - } - }; +} + +export function readChunkImpl(Left) { + return Right => chunk => { + if (chunk instanceof Buffer) { + return Right(chunk); + } else if (typeof chunk === "string") { + return Left(chunk); + } else { + throw new Error( + "Node.Stream.readChunkImpl: Unrecognised " + + "chunk type; expected String or Buffer, got: " + + chunk + ); + } }; -}; - -exports.onDataEitherImpl = function (readChunk) { - return function (r) { - return function (f) { - return function () { - r.on("data", function (data) { - f(readChunk(data))(); - }); - }; - }; +} + +export function onDataEitherImpl(readChunk) { + return r => f => () => { + r.on("data", data => { + f(readChunk(data))(); + }); }; -}; +} -exports.onEnd = function (s) { - return function (f) { - return function () { - s.on("end", f); - }; +export function onEnd(s) { + return f => () => { + s.on("end", f); }; -}; +} -exports.onFinish = function (s) { - return function (f) { - return function () { - s.on("finish", f); - }; +export function onFinish(s) { + return f => () => { + s.on("finish", f); }; -}; +} -exports.onReadable = function (s) { - return function (f) { - return function () { - s.on("readable", f); - }; +export function onReadable(s) { + return f => () => { + s.on("readable", f); }; -}; - -exports.onError = function (s) { - return function (f) { - return function () { - s.on("error", function (e) { - f(e)(); - }); - }; +} + +export function onError(s) { + return f => () => { + s.on("error", e => { + f(e)(); + }); }; -}; +} -exports.onClose = function (s) { - return function (f) { - return function () { - s.on("close", f); - }; +export function onClose(s) { + return f => () => { + s.on("close", f); }; -}; +} -exports.resume = function (s) { - return function () { +export function resume(s) { + return () => { s.resume(); }; -}; +} -exports.pause = function (s) { - return function () { +export function pause(s) { + return () => { s.pause(); }; -}; +} -exports.isPaused = function (s) { - return function () { - return s.isPaused(); - }; -}; +export function isPaused(s) { + return () => s.isPaused(); +} -exports.pipe = function (r) { - return function (w) { - return function () { - return r.pipe(w); - }; - }; -}; +export function pipe(r) { + return w => () => r.pipe(w); +} -exports.unpipe = function (r) { - return function (w) { - return function () { - return r.unpipe(w); - }; - }; -}; +export function unpipe(r) { + return w => () => r.unpipe(w); +} -exports.unpipeAll = function (r) { - return function () { - return r.unpipe(); - }; -}; - -exports.readImpl = function (readChunk) { - return function (Nothing) { - return function (Just) { - return function (r) { - return function (s) { - return function () { - var v = r.read(s); - if (v === null) { - return Nothing; - } else { - return Just(readChunk(v)); - } - }; - }; - }; - }; - }; -}; - -exports.write = function (w) { - return function (chunk) { - return function (done) { - return function () { - return w.write(chunk, null, done); - }; - }; - }; -}; - -exports.writeStringImpl = function (w) { - return function (enc) { - return function (s) { - return function (done) { - return function () { - return w.write(s, enc, done); - }; - }; - }; - }; -}; +export function unpipeAll(r) { + return () => r.unpipe(); +} -exports.cork = function (w) { - return function () { - return w.cork(); +export function readImpl(readChunk) { + return Nothing => Just => r => s => () => { + const v = r.read(s); + if (v === null) { + return Nothing; + } else { + return Just(readChunk(v)); + } }; -}; +} -exports.uncork = function (w) { - return function () { - return w.uncork(); - }; -}; +export function write(w) { + return chunk => done => () => w.write(chunk, null, done); +} -exports.setDefaultEncodingImpl = function (w) { - return function (enc) { - return function () { - w.setDefaultEncoding(enc); - }; +export function writeStringImpl(w) { + return enc => s => done => () => w.write(s, enc, done); +} + +export function cork(w) { + return () => w.cork(); +} + +export function uncork(w) { + return () => w.uncork(); +} + +export function setDefaultEncodingImpl(w) { + return enc => () => { + w.setDefaultEncoding(enc); }; -}; - -exports.end = function (w) { - return function (done) { - return function () { - w.end(null, null, function () { - done(); - }); - }; +} + +export function end(w) { + return done => () => { + w.end(null, null, () => { + done(); + }); }; -}; +} -exports.destroy = function (strm) { - return function () { +export function destroy(strm) { + return () => { strm.destroy(null); }; -}; +} -exports.destroyWithError = function (strm) { - return function (e) { - return function () { - strm.destroy(e); - }; +export function destroyWithError(strm) { + return e => () => { + strm.destroy(e); }; -}; +} diff --git a/test/Main.js b/test/Main.js index 79b1e12..f105e15 100644 --- a/test/Main.js +++ b/test/Main.js @@ -1,35 +1,26 @@ -"use strict"; +import { WritableStreamBuffer, ReadableStreamBuffer } from 'stream-buffers'; +import { PassThrough } from 'stream'; -exports.writableStreamBuffer = function() { - var W = require('stream-buffers').WritableStreamBuffer; - return new W; -}; +export function writableStreamBuffer() { + return new WritableStreamBuffer; +} -exports.getContentsAsString = function(w) { - return function() { - return w.getContentsAsString('utf8'); - }; -}; +export function getContentsAsString(w) { + return () => w.getContentsAsString('utf8'); +} -exports.readableStreamBuffer = function() { - var R = require('stream-buffers').ReadableStreamBuffer; - return new R; -}; +export function readableStreamBuffer() { + return new ReadableStreamBuffer; +} -exports.putImpl = function(str) { - return function(enc) { - return function(r) { - return function() { - r.put(str, enc); - }; - }; +export function putImpl(str) { + return enc => r => () => { + r.put(str, enc); }; -}; +} -exports.createGzip = require('zlib').createGzip; -exports.createGunzip = require('zlib').createGunzip; +export { createGzip, createGunzip } from 'zlib'; -exports.passThrough = function () { - var s = require('stream'); - return new s.PassThrough(); -}; +export function passThrough() { + return new PassThrough; +}