From 48f66829631a820c7f7e2ee1af2d197a8ebe4889 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 01/14] Migrated FFI to ES modules via 'lebab' --- src/Data/ArrayBuffer/ArrayBuffer.js | 8 +- src/Data/ArrayBuffer/DataView.js | 32 +++---- src/Data/ArrayBuffer/Typed.js | 144 ++++++++++++++-------------- 3 files changed, 90 insertions(+), 94 deletions(-) diff --git a/src/Data/ArrayBuffer/ArrayBuffer.js b/src/Data/ArrayBuffer/ArrayBuffer.js index b341921..30033c4 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.js +++ b/src/Data/ArrayBuffer/ArrayBuffer.js @@ -6,10 +6,10 @@ exports.emptyImpl = function empty (s) { return new ArrayBuffer(s); }; -exports.byteLength = function byteLength (a) { +export function byteLength(a) { return a.byteLength; -}; +} -exports.sliceImpl = function sliceImpl (a, s, e) { +export function sliceImpl(a, s, e) { return a.slice(s, e); -}; +} diff --git a/src/Data/ArrayBuffer/DataView.js b/src/Data/ArrayBuffer/DataView.js index 6bfee81..4c6a9db 100644 --- a/src/Data/ArrayBuffer/DataView.js +++ b/src/Data/ArrayBuffer/DataView.js @@ -3,41 +3,41 @@ // module Data.ArrayBuffer.DataView -exports.whole = function whole (b) { +export function whole(b) { return new DataView(b); -}; +} -exports.remainderImpl = function remainderImpl (b,i) { +export function remainderImpl(b, i) { return new DataView(b,i); -}; +} -exports.partImpl = function partImpl (b,i,j) { +export function partImpl(b, i, j) { return new DataView(b,i,j); -}; +} -exports.buffer = function buffer (v) { +export function buffer(v) { return v.buffer; -}; +} -exports.byteOffset = function byteOffset (v) { +export function byteOffset(v) { return v.byteOffset; -}; +} -exports.byteLength = function byteLength (v) { +export function byteLength(v) { return v.byteLength; -}; +} -exports.getterImpl = function getterImpl (data, v, o) { +export function getterImpl(data, v, o) { return ((o + data.bytesPerValue) >>> 0) <= v.byteLength ? v[data.functionName].call(v,o,data.littleEndian) : null; -}; +} -exports.setterImpl = function setterImpl (data, v, o, n) { +export function setterImpl(data, v, o, n) { if (((o + data.bytesPerValue) >>> 0) <= v.byteLength) { v[data.functionName].call(v,o,n,data.littleEndian); return true; } else { return false; } -}; +} diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 2ab0cb6..4463750 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -2,17 +2,17 @@ // module Data.ArrayBuffer.Typed -exports.buffer = function buffer (v) { +export function buffer(v) { return v.buffer; -}; +} -exports.byteOffset = function byteOffset (v) { +export function byteOffset(v) { return v.byteOffset; -}; +} -exports.byteLength = function byteLength (v) { +export function byteLength(v) { return v.byteLength; -}; +} exports.lengthImpl = function lemgthImpl (v) { return v.length; @@ -36,130 +36,126 @@ function newArray (f) { }; } -exports.newUint8ClampedArray = newArray(Uint8ClampedArray); -exports.newUint32Array = newArray(Uint32Array); -exports.newUint16Array = newArray(Uint16Array); -exports.newUint8Array = newArray(Uint8Array); -exports.newInt32Array = newArray(Int32Array); -exports.newInt16Array = newArray(Int16Array); -exports.newInt8Array = newArray(Int8Array); -exports.newFloat32Array = newArray(Float32Array); -exports.newFloat64Array = newArray(Float64Array); - +export var newUint8ClampedArray = newArray(Uint8ClampedArray); +export var newUint32Array = newArray(Uint32Array); +export var newUint16Array = newArray(Uint16Array); +export var newUint8Array = newArray(Uint8Array); +export var newInt32Array = newArray(Int32Array); +export var newInt16Array = newArray(Int16Array); +export var newInt8Array = newArray(Int8Array); +export var newFloat32Array = newArray(Float32Array); +export var newFloat64Array = newArray(Float64Array); // ------ -exports.everyImpl = function everyImpl (a,p) { +export function everyImpl(a, p) { return a.every(p); -}; -exports.someImpl = function someImpl (a,p) { - return a.some(p); -}; +} +export function someImpl(a, p) { + return a.some(p); +} -exports.fillImpl = function fillImpl (x, s, e, a) { +export function fillImpl(x, s, e, a) { return a.fill(x,s,e); -}; - +} -exports.mapImpl = function mapImpl (a,f) { +export function mapImpl(a, f) { return a.map(f); -}; +} -exports.forEachImpl = function forEachImpl (a,f) { +export function forEachImpl(a, f) { a.forEach(f); -}; +} -exports.filterImpl = function filterImpl (a,p) { +export function filterImpl(a, p) { return a.filter(p); -}; +} -exports.includesImpl = function includesImpl (a,x,mo) { +export function includesImpl(a, x, mo) { return mo === null ? a.includes(x) : a.includes(x,mo); -}; +} -exports.reduceImpl = function reduceImpl (a,f,i) { +export function reduceImpl(a, f, i) { return a.reduce(f,i); -}; -exports.reduce1Impl = function reduce1Impl (a,f) { +} + +export function reduce1Impl(a, f) { return a.reduce(f); -}; -exports.reduceRightImpl = function reduceRightImpl (a,f,i) { +} + +export function reduceRightImpl(a, f, i) { return a.reduceRight(f,i); -}; -exports.reduceRight1Impl = function reduceRight1Impl (a,f) { +} + +export function reduceRight1Impl(a, f) { return a.reduceRight(f); -}; +} -exports.findImpl = function findImpl (a,f) { +export function findImpl(a, f) { return a.find(f); -}; +} -exports.findIndexImpl = function findIndexImpl (a,f) { +export function findIndexImpl(a, f) { var r = a.findIndex(f); return r === -1 ? null : r; -}; -exports.indexOfImpl = function indexOfImpl (a,x,mo) { +} + +export function indexOfImpl(a, x, mo) { var r = mo === null ? a.indexOf(x) : a.indexOf(x,mo); return r === -1 ? null : r; -}; -exports.lastIndexOfImpl = function lastIndexOfImpl (a,x,mo) { +} + +export function lastIndexOfImpl(a, x, mo) { var r = mo === null ? a.lastIndexOf(x) : a.lastIndexOf(x,mo); return r === -1 ? null : r; -}; - - +} -exports.copyWithinImpl = function copyWithinImpl (a,t,s,me) { +export function copyWithinImpl(a, t, s, me) { if (me === null) { a.copyWithin(t,s); } else { a.copyWithin(t,s,me); } -}; - +} -exports.reverseImpl = function reverseImpl (a) { +export function reverseImpl(a) { a.reverse(); -}; - +} -exports.setImpl = function setImpl (a, off, b) { +export function setImpl(a, off, b) { a.set(b,off); -}; - +} -exports.sliceImpl = function sliceImpl (a, s, e) { +export function sliceImpl(a, s, e) { return a.slice(s,e); -}; +} -exports.sortImpl = function sortImpl (a) { +export function sortImpl(a) { a.sort(); -}; - +} -exports.subArrayImpl = function subArrayImpl (a, s, e) { +export function subArrayImpl(a, s, e) { return a.subarray(s, e); -}; - +} -exports.toStringImpl = function toStringImpl (a) { +export function toStringImpl(a) { return a.toString(); -}; +} -exports.joinImpl = function joinImpl (a,s) { +export function joinImpl(a, s) { return a.join(s); -}; +} -exports.unsafeAtImpl = function(a, i) { +export function unsafeAtImpl(a, i) { return a[i]; } -exports.hasIndexImpl = function(a, i) { +export function hasIndexImpl(a, i) { return i in a; } -exports.toArrayImpl = function(a) { +export function toArrayImpl(a) { var l = a.length; var ret = new Array(l); for (var i = 0; i < l; i++) From f2e09f42d1a0dd8c3933d7194a8e348fdde6c624 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 02/14] Replaced 'export var' with 'export const' --- src/Data/ArrayBuffer/Typed.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 4463750..07ce521 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -36,15 +36,15 @@ function newArray (f) { }; } -export var newUint8ClampedArray = newArray(Uint8ClampedArray); -export var newUint32Array = newArray(Uint32Array); -export var newUint16Array = newArray(Uint16Array); -export var newUint8Array = newArray(Uint8Array); -export var newInt32Array = newArray(Int32Array); -export var newInt16Array = newArray(Int16Array); -export var newInt8Array = newArray(Int8Array); -export var newFloat32Array = newArray(Float32Array); -export var newFloat64Array = newArray(Float64Array); +export const newUint8ClampedArray = newArray(Uint8ClampedArray); +export const newUint32Array = newArray(Uint32Array); +export const newUint16Array = newArray(Uint16Array); +export const newUint8Array = newArray(Uint8Array); +export const newInt32Array = newArray(Int32Array); +export const newInt16Array = newArray(Int16Array); +export const newInt8Array = newArray(Int8Array); +export const newFloat32Array = newArray(Float32Array); +export const newFloat64Array = newArray(Float64Array); // ------ From 2e83482f31d4f0286814ca85bd7f22cef9dcdbec Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 03/14] Removed '"use strict";' in FFI files --- src/Data/ArrayBuffer/ArrayBuffer.js | 2 -- src/Data/ArrayBuffer/DataView.js | 2 -- src/Data/ArrayBuffer/Typed.js | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/Data/ArrayBuffer/ArrayBuffer.js b/src/Data/ArrayBuffer/ArrayBuffer.js index 30033c4..da66aec 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.js +++ b/src/Data/ArrayBuffer/ArrayBuffer.js @@ -1,5 +1,3 @@ -"use strict"; - // module Data.ArrayBuffer.ArrayBuffer exports.emptyImpl = function empty (s) { diff --git a/src/Data/ArrayBuffer/DataView.js b/src/Data/ArrayBuffer/DataView.js index 4c6a9db..1eeb060 100644 --- a/src/Data/ArrayBuffer/DataView.js +++ b/src/Data/ArrayBuffer/DataView.js @@ -1,5 +1,3 @@ -"use strict"; - // module Data.ArrayBuffer.DataView diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index 07ce521..c4a118d 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -1,5 +1,3 @@ -"use strict"; - // module Data.ArrayBuffer.Typed export function buffer(v) { From 10281271f94405968334ffb1d08023377aca06a4 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 04/14] Update to CI to use 'unstable' purescript --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aaad3f..6dd236d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: - name: Set up a PureScript toolchain uses: purescript-contrib/setup-purescript@main with: + purescript: "unstable" purs-tidy: "latest" - name: Cache PureScript dependencies From 2e676a12d2e924c144aaffc094705bd13c9fde9a Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 05/14] Add CI test: verify 'bower.json' file works via pulp --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dd236d..a9d110d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,3 +44,12 @@ jobs: - name: Check formatting run: purs-tidy check src test + + - name: Verify Bower & Pulp + run: | + npm install bower pulp@16.0.0-0 + npx bower install + npx pulp build -- --censor-lib --strict + if [ -d "test" ]; then + npx pulp test + fi From 39755a3995e28ed46e934561940da2ee034c13c5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 06/14] Ignore spago-based tests (temporarily) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9d110d..7dc276f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: - name: Build tests run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --strict' - - name: Run tests +# - name: Run tests run: spago -x spago-test.dhall test --no-install - name: Check formatting From 431e1e465210f9b83cb4606b34e0951739e24485 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 07/14] Update Bower dependencies to master or main --- bower.json | 56 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/bower.json b/bower.json index 4d6947c..ab386cc 100644 --- a/bower.json +++ b/bower.json @@ -1,30 +1,30 @@ { - "name": "purescript-arraybuffer", - "license": [ - "MIT" - ], - "repository": { - "type": "git", - "url": "https://github.com/purescript-contrib/purescript-arraybuffer" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-arraybuffer-types": "^v3.0.1", - "purescript-arrays": "^v6.0.1", - "purescript-effect": "^v3.0.0", - "purescript-float32": "^v1.0.0", - "purescript-functions": "^v5.0.0", - "purescript-gen": "^v3.0.0", - "purescript-maybe": "^v5.0.0", - "purescript-nullable": "^v5.0.0", - "purescript-prelude": "^v5.0.1", - "purescript-tailrec": "^v5.0.1", - "purescript-uint": "^v6.0.3", - "purescript-unfoldable": "^v5.0.0" - } + "name": "purescript-arraybuffer", + "license": [ + "MIT" + ], + "repository": { + "type": "git", + "url": "https://github.com/purescript-contrib/purescript-arraybuffer" + }, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-arraybuffer-types": "main", + "purescript-arrays": "master", + "purescript-effect": "master", + "purescript-float32": "main", + "purescript-functions": "master", + "purescript-gen": "master", + "purescript-maybe": "master", + "purescript-nullable": "main", + "purescript-prelude": "master", + "purescript-tailrec": "master", + "purescript-uint": "main", + "purescript-unfoldable": "master" + } } From 5d9245b08658378e462dde2d2729113ce06c3386 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 09:20:26 -0500 Subject: [PATCH 08/14] Update packages.dhall to 'prepare-0.15' package set --- packages.dhall | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages.dhall b/packages.dhall index bea1ce8..582d6d3 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,8 +1,4 @@ let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210722/packages.dhall sha256:1ceb43aa59436bf5601bac45f6f3781c4e1f0e4c2b8458105b018e5ed8c30f8c + https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall -let overrides = {=} - -let additions = {=} - -in upstream // overrides // additions +in upstream From f831d437f2ab34331c2ec64e14a6c601dace468f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 13:58:34 -0500 Subject: [PATCH 09/14] Fix FFI exports --- src/Data/ArrayBuffer/ArrayBuffer.js | 2 +- src/Data/ArrayBuffer/Typed.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Data/ArrayBuffer/ArrayBuffer.js b/src/Data/ArrayBuffer/ArrayBuffer.js index da66aec..9bb2fc1 100644 --- a/src/Data/ArrayBuffer/ArrayBuffer.js +++ b/src/Data/ArrayBuffer/ArrayBuffer.js @@ -1,6 +1,6 @@ // module Data.ArrayBuffer.ArrayBuffer -exports.emptyImpl = function empty (s) { +export function emptyImpl(s) { return new ArrayBuffer(s); }; diff --git a/src/Data/ArrayBuffer/Typed.js b/src/Data/ArrayBuffer/Typed.js index c4a118d..fc19771 100644 --- a/src/Data/ArrayBuffer/Typed.js +++ b/src/Data/ArrayBuffer/Typed.js @@ -12,7 +12,7 @@ export function byteLength(v) { return v.byteLength; } -exports.lengthImpl = function lemgthImpl (v) { +export function lengthImpl(v) { return v.length; }; From d0ce6a924f9cab182c37087ef64f05c08ef20987 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 13:59:34 -0500 Subject: [PATCH 10/14] Update SProxy to use Proxy --- src/Data/ArrayBuffer/DataView.purs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/ArrayBuffer/DataView.purs b/src/Data/ArrayBuffer/DataView.purs index 610090e..badab60 100644 --- a/src/Data/ArrayBuffer/DataView.purs +++ b/src/Data/ArrayBuffer/DataView.purs @@ -49,7 +49,7 @@ import Data.ArrayBuffer.ValueMapping (class BinaryValue, class BytesPerType, cla import Data.Float32 (Float32) as F import Data.Maybe (Maybe) import Data.Nullable (Nullable, toMaybe) -import Data.Symbol (SProxy(..), class IsSymbol, reflectSymbol) +import Data.Symbol (class IsSymbol, reflectSymbol) import Data.UInt (UInt) import Effect (Effect) import Effect.Uncurried (EffectFn2, EffectFn3, EffectFn4, runEffectFn2, runEffectFn3, runEffectFn4) @@ -131,7 +131,7 @@ get get endian prx = do let le = endian == LE - pnm = "get" <> reflectSymbol (SProxy :: SProxy name) + pnm = "get" <> reflectSymbol (Proxy :: Proxy name) bpv = byteWidth prx getter @@ -203,7 +203,7 @@ set set endian prx = do let le = endian == LE - pnm = "set" <> reflectSymbol (SProxy :: SProxy name) + pnm = "set" <> reflectSymbol (Proxy :: Proxy name) bpv = byteWidth prx setter From 68b764819d6878006e59a37c3e4b2ef0ad18c2fb Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 14:01:50 -0500 Subject: [PATCH 11/14] Installed bower dev dependency: purescript-quickcheck-laws@main --- bower.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bower.json b/bower.json index ab386cc..85fd87c 100644 --- a/bower.json +++ b/bower.json @@ -26,5 +26,8 @@ "purescript-tailrec": "master", "purescript-uint": "main", "purescript-unfoldable": "master" + }, + "devDependencies": { + "purescript-quickcheck-laws": "main" } } From d1588ee38cb09e90c73e10f5f7563ebb7534afde Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 14:02:44 -0500 Subject: [PATCH 12/14] Fix Proxy import --- test/Properties/Typed/Laws.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Properties/Typed/Laws.purs b/test/Properties/Typed/Laws.purs index b58f08c..21ac0dd 100644 --- a/test/Properties/Typed/Laws.purs +++ b/test/Properties/Typed/Laws.purs @@ -12,7 +12,7 @@ import Effect.Ref as Ref import Test.QuickCheck (class Arbitrary, arbitrary) import Test.QuickCheck.Gen (Gen) import Test.QuickCheck.Laws.Data (checkEq, checkMonoid, checkOrd, checkSemigroup) -import Type.Prelude (Proxy(..)) +import Type.Proxy (Proxy(..)) import Data.ArrayBuffer.Typed as TA import Data.Generic.Rep (class Generic) import Data.Maybe (Maybe(..)) From a69571a96bc69e0bfaf87ca7dbb8402095d7e29c Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 22 Mar 2022 14:04:39 -0500 Subject: [PATCH 13/14] Add changelog entry --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ed4a7..982d560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +Breaking Changes: +- Migrate FFI to ES modules (#41 by @JordanMartinez) +- Replaced polymorphic proxies with monomorphic `Proxy` (#41 by @JordanMartinez) + ## v12.0.0 Delete the `TypedArray` polyfill which was preventing this From 15c608ac13eb4a4db9170a49cf52d2542ffbcbbc Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Tue, 22 Mar 2022 14:38:41 -0500 Subject: [PATCH 14/14] Update .github/workflows/ci.yml Co-authored-by: Thomas Honeyman --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dc276f..f5d37bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --strict' # - name: Run tests - run: spago -x spago-test.dhall test --no-install +# run: spago -x spago-test.dhall test --no-install - name: Check formatting run: purs-tidy check src test