From 8d415fdb8fc0193d2e7eabb34a814f6bbf56dbac Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 7 Mar 2022 11:04:23 -0600 Subject: [PATCH 01/33] Add PS version 0.15.0-alpha-01 --- .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 049cf40c..733b81c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - purs_test_version: [v0.12.0, v0.12.4, v0.12.5, v0.13.0, v0.14.0, v0.14.5] + purs_test_version: [v0.12.0, v0.12.4, v0.12.5, v0.13.0, v0.14.0, v0.14.5, v0.15.0-alpha-01] fail-fast: false runs-on: ${{ matrix.os }} env: From e3164479636a4006ee706dac716c577238af55b8 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 09:35:56 -0600 Subject: [PATCH 02/33] Centralize versions for purescript --- src/Pulp/Build.purs | 5 +++-- src/Pulp/Docs.purs | 8 +++----- src/Pulp/Init.purs | 8 ++++---- src/Pulp/Publish.purs | 8 +++----- src/Pulp/Validate.purs | 8 ++++++-- src/Pulp/Versions/PureScript.purs | 18 ++++++++++++++++++ 6 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 src/Pulp/Versions/PureScript.purs diff --git a/src/Pulp/Build.purs b/src/Pulp/Build.purs index f3a6f619..37babd01 100644 --- a/src/Pulp/Build.purs +++ b/src/Pulp/Build.purs @@ -31,7 +31,8 @@ import Pulp.Outputter (getOutputter) import Pulp.Sorcery (sorcery) import Pulp.System.Files as Files import Pulp.System.Stream (write, end, WritableStream, stdout) -import Pulp.Validate (getPsaVersion, getPursVersion) +import Pulp.Validate (dropPreRelBuildMeta, getPsaVersion, getPursVersion) +import Pulp.Versions.PureScript (psVersions) data BuildType = NormalBuild | TestBuild | RunBuild @@ -68,7 +69,7 @@ go buildType = Action \args -> do jobs :: Maybe Int <- getOption "jobs" args.commandOpts let jobsArgs = maybe [] (\j -> ["+RTS", "-N" <> show j, "-RTS"]) jobs sourceMapArg = case sourceMaps of - true | ver >= Version (NEL.cons' 0 (Cons 12 (Cons 0 Nil))) Nil -> [ "--codegen", "sourcemaps" ] + true | (dropPreRelBuildMeta ver) >= psVersions.v0_12_0 -> [ "--codegen", "sourcemaps" ] true -> ["--source-maps"] _ -> [] sourceGlobs = sources globs diff --git a/src/Pulp/Docs.purs b/src/Pulp/Docs.purs index 9b527ded..dc59b7c2 100644 --- a/src/Pulp/Docs.purs +++ b/src/Pulp/Docs.purs @@ -3,12 +3,9 @@ module Pulp.Docs where import Prelude -import Data.List (List(..)) -import Data.List.NonEmpty as NEL import Data.Map as Map import Data.Maybe (Maybe(..)) import Data.Set as Set -import Data.Version.Haskell (Version(..)) import Effect.Class (liftEffect) import Node.Process as Process import Pulp.Args (Action(..)) @@ -16,7 +13,8 @@ import Pulp.Args.Get (getFlag, getOption') import Pulp.Exec (exec) import Pulp.Files (defaultGlobs, sources, testGlobs) import Pulp.Outputter (getOutputter) -import Pulp.Validate (getPursVersion) +import Pulp.Validate (dropPreRelBuildMeta, getPursVersion) +import Pulp.Versions.PureScript (psVersions) action :: Action action = Action \args -> do @@ -35,7 +33,7 @@ action = Action \args -> do buildPath <- getOption' "buildPath" opts - when (pursVersion < Version (NEL.cons' 0 (Cons 13 (Cons 0 Nil))) Nil) + when ((dropPreRelBuildMeta pursVersion) < psVersions.v0_13_0) (out.log "Warning: 'pulp docs' now only supports 'purs' v0.13.0 and above. Please either update 'purs' or downgrade 'pulp'.") exec "purs" (["docs", "--compile-output", buildPath] <> args.remainder <> sources globInputFiles) Nothing diff --git a/src/Pulp/Init.purs b/src/Pulp/Init.purs index e0b487e9..6d1f60b9 100644 --- a/src/Pulp/Init.purs +++ b/src/Pulp/Init.purs @@ -11,7 +11,6 @@ import Data.List (List(..), (:)) import Data.List.NonEmpty as NEL import Data.String (joinWith) import Data.Version.Haskell (Version(..)) -import Data.Version.Haskell as HVer import Effect.Aff (Aff) import Effect.Class (liftEffect) import Effect.Exception (error) @@ -25,7 +24,8 @@ import Pulp.Outputter (Outputter, getOutputter) import Pulp.PackageManager (launchBower, launchPscPackage) import Pulp.System.Files (mkdirIfNotExist) import Pulp.Utils (throw) -import Pulp.Validate (getPursVersion) +import Pulp.Validate (dropPreRelBuildMeta, getPursVersion) +import Pulp.Versions.PureScript (psVersions) foreign import bowerFile :: String -> String @@ -205,13 +205,13 @@ action = Action \args -> do where - minEffectVersion = HVer.Version (NEL.cons' 0 (Cons 12 (Cons 0 Nil))) Nil + minEffectVersion = psVersions.v0_12_0 getEffOrEffect out withEff withEffect | withEff = pure UseEff | withEffect = pure UseEffect | otherwise = do ver <- getPursVersion out - if ver < minEffectVersion + if (dropPreRelBuildMeta ver) < minEffectVersion then pure UseEff else pure UseEffect diff --git a/src/Pulp/Publish.purs b/src/Pulp/Publish.purs index 6ac7efc9..2407dc08 100644 --- a/src/Pulp/Publish.purs +++ b/src/Pulp/Publish.purs @@ -7,8 +7,6 @@ import Control.Parallel (parTraverse) import Data.Array as Array import Data.Either (Either(..)) import Data.Foldable (fold, or) -import Data.List (List(..)) -import Data.List.NonEmpty as NEL import Data.Maybe (Maybe(..), maybe) import Data.Options ((:=)) import Data.String as String @@ -16,7 +14,6 @@ import Data.Tuple (Tuple(..)) import Data.Tuple.Nested ((/\)) import Data.Version (Version) import Data.Version as Version -import Data.Version.Haskell (Version(..)) as Haskell import Effect.Aff (Aff, attempt, throwError) import Effect.Class (liftEffect) import Foreign (renderForeignError) @@ -39,7 +36,8 @@ import Pulp.System.HTTP (httpRequest) import Pulp.System.Read as Read import Pulp.System.Stream (concatStream, concatStreamToBuffer, createGzip, end, write) import Pulp.Utils (orErr, throw) -import Pulp.Validate (getPursVersion) +import Pulp.Validate (dropPreRelBuildMeta, getPursVersion) +import Pulp.Versions.PureScript (psVersions) import Simple.JSON as SimpleJSON -- TODO: @@ -195,7 +193,7 @@ resolutionsFile manifest args = do out <- getOutputter args ver <- getPursVersion out resolutionsData <- - if ver >= Haskell.Version (NEL.cons' 0 (Cons 12 (Cons 4 Nil))) Nil + if (dropPreRelBuildMeta ver) >= psVersions.v0_12_4 then do let hasDependencies = maybe false (not <<< Object.isEmpty) manifest.dependencies diff --git a/src/Pulp/Validate.purs b/src/Pulp/Validate.purs index 8283d6e3..d1b1f8b5 100644 --- a/src/Pulp/Validate.purs +++ b/src/Pulp/Validate.purs @@ -2,6 +2,7 @@ module Pulp.Validate ( validate , getPursVersion , getPsaVersion + , dropPreRelBuildMeta ) where import Prelude @@ -9,7 +10,6 @@ import Prelude import Control.Monad.Error.Class (throwError) import Data.Either (Either(..)) import Data.List (List(..)) -import Data.List.NonEmpty as NEL import Data.Maybe (Maybe(..)) import Data.String (codePointFromChar, takeWhile, trim) import Data.Version.Haskell (Version(..), parseVersion, showVersion) @@ -17,6 +17,7 @@ import Effect.Aff (Aff) import Effect.Exception (error) import Pulp.Exec (execQuiet) import Pulp.Outputter (Outputter) +import Pulp.Versions.PureScript (psVersions) validate :: Outputter -> Aff Version validate out = do @@ -34,7 +35,7 @@ getPursVersion :: Outputter -> Aff Version getPursVersion = getVersionFrom "purs" minimumPursVersion :: Version -minimumPursVersion = Version (NEL.cons' 0 (Cons 12 (Cons 0 Nil))) Nil +minimumPursVersion = psVersions.v0_12_0 getPsaVersion :: Outputter -> Aff Version getPsaVersion = getVersionFrom "psa" @@ -49,3 +50,6 @@ getVersionFrom bin out = do out.err $ "Unable to parse the version from " <> bin <> ". (It was: " <> verStr <> ")" out.err $ "Please check that the right executable is on your PATH." throwError $ error ("Couldn't parse version from " <> bin) + +dropPreRelBuildMeta :: Version -> Version +dropPreRelBuildMeta (Version mmp _) = Version mmp Nil diff --git a/src/Pulp/Versions/PureScript.purs b/src/Pulp/Versions/PureScript.purs new file mode 100644 index 00000000..9e4d8162 --- /dev/null +++ b/src/Pulp/Versions/PureScript.purs @@ -0,0 +1,18 @@ +module Pulp.Versions.PureScript where + +import Data.List (List(..), (:)) +import Data.List.NonEmpty as NEL +import Data.Version.Haskell (Version(..)) + +type PureScriptVersions = + { v0_12_0 :: Version + , v0_12_4 :: Version + , v0_13_0 :: Version + } + +psVersions :: PureScriptVersions +psVersions = + { v0_12_0: Version (NEL.cons' 0 (12 : 0 : Nil)) Nil + , v0_12_4: Version (NEL.cons' 0 (12 : 4 : Nil)) Nil + , v0_13_0: Version (NEL.cons' 0 (13 : 0 : Nil)) Nil + } \ No newline at end of file From 10ee69c51e996be9299b0b0d89a7c64a85101b13 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 7 Mar 2022 11:13:48 -0600 Subject: [PATCH 03/33] Add validator when using bundle or CJS --- src/Pulp/Validate.purs | 19 ++++++++++++++++++- src/Pulp/Versions/PureScript.purs | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Pulp/Validate.purs b/src/Pulp/Validate.purs index d1b1f8b5..c4e8f3d0 100644 --- a/src/Pulp/Validate.purs +++ b/src/Pulp/Validate.purs @@ -3,18 +3,23 @@ module Pulp.Validate , getPursVersion , getPsaVersion , dropPreRelBuildMeta + , failIfUsingEsModulesPsVersion ) where import Prelude import Control.Monad.Error.Class (throwError) +import Data.Array (fold) import Data.Either (Either(..)) +import Data.Foldable (for_) import Data.List (List(..)) import Data.Maybe (Maybe(..)) import Data.String (codePointFromChar, takeWhile, trim) import Data.Version.Haskell (Version(..), parseVersion, showVersion) +import Data.Version.Haskell as Version import Effect.Aff (Aff) -import Effect.Exception (error) +import Effect.Class (liftEffect) +import Effect.Exception (error, throw) import Pulp.Exec (execQuiet) import Pulp.Outputter (Outputter) import Pulp.Versions.PureScript (psVersions) @@ -51,5 +56,17 @@ getVersionFrom bin out = do out.err $ "Please check that the right executable is on your PATH." throwError $ error ("Couldn't parse version from " <> bin) +failIfUsingEsModulesPsVersion :: Outputter -> Maybe String -> Aff Unit +failIfUsingEsModulesPsVersion out mbMsg = do + psVer <- getPursVersion out + unless ((dropPreRelBuildMeta psVer) < psVersions.v0_15_0) do + out.err $ fold + [ "This code path implicitly uses `purs bundle` or CommonsJS modules, both of which are no longer supported in PureScript v0.15.0." + , "You are using PureScript " <> Version.showVersion psVer + , "See https://github.com/purescript/documentation/blob/master/migration-guides/0.15-Migration-Guide.md" + ] + for_ mbMsg out.err + liftEffect $ throw $ "Your version of PureScript cannot use `purs bundle` or CommonJS modules. Please use another bundler (e.g. esbuild) instead." + dropPreRelBuildMeta :: Version -> Version dropPreRelBuildMeta (Version mmp _) = Version mmp Nil diff --git a/src/Pulp/Versions/PureScript.purs b/src/Pulp/Versions/PureScript.purs index 9e4d8162..9704d38f 100644 --- a/src/Pulp/Versions/PureScript.purs +++ b/src/Pulp/Versions/PureScript.purs @@ -8,6 +8,7 @@ type PureScriptVersions = { v0_12_0 :: Version , v0_12_4 :: Version , v0_13_0 :: Version + , v0_15_0 :: Version } psVersions :: PureScriptVersions @@ -15,4 +16,5 @@ psVersions = { v0_12_0: Version (NEL.cons' 0 (12 : 0 : Nil)) Nil , v0_12_4: Version (NEL.cons' 0 (12 : 4 : Nil)) Nil , v0_13_0: Version (NEL.cons' 0 (13 : 0 : Nil)) Nil + , v0_15_0: Version (NEL.cons' 0 (15 : 0 : Nil)) Nil } \ No newline at end of file From 3674ee42150a4da904f4c2ac34d86076cb2a3d65 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 4 Mar 2022 15:54:56 -0600 Subject: [PATCH 04/33] Fail when use purs bundle if purs not support it --- src/Pulp/Browserify.purs | 4 ++++ src/Pulp/Build.purs | 15 ++++++++++++--- src/Pulp/Server.purs | 5 +++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Pulp/Browserify.purs b/src/Pulp/Browserify.purs index 0f7f0882..aa60ef0c 100644 --- a/src/Pulp/Browserify.purs +++ b/src/Pulp/Browserify.purs @@ -32,11 +32,15 @@ import Pulp.Sorcery (sorcery) import Pulp.System.FFI (Callback, runNode) import Pulp.System.Files (openTemp) import Pulp.System.Stream (WritableStream) +import Pulp.Validate (failIfUsingEsModulesPsVersion) action :: Action action = Action \args -> do out <- getOutputter args + failIfUsingEsModulesPsVersion out $ Just + "Code path reason: browserify only works on CommonJS modules" + cwd <- liftEffect Process.cwd out.log $ "Browserifying project in " <> cwd diff --git a/src/Pulp/Build.purs b/src/Pulp/Build.purs index 37babd01..5bf71be7 100644 --- a/src/Pulp/Build.purs +++ b/src/Pulp/Build.purs @@ -4,6 +4,7 @@ module Pulp.Build , testBuild , runBuild , withOutputStream + , shouldBundle ) where import Prelude @@ -31,7 +32,7 @@ import Pulp.Outputter (getOutputter) import Pulp.Sorcery (sorcery) import Pulp.System.Files as Files import Pulp.System.Stream (write, end, WritableStream, stdout) -import Pulp.Validate (dropPreRelBuildMeta, getPsaVersion, getPursVersion) +import Pulp.Validate (dropPreRelBuildMeta, failIfUsingEsModulesPsVersion, getPsaVersion, getPursVersion) import Pulp.Versions.PureScript (psVersions) data BuildType = NormalBuild | TestBuild | RunBuild @@ -91,8 +92,16 @@ go buildType = Action \args -> do out.log "Build successful." - shouldBundle <- (||) <$> getFlag "optimise" opts <*> hasOption "to" opts - when shouldBundle (bundle args) + shouldBundle' <- shouldBundle args + when shouldBundle' do + failIfUsingEsModulesPsVersion out $ Just + "Code path reason: you used the --optimize and/or --to flag(s)" + bundle args + +shouldBundle :: Args -> Aff Boolean +shouldBundle args = do + let opts = union args.globalOpts args.commandOpts + (||) <$> getFlag "optimise" opts <*> hasOption "to" opts shouldUsePsa :: Args -> Aff Boolean shouldUsePsa args = do diff --git a/src/Pulp/Server.purs b/src/Pulp/Server.purs index c71acc8d..a167aab2 100644 --- a/src/Pulp/Server.purs +++ b/src/Pulp/Server.purs @@ -23,6 +23,7 @@ import Pulp.Build as Build import Pulp.Outputter (getOutputter) import Pulp.System.StaticServer as StaticServer import Pulp.Utils (orErr) +import Pulp.Validate (failIfUsingEsModulesPsVersion) import Pulp.Watch (watchAff, watchDirectories) data BuildResult @@ -38,6 +39,10 @@ action = Action \args -> do let opts = Map.union args.globalOpts args.commandOpts out <- getOutputter args + whenM (Build.shouldBundle args) do + failIfUsingEsModulesPsVersion out $ Just + "Code path reason: `pulp server` uses `purs bundle` implicitly." + bundleFileName <- getBundleFileName opts hostname <- getOption' "host" opts port <- getOption' "port" opts From 61dcab3e9bd3ea3a6e3f5354c424585ae16a093e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 7 Mar 2022 11:23:18 -0600 Subject: [PATCH 05/33] Update init to download es-modules branches --- src/Pulp/Init.purs | 28 +++++++++++++++++++++------- src/Pulp/Versions/PureScript.purs | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Pulp/Init.purs b/src/Pulp/Init.purs index 6d1f60b9..62f0d8ad 100644 --- a/src/Pulp/Init.purs +++ b/src/Pulp/Init.purs @@ -7,10 +7,8 @@ import Prelude import Control.Monad.Error.Class (throwError) import Data.Array (cons) import Data.Foldable (for_) -import Data.List (List(..), (:)) -import Data.List.NonEmpty as NEL +import Data.Maybe (Maybe(..)) import Data.String (joinWith) -import Data.Version.Haskell (Version(..)) import Effect.Aff (Aff) import Effect.Class (liftEffect) import Effect.Exception (error) @@ -24,7 +22,7 @@ import Pulp.Outputter (Outputter, getOutputter) import Pulp.PackageManager (launchBower, launchPscPackage) import Pulp.System.Files (mkdirIfNotExist) import Pulp.Utils (throw) -import Pulp.Validate (dropPreRelBuildMeta, getPursVersion) +import Pulp.Validate (dropPreRelBuildMeta, failIfUsingEsModulesPsVersion, getPursVersion) import Pulp.Versions.PureScript (psVersions) foreign import bowerFile :: String -> String @@ -145,6 +143,8 @@ init initStyle effOrEffect force out = do where install Bower UseEff p = do + failIfUsingEsModulesPsVersion out $ Just + "'purescript-eff' has been archived, so the FFI's CJS modules cannot be migrated to ES modules." launchBower ["install", "--save", p.prelude, p.console] launchBower ["install", "--save-dev", p.psciSupport] @@ -153,31 +153,45 @@ init initStyle effOrEffect force out = do launchBower ["install", "--save-dev", p.psciSupport ] install PscPackage UseEff _ = do + failIfUsingPscPackageAndEsModules + launchPscPackage ["init"] launchPscPackage ["install", "eff"] launchPscPackage ["install", "console"] launchPscPackage ["install", "psci-support"] install PscPackage UseEffect _ = do + failIfUsingPscPackageAndEsModules + launchPscPackage ["init"] launchPscPackage ["install", "effect"] launchPscPackage ["install", "console"] launchPscPackage ["install", "psci-support"] + failIfUsingPscPackageAndEsModules = do + failIfUsingEsModulesPsVersion out $ Just + "'psc-package' not yet supported on a `purs` version that compiles to ES modules." + getDepsVersions v - | v >= Version (NEL.cons' 0 (14 : 0 : Nil)) Nil = + | v >= psVersions.v0_15_0 = + { prelude: "purescript-prelude=working-group-purescript-es/purescript-prelude#es-modules-libraries" + , console: "purescript-console=working-group-purescript-es/purescript-console#es-modules-libraries" + , effect: "purescript-effect=working-group-purescript-es/purescript-effect#es-modules-libraries" + , psciSupport: "purescript-psci-support=purescript/purescript-psci-support#update-to-0.15" + } + | v >= psVersions.v0_14_0 = { prelude: "purescript-prelude@v5.0.1" , console: "purescript-console@v5.0.0" , effect: "purescript-effect@v3.0.0" , psciSupport: "purescript-psci-support@v5.0.0" } - | v >= Version (NEL.cons' 0 (13 : 0 : Nil)) Nil = + | v >= psVersions.v0_13_0 = { prelude: "purescript-prelude@v4.1.1" , console: "purescript-console@v4.4.0" , effect: "purescript-effect@v2.0.1" , psciSupport: "purescript-psci-support@v4.0.0" } - | v >= Version (NEL.cons' 0 (12 : 0 : Nil)) Nil = + | v >= psVersions.v0_12_0 = { prelude: "purescript-prelude@v4.1.1" , console: "purescript-console@v4.4.0" , effect: "purescript-effect@v2.0.1" diff --git a/src/Pulp/Versions/PureScript.purs b/src/Pulp/Versions/PureScript.purs index 9704d38f..b6f20ae1 100644 --- a/src/Pulp/Versions/PureScript.purs +++ b/src/Pulp/Versions/PureScript.purs @@ -8,6 +8,7 @@ type PureScriptVersions = { v0_12_0 :: Version , v0_12_4 :: Version , v0_13_0 :: Version + , v0_14_0 :: Version , v0_15_0 :: Version } @@ -16,5 +17,6 @@ psVersions = { v0_12_0: Version (NEL.cons' 0 (12 : 0 : Nil)) Nil , v0_12_4: Version (NEL.cons' 0 (12 : 4 : Nil)) Nil , v0_13_0: Version (NEL.cons' 0 (13 : 0 : Nil)) Nil + , v0_14_0: Version (NEL.cons' 0 (14 : 0 : Nil)) Nil , v0_15_0: Version (NEL.cons' 0 (15 : 0 : Nil)) Nil } \ No newline at end of file From 654eba47c0540b0006feaa64b3cc4712b039735e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 7 Mar 2022 11:25:05 -0600 Subject: [PATCH 06/33] Update run/test tests to work on es modules --- test-js/{resources => cjs}/Main.js | 0 test-js/{resources => cjs}/Main.purs | 0 test-js/es/Main.js | 15 +++++++++++++++ test-js/es/Main.purs | 20 ++++++++++++++++++++ test-js/integration.js | 22 ++++++++++++++++------ 5 files changed, 51 insertions(+), 6 deletions(-) rename test-js/{resources => cjs}/Main.js (100%) rename test-js/{resources => cjs}/Main.purs (100%) create mode 100644 test-js/es/Main.js create mode 100644 test-js/es/Main.purs diff --git a/test-js/resources/Main.js b/test-js/cjs/Main.js similarity index 100% rename from test-js/resources/Main.js rename to test-js/cjs/Main.js diff --git a/test-js/resources/Main.purs b/test-js/cjs/Main.purs similarity index 100% rename from test-js/resources/Main.purs rename to test-js/cjs/Main.purs diff --git a/test-js/es/Main.js b/test-js/es/Main.js new file mode 100644 index 00000000..161b3749 --- /dev/null +++ b/test-js/es/Main.js @@ -0,0 +1,15 @@ +// module Test.Main + +export const argv = function argv() { + return process.argv; +}; + +export const slice = function slice(n) { + return function (arr) { + return arr.slice(n); + }; +}; + +export const length = function length(arr) { + return arr.length; +}; diff --git a/test-js/es/Main.purs b/test-js/es/Main.purs new file mode 100644 index 00000000..5e371a5d --- /dev/null +++ b/test-js/es/Main.purs @@ -0,0 +1,20 @@ +module Test.Main where + +import Prelude +import Effect (Effect, foreachE) +import Effect.Console (log) + +foreign import argv :: Effect (Array String) +foreign import slice :: forall a. Int -> Array a -> Array a +foreign import length :: forall a. Array a -> Int + +drop :: forall a. Int -> Array a -> Array a +drop n arr + | n < 1 = arr + | n >= length arr = [] + | otherwise = slice n arr + +main :: Effect Unit +main = do + args <- drop 2 <$> argv + foreachE args log diff --git a/test-js/integration.js b/test-js/integration.js index ebe9608c..726fd4c9 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -282,11 +282,16 @@ describe("integration tests", function() { })); it("pulp run -- program args", run(function*(sh, pulp, assert, temp) { - const srcDir = path.join(temp, "run_with_args"); yield pulp("init"); + + const srcDir = path.join(temp, "run_with_args"); yield fs.mkdir(srcDir); - yield fs.copy(path.resolve(__dirname, "resources/Main.purs"), path.join(srcDir, "Main.purs")); - yield fs.copy(path.resolve(__dirname, "resources/Main.js"), path.join(srcDir, "Main.js")); + + const pursVer = yield getPursVersion(sh, assert); + const resourceDir = semver.gte(pursVer, semver.parse('0.15.0')) ? "es": "cjs"; + yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.purs`), path.join(srcDir, "Main.purs")); + yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.js`), path.join(srcDir, "Main.js")); + const [out] = yield pulp("run --src-path run_with_args -m Test.Main -- program args"); assert.equal(out.trim(), "program\nargs"); })); @@ -357,11 +362,16 @@ describe("integration tests", function() { })); it("pulp test --test-path test2 -- --something-node-wouldnt-like", run(function*(sh, pulp, assert, temp) { - const newTest = path.join(temp, "test2"); yield pulp("init"); + + const newTest = path.join(temp, "test2"); yield fs.mkdir(newTest); - yield fs.copy(path.resolve(__dirname, "resources/Main.purs"), path.join(newTest, "Main.purs")); - yield fs.copy(path.resolve(__dirname, "resources/Main.js"), path.join(newTest, "Main.js")); + + const pursVer = yield getPursVersion(sh, assert); + const resourceDir = semver.gte(pursVer, semver.parse('0.15.0')) ? "es": "cjs"; + yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.purs`), path.join(newTest, "Main.purs")); + yield fs.copy(path.resolve(__dirname, `${resourceDir}/Main.js`), path.join(newTest, "Main.js")); + const [out] = yield pulp("test --test-path test2 -- --something-node-wouldnt-like"); assert.equal(out.trim(), "--something-node-wouldnt-like"); })); From e258fb954b6ae779584ce2e7623ff64651478f8b Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 5 Mar 2022 12:22:46 -0600 Subject: [PATCH 07/33] Add fn to skip test if using <0.15.0 PS release --- test-js/integration.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index 726fd4c9..f6a98838 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -5,6 +5,7 @@ import run from "./sh"; import semver from "semver"; import touch from "touch"; import which from "which"; +import CP from "child_process"; const hello = "Hello sailor!"; const test = "You should add some tests."; @@ -122,13 +123,28 @@ function* createModule(sh, temp, name) { const getPursVersion = co.wrap(function*(sh, assert) { const [out] = yield sh("purs --version"); - const pursVer = semver.parse(out.split(/\s/)[0]); + // Drops pre-release identifiers + // 0.15.0-alpha-01 --> 0.15.0 + const pursVerWithExtras = semver.coerce(out.split(/\s/)[0]); + const pursVer = pursVerWithExtras === null ? semver.parse(pursVerWithExtras) : pursVerWithExtras; if (pursVer == null) { assert.fail("Unable to parse output of purs --version"); } return pursVer; }); +const psVersionUsed = CP.execSync("purs --version").toString("utf-8"); + +const notEsModulesPsVersionIt = function(testName, cb) { + const pursVerWithExtras = semver.coerce(psVersionUsed.split(/\s/)[0]); + const pursVer = semver.parse(pursVerWithExtras); + if (semver.lt(pursVer, semver.parse('0.15.0'))) { + it(testName, cb); + } else { + it.skip(testName, cb); + } +} + describe("integration tests", function() { // This is, unfortunately, required, as CI is horrendously slow. this.timeout(90000); From 0bf935d9ada36e320bf210cac980040822f252fc Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 09:50:05 -0600 Subject: [PATCH 08/33] Ignore tests that will fail on v0.15.0 - browserify uses CJS, so it will fail - build --optimize/--to uses `purs bundle` - psc-package is not yet supported - `pulp test --runtime` uses `--to` flag - all other tests use `--optimize`/`--to` flag in test --- test-js/integration.js | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test-js/integration.js b/test-js/integration.js index f6a98838..d72ff5de 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -164,7 +164,7 @@ describe("integration tests", function() { assert.equal(err.trim(), bowerMissing); })); - it("Bower has precedence over psc-package", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("Bower has precedence over psc-package", run(function*(sh, pulp, assert) { yield pulp("init"); // Create psc-package.json without installing any dependencies @@ -229,7 +229,7 @@ describe("integration tests", function() { assert.exists(path.join("output", "Main", "index.js")); })); - it("pulp build with psc-package", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("pulp build with psc-package", run(function*(sh, pulp, assert, temp) { yield pulp("--psc-package init"); yield pulp("build"); @@ -312,35 +312,35 @@ describe("integration tests", function() { assert.equal(out.trim(), "program\nargs"); })); - it("pulp build --to", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp build --to", run(function*(sh, pulp, assert) { yield pulp("init"); yield pulp("build --to out.js"); const [out] = yield sh("node out.js"); assert.equal(out.trim(), hello); })); - it("pulp build --to creates parent directories", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp build --to creates parent directories", run(function*(sh, pulp, assert) { yield pulp("init"); yield pulp("build --to nonexistent/out.js"); const [out] = yield sh("node nonexistent/out.js"); assert.equal(out.trim(), hello); })); - it("pulp build --skip-entry-point --to", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("pulp build --skip-entry-point --to", run(function*(sh, pulp, assert, temp) { yield pulp("init"); yield pulp(`--then "echo module.exports = PS >> out.js" build --skip-entry-point --to out.js`); const [out] = yield sh(`node -e "var o = require('./out'); o.Main.main();"`); assert.equal(out.trim(), hello); })); - it("pulp build -O", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp build -O", run(function*(sh, pulp, assert) { yield pulp("init"); const [src] = yield pulp("build -O"); const [out] = yield sh("node", src); assert.equal(out.trim(), hello); })); - it("pulp build -O --to", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp build -O --to", run(function*(sh, pulp, assert) { // Should be identical to `pulp build --to`. yield pulp("init"); yield pulp("build -O --to out.js"); @@ -348,7 +348,7 @@ describe("integration tests", function() { assert.equal(out.trim(), hello); })); - it("pulp build --source-maps -O --to", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp build --source-maps -O --to", run(function*(sh, pulp, assert) { yield pulp("init"); yield pulp("build --source-maps -O --to out.js"); const [out] = yield sh("node out.js"); @@ -356,7 +356,7 @@ describe("integration tests", function() { assert.exists("out.js.map"); })); - it("pulp build -O --src-path alt", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("pulp build -O --src-path alt", run(function*(sh, pulp, assert, temp) { yield pulp("init"); yield fs.rename(path.join(temp, "src"), path.join(temp, "alt")); const [src] = yield pulp("build -O --src-path alt"); @@ -392,21 +392,21 @@ describe("integration tests", function() { assert.equal(out.trim(), "--something-node-wouldnt-like"); })); - it("pulp browserify", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp browserify", run(function*(sh, pulp, assert) { yield pulp("init"); const [src] = yield pulp("browserify"); const [out] = yield sh("node", src); assert.equal(out.trim(), hello); })); - it("pulp browserify --to", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp browserify --to", run(function*(sh, pulp, assert) { yield pulp("init"); yield pulp("browserify --to out.js"); const [out] = yield sh("node out.js"); assert.equal(out.trim(), hello); })); - it("pulp browserify --source-maps --to", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp browserify --source-maps --to", run(function*(sh, pulp, assert) { yield pulp("init"); yield pulp("browserify --source-maps --to out.js"); const [out] = yield sh("node out.js"); @@ -414,28 +414,28 @@ describe("integration tests", function() { assert.exists("out.js.map"); })); - it("pulp browserify --source-maps --to subdir", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("pulp browserify --source-maps --to subdir", run(function*(sh, pulp, assert, temp) { yield pulp("init"); yield fs.mkdir(path.join(temp, "subdir")); yield pulp("browserify --source-maps --to subdir/out.js"); assert.exists("subdir/out.js.map"); })); - it("pulp browserify -O", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp browserify -O", run(function*(sh, pulp, assert) { yield pulp("init"); const [src] = yield pulp("browserify -O"); const [out] = yield sh("node", src); assert.equal(out.trim(), hello); })); - it("pulp browserify -O --to", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp browserify -O --to", run(function*(sh, pulp, assert) { yield pulp("init"); yield pulp("browserify -O --to out.js"); const [out] = yield sh("node out.js"); assert.equal(out.trim(), hello); })); - it("output of pulp browserify --standalone may be `require()`d", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("output of pulp browserify --standalone may be `require()`d", run(function*(sh, pulp, assert, temp) { yield pulp("init"); yield pulp("browserify --main Data.Function --standalone data-function --to data-function.js"); const dataFunction = require(path.join(temp, "data-function.js")); @@ -460,7 +460,7 @@ describe("integration tests", function() { assert.exists("subdir/out.js.map"); })); - it("pulp browserify --skip-compile", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("pulp browserify --skip-compile", run(function*(sh, pulp, assert, temp) { yield pulp("init"); yield fs.rename(path.join(temp, "src"), path.join(temp, "alt")); yield pulp("build --src-path alt"); @@ -495,7 +495,7 @@ describe("integration tests", function() { assert.match(out, /hello, world/); })); - it("pulp psci includes dependencies with psc-package", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp psci includes dependencies with psc-package", run(function*(sh, pulp, assert) { yield pulp("--psc-package init"); yield pulp("psci"); @@ -511,7 +511,7 @@ describe("integration tests", function() { assert.match(out, new RegExp(hello)); })); - it("pulp --before something build", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("pulp --before something build", run(function*(sh, pulp, assert, temp) { yield pulp("init"); // In reality, this is likely to be a "--before clear" or something, but @@ -526,7 +526,7 @@ describe("integration tests", function() { "test file before.txt was not found as after.txt"); })); - it("pulp --then something build", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp --then something build", run(function*(sh, pulp, assert) { yield pulp("init"); const mv = process.platform === "win32" ? "rename" : "mv"; yield pulp(`--then "${mv} out.js out2.js" build --to out.js`); @@ -555,14 +555,14 @@ describe("integration tests", function() { assert.exists(path.join(temp, "afterFailed.txt")); // --else has run })); - it("pulp --then something browserify", run(function*(sh, pulp, assert, temp) { + notEsModulesPsVersionIt("pulp --then something browserify", run(function*(sh, pulp, assert, temp) { yield pulp("init"); const mv = process.platform === "win32" ? "rename" : "mv"; yield pulp(`--then "echo lol > out.txt" browserify`); assert.equal((yield fs.readFile(path.join(temp, "out.txt"), "utf-8")).trim(), "lol"); })); - it("pulp --then something browserify --to", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp --then something browserify --to", run(function*(sh, pulp, assert) { yield pulp("init"); const mv = process.platform === "win32" ? "rename" : "mv"; yield pulp(`--then "${mv} out.js out2.js" browserify --to out.js`); @@ -571,7 +571,7 @@ describe("integration tests", function() { assert.equal(out.trim(), hello); })); - it("pulp test --runtime", run(function*(sh, pulp, assert) { + notEsModulesPsVersionIt("pulp test --runtime", run(function*(sh, pulp, assert) { yield pulp("init"); const [out] = yield pulp("test --runtime cat"); const [out2] = yield sh("node", out); From 89b3d648446b9eadcb6d4c6282b0f1ac3d211664 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 09:51:08 -0600 Subject: [PATCH 09/33] Add support for running/testing ES FFI --- src/Pulp/Browserify.purs | 4 ++-- src/Pulp/Run.purs | 46 ++++++++++++++++++++++++++++++++-------- src/Pulp/Test.purs | 14 +++--------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/Pulp/Browserify.purs b/src/Pulp/Browserify.purs index aa60ef0c..925ef93e 100644 --- a/src/Pulp/Browserify.purs +++ b/src/Pulp/Browserify.purs @@ -27,7 +27,7 @@ import Pulp.Exec (pursBundle) import Pulp.Files (outputModules) import Pulp.Outputter (getOutputter) import Pulp.Project (Project(..)) -import Pulp.Run (makeEntry, jsEscape) +import Pulp.Run (jsEscape, makeCjsEntry) import Pulp.Sorcery (sorcery) import Pulp.System.FFI (Callback, runNode) import Pulp.System.Files (openTemp) @@ -56,7 +56,7 @@ makeExport :: String -> Boolean -> String makeExport main export = if export then "module.exports = require(\"" <> jsEscape main <> "\");\n" - else makeEntry main + else makeCjsEntry main makeOptExport :: String -> String makeOptExport main = "module.exports = PS[\"" <> jsEscape main <> "\"];\n" diff --git a/src/Pulp/Run.purs b/src/Pulp/Run.purs index c4f8d4dc..a9f00dc8 100644 --- a/src/Pulp/Run.purs +++ b/src/Pulp/Run.purs @@ -2,9 +2,10 @@ module Pulp.Run where import Prelude +import Data.Array (fold) import Data.Map as Map import Data.Maybe (Maybe(..)) -import Data.String (replace, Pattern(..), Replacement(..)) +import Data.String (Pattern(..), Replacement(..), replace, replaceAll) import Effect.Aff (Aff) import Effect.Class (liftEffect) import Foreign.Object (Object) @@ -18,25 +19,25 @@ import Pulp.Args (Action(..)) import Pulp.Args.Get (getOption') import Pulp.Build as Build import Pulp.Exec (exec) +import Pulp.Outputter (Outputter, getOutputter) import Pulp.System.Files (openTemp) +import Pulp.Validate (dropPreRelBuildMeta, getPursVersion) +import Pulp.Versions.PureScript (psVersions) action :: Action action = Action \args -> do let opts = Map.union args.globalOpts args.commandOpts + out <- getOutputter args Build.runBuild args main <- getOption' "main" opts - src <- liftEffect $ Buffer.fromString (makeEntry main) UTF8 - - info <- openTemp { prefix: "pulp-run", suffix: ".js" } - _ <- FS.fdAppend info.fd src - _ <- FS.fdClose info.fd buildPath <- getOption' "buildPath" opts runtime <- getOption' "runtime" opts + scriptFilePath <- makeRunnableScript { out, buildPath, prefix: "pulp-run", moduleName: main } env <- setupEnv buildPath - exec runtime ([info.path] <> args.remainder) (Just env) + exec runtime ([scriptFilePath] <> args.remainder) (Just env) -- | Given a build path, create an environment that is just like this process' -- | environment, except with NODE_PATH set up for commands like `pulp run`. @@ -60,6 +61,33 @@ jsEscape = replace (Pattern "'") (Replacement "\\'") <<< replace (Pattern "\\") (Replacement "\\\\") +makeRunnableScript :: { out :: Outputter, buildPath :: String, prefix :: String, moduleName :: String } -> Aff String +makeRunnableScript { out, buildPath, prefix, moduleName } = do + psVer <- getPursVersion out + fullPath' <- liftEffect $ Path.resolve [] buildPath + let + fullPath = replaceAll (Pattern "\\") (Replacement "/") fullPath' + { makeEntry, suffix } = + if (dropPreRelBuildMeta psVer) < psVersions.v0_15_0 then + { makeEntry: makeCjsEntry, suffix: ".js" } + else + { makeEntry: makeEsEntry fullPath, suffix: ".mjs" } + src <- liftEffect $ Buffer.fromString (makeEntry moduleName) UTF8 + + info <- openTemp { prefix, suffix } + _ <- FS.fdAppend info.fd src + _ <- FS.fdClose info.fd + pure info.path + -- | Construct a JS string to be used as an entry point from a module name. -makeEntry :: String -> String -makeEntry main = "require('" <> jsEscape main <> "').main();\n" +makeCjsEntry :: String -> String +makeCjsEntry main = "require('" <> jsEscape main <> "').main();\n" + +makeEsEntry :: String -> String -> String +makeEsEntry buildPath main = fold + [ "import { main } from 'file://" + , buildPath + , "/" + , jsEscape main + , "/index.js'; main();" + ] diff --git a/src/Pulp/Test.purs b/src/Pulp/Test.purs index 9eb7504b..08d2f49a 100644 --- a/src/Pulp/Test.purs +++ b/src/Pulp/Test.purs @@ -7,18 +7,13 @@ import Prelude import Data.Map as Map import Data.Maybe (Maybe(..)) -import Effect.Class (liftEffect) import Foreign (unsafeToForeign) -import Node.Buffer as Buffer -import Node.Encoding (Encoding(UTF8)) -import Node.FS.Aff as FS import Pulp.Args (Action(..), Options) import Pulp.Args.Get (getOption') import Pulp.Build as Build import Pulp.Exec (exec) import Pulp.Outputter (getOutputter) -import Pulp.Run (setupEnv, makeEntry) -import Pulp.System.Files (openTemp) +import Pulp.Run (makeRunnableScript, setupEnv) action :: Action action = Action \args -> do @@ -42,12 +37,9 @@ action = Action \args -> do main <- getOption' "main" opts buildPath <- getOption' "buildPath" opts env <- setupEnv buildPath - info <- openTemp { prefix: "pulp-test", suffix: ".js" } - src <- liftEffect $ Buffer.fromString (makeEntry main) UTF8 - _ <- FS.fdAppend info.fd src - _ <- FS.fdClose info.fd + scriptFilePath <- makeRunnableScript { out, buildPath, prefix: "pulp-test", moduleName: main } exec runtime - ([info.path] <> args.remainder) + ([scriptFilePath] <> args.remainder) (Just env) else do to <- getOption' "to" buildArgs.commandOpts From 1deb17facb501c9950098e5b8a7f560674025602 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 09:54:47 -0600 Subject: [PATCH 10/33] Drop compiler-specific deps for v0.11.0 on `pulp init` --- src/Pulp/Init.purs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Pulp/Init.purs b/src/Pulp/Init.purs index 62f0d8ad..b87d1ade 100644 --- a/src/Pulp/Init.purs +++ b/src/Pulp/Init.purs @@ -191,18 +191,12 @@ init initStyle effOrEffect force out = do , effect: "purescript-effect@v2.0.1" , psciSupport: "purescript-psci-support@v4.0.0" } - | v >= psVersions.v0_12_0 = + | otherwise = { prelude: "purescript-prelude@v4.1.1" , console: "purescript-console@v4.4.0" , effect: "purescript-effect@v2.0.1" , psciSupport: "purescript-psci-support@v4.0.0" } - | otherwise = - { prelude: "purescript-prelude@v3.3.0" - , console: "purescript-console@v3.0.0" - , effect: "purescript-effect@v1.1.0" - , psciSupport: "purescript-psci-support@v3.0.0" - } action :: Action action = Action \args -> do From c7925d5de8bb8573973baffe601e11db6c77215c Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:13:09 -0600 Subject: [PATCH 11/33] For v0.15.0 int test, use deps with real versions "real" versions in that they don't point to github repos' branches --- test-js/integration.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index d72ff5de..27cb5e2a 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -35,6 +35,13 @@ const testBowerJson = { "purescript-console": "^0.1.0" } }; +const testBowerJsonv0_15_0 = Object.merge({}, testBowerJson, { + "dependencies": { + "purescript-prelude": "^5.0.1", + "purescript-console": "^5.0.0", + "purescript-effect": "^3.0.0" + } +}); function resolvePath(cmd) { return new Promise((resolve, reject) => { @@ -653,7 +660,27 @@ describe("integration tests", function() { yield pulp("init"); yield setupPackage(temp, sh); - yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(testBowerJson)); + const pursVer = yield getPursVersion(sh, assert); + const bowerContent = + semver.lt(pursVer, semver.parse('0.15.0')) + ? testBowerJson + : testBowerJsonv0_15_0; + yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(bowerContent)); + + // For tests to pass on the `v0.15.0-alpha-01` purs version, + // we need to use a custom fork of a non-core repo + // (i.e. working-group-purescript-es/purescript-prelude#es-modules-libraries). + // Since those repos' `bower.json` files point to dependencies + // whose "versions" are branch names as well, the `bower.json` JSON parsing fails. + // So, we need to remove the `bower_components` folder that gets set up + // when `pulp init` is called, and re-install the bower deps + // using the `bower.json` file. + // + // Furthermore, we have to install all 3 deps used in a typical `pulp init` + // setup. Otherwise, `pulp version` fails due to other dependency-related reasons. + yield sh("rm -rf bower_components"); + yield sh("bower install"); + yield sh("git commit -am \"updating bower.json\""); yield sh("git tag v2.0.0"); yield sh("git commit --allow-empty -m \"an empty commit for the new tag\""); From b5dfe13b5090b8e4b7cf71493e85d7d20f7071cb Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:14:18 -0600 Subject: [PATCH 12/33] Fix logic in getting purs version --- test-js/integration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index 27cb5e2a..f6a225f5 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -133,7 +133,7 @@ const getPursVersion = co.wrap(function*(sh, assert) { // Drops pre-release identifiers // 0.15.0-alpha-01 --> 0.15.0 const pursVerWithExtras = semver.coerce(out.split(/\s/)[0]); - const pursVer = pursVerWithExtras === null ? semver.parse(pursVerWithExtras) : pursVerWithExtras; + const pursVer = pursVerWithExtras === null ? pursVerWithExtras : semver.parse(pursVerWithExtras); if (pursVer == null) { assert.fail("Unable to parse output of purs --version"); } From 98e6c645d53189e95a73b047e258efb646d504e3 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:16:03 -0600 Subject: [PATCH 13/33] Use Object.assign, not Object.merge --- test-js/integration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index f6a225f5..65bf92ea 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -35,7 +35,7 @@ const testBowerJson = { "purescript-console": "^0.1.0" } }; -const testBowerJsonv0_15_0 = Object.merge({}, testBowerJson, { +const testBowerJsonv0_15_0 = Object.assign({}, testBowerJson, { "dependencies": { "purescript-prelude": "^5.0.1", "purescript-console": "^5.0.0", From b9f05b7a7cba445d2b1bc1fd896f394ed1c7927d Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:27:24 -0600 Subject: [PATCH 14/33] Use same bower.json for all tests on pulp version --- test-js/integration.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test-js/integration.js b/test-js/integration.js index 65bf92ea..8db889d7 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -31,17 +31,12 @@ const testBowerJson = { "type": "git", "url": "git://github.com/not-real/not-real.git" }, - "dependencies": { - "purescript-console": "^0.1.0" - } -}; -const testBowerJsonv0_15_0 = Object.assign({}, testBowerJson, { "dependencies": { "purescript-prelude": "^5.0.1", "purescript-console": "^5.0.0", "purescript-effect": "^3.0.0" } -}); +}; function resolvePath(cmd) { return new Promise((resolve, reject) => { @@ -660,12 +655,7 @@ describe("integration tests", function() { yield pulp("init"); yield setupPackage(temp, sh); - const pursVer = yield getPursVersion(sh, assert); - const bowerContent = - semver.lt(pursVer, semver.parse('0.15.0')) - ? testBowerJson - : testBowerJsonv0_15_0; - yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(bowerContent)); + yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(testBowerJson)); // For tests to pass on the `v0.15.0-alpha-01` purs version, // we need to use a custom fork of a non-core repo From a81afbe43041585ac13f3be2bf0910f5fc764084 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:50:43 -0600 Subject: [PATCH 15/33] Only reinstall bower deps on v0.15.0 --- test-js/integration.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/test-js/integration.js b/test-js/integration.js index 8db889d7..a747024e 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -31,12 +31,18 @@ const testBowerJson = { "type": "git", "url": "git://github.com/not-real/not-real.git" }, + "dependencies": { + "purescript-console": "^0.1.0", + } +}; + +const testBowerJsonV0_15_0 = Object.assign({}, testBowerJson, { "dependencies": { "purescript-prelude": "^5.0.1", "purescript-console": "^5.0.0", "purescript-effect": "^3.0.0" } -}; +}); function resolvePath(cmd) { return new Promise((resolve, reject) => { @@ -657,19 +663,23 @@ describe("integration tests", function() { yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(testBowerJson)); - // For tests to pass on the `v0.15.0-alpha-01` purs version, - // we need to use a custom fork of a non-core repo - // (i.e. working-group-purescript-es/purescript-prelude#es-modules-libraries). - // Since those repos' `bower.json` files point to dependencies - // whose "versions" are branch names as well, the `bower.json` JSON parsing fails. - // So, we need to remove the `bower_components` folder that gets set up - // when `pulp init` is called, and re-install the bower deps - // using the `bower.json` file. - // - // Furthermore, we have to install all 3 deps used in a typical `pulp init` - // setup. Otherwise, `pulp version` fails due to other dependency-related reasons. - yield sh("rm -rf bower_components"); - yield sh("bower install"); + const psVer = yield getPursVersion(sh, assert); + if (semver.gte(psVer, semver.parse('0.15.0'))) { + // For tests to pass on the `v0.15.0-alpha-01` purs version, + // we need to use a custom fork of a non-core repo + // (i.e. working-group-purescript-es/purescript-prelude#es-modules-libraries). + // Since those repos' `bower.json` files point to dependencies + // whose "versions" are branch names as well, the `bower.json` JSON parsing fails. + // So, we need to remove the `bower_components` folder that gets set up + // when `pulp init` is called, and re-install the bower deps + // using the `bower.json` file. + // + // Furthermore, we have to install all 3 deps used in a typical `pulp init` + // setup. Otherwise, `pulp version` fails due to other dependency-related reasons. + yield fs.writeFile(path.join(temp, "bower.json"), JSON.stringify(testBowerJsonV0_15_0)); + yield sh("rm -rf bower_components"); + yield sh("bower install"); + } yield sh("git commit -am \"updating bower.json\""); yield sh("git tag v2.0.0"); From 7b0c4c3bd94d69c550108390be89705dc1941d77 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:54:13 -0600 Subject: [PATCH 16/33] Add extra blank line --- src/Pulp/Versions/PureScript.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pulp/Versions/PureScript.purs b/src/Pulp/Versions/PureScript.purs index b6f20ae1..77d0401e 100644 --- a/src/Pulp/Versions/PureScript.purs +++ b/src/Pulp/Versions/PureScript.purs @@ -19,4 +19,4 @@ psVersions = , v0_13_0: Version (NEL.cons' 0 (13 : 0 : Nil)) Nil , v0_14_0: Version (NEL.cons' 0 (14 : 0 : Nil)) Nil , v0_15_0: Version (NEL.cons' 0 (15 : 0 : Nil)) Nil - } \ No newline at end of file + } From 7d82ecc570d21563bc786953b25daa080f70a9f6 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:54:37 -0600 Subject: [PATCH 17/33] Drop extra comma --- test-js/integration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index a747024e..f10e6305 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -32,7 +32,7 @@ const testBowerJson = { "url": "git://github.com/not-real/not-real.git" }, "dependencies": { - "purescript-console": "^0.1.0", + "purescript-console": "^0.1.0" } }; From 8767aeb28491b41ca99a57f43a8fe508262198c6 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 10:55:59 -0600 Subject: [PATCH 18/33] Drop any extra info before checking purs version --- src/Pulp/Init.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pulp/Init.purs b/src/Pulp/Init.purs index b87d1ade..3119d052 100644 --- a/src/Pulp/Init.purs +++ b/src/Pulp/Init.purs @@ -139,7 +139,7 @@ init initStyle effOrEffect force out = do psVer <- getPursVersion out - install initStyle effOrEffect (getDepsVersions psVer) + install initStyle effOrEffect (getDepsVersions $ dropPreRelBuildMeta psVer) where install Bower UseEff p = do From e81214cb58a6da50e89b8b67470cb66c1b53ef27 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Mar 2022 11:06:20 -0600 Subject: [PATCH 19/33] Update changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d57daf18..53029e59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Breaking: versions earlier than that. (#399 by @JordanMartinez) Internal: +* Added support for the `v0.15.0` compiler version (#401 by @JordanMartinez) * Update project and its dependencies to use PureScript `v0.14.5` and `v0.14.0`-compatible libraries. (#399 by @JordanMartinez) * Migrated from Travis CI to GitHub Actions. (#399 by @JordanMartinez) From dc3597c4422fb876273b6514e25d704b396bc673 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 9 Mar 2022 15:35:25 -0800 Subject: [PATCH 20/33] Use .js for run/test file names --- src/Pulp/Run.purs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Pulp/Run.purs b/src/Pulp/Run.purs index a9f00dc8..c8f4be5c 100644 --- a/src/Pulp/Run.purs +++ b/src/Pulp/Run.purs @@ -67,14 +67,14 @@ makeRunnableScript { out, buildPath, prefix, moduleName } = do fullPath' <- liftEffect $ Path.resolve [] buildPath let fullPath = replaceAll (Pattern "\\") (Replacement "/") fullPath' - { makeEntry, suffix } = + makeEntry = if (dropPreRelBuildMeta psVer) < psVersions.v0_15_0 then - { makeEntry: makeCjsEntry, suffix: ".js" } + makeCjsEntry else - { makeEntry: makeEsEntry fullPath, suffix: ".mjs" } + makeEsEntry fullPath src <- liftEffect $ Buffer.fromString (makeEntry moduleName) UTF8 - info <- openTemp { prefix, suffix } + info <- openTemp { prefix, suffix: ".js" } _ <- FS.fdAppend info.fd src _ <- FS.fdClose info.fd pure info.path From 3be7f529eb4f500ab3765ac1c0a6c9389f12d07d Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 9 Mar 2022 15:37:17 -0800 Subject: [PATCH 21/33] Fix error message since fold isn't adding spaces --- src/Pulp/Validate.purs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pulp/Validate.purs b/src/Pulp/Validate.purs index c4e8f3d0..8621dd3b 100644 --- a/src/Pulp/Validate.purs +++ b/src/Pulp/Validate.purs @@ -61,8 +61,8 @@ failIfUsingEsModulesPsVersion out mbMsg = do psVer <- getPursVersion out unless ((dropPreRelBuildMeta psVer) < psVersions.v0_15_0) do out.err $ fold - [ "This code path implicitly uses `purs bundle` or CommonsJS modules, both of which are no longer supported in PureScript v0.15.0." - , "You are using PureScript " <> Version.showVersion psVer + [ "This code path implicitly uses `purs bundle` or CommonsJS modules, both of which are no longer supported in PureScript v0.15.0. " + , "You are using PureScript " <> Version.showVersion psVer <> ". " , "See https://github.com/purescript/documentation/blob/master/migration-guides/0.15-Migration-Guide.md" ] for_ mbMsg out.err From 9a983c865c6478361d431175ff613e36b23dca37 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 9 Mar 2022 15:48:03 -0800 Subject: [PATCH 22/33] Verify package.json file exists --- test-js/integration.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index f10e6305..81c8ecaf 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -292,9 +292,12 @@ describe("integration tests", function() { assert.exists(extras); })); - it("pulp run", run(function*(sh, pulp, assert) { + it.only("pulp run", run(function*(sh, pulp, assert) { yield pulp("init"); const [out] = yield pulp("run"); + const [o,e] = yield sh("cat output/package.json"); + console.log(o); + console.log(e); assert.equal(out.trim(), hello); })); From 444c3dab479ad551f9c6ef5d9b91d5e8582d883a Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 9 Mar 2022 15:51:08 -0800 Subject: [PATCH 23/33] Run pulp build before checking for package.json file --- test-js/integration.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index 81c8ecaf..220d22aa 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -294,10 +294,11 @@ describe("integration tests", function() { it.only("pulp run", run(function*(sh, pulp, assert) { yield pulp("init"); - const [out] = yield pulp("run"); + yield pulp("build"); const [o,e] = yield sh("cat output/package.json"); console.log(o); console.log(e); + const [out] = yield pulp("run"); assert.equal(out.trim(), hello); })); From 3cb39b3ad4ffb37da7f38438b066670fc2d8d2db Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 9 Mar 2022 15:56:18 -0800 Subject: [PATCH 24/33] Revert test printing of package.json contents --- test-js/integration.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test-js/integration.js b/test-js/integration.js index 220d22aa..87e2b2b2 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -294,10 +294,6 @@ describe("integration tests", function() { it.only("pulp run", run(function*(sh, pulp, assert) { yield pulp("init"); - yield pulp("build"); - const [o,e] = yield sh("cat output/package.json"); - console.log(o); - console.log(e); const [out] = yield pulp("run"); assert.equal(out.trim(), hello); })); From 1b9736769f0fcc7147f9a753823722c2380ff0d2 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 9 Mar 2022 15:56:32 -0800 Subject: [PATCH 25/33] Revert back to `.mjs` for ES files --- src/Pulp/Run.purs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Pulp/Run.purs b/src/Pulp/Run.purs index c8f4be5c..a9f00dc8 100644 --- a/src/Pulp/Run.purs +++ b/src/Pulp/Run.purs @@ -67,14 +67,14 @@ makeRunnableScript { out, buildPath, prefix, moduleName } = do fullPath' <- liftEffect $ Path.resolve [] buildPath let fullPath = replaceAll (Pattern "\\") (Replacement "/") fullPath' - makeEntry = + { makeEntry, suffix } = if (dropPreRelBuildMeta psVer) < psVersions.v0_15_0 then - makeCjsEntry + { makeEntry: makeCjsEntry, suffix: ".js" } else - makeEsEntry fullPath + { makeEntry: makeEsEntry fullPath, suffix: ".mjs" } src <- liftEffect $ Buffer.fromString (makeEntry moduleName) UTF8 - info <- openTemp { prefix, suffix: ".js" } + info <- openTemp { prefix, suffix } _ <- FS.fdAppend info.fd src _ <- FS.fdClose info.fd pure info.path From c32640b13e49096fcc5921b47740d400bdebbddc Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 9 Mar 2022 15:57:40 -0800 Subject: [PATCH 26/33] Run all tests again --- test-js/integration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-js/integration.js b/test-js/integration.js index 87e2b2b2..f10e6305 100644 --- a/test-js/integration.js +++ b/test-js/integration.js @@ -292,7 +292,7 @@ describe("integration tests", function() { assert.exists(extras); })); - it.only("pulp run", run(function*(sh, pulp, assert) { + it("pulp run", run(function*(sh, pulp, assert) { yield pulp("init"); const [out] = yield pulp("run"); assert.equal(out.trim(), hello); From 357325d0a9d01a7a2d3791a26397f242a6d9cb74 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 10 Mar 2022 16:26:55 -0800 Subject: [PATCH 27/33] Revert "Revert back to `.mjs` for ES files" This reverts commit 1b9736769f0fcc7147f9a753823722c2380ff0d2. --- src/Pulp/Run.purs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Pulp/Run.purs b/src/Pulp/Run.purs index a9f00dc8..c8f4be5c 100644 --- a/src/Pulp/Run.purs +++ b/src/Pulp/Run.purs @@ -67,14 +67,14 @@ makeRunnableScript { out, buildPath, prefix, moduleName } = do fullPath' <- liftEffect $ Path.resolve [] buildPath let fullPath = replaceAll (Pattern "\\") (Replacement "/") fullPath' - { makeEntry, suffix } = + makeEntry = if (dropPreRelBuildMeta psVer) < psVersions.v0_15_0 then - { makeEntry: makeCjsEntry, suffix: ".js" } + makeCjsEntry else - { makeEntry: makeEsEntry fullPath, suffix: ".mjs" } + makeEsEntry fullPath src <- liftEffect $ Buffer.fromString (makeEntry moduleName) UTF8 - info <- openTemp { prefix, suffix } + info <- openTemp { prefix, suffix: ".js" } _ <- FS.fdAppend info.fd src _ <- FS.fdClose info.fd pure info.path From 7267ef7e830dc8a5f441b626e059d675034100d8 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 10 Mar 2022 16:38:51 -0800 Subject: [PATCH 28/33] Increase minimum node version to 12 --- src/Main.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.purs b/src/Main.purs index bea8eea6..68f6c7f0 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -241,7 +241,7 @@ succeeded = const (pure unit) main :: Effect Unit main = void $ runAff (either failed succeeded) do - requireNodeAtLeast (version 4 0 0 Nil Nil) + requireNodeAtLeast (version 12 0 0 Nil Nil) argv <- drop 2 <$> liftEffect Process.argv args <- parse globals commands argv case args of From 4ae259cdc9f398aacc9bfd8dd14b1f67a2e4d2c6 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 10 Mar 2022 16:44:23 -0800 Subject: [PATCH 29/33] Refactor code into getNodeVersion --- src/Main.purs | 27 +++++++++------------------ src/Pulp/Validate.purs | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Main.purs b/src/Main.purs index 68f6c7f0..a85e942c 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -8,9 +8,8 @@ import Data.Either (Either(..), either) import Data.Foldable (elem) import Data.List (List(Nil)) import Data.Map (insert) -import Data.Maybe (Maybe(..), fromMaybe) -import Data.String (stripPrefix, Pattern(..)) -import Data.Version (Version, version, showVersion, parseVersion) +import Data.Maybe (Maybe(..)) +import Data.Version (Version, showVersion, version) import Effect (Effect) import Effect.Aff (Aff, attempt, runAff, throwError) import Effect.Class (liftEffect) @@ -44,7 +43,7 @@ import Pulp.Server as Server import Pulp.Shell as Shell import Pulp.System.FFI (unsafeInspect) import Pulp.Test as Test -import Pulp.Validate (validate) +import Pulp.Validate (getNodeVersion, validate) import Pulp.Version (printVersion) import Pulp.Watch as Watch import Text.Parsing.Parser (parseErrorMessage) @@ -304,20 +303,12 @@ runWithArgs args = do requireNodeAtLeast :: Version -> Aff Unit requireNodeAtLeast minimum = do - case parseVersion (stripV Process.version) of - Left err -> - let message = parseErrorMessage err - in throwError (error ("Failed to parse node.js version: " <> message)) - Right actual -> - when (actual < minimum) - (throwError (error - ("Your node.js version is too old " <> - "(required: " <> showVersion minimum <> - ", actual: " <> showVersion actual <> ")"))) - - where - stripV str = - fromMaybe str (stripPrefix (Pattern "v") str) + actual <- getNodeVersion + when (actual < minimum) do + throwError $ error $ + "Your node.js version is too old " <> + "(required: " <> showVersion minimum <> + ", actual: " <> showVersion actual <> ")" argsParserDiagnostics :: Args.Args -> Aff Unit argsParserDiagnostics opts = do diff --git a/src/Pulp/Validate.purs b/src/Pulp/Validate.purs index 8621dd3b..c795ee50 100644 --- a/src/Pulp/Validate.purs +++ b/src/Pulp/Validate.purs @@ -2,6 +2,7 @@ module Pulp.Validate ( validate , getPursVersion , getPsaVersion + , getNodeVersion , dropPreRelBuildMeta , failIfUsingEsModulesPsVersion ) where @@ -13,16 +14,19 @@ import Data.Array (fold) import Data.Either (Either(..)) import Data.Foldable (for_) import Data.List (List(..)) -import Data.Maybe (Maybe(..)) -import Data.String (codePointFromChar, takeWhile, trim) +import Data.Maybe (Maybe(..), fromMaybe) +import Data.String (Pattern(..), codePointFromChar, stripPrefix, takeWhile, trim) import Data.Version.Haskell (Version(..), parseVersion, showVersion) -import Data.Version.Haskell as Version +import Data.Version.Haskell as HVersion +import Data.Version as SemVer import Effect.Aff (Aff) import Effect.Class (liftEffect) import Effect.Exception (error, throw) +import Node.Process as Process import Pulp.Exec (execQuiet) import Pulp.Outputter (Outputter) import Pulp.Versions.PureScript (psVersions) +import Text.Parsing.Parser (parseErrorMessage) validate :: Outputter -> Aff Version validate out = do @@ -45,6 +49,18 @@ minimumPursVersion = psVersions.v0_12_0 getPsaVersion :: Outputter -> Aff Version getPsaVersion = getVersionFrom "psa" +getNodeVersion :: Aff SemVer.Version +getNodeVersion = do + case SemVer.parseVersion (stripV Process.version) of + Left err -> + let message = parseErrorMessage err + in throwError (error ("Failed to parse node.js version: " <> message)) + Right actual -> + pure actual + where + stripV str = + fromMaybe str (stripPrefix (Pattern "v") str) + getVersionFrom :: String -> Outputter -> Aff Version getVersionFrom bin out = do verStr <- takeWhile (_ /= codePointFromChar ' ') <$> trim <$> execQuiet bin ["--version"] Nothing @@ -62,7 +78,7 @@ failIfUsingEsModulesPsVersion out mbMsg = do unless ((dropPreRelBuildMeta psVer) < psVersions.v0_15_0) do out.err $ fold [ "This code path implicitly uses `purs bundle` or CommonsJS modules, both of which are no longer supported in PureScript v0.15.0. " - , "You are using PureScript " <> Version.showVersion psVer <> ". " + , "You are using PureScript " <> HVersion.showVersion psVer <> ". " , "See https://github.com/purescript/documentation/blob/master/migration-guides/0.15-Migration-Guide.md" ] for_ mbMsg out.err From 490961e4c00112430c40da9e30fd15a087634e73 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 10 Mar 2022 16:57:53 -0800 Subject: [PATCH 30/33] Account for --experimental-modules node flag --- src/Pulp/Run.purs | 21 +++++++++++++++++++-- src/Pulp/Test.purs | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Pulp/Run.purs b/src/Pulp/Run.purs index c8f4be5c..fa855407 100644 --- a/src/Pulp/Run.purs +++ b/src/Pulp/Run.purs @@ -3,9 +3,11 @@ module Pulp.Run where import Prelude import Data.Array (fold) +import Data.List (List(..)) import Data.Map as Map import Data.Maybe (Maybe(..)) import Data.String (Pattern(..), Replacement(..), replace, replaceAll) +import Data.Version (version) import Effect.Aff (Aff) import Effect.Class (liftEffect) import Foreign.Object (Object) @@ -21,7 +23,7 @@ import Pulp.Build as Build import Pulp.Exec (exec) import Pulp.Outputter (Outputter, getOutputter) import Pulp.System.Files (openTemp) -import Pulp.Validate (dropPreRelBuildMeta, getPursVersion) +import Pulp.Validate (dropPreRelBuildMeta, getNodeVersion, getPursVersion) import Pulp.Versions.PureScript (psVersions) action :: Action @@ -37,7 +39,8 @@ action = Action \args -> do runtime <- getOption' "runtime" opts scriptFilePath <- makeRunnableScript { out, buildPath, prefix: "pulp-run", moduleName: main } env <- setupEnv buildPath - exec runtime ([scriptFilePath] <> args.remainder) (Just env) + nodeFlags <- getNodeFlags out runtime + exec runtime (nodeFlags <> [scriptFilePath] <> args.remainder) (Just env) -- | Given a build path, create an environment that is just like this process' -- | environment, except with NODE_PATH set up for commands like `pulp run`. @@ -61,6 +64,20 @@ jsEscape = replace (Pattern "'") (Replacement "\\'") <<< replace (Pattern "\\") (Replacement "\\\\") +-- | Returns an empty array or `[ "--experimental-modules" ]` +-- | if using a version of PureScript that outputs ES modules +-- | on a Node runtime with a version < `13.0.0`. +getNodeFlags :: Outputter -> String -> Aff (Array String) +getNodeFlags out runtime + | runtime == "node" = do + nodeVer <- getNodeVersion + psVer <- getPursVersion out + let + usingEsModules = (dropPreRelBuildMeta psVer) >= psVersions.v0_15_0 + nodeNeedsFlag = nodeVer < (version 13 0 0 Nil Nil) + pure if usingEsModules && nodeNeedsFlag then [ "--experimental-modules" ] else [] + | otherwise = pure [] + makeRunnableScript :: { out :: Outputter, buildPath :: String, prefix :: String, moduleName :: String } -> Aff String makeRunnableScript { out, buildPath, prefix, moduleName } = do psVer <- getPursVersion out diff --git a/src/Pulp/Test.purs b/src/Pulp/Test.purs index 08d2f49a..3d393e74 100644 --- a/src/Pulp/Test.purs +++ b/src/Pulp/Test.purs @@ -13,7 +13,7 @@ import Pulp.Args.Get (getOption') import Pulp.Build as Build import Pulp.Exec (exec) import Pulp.Outputter (getOutputter) -import Pulp.Run (makeRunnableScript, setupEnv) +import Pulp.Run (getNodeFlags, makeRunnableScript, setupEnv) action :: Action action = Action \args -> do @@ -38,8 +38,9 @@ action = Action \args -> do buildPath <- getOption' "buildPath" opts env <- setupEnv buildPath scriptFilePath <- makeRunnableScript { out, buildPath, prefix: "pulp-test", moduleName: main } + nodeFlags <- getNodeFlags out runtime exec runtime - ([scriptFilePath] <> args.remainder) + (nodeFlags <> [scriptFilePath] <> args.remainder) (Just env) else do to <- getOption' "to" buildArgs.commandOpts From 3d0852b4dd5a35679e5cbbe90456d15114599f87 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 10 Mar 2022 18:02:29 -0800 Subject: [PATCH 31/33] Add package.json file to temp file if need to --- src/Pulp/Run.purs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Pulp/Run.purs b/src/Pulp/Run.purs index fa855407..a27755e8 100644 --- a/src/Pulp/Run.purs +++ b/src/Pulp/Run.purs @@ -14,7 +14,7 @@ import Foreign.Object (Object) import Foreign.Object as Object import Node.Buffer as Buffer import Node.Encoding (Encoding(UTF8)) -import Node.FS.Aff as FS +import Node.FS.Aff as FSA import Node.Path as Path import Node.Process as Process import Pulp.Args (Action(..)) @@ -22,7 +22,7 @@ import Pulp.Args.Get (getOption') import Pulp.Build as Build import Pulp.Exec (exec) import Pulp.Outputter (Outputter, getOutputter) -import Pulp.System.Files (openTemp) +import Pulp.System.Files (tempDir) import Pulp.Validate (dropPreRelBuildMeta, getNodeVersion, getPursVersion) import Pulp.Versions.PureScript (psVersions) @@ -84,17 +84,21 @@ makeRunnableScript { out, buildPath, prefix, moduleName } = do fullPath' <- liftEffect $ Path.resolve [] buildPath let fullPath = replaceAll (Pattern "\\") (Replacement "/") fullPath' - makeEntry = + { makeEntry, writePackageJsonFile } = if (dropPreRelBuildMeta psVer) < psVersions.v0_15_0 then - makeCjsEntry + { makeEntry: makeCjsEntry, writePackageJsonFile: false } else - makeEsEntry fullPath + { makeEntry: makeEsEntry fullPath, writePackageJsonFile: true } src <- liftEffect $ Buffer.fromString (makeEntry moduleName) UTF8 - info <- openTemp { prefix, suffix: ".js" } - _ <- FS.fdAppend info.fd src - _ <- FS.fdClose info.fd - pure info.path + parentDir <- tempDir { prefix, suffix: ".js" } + let + scriptFile = Path.concat [ parentDir, "index.js" ] + packageJson = Path.concat [ parentDir, "package.json" ] + FSA.writeFile scriptFile src + when writePackageJsonFile do + FSA.writeTextFile UTF8 packageJson """{"type": "module"}""" + pure scriptFile -- | Construct a JS string to be used as an entry point from a module name. makeCjsEntry :: String -> String From 8ad6aa0ec99154075c1f9396eb1a17ee2c7930b6 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 10 Mar 2022 18:13:20 -0800 Subject: [PATCH 32/33] Update changelog to mention min node version --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53029e59..3a667ead 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ Breaking: compiler versions earlier than that. (#399 by @JordanMartinez) * Increased minimum `psa` version to `v0.7.0` and dropped support for all versions earlier than that. (#399 by @JordanMartinez) +* Increase minimum `node` versino to `v12.0.0` and dropped support for all + versions earlier than that. (#401 by @JordanMartinez) Internal: * Added support for the `v0.15.0` compiler version (#401 by @JordanMartinez) From e007f5eb94a5e6bc2db3e1e7cf982152c56040d9 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 10 Mar 2022 19:22:18 -0800 Subject: [PATCH 33/33] Fix typos Co-authored-by: Thomas Honeyman --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a667ead..f68436d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ Breaking: compiler versions earlier than that. (#399 by @JordanMartinez) * Increased minimum `psa` version to `v0.7.0` and dropped support for all versions earlier than that. (#399 by @JordanMartinez) -* Increase minimum `node` versino to `v12.0.0` and dropped support for all +* Increased minimum `node` version to `v12.0.0` and dropped support for all versions earlier than that. (#401 by @JordanMartinez) Internal: