From 4b4b442e21d5aaee2cec130d64423e0c21dc73ea Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Sat, 12 Feb 2022 12:19:18 +0000 Subject: [PATCH 01/10] ESM conversion --- src/Node/Stream.js | 94 +++++++++++++++++++++++----------------------- test/Main.js | 35 +++++++++-------- 2 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/Node/Stream.js b/src/Node/Stream.js index d4fb2b1..7623916 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -1,16 +1,16 @@ "use strict"; -exports.undefined = undefined; +export {undefined}; -exports.setEncodingImpl = function (s) { +export function setEncodingImpl(s) { return function (enc) { return function () { s.setEncoding(enc); }; }; -}; +} -exports.readChunkImpl = function (Left) { +export function readChunkImpl(Left) { return function (Right) { return function (chunk) { if (chunk instanceof Buffer) { @@ -26,9 +26,9 @@ exports.readChunkImpl = function (Left) { } }; }; -}; +} -exports.onDataEitherImpl = function (readChunk) { +export function onDataEitherImpl(readChunk) { return function (r) { return function (f) { return function () { @@ -38,33 +38,33 @@ exports.onDataEitherImpl = function (readChunk) { }; }; }; -}; +} -exports.onEnd = function (s) { +export function onEnd(s) { return function (f) { return function () { s.on("end", f); }; }; -}; +} -exports.onFinish = function (s) { +export function onFinish(s) { return function (f) { return function () { s.on("finish", f); }; }; -}; +} -exports.onReadable = function (s) { +export function onReadable(s) { return function (f) { return function () { s.on("readable", f); }; }; -}; +} -exports.onError = function (s) { +export function onError(s) { return function (f) { return function () { s.on("error", function (e) { @@ -72,57 +72,57 @@ exports.onError = function (s) { }); }; }; -}; +} -exports.onClose = function (s) { +export function onClose(s) { return function (f) { return function () { s.on("close", f); }; }; -}; +} -exports.resume = function (s) { +export function resume(s) { return function () { s.resume(); }; -}; +} -exports.pause = function (s) { +export function pause(s) { return function () { s.pause(); }; -}; +} -exports.isPaused = function (s) { +export function isPaused(s) { return function () { return s.isPaused(); }; -}; +} -exports.pipe = function (r) { +export function pipe(r) { return function (w) { return function () { return r.pipe(w); }; }; -}; +} -exports.unpipe = function (r) { +export function unpipe(r) { return function (w) { return function () { return r.unpipe(w); }; }; -}; +} -exports.unpipeAll = function (r) { +export function unpipeAll(r) { return function () { return r.unpipe(); }; -}; +} -exports.readImpl = function (readChunk) { +export function readImpl(readChunk) { return function (Nothing) { return function (Just) { return function (r) { @@ -139,9 +139,9 @@ exports.readImpl = function (readChunk) { }; }; }; -}; +} -exports.write = function (w) { +export function write(w) { return function (chunk) { return function (done) { return function () { @@ -149,9 +149,9 @@ exports.write = function (w) { }; }; }; -}; +} -exports.writeStringImpl = function (w) { +export function writeStringImpl(w) { return function (enc) { return function (s) { return function (done) { @@ -161,29 +161,29 @@ exports.writeStringImpl = function (w) { }; }; }; -}; +} -exports.cork = function (w) { +export function cork(w) { return function () { return w.cork(); }; -}; +} -exports.uncork = function (w) { +export function uncork(w) { return function () { return w.uncork(); }; -}; +} -exports.setDefaultEncodingImpl = function (w) { +export function setDefaultEncodingImpl(w) { return function (enc) { return function () { w.setDefaultEncoding(enc); }; }; -}; +} -exports.end = function (w) { +export function end(w) { return function (done) { return function () { w.end(null, null, function () { @@ -191,18 +191,18 @@ exports.end = function (w) { }); }; }; -}; +} -exports.destroy = function (strm) { +export function destroy(strm) { return function () { strm.destroy(null); }; -}; +} -exports.destroyWithError = function (strm) { +export function destroyWithError(strm) { return function (e) { return function () { strm.destroy(e); }; }; -}; +} diff --git a/test/Main.js b/test/Main.js index 79b1e12..42368f1 100644 --- a/test/Main.js +++ b/test/Main.js @@ -1,22 +1,23 @@ "use strict"; -exports.writableStreamBuffer = function() { - var W = require('stream-buffers').WritableStreamBuffer; - return new W; -}; +import { WritableStreamBuffer, ReadableStreamBuffer } from 'stream-buffers'; +import { PassThrough } from 'stream'; -exports.getContentsAsString = function(w) { +export function writableStreamBuffer() { + return new WritableStreamBuffer; +} + +export function getContentsAsString(w) { return function() { 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) { +export function putImpl(str) { return function(enc) { return function(r) { return function() { @@ -24,12 +25,10 @@ exports.putImpl = function(str) { }; }; }; -}; +} -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; +} From bb765970e14ff12b8caf2f465e056105eb2dccd6 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Sat, 12 Feb 2022 12:26:48 +0000 Subject: [PATCH 02/10] ES6 transformations --- src/Node/Stream.js | 177 +++++++++++++++------------------------------ test/Main.js | 12 +-- 2 files changed, 61 insertions(+), 128 deletions(-) diff --git a/src/Node/Stream.js b/src/Node/Stream.js index 7623916..fff98b2 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -1,208 +1,147 @@ "use strict"; -export {undefined}; +const _undefined = undefined; +export { _undefined as undefined }; export function setEncodingImpl(s) { - return function (enc) { - return function () { - s.setEncoding(enc); - }; + return enc => () => { + s.setEncoding(enc); }; } export function readChunkImpl(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 - ); - } - }; + 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 + ); + } }; } export function onDataEitherImpl(readChunk) { - return function (r) { - return function (f) { - return function () { - r.on("data", function (data) { - f(readChunk(data))(); - }); - }; - }; + return r => f => () => { + r.on("data", data => { + f(readChunk(data))(); + }); }; } export function onEnd(s) { - return function (f) { - return function () { - s.on("end", f); - }; + return f => () => { + s.on("end", f); }; } export function onFinish(s) { - return function (f) { - return function () { - s.on("finish", f); - }; + return f => () => { + s.on("finish", f); }; } export function onReadable(s) { - return function (f) { - return function () { - s.on("readable", f); - }; + return f => () => { + s.on("readable", f); }; } export function onError(s) { - return function (f) { - return function () { - s.on("error", function (e) { - f(e)(); - }); - }; + return f => () => { + s.on("error", e => { + f(e)(); + }); }; } export function onClose(s) { - return function (f) { - return function () { - s.on("close", f); - }; + return f => () => { + s.on("close", f); }; } export function resume(s) { - return function () { + return () => { s.resume(); }; } export function pause(s) { - return function () { + return () => { s.pause(); }; } export function isPaused(s) { - return function () { - return s.isPaused(); - }; + return () => s.isPaused(); } export function pipe(r) { - return function (w) { - return function () { - return r.pipe(w); - }; - }; + return w => () => r.pipe(w); } export function unpipe(r) { - return function (w) { - return function () { - return r.unpipe(w); - }; - }; + return w => () => r.unpipe(w); } export function unpipeAll(r) { - return function () { - return r.unpipe(); - }; + return () => r.unpipe(); } export function readImpl(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)); - } - }; - }; - }; - }; + return Nothing => Just => r => s => () => { + const v = r.read(s); + if (v === null) { + return Nothing; + } else { + return Just(readChunk(v)); + } }; } export function write(w) { - return function (chunk) { - return function (done) { - return function () { - return w.write(chunk, null, done); - }; - }; - }; + return chunk => done => () => w.write(chunk, null, done); } export function writeStringImpl(w) { - return function (enc) { - return function (s) { - return function (done) { - return function () { - return w.write(s, enc, done); - }; - }; - }; - }; + return enc => s => done => () => w.write(s, enc, done); } export function cork(w) { - return function () { - return w.cork(); - }; + return () => w.cork(); } export function uncork(w) { - return function () { - return w.uncork(); - }; + return () => w.uncork(); } export function setDefaultEncodingImpl(w) { - return function (enc) { - return function () { - w.setDefaultEncoding(enc); - }; + return enc => () => { + w.setDefaultEncoding(enc); }; } export function end(w) { - return function (done) { - return function () { - w.end(null, null, function () { - done(); - }); - }; + return done => () => { + w.end(null, null, () => { + done(); + }); }; } export function destroy(strm) { - return function () { + return () => { strm.destroy(null); }; } export function destroyWithError(strm) { - return function (e) { - return function () { - strm.destroy(e); - }; + return e => () => { + strm.destroy(e); }; } diff --git a/test/Main.js b/test/Main.js index 42368f1..24bdee4 100644 --- a/test/Main.js +++ b/test/Main.js @@ -8,9 +8,7 @@ export function writableStreamBuffer() { } export function getContentsAsString(w) { - return function() { - return w.getContentsAsString('utf8'); - }; + return () => w.getContentsAsString('utf8'); } export function readableStreamBuffer() { @@ -18,12 +16,8 @@ export function readableStreamBuffer() { } export function putImpl(str) { - return function(enc) { - return function(r) { - return function() { - r.put(str, enc); - }; - }; + return enc => r => () => { + r.put(str, enc); }; } From da1feef0e8051a8b531df7c2ed1b74d5cbb0b8a0 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 16:46:20 +0000 Subject: [PATCH 03/10] Removed '"use strict";' in FFI files --- src/Node/Stream.js | 2 -- test/Main.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/Node/Stream.js b/src/Node/Stream.js index fff98b2..4900bf6 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -1,5 +1,3 @@ -"use strict"; - const _undefined = undefined; export { _undefined as undefined }; diff --git a/test/Main.js b/test/Main.js index 24bdee4..f105e15 100644 --- a/test/Main.js +++ b/test/Main.js @@ -1,5 +1,3 @@ -"use strict"; - import { WritableStreamBuffer, ReadableStreamBuffer } from 'stream-buffers'; import { PassThrough } from 'stream'; From 1a6c370147321d95672d6c4a47a7b259394e59b7 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 16:46:20 +0000 Subject: [PATCH 04/10] Update to CI to use 'unstable' purescript --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 063845e..f5a96fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: - uses: actions/checkout@v2 - uses: purescript-contrib/setup-purescript@main + with: + purescript: "unstable" - uses: actions/setup-node@v1 with: From 371b8d6f04e3cf3c69781e12d40413199516e457 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 16:46:20 +0000 Subject: [PATCH 05/10] Update Bower dependencies to master or main --- bower.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index e9a420c..1669dcd 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-effect": "master", + "purescript-either": "master", + "purescript-exceptions": "master", "purescript-node-buffer": "^7.0.0", - "purescript-prelude": "^5.0.0" + "purescript-prelude": "master" } } From 7b70720df677b26ad5cd8ab5fc9e7a478a2fdec9 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 16:46:20 +0000 Subject: [PATCH 06/10] Update pulp to 16.0.0-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 901476d..8ce6501 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "eslint": "^7.15.0", - "pulp": "^15.0.0", + "pulp": "16.0.0-0", "purescript-psa": "^0.8.0", "rimraf": "^3.0.2", "stream-buffers": "^3.0.2" From a56f3424ffc9433e1fbd007371b7f05cc4323eac Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 16:46:20 +0000 Subject: [PATCH 07/10] Update psa to 0.8.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ce6501..0672c6f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "devDependencies": { "eslint": "^7.15.0", "pulp": "16.0.0-0", - "purescript-psa": "^0.8.0", + "purescript-psa": "^0.8.2", "rimraf": "^3.0.2", "stream-buffers": "^3.0.2" } From b87c7a0060a528f6a3559459b6019488373fc03b Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 17:02:25 +0000 Subject: [PATCH 08/10] Update Bower dependencies to master or main --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 1669dcd..42d9e4c 100644 --- a/bower.json +++ b/bower.json @@ -20,7 +20,7 @@ "purescript-effect": "master", "purescript-either": "master", "purescript-exceptions": "master", - "purescript-node-buffer": "^7.0.0", + "purescript-node-buffer": "master", "purescript-prelude": "master" } } From 4dea6140af5fac51963155a95025a238620e3aec Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 17:04:26 +0000 Subject: [PATCH 09/10] Update ci.yml to v2 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5a96fe..06ed895 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,9 +16,9 @@ jobs: with: purescript: "unstable" - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: "10" + node-version: "14" - name: Install dependencies run: | From 7ba6af2161acc5d2c04461390ee08b10448a395e Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Tue, 22 Mar 2022 17:05:54 +0000 Subject: [PATCH 10/10] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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: