Skip to content

Commit

Permalink
Update Node deps to breaking changes (#671)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Honeyman <[email protected]>
  • Loading branch information
JordanMartinez and thomashoneyman authored Nov 30, 2023
1 parent 75cdd4d commit d7d35c9
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 199 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/node_modules
/output
/scratch
/.vscode

result

Expand Down
2 changes: 1 addition & 1 deletion app/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ package:
- httpurple
- identity
- integers
- js-fetch
- js-date
- js-uri
- js-promise-aff
Expand All @@ -43,7 +44,6 @@ package:
- node-child-process
- node-execa
- node-fs
- node-fs-aff
- node-path
- node-process
- now
Expand Down
13 changes: 7 additions & 6 deletions app/src/App/API.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Data.String.NonEmpty as NonEmptyString
import Data.String.Regex as Regex
import Effect.Aff as Aff
import Effect.Ref as Ref
import Node.ChildProcess.Types (Exit(..))
import Node.FS.Aff as FS.Aff
import Node.FS.Stats as FS.Stats
import Node.FS.Sync as FS.Sync
Expand Down Expand Up @@ -722,7 +723,7 @@ publishRegistry { source, payload, metadata: Metadata metadata, manifest: Manife
Tar.create { cwd: tmp, folderName: newDir }

Log.info "Tarball created. Verifying its size..."
FS.Stats.Stats { size: bytes } <- Run.liftAff $ FS.Aff.stat tarballPath
bytes <- Run.liftAff $ map FS.Stats.size $ FS.Aff.stat tarballPath
for_ (Operation.Validation.validateTarballSize bytes) case _ of
Operation.Validation.ExceedsMaximum maxPackageBytes ->
Except.throw $ "Package tarball is " <> show bytes <> " bytes, which exceeds the maximum size of " <> show maxPackageBytes <> " bytes."
Expand Down Expand Up @@ -1144,11 +1145,11 @@ jsonToDhallManifest dhallTypes jsonStr = do
-- will remove the './' prefix. We need to manually append this to the relative path.
let args = [ "--records-loose", "--unions-strict", Path.concat [ dhallTypes, "v1", "Manifest.dhall" ] ]
process <- Execa.execa cmd args identity
process.stdin.writeUtf8End jsonStr
result <- process.result
pure case result of
Right _ -> Right jsonStr
Left { stderr } -> Left stderr
for_ process.stdin \{ writeUtf8End } -> writeUtf8End jsonStr
result <- process.getResult
pure case result.exit of
Normally 0 -> Right jsonStr
_ -> Left result.stderr

getPacchettiBotti :: forall r. Run (PACCHETTIBOTTI_ENV + r) Owner
getPacchettiBotti = do
Expand Down
9 changes: 5 additions & 4 deletions app/src/App/CLI/Git.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Data.Array as Array
import Data.Array.NonEmpty as NonEmptyArray
import Data.String as String
import Data.String.CodeUnits as CodeUnits
import Node.ChildProcess.Types (Exit(..))
import Node.Library.Execa as Execa
import Parsing as Parsing
import Parsing.Combinators as Parsing.Combinators
Expand Down Expand Up @@ -73,10 +74,10 @@ mkAuthOrigin address committer = AuthOrigin $ Array.fold
-- | Run the `git` tool via the command line.
gitCLI :: Array String -> Maybe FilePath -> Aff (Either String String)
gitCLI args cwd = do
result <- liftAff $ _.result =<< Execa.execa "git" args (_ { cwd = cwd })
pure case result of
Right { stdout } -> Right (String.trim stdout)
Left { stdout, stderr } -> Left (stdout <> stderr)
result <- liftAff $ _.getResult =<< Execa.execa "git" args (_ { cwd = cwd })
pure case result.exit of
Normally 0 -> Right (String.trim result.stdout)
_ -> Left (result.stdout <> result.stderr)

withGit :: forall r. FilePath -> Array String -> (String -> String) -> Run (AFF + EXCEPT String + r) String
withGit cwd args onError = Run.liftAff (gitCLI args (Just cwd)) >>= case _ of
Expand Down
15 changes: 6 additions & 9 deletions app/src/App/CLI/Licensee.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Control.Parallel as Parallel
import Data.Array as Array
import Data.Codec.Argonaut as CA
import Data.Codec.Argonaut.Record as CA.Record
import Node.ChildProcess.Types (Exit(..))
import Node.FS.Aff as FS
import Node.Library.Execa as Execa
import Node.Path as Path
Expand All @@ -25,23 +26,19 @@ detect :: FilePath -> Aff (Either String (Array String))
detect directory = do
let cmd = "licensee"
let args = [ "detect", "--json", directory ]
result <- _.result =<< Execa.execa cmd args identity
let
{ exitCode, stdout, stderr } = case result of
Left { exitCode, stdout, stderr } -> { exitCode, stdout, stderr }
Right { exitCode, stdout, stderr } -> { exitCode: Just exitCode, stdout, stderr }
pure case exitCode of
result <- _.getResult =<< Execa.execa cmd args identity
pure case result.exit of
-- Licensee will exit with `1` if it didn't parse any licenses,
-- but we consider this valid Licensee output.
Just n | n == 0 || n == 1 -> do
Normally n | n == 0 || n == 1 -> do
let
parse :: String -> Either JsonDecodeError (Array String)
parse str = map (map _.spdx_id <<< _.licenses) $ flip parseJson str $ CA.Record.object "Licenses"
{ licenses: CA.array $ CA.Record.object "SPDXIds"
{ spdx_id: CA.string }
}

case parse stdout of
case parse result.stdout of
Left error -> do
let printedError = CA.printJsonDecodeError error
Left printedError
Expand All @@ -52,4 +49,4 @@ detect directory = do
Right $ Array.filter (_ /= "NOASSERTION") out

_ ->
Left stderr
Left result.stderr
34 changes: 18 additions & 16 deletions app/src/App/CLI/Purs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Data.Codec.Argonaut.Compat as CA.Compat
import Data.Codec.Argonaut.Record as CA.Record
import Data.Foldable (foldMap)
import Data.String as String
import Node.ChildProcess.Types (Exit(..))
import Node.Library.Execa as Execa
import Registry.Version as Version

Expand Down Expand Up @@ -123,19 +124,20 @@ callCompiler compilerArgs = do
{ errors: CA.array compilerErrorCodec
}

result <- _.result =<< Execa.execa purs (printCommand compilerArgs.command) (_ { cwd = compilerArgs.cwd })
pure case result of
Left { originalMessage }
| originalMessage == Just (String.joinWith " " [ "spawn", purs, "ENOENT" ]) -> Left MissingCompiler
Left { stdout, stderr } -> Left do
let
output = case compilerArgs.version of
Nothing -> stdout
Just version | Right min <- Version.parse "0.14.0", version < min -> stderr
Just _ -> stdout
case parseJson errorsCodec output of
Left err -> UnknownError $ String.joinWith "\n" [ stdout, stderr, CA.printJsonDecodeError err ]
Right ({ errors } :: { errors :: Array CompilerError })
| Array.null errors -> UnknownError "Non-normal exit code, but no errors reported."
| otherwise -> CompilationError errors
Right { stdout } -> Right stdout
result <- _.getResult =<< Execa.execa purs (printCommand compilerArgs.command) (_ { cwd = compilerArgs.cwd })
pure case result.exit of
Normally 0 ->
Right result.stdout
_
| result.originalMessage == Just (String.joinWith " " [ "spawn", purs, "ENOENT" ]) -> Left MissingCompiler
| otherwise -> Left do
let
output = case compilerArgs.version of
Nothing -> result.stdout
Just version | Right min <- Version.parse "0.14.0", version < min -> result.stderr
Just _ -> result.stdout
case parseJson errorsCodec output of
Left err -> UnknownError $ String.joinWith "\n" [ result.stdout, result.stderr, CA.printJsonDecodeError err ]
Right ({ errors } :: { errors :: Array CompilerError })
| Array.null errors -> UnknownError "Non-normal exit code, but no errors reported."
| otherwise -> CompilationError errors
9 changes: 6 additions & 3 deletions app/src/App/CLI/PursVersions.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Registry.App.Prelude
import Data.Array as Array
import Data.Array.NonEmpty as NEA
import Data.String as String
import Node.ChildProcess.Types (Exit(..))
import Node.Library.Execa as Execa
import Registry.Version as Version
import Run (AFF, Run)
Expand All @@ -15,9 +16,11 @@ import Run.Except as Except
-- | Returns a sorted array of PureScript compilers supported by the Registry
pursVersions :: forall r. Run (EXCEPT String + AFF + r) (NonEmptyArray Version)
pursVersions = do
result <- Run.liftAff $ _.result =<< Execa.execa "purs-versions" [] identity
{ stdout } <- Except.rethrow $ lmap (\{ stdout, stderr } -> stdout <> stderr) result
let { fail, success } = partitionEithers $ map Version.parse (String.split (String.Pattern " ") stdout)
result <- Run.liftAff $ _.getResult =<< Execa.execa "purs-versions" [] identity
case result.exit of
Normally 0 -> pure unit
_ -> Except.throw $ result.stdout <> result.stderr
let { fail, success } = partitionEithers $ map Version.parse (String.split (String.Pattern " ") result.stdout)

when (Array.length fail > 0) do
Except.throw (String.joinWith ", " fail)
Expand Down
4 changes: 2 additions & 2 deletions app/src/App/CLI/Tar.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ExtractArgs = { cwd :: String, archive :: FilePath }
extract :: forall m. MonadEffect m => ExtractArgs -> m Unit
extract { cwd, archive } = liftEffect do
let cmd = "tar -xzf " <> archive
void $ ChildProcess.execSync cmd (ChildProcess.defaultExecSyncOptions { cwd = Just cwd })
void $ ChildProcess.execSync' cmd (_ { cwd = Just cwd })

type CreateArgs = { cwd :: String, folderName :: String }

Expand All @@ -39,4 +39,4 @@ create { cwd, folderName } = liftEffect do
, "-"
, folderName
]
void $ ChildProcess.execSync cmd (ChildProcess.defaultExecSyncOptions { cwd = Just cwd })
void $ ChildProcess.execSync' cmd (_ { cwd = Just cwd })
2 changes: 1 addition & 1 deletion app/src/App/GitHubIssue.purs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ main = launchAff_ $ do

liftEffect (Ref.read thrownRef) >>= case _ of
true ->
liftEffect $ Process.exit 1
liftEffect $ Process.exit' 1
_ -> do
-- After the run, close the issue. If an exception was thrown then the issue will remain open.
_ <- Octokit.request env.octokit (Octokit.closeIssueRequest { address: Constants.registry, issue: env.issue })
Expand Down
11 changes: 6 additions & 5 deletions app/src/App/Legacy/Manifest.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Data.These (These(..))
import Data.These as These
import Data.Variant as Variant
import Effect.Aff as Aff
import Node.ChildProcess.Types (Exit(..))
import Node.FS.Aff as FS.Aff
import Node.Library.Execa as Execa
import Node.Path as Path
Expand Down Expand Up @@ -359,11 +360,11 @@ fetchSpagoDhallJson address ref = Run.Except.runExceptAt _spagoDhallError do
let cmd = "dhall-to-json"
let args = []
process <- Execa.execa cmd args (_ { cwd = cwd })
process.stdin.writeUtf8End dhall
result <- process.result
pure case result of
Right { stdout } -> lmap CA.printJsonDecodeError $ parseJson CA.json stdout
Left { stderr } -> Left stderr
for_ process.stdin \{ writeUtf8End } -> writeUtf8End dhall
result <- process.getResult
pure case result.exit of
Normally 0 -> lmap CA.printJsonDecodeError $ parseJson CA.json result.stdout
_ -> Left result.stderr

newtype Bowerfile = Bowerfile
{ description :: Maybe String
Expand Down
2 changes: 1 addition & 1 deletion app/src/App/Server.purs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ main = do
createServerEnv # Aff.runAff_ case _ of
Left error -> do
Console.log $ "Failed to start server: " <> Aff.message error
Process.exit 1
Process.exit' 1
Right env -> do
_healthcheck <- Aff.launchAff do
let
Expand Down
4 changes: 2 additions & 2 deletions app/src/Fetch/Retry.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Effect.Aff (Error)
import Effect.Aff as Aff
import Fetch (class ToCoreRequestOptions, HighlevelRequestOptions, Response, new)
import Fetch (Response) as ReExport
import Fetch.Core as Core
import Fetch.Core.Request as CoreRequest
import Fetch.Internal.Request as Request
import Fetch.Internal.Response as Response
import JS.Fetch as Core
import JS.Fetch.Request as CoreRequest
import Prim.Row (class Union)
import Promise.Aff as Promise.Aff

Expand Down
4 changes: 2 additions & 2 deletions app/test/App/CLI/Tar.purs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ spec = do
FS.Aff.writeTextFile UTF8 (Path.concat [ tmp, name ]) contents

hashAndBytes path = do
FS.Stats.Stats { size: bytes } <- FS.Aff.stat path
stats <- FS.Aff.stat path
hash <- Sha256.hashFile path
pure { hash, bytes }
pure { hash, bytes: FS.Stats.size stats }
1 change: 0 additions & 1 deletion foreign/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ package:
main: Test.Foreign
dependencies:
- node-fs
- node-fs-aff
- node-process
- spec
2 changes: 1 addition & 1 deletion foreign/src/Foreign/Gzip.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Exception (Error)
import Effect.Uncurried (EffectFn1, EffectFn3, mkEffectFn1, runEffectFn3)
import Fetch (class ToRequestBody)
import Fetch.Core.RequestBody (RequestBody)
import JS.Fetch.RequestBody (RequestBody)
import Node.Buffer (Buffer)
import Unsafe.Coerce (unsafeCoerce)

Expand Down
9 changes: 6 additions & 3 deletions foreign/test/Foreign/Gzip.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Test.Registry.Foreign.Gzip (spec) where

import Prelude

import Data.Either (Either(..))
import Data.Maybe (fromMaybe)
import Node.ChildProcess.Types (Exit(..))
import Node.FS.Aff as FS.Aff
import Node.Library.Execa as Execa
import Node.Path as Path
Expand All @@ -22,5 +23,7 @@ spec = do
contents = "<contents>"
Gzip buffer <- Gzip.compress contents
FS.Aff.writeFile file buffer
result <- _.result =<< Execa.execa "zcat" [ file ] identity
(_.stdout <$> result) `Assert.shouldEqual` Right contents
result <- _.getResult =<< Execa.execa "zcat" [ file ] identity
case result.exit of
Normally 0 -> result.stdout `Assert.shouldEqual` contents
_ -> Assert.fail $ fromMaybe result.message result.originalMessage
1 change: 0 additions & 1 deletion lib/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package:
- newtype
- node-buffer
- node-fs
- node-fs-aff
- node-path
- nullable
- ordered-collections
Expand Down
13 changes: 7 additions & 6 deletions lib/test/Registry/Sha256.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Control.Monad.Except as Except
import Data.Either (Either(..))
import Data.String as String
import Effect.Aff (Aff)
import Node.ChildProcess.Types (Exit(..))
import Node.Library.Execa as Execa
import Node.Path (FilePath)
import Node.Path as Path
Expand Down Expand Up @@ -61,9 +62,9 @@ sha256Nix :: FilePath -> ExceptT String Aff Sha256.Sha256
sha256Nix path = ExceptT do
-- In Nix 2.4 this will become `nix hash file`
let args = [ "hash-file", "--sri", path ]
result <- _.result =<< Execa.execa "nix" args identity
pure $ case result of
Right { stdout } ->
Sha256.parse $ String.trim stdout
Left { stderr } ->
Left stderr
result <- _.getResult =<< Execa.execa "nix" args identity
pure $ case result.exit of
Normally 0 ->
Sha256.parse $ String.trim result.stdout
_ ->
Left result.stderr
6 changes: 3 additions & 3 deletions scripts/src/CompilerVersions.purs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ main = launchAff_ do
args <- Array.drop 2 <$> liftEffect Process.argv
let description = "A script for determining the supported compiler versions for packages."
arguments <- case Arg.parseArgs "compiler-versions" description parser args of
Left err -> Console.log (Arg.printArgError err) *> liftEffect (Process.exit 1)
Left err -> Console.log (Arg.printArgError err) *> liftEffect (Process.exit' 1)
Right command -> pure command

-- Environment
Expand Down Expand Up @@ -141,7 +141,7 @@ main = launchAff_ do
let
interpret :: Run _ ~> Aff
interpret =
Except.catch (\error -> Run.liftEffect (Console.log error *> Process.exit 1))
Except.catch (\error -> Run.liftEffect (Console.log error *> Process.exit' 1))
>>> Registry.interpret (Registry.handle registryEnv)
>>> Storage.interpret (Storage.handleReadOnly cache)
>>> GitHub.interpret (GitHub.handle { octokit, cache, ref: githubCacheRef })
Expand Down Expand Up @@ -229,7 +229,7 @@ compilersForPackageVersion package version target = do

if Array.null supported then do
Log.error $ "Could not find supported compiler versions for " <> formatPackageVersion package version
Run.liftEffect $ Process.exit 1
Run.liftEffect $ Process.exit' 1
else
Log.info $ "Found supported compiler versions for " <> formatPackageVersion package version <> ": " <> Array.intercalate ", " (map Version.print supported)

Expand Down
4 changes: 2 additions & 2 deletions scripts/src/LegacyImporter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ main = launchAff_ do

let description = "A script for uploading legacy registry packages."
mode <- case Arg.parseArgs "legacy-importer" description parser args of
Left err -> Console.log (Arg.printArgError err) *> liftEffect (Process.exit 1)
Left err -> Console.log (Arg.printArgError err) *> liftEffect (Process.exit' 1)
Right command -> pure command

Env.loadEnvFile ".env"
Expand Down Expand Up @@ -166,7 +166,7 @@ main = launchAff_ do
# runAppEffects
# Cache.interpret Legacy.Manifest._legacyCache (Cache.handleMemoryFs { cache, ref: legacyCacheRef })
# Cache.interpret _importCache (Cache.handleMemoryFs { cache, ref: importCacheRef })
# Except.catch (\msg -> Log.error msg *> Run.liftEffect (Process.exit 1))
# Except.catch (\msg -> Log.error msg *> Run.liftEffect (Process.exit' 1))
# Comment.interpret Comment.handleLog
# Log.interpret (\log -> Log.handleTerminal Normal log *> Log.handleFs Verbose logPath log)
# Env.runResourceEnv resourceEnv
Expand Down
Loading

0 comments on commit d7d35c9

Please sign in to comment.