From cd6e8f281124d7e7f800cc82d5aa3c186639935b Mon Sep 17 00:00:00 2001 From: Przemek Kaminski Date: Wed, 11 May 2022 10:54:05 +0200 Subject: [PATCH 1/2] PS 0.15.0 upgrade (pure code changes) --- src/Simple/JSON.js | 6 +++--- src/Simple/JSON.purs | 12 ++++++------ test/EnumSumGeneric.purs | 5 +++-- test/Inferred.purs | 6 +++--- test/Util.purs | 11 ++++++----- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Simple/JSON.js b/src/Simple/JSON.js index 03e5cdf..fcb2730 100644 --- a/src/Simple/JSON.js +++ b/src/Simple/JSON.js @@ -1,5 +1,5 @@ -exports._parseJSON = JSON.parse; +export function _parseJSON() { return JSON.parse.apply(this, arguments) }; -exports._undefined = undefined; +export const _undefined = undefined; -exports._unsafeStringify = JSON.stringify; +export function _unsafeStringify() { return JSON.stringify.apply(this, arguments) }; diff --git a/src/Simple/JSON.purs b/src/Simple/JSON.purs index f73eca8..05cde98 100644 --- a/src/Simple/JSON.purs +++ b/src/Simple/JSON.purs @@ -39,7 +39,7 @@ import Data.Identity (Identity(..)) import Data.List.NonEmpty (singleton) import Data.Maybe (Maybe(..), maybe) import Data.Nullable (Nullable, toMaybe, toNullable) -import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol) +import Data.Symbol (class IsSymbol, reflectSymbol) import Data.Traversable (sequence, traverse) import Data.TraversableWithIndex (traverseWithIndex) import Data.Variant (Variant, inj, on) @@ -56,7 +56,7 @@ import Prim.RowList (class RowToList, Cons, Nil, RowList) import Record (get) import Record.Builder (Builder) import Record.Builder as Builder -import Type.Prelude (Proxy(..)) +import Type.Proxy (Proxy(..)) -- | An alias for the Either result of decoding type E a = Either MultipleErrors a @@ -227,7 +227,7 @@ instance readFieldsCons :: value <- withExcept' (readImpl =<< readProp name obj) pure $ Builder.insert nameP value rest = getFields tailP obj - nameP = SProxy :: SProxy name + nameP = Proxy :: Proxy name tailP = Proxy :: Proxy tail name = reflectSymbol nameP withExcept' = withExcept <<< map $ ErrorAtProperty name @@ -280,7 +280,7 @@ instance readVariantCons :: (fail <<< ForeignError $ "Did not match variant tag " <> name) <|> readVariantImpl (Proxy :: Proxy tail) o where - namep = SProxy :: SProxy name + namep = Proxy :: Proxy name name = reflectSymbol namep -- -- | A class for writing a value into JSON @@ -341,7 +341,7 @@ instance consWriteForeignFields :: ) => WriteForeignFields (Cons name ty tail) row from to where writeImplFields _ rec = result where - namep = SProxy :: SProxy name + namep = Proxy :: Proxy name value = writeImpl $ get namep rec tailp = Proxy :: Proxy tail rest = writeImplFields tailp rec @@ -379,7 +379,7 @@ instance consWriteForeignVariant :: (writeVariantImpl (Proxy :: Proxy tail)) variant where - namep = SProxy :: SProxy name + namep = Proxy :: Proxy name writeVariant value = unsafeToForeign { type: reflectSymbol namep , value: writeImpl value diff --git a/test/EnumSumGeneric.purs b/test/EnumSumGeneric.purs index 3d2f403..6da72cb 100644 --- a/test/EnumSumGeneric.purs +++ b/test/EnumSumGeneric.purs @@ -12,7 +12,8 @@ import Foreign (Foreign) import Foreign as Foreign import Simple.JSON as JSON import Test.Assert (assert) -import Type.Prelude (class IsSymbol, SProxy(..), reflectSymbol) +import Type.Prelude (class IsSymbol, reflectSymbol) +import Type.Proxy (Proxy(..)) enumReadForeign :: forall a rep . Generic a rep @@ -44,7 +45,7 @@ instance constructorEnumReadForeign :: else throwError <<< pure <<< Foreign.ForeignError $ "Enum string " <> s <> " did not match expected string " <> name where - name = reflectSymbol (SProxy :: SProxy name) + name = reflectSymbol (Proxy :: Proxy name) data Fruit = Abogado diff --git a/test/Inferred.purs b/test/Inferred.purs index 7dea705..f2b25fc 100644 --- a/test/Inferred.purs +++ b/test/Inferred.purs @@ -11,7 +11,7 @@ import Foreign as Foreign import Record as Record import Simple.JSON as JSON import Test.Assert (assert) -import Type.Prelude (SProxy(..)) +import Type.Proxy (Proxy(..)) type RecordWithEither = { apple :: Int @@ -43,8 +43,8 @@ readRecordMisnamedField s = do inter <- JSON.readJSON s pure $ Record.rename grapeP cherryP inter where - grapeP = SProxy :: SProxy "grape" - cherryP = SProxy :: SProxy "cherry" + grapeP = Proxy :: Proxy "grape" + cherryP = Proxy :: Proxy "cherry" main :: Effect Unit main = do diff --git a/test/Util.purs b/test/Util.purs index 52b8a96..d35600a 100644 --- a/test/Util.purs +++ b/test/Util.purs @@ -5,7 +5,8 @@ import Prelude import Prim.Row as Row import Prim.RowList (class RowToList, Cons, Nil, RowList) import Record (get) -import Type.Prelude (class IsSymbol, RLProxy(..), SProxy(..)) +import Type.Prelude (class IsSymbol) +import Type.Proxy (Proxy(..)) -- | Check two records of the same type for equality. equal @@ -15,10 +16,10 @@ equal => Record r -> Record r -> Boolean -equal a b = equalFields (RLProxy :: RLProxy rs) a b +equal a b = equalFields (Proxy :: Proxy rs) a b class EqualFields (rs :: RowList Type) (row :: Row Type) | rs -> row where - equalFields :: RLProxy rs -> Record row -> Record row -> Boolean + equalFields :: Proxy rs -> Record row -> Record row -> Boolean instance equalFieldsCons :: @@ -29,8 +30,8 @@ instance equalFieldsCons ) => EqualFields (Cons name ty tail) row where equalFields _ a b = get' a == get' b && rest where - get' = get (SProxy :: SProxy name) - rest = equalFields (RLProxy :: RLProxy tail) a b + get' = get (Proxy :: Proxy name) + rest = equalFields (Proxy :: Proxy tail) a b instance equalFieldsNil :: EqualFields Nil row where equalFields _ _ _ = true From c0cb9a06d222d6b54f32838fc4c4bd4ec16ee6e4 Mon Sep 17 00:00:00 2001 From: justinwoo Date: Thu, 12 May 2022 21:37:05 +0300 Subject: [PATCH 2/2] more updates --- bower.json | 20 ++++++++++---------- ci.nix | 34 +++++++++++++++++----------------- src/Simple/JSON.js | 4 ++-- src/Simple/JSON.purs | 1 + test.bash | 10 +++------- test/index.mjs | 3 +++ 6 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 test/index.mjs diff --git a/bower.json b/bower.json index cac5e2a..d53cfc8 100644 --- a/bower.json +++ b/bower.json @@ -12,17 +12,17 @@ "output" ], "dependencies": { - "purescript-prelude": "^5.0.0", - "purescript-typelevel-prelude": "^6.0.0", - "purescript-record": "^3.0.0", - "purescript-variant": "^7.0.1", - "purescript-nullable": "^5.0.0", - "purescript-foreign-object": "^3.0.0", - "purescript-foreign": "^6.0.0", - "purescript-exceptions": "^5.0.0", - "purescript-arrays": "^6.0.0" + "purescript-prelude": "^6.0.0", + "purescript-typelevel-prelude": "^7.0.0", + "purescript-record": "^4.0.0", + "purescript-variant": "^8.0.0", + "purescript-nullable": "^6.0.0", + "purescript-foreign-object": "^4.0.0", + "purescript-foreign": "^7.0.0", + "purescript-exceptions": "^6.0.0", + "purescript-arrays": "^7.0.0" }, "devDependencies": { - "purescript-assert": "^5.0.0" + "purescript-assert": "^6.0.0" } } diff --git a/ci.nix b/ci.nix index 21391e1..f37e3f4 100644 --- a/ci.nix +++ b/ci.nix @@ -5,22 +5,22 @@ let }; in -{ pkgs ? import nixpkgs {} }: +{ pkgs ? import nixpkgs { } }: - let - ezPscSrc = pkgs.fetchFromGitHub { - owner = "justinwoo"; - repo = "easy-purescript-nix"; - rev = "e8a1ffafafcdf2e81adba419693eb35f3ee422f8"; - sha256 = "0bk32wckk82f1j5i5gva63f3b3jl8swc941c33bqc3pfg5cgkyyf"; - }; - ezPsc = import ezPscSrc { inherit pkgs; }; - in +let + ezPscSrc = pkgs.fetchFromGitHub { + owner = "justinwoo"; + repo = "easy-purescript-nix"; + rev = "0ad5775c1e80cdd952527db2da969982e39ff592"; + sha256 = "0x53ads5v8zqsk4r1mfpzf5913byifdpv5shnvxpgw634ifyj1kg"; + }; + ezPsc = import ezPscSrc { inherit pkgs; }; +in - pkgs.mkShell { - buildInputs = [ - ezPsc.purs-0_14_0 - pkgs.nodePackages_10_x.bower - pkgs.nodePackages_10_x.pulp - ]; - } +pkgs.mkShell { + buildInputs = [ + ezPsc.purs-0_15_0 + ezPsc.pulp + pkgs.nodePackages_10_x.bower + ]; +} diff --git a/src/Simple/JSON.js b/src/Simple/JSON.js index fcb2730..dea1f65 100644 --- a/src/Simple/JSON.js +++ b/src/Simple/JSON.js @@ -1,5 +1,5 @@ -export function _parseJSON() { return JSON.parse.apply(this, arguments) }; +export const _parseJSON = JSON.parse; export const _undefined = undefined; -export function _unsafeStringify() { return JSON.stringify.apply(this, arguments) }; +export const _unsafeStringify = JSON.stringify; diff --git a/src/Simple/JSON.purs b/src/Simple/JSON.purs index 05cde98..4d49b4b 100644 --- a/src/Simple/JSON.purs +++ b/src/Simple/JSON.purs @@ -8,6 +8,7 @@ module Simple.JSON , read , read' , read_ +, readAsForeign , parseJSON , undefined , unsafeStringify diff --git a/test.bash b/test.bash index 69a3688..ce9dbbb 100755 --- a/test.bash +++ b/test.bash @@ -3,10 +3,6 @@ bower install -# NOTE: The following bug has been fixed, but the fix hasn't been upstreamed -# to the version of nixpkgs pinned in this repo: -# -# https://github.com/purescript-contrib/pulp/issues/392 -# -# Once pulp has been updated, drop '--no-check-main' -pulp test --no-check-main +pulp build --include test + +node ./test/index.mjs diff --git a/test/index.mjs b/test/index.mjs new file mode 100644 index 0000000..6c2c897 --- /dev/null +++ b/test/index.mjs @@ -0,0 +1,3 @@ +import { main } from "../output/Test.Main/index.js"; + +main();