diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6dc8b51ad..4291ae3b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: include: - os: ubuntu-latest - os: macOS-latest - # - os: windows-latest + - os: windows-latest steps: # We set LF endings so that the Windows environment is consistent with the rest # See here for context: https://github.com/actions/checkout/issues/135 @@ -52,8 +52,8 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Setup PureScript dependencies - run: npm i --global purescript@0.15.10 spago@0.93.11 purs-tidy@latest esbuild@latest + - name: Install global NPM packages + run: npm i --global purescript@0.15.10 spago@next purs-tidy@latest esbuild@latest - name: Cache PureScript dependencies uses: actions/cache@v2 @@ -64,13 +64,16 @@ jobs: output - name: Install NPM dependencies - run: npm install + run: npm ci - name: Install PureScript dependencies run: spago install - - name: Build executable - run: spago bundle -p spago-bin + - name: Build the project + run: spago build + + - name: Bootstrap executable + run: ./bin/index.dev.js -p spago-bin - name: Run tests run: spago test diff --git a/bin/spago.yaml b/bin/spago.yaml index 1a40e07a6..30781e96d 100644 --- a/bin/spago.yaml +++ b/bin/spago.yaml @@ -1,7 +1,7 @@ package: name: spago-bin publish: - version: 0.93.11 + version: 0.93.13 license: BSD-3-Clause dependencies: - aff diff --git a/package-lock.json b/package-lock.json index b3ec18d8c..795987d09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "spago", - "version": "0.93.11", + "version": "0.93.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "spago", - "version": "0.93.11", + "version": "0.93.13", "license": "BSD-3-Clause", "dependencies": { "env-paths": "^3.0.0", diff --git a/package.json b/package.json index dc215354a..fedb99c8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spago", - "version": "0.93.11", + "version": "0.93.13", "license": "BSD-3-Clause", "description": "🍝 PureScript package manager and build tool", "keywords": [ diff --git a/spago.lock b/spago.lock index 478461c9a..909cfb5aa 100644 --- a/spago.lock +++ b/spago.lock @@ -106,11 +106,11 @@ workspace: extra_packages: registry-foreign: git: https://github.com/purescript/registry-dev.git - ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e + ref: 6a803c37577af368caa221a2a06d6be2079d32da subdir: foreign registry-lib: git: https://github.com/purescript/registry-dev.git - ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e + ref: 6a803c37577af368caa221a2a06d6be2079d32da subdir: lib packages: aff: @@ -469,6 +469,52 @@ packages: integrity: sha256-A0JQHpTfo1dNOj9U5/Fd3xndlRSE0g2IQWOGor2yXn8= dependencies: - unsafe-coerce + fetch: + type: registry + version: 1.1.4 + integrity: sha256-Tmt60rjS4PNtKMVGpo8O6W1Fdhcu3a3CvyN/x+SwXEs= + dependencies: + - aff + - aff-promise + - arraybuffer-types + - effect + - fetch-core + - foreign + - http-methods + - newtype + - prelude + - record + - typelevel-prelude + - unsafe-coerce + - web-file + - web-promise + - web-streams + fetch-core: + type: registry + version: 4.0.4 + integrity: sha256-lS4yhvznII/vg37LewU/Ubeoj6OpxED2kb5/yn58YQQ= + dependencies: + - arraybuffer-types + - arrays + - console + - effect + - foldable-traversable + - foreign + - foreign-object + - functions + - http-methods + - maybe + - newtype + - nullable + - prelude + - record + - tuples + - typelevel-prelude + - unfoldable + - unsafe-coerce + - web-file + - web-promise + - web-streams filterable: type: registry version: 5.0.0 @@ -1175,7 +1221,7 @@ packages: registry-foreign: type: git url: https://github.com/purescript/registry-dev.git - rev: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e + rev: 6a803c37577af368caa221a2a06d6be2079d32da subdir: foreign dependencies: - aff @@ -1189,6 +1235,7 @@ packages: - datetime - effect - either + - fetch - filterable - foldable-traversable - foreign-object @@ -1212,7 +1259,7 @@ packages: registry-lib: type: git url: https://github.com/purescript/registry-dev.git - rev: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e + rev: 6a803c37577af368caa221a2a06d6be2079d32da subdir: lib dependencies: - aff @@ -1468,6 +1515,17 @@ packages: - web-dom - web-file - web-storage + web-promise: + type: registry + version: 3.1.0 + integrity: sha256-YfqJyEC3bHH6D8QgTi0ME5oJmGYOuZ2TlcyOdpG8dIE= + dependencies: + - effect + - exceptions + - foldable-traversable + - functions + - maybe + - prelude web-storage: type: registry version: 5.0.0 @@ -1475,6 +1533,18 @@ packages: dependencies: - nullable - web-events + web-streams: + type: registry + version: 3.0.0 + integrity: sha256-+QELAR7lb08Ebr4lCntxeGk5Z1i+NInDJwzEzz3Pigc= + dependencies: + - arraybuffer-types + - effect + - exceptions + - nullable + - prelude + - tuples + - web-promise web-xhr: type: registry version: 5.0.1 diff --git a/spago.yaml b/spago.yaml index e24b1e9ed..bb1a25d0e 100644 --- a/spago.yaml +++ b/spago.yaml @@ -1,7 +1,7 @@ package: name: spago publish: - version: 0.93.11 + version: 0.93.13 license: BSD-3-Clause location: githubOwner: purescript @@ -58,9 +58,9 @@ workspace: extra_packages: registry-lib: git: https://github.com/purescript/registry-dev.git - ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e + ref: 6a803c37577af368caa221a2a06d6be2079d32da subdir: lib registry-foreign: git: https://github.com/purescript/registry-dev.git - ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e + ref: 6a803c37577af368caa221a2a06d6be2079d32da subdir: foreign diff --git a/src/Spago/Cmd.purs b/src/Spago/Cmd.purs index 87b003954..94461a09c 100644 --- a/src/Spago/Cmd.purs +++ b/src/Spago/Cmd.purs @@ -3,12 +3,13 @@ module Spago.Cmd where import Spago.Prelude import Data.Array as Array -import Data.Nullable (Nullable) import Data.String (Pattern(..)) import Data.String as String +import Data.Time.Duration (Milliseconds(..)) import Node.Library.Execa as Execa +import Node.Platform as Platform +import Node.Process as Process import Partial.Unsafe (unsafeCrashWith) -import Data.Time.Duration (Milliseconds(..)) data StdinConfig = StdinPipeParent @@ -97,3 +98,32 @@ findFlag { flags, args } = case Array.uncons args of _ -> Nothing _ -> Just h1 _ -> Nothing + +getExecutable :: forall a. String -> Spago (LogEnv a) { cmd :: String, output :: String } +getExecutable command = + case Process.platform of + Just Platform.Win32 -> do + -- On Windows, we often need to call the `.cmd` version + let cmd1 = mkCmd command (Just "cmd") + askVersion cmd1 >>= case _ of + Right r -> pure { cmd: cmd1, output: r.stdout } + Left err' -> do + let cmd2 = mkCmd command Nothing + logDebug [ "Failed to find purs.cmd. Trying with just purs...", show err' ] + askVersion cmd2 >>= case _ of + Right r -> pure { cmd: cmd2, output: r.stdout } + Left err -> complain err + _ -> do + -- On other platforms, we just call `purs` + let cmd1 = mkCmd command Nothing + askVersion cmd1 >>= case _ of + Right r -> pure { cmd: cmd1, output: r.stdout } + Left err -> complain err + where + askVersion cmd = exec cmd [ "--version" ] defaultExecOptions { pipeStdout = false, pipeStderr = false } + + mkCmd cmd maybeExtension = cmd <> maybe "" (append ".") maybeExtension + + complain err = do + logDebug $ show err + die [ "Failed to find " <> command <> ". Have you installed it, and is it in your PATH?" ] diff --git a/src/Spago/Command/Bundle.purs b/src/Spago/Command/Bundle.purs index c2b51aca6..bf415cde9 100644 --- a/src/Spago/Command/Bundle.purs +++ b/src/Spago/Command/Bundle.purs @@ -54,9 +54,7 @@ run = do Nothing -> "output" Just o -> o -- TODO: we might need to use `Path.relative selected.path output` instead of just output there - mainPath = - String.replaceAll (Pattern "\\") (Replacement "/") $ - Path.concat [ output, opts.module, "index.js" ] + mainPath = withForwardSlashes $ Path.concat [ output, opts.module, "index.js" ] { input, entrypoint } = case opts.type of BundleApp -> { entrypoint: [], input: Cmd.StdinWrite ("#!/usr/bin/env node\n\nimport { main } from './" <> mainPath <> "'; main();") } diff --git a/src/Spago/Command/Fetch.purs b/src/Spago/Command/Fetch.purs index da74a07e4..3948e593d 100644 --- a/src/Spago/Command/Fetch.purs +++ b/src/Spago/Command/Fetch.purs @@ -207,21 +207,23 @@ run { packages, ensureRanges } = do case tarExists, tarIsGood of true, true -> pure unit -- Tar exists and is good, and we already unpacked it. Happy days! _, _ -> do + let packageUrl = "https://packages.registry.purescript.org/" <> PackageName.print name <> "/" <> versionString <> ".tar.gz" logInfo $ "Fetching package " <> packageVersion - response <- liftAff $ Http.request + response <- liftAff $ withBackoff' $ Http.request ( Http.defaultRequest { method = Left Method.GET , responseFormat = Response.arrayBuffer - , url = "https://packages.registry.purescript.org/" <> PackageName.print name <> "/" <> versionString <> ".tar.gz" + , url = packageUrl } ) case response of - Left err -> die $ "Couldn't fetch package " <> packageVersion <> ":\n " <> Http.printError err - Right { status, body } | status /= StatusCode 200 -> do + Nothing -> die $ "Couldn't reach the registry at " <> packageUrl + Just (Left err) -> die $ "Couldn't fetch package " <> packageVersion <> ":\n " <> Http.printError err + Just (Right { status, body }) | status /= StatusCode 200 -> do (buf :: Buffer) <- liftEffect $ Buffer.fromArrayBuffer body bodyString <- liftEffect $ Buffer.toString Encoding.UTF8 buf die $ "Couldn't fetch package " <> packageVersion <> ", status was not ok " <> show status <> ", got answer:\n " <> bodyString - Right r@{ body: archiveArrayBuffer } -> do + Just (Right r@{ body: archiveArrayBuffer }) -> do logDebug $ "Got status: " <> show r.status -- check the size and hash of the tar against the metadata archiveBuffer <- liftEffect $ Buffer.fromArrayBuffer archiveArrayBuffer diff --git a/src/Spago/Command/Init.purs b/src/Spago/Command/Init.purs index 706c7cbdd..ec52a159d 100644 --- a/src/Spago/Command/Init.purs +++ b/src/Spago/Command/Init.purs @@ -9,6 +9,7 @@ module Spago.Command.Init import Spago.Prelude import Data.Map as Map +import Node.Path as Path import Registry.PackageName as PackageName import Registry.Version as Version import Spago.Config (Dependencies(..), SetAddress(..), Config) @@ -46,11 +47,11 @@ run opts = do -- or just migrate a psc-package project let mainModuleName = "Main" whenDirNotExists "src" do - copyIfNotExists ("src/" <> mainModuleName <> ".purs") (srcMainTemplate mainModuleName) + copyIfNotExists ("src" <> Path.sep <> mainModuleName <> ".purs") (srcMainTemplate mainModuleName) whenDirNotExists "test" $ do - FS.mkdirp "test/Test" - copyIfNotExists "test/Test/Main.purs" (testMainTemplate "Test.Main") + FS.mkdirp (Path.concat [ "test", "Test" ]) + copyIfNotExists (Path.concat [ "test", "Test", "Main.purs" ]) (testMainTemplate "Test.Main") copyIfNotExists ".gitignore" gitignoreTemplate diff --git a/src/Spago/Command/Publish.purs b/src/Spago/Command/Publish.purs index 859b38941..9614d6a2e 100644 --- a/src/Spago/Command/Publish.purs +++ b/src/Spago/Command/Publish.purs @@ -175,7 +175,8 @@ publish _args = do , version: publishConfig.version , license: publishConfig.license , owners: Nothing -- TODO specify owners in spago config - , files: Nothing -- TODO specify files in spago config + , excludeFiles: Nothing -- TODO specify files in spago config + , includeFiles: Nothing -- TODO specify files in spago config } unless (Operation.Validation.locationMatches (Manifest manifest) (Metadata metadata)) $ addError $ toDoc diff --git a/src/Spago/Command/Run.purs b/src/Spago/Command/Run.purs index af891784b..71162b04c 100644 --- a/src/Spago/Command/Run.purs +++ b/src/Spago/Command/Run.purs @@ -85,7 +85,7 @@ run = do nodeContents = Array.fold [ "import { main } from 'file://" - , String.replaceAll (Pattern "\\") (Replacement "/") opts.sourceDir + , withForwardSlashes opts.sourceDir , "/" , fromMaybe "output" workspace.buildOptions.output , "/" diff --git a/src/Spago/Config.purs b/src/Spago/Config.purs index 6c7087219..79c9a0bf7 100644 --- a/src/Spago/Config.purs +++ b/src/Spago/Config.purs @@ -166,7 +166,7 @@ readWorkspace maybeSelectedPackage = do | otherwise -> do -- TODO: here figure out if the lockfile is still valid by checking if: -- - the package set section of the workspace is the same - -- - the dependencies of each package are the same + -- - the dependencies of each package are the same pure (UseLockfile contents) false -- If the user specifies lock: true then we always create a lockfile. diff --git a/src/Spago/Esbuild.purs b/src/Spago/Esbuild.purs index 7842616c6..e158ce85a 100644 --- a/src/Spago/Esbuild.purs +++ b/src/Spago/Esbuild.purs @@ -10,9 +10,6 @@ type Esbuild = } getEsbuild :: forall a. Spago (LogEnv a) Esbuild -getEsbuild = - Cmd.exec "esbuild" [ "--version" ] Cmd.defaultExecOptions { pipeStdout = false, pipeStderr = false } >>= case _ of - Left err -> do - logDebug $ show err - die [ "Failed to find esbuild. See https://esbuild.github.io/getting-started/#install-esbuild for ways to install esbuild." ] - Right r -> pure { cmd: "esbuild", version: r.stdout } +getEsbuild = do + { cmd, output } <- Cmd.getExecutable "esbuild" + pure { cmd, version: output } diff --git a/src/Spago/Prelude.purs b/src/Spago/Prelude.purs index 7c8be3ce3..96a41c605 100644 --- a/src/Spago/Prelude.purs +++ b/src/Spago/Prelude.purs @@ -12,6 +12,7 @@ module Spago.Prelude , withBackoff' , mkTemp , mkTemp' + , withForwardSlashes ) where import Spago.Core.Prelude @@ -24,6 +25,7 @@ import Data.Foldable as Foldable import Data.Function.Uncurried (Fn3, runFn3) import Data.Int as Int import Data.Maybe as Maybe +import Data.String (Pattern(..), Replacement(..)) import Data.String as String import Effect.Aff as Aff import Effect.Now as Now @@ -148,3 +150,6 @@ mkTemp' maybeSuffix = liftAff do mkTemp :: forall m. MonadAff m => m FilePath mkTemp = mkTemp' Nothing + +withForwardSlashes :: String -> String +withForwardSlashes = String.replaceAll (Pattern "\\") (Replacement "/") diff --git a/src/Spago/Purs.purs b/src/Spago/Purs.purs index ae303afb8..82c09b6a5 100644 --- a/src/Spago/Purs.purs +++ b/src/Spago/Purs.purs @@ -8,8 +8,6 @@ import Data.Codec.Argonaut.Record as CAR import Data.Profunctor as Profunctor import Data.Set as Set import Data.String as String -import Node.Platform as Platform -import Node.Process as Process import Registry.Internal.Codec as Internal.Codec import Registry.Version as Version import Spago.Cmd as Cmd @@ -26,43 +24,22 @@ type Purs = } getPurs :: forall a. Spago (LogEnv a) Purs -getPurs = - case Process.platform of - Just Platform.Win32 -> do - -- On Windows, we often need to call `purs.cmd` instead of `purs` - pursVersion "purs.cmd" >>= case _ of - Right r -> parseVersionOutput "purs.cmd" r - Left err' -> do - logDebug [ "Failed to find purs.cmd. Trying with just purs...", show err' ] - pursVersion "purs" >>= case _ of - Right r -> parseVersionOutput "purs" r - Left err -> complain err - _ -> do - -- On other platforms, we just call `purs` - pursVersion "purs" >>= case _ of - Right r -> parseVersionOutput "purs" r - Left err -> complain err +getPurs = Cmd.getExecutable "purs" >>= parseVersionOutput + +-- Drop the stuff after a space: dev builds look like this: 0.15.6 [development build; commit: 8da7e96005f717f03d6eee3c12b1f1416659a919] +-- Drop the stuff after a hyphen: prerelease builds look like this: 0.15.6-2 +parseVersionOutput :: forall a. { cmd :: String, output :: String } -> Spago (LogEnv a) Purs +parseVersionOutput { cmd, output: stdout } = case parseLenientVersion (dropStuff "-" $ dropStuff " " stdout) of + Left _err -> die $ "Failed to parse purs version. Was: " <> stdout + -- Fail if Purs is lower than 0.15.4 + Right v -> + if Version.minor v >= 15 && Version.patch v >= 4 then + pure { cmd, version: v } + else + die [ "Unsupported PureScript version " <> Version.print v, "Please install PureScript v0.15.4 or higher." ] where - pursVersion cmd = Cmd.exec cmd [ "--version" ] Cmd.defaultExecOptions { pipeStdout = false, pipeStderr = false } - dropStuff pattern = fromMaybe "" <<< Array.head <<< String.split (String.Pattern pattern) - complain err = do - logDebug $ show err - die [ "Failed to find purs. Have you installed it, and is it in your PATH?" ] - - -- Drop the stuff after a space: dev builds look like this: 0.15.6 [development build; commit: 8da7e96005f717f03d6eee3c12b1f1416659a919] - -- Drop the stuff after a hyphen: prerelease builds look like this: 0.15.6-2 - parseVersionOutput :: String -> _ -> Spago (LogEnv a) Purs - parseVersionOutput cmd result = case parseLenientVersion (dropStuff "-" $ dropStuff " " result.stdout) of - Left _err -> die $ "Failed to parse purs version. Was: " <> result.stdout - -- Fail if Purs is lower than 0.15.4 - Right v -> - if Version.minor v >= 15 && Version.patch v >= 4 then - pure { cmd, version: v } - else - die [ "Unsupported PureScript version " <> Version.print v, "Please install PureScript v0.15.4 or higher." ] - compile :: forall a. Set FilePath -> Array String -> Spago (PursEnv a) (Either Cmd.ExecError Cmd.ExecResult) compile globs pursArgs = do { purs } <- ask diff --git a/src/Spago/Purs/Graph.purs b/src/Spago/Purs/Graph.purs index 715e3d4fc..5c84511eb 100644 --- a/src/Spago/Purs/Graph.purs +++ b/src/Spago/Purs/Graph.purs @@ -96,9 +96,11 @@ checkImports = do addPackageInfo :: PackageGraph -> Tuple ModuleName ModuleGraphNode -> PackageGraph addPackageInfo pkgGraph (Tuple moduleName { path, depends }) = let + -- Windows paths will need a conversion to forward slashes to be matched to globs + newPath = withForwardSlashes path newVal = do - package <- Map.lookup path pathToPackage - pure { path, depends, package } + package <- Map.lookup newPath pathToPackage + pure { path: newPath, depends, package } in maybe pkgGraph (\v -> Map.insert moduleName v pkgGraph) newVal packageGraph = foldl addPackageInfo Map.empty (Map.toUnfoldable graph :: Array _) @@ -149,7 +151,7 @@ checkImports = do compileGlob :: forall a. FilePath -> Spago (LogEnv a) (Array FilePath) compileGlob sourcePath = do - { succeeded, failed } <- Glob.match Paths.cwd [ sourcePath ] + { succeeded, failed } <- Glob.match Paths.cwd [ withForwardSlashes sourcePath ] unless (Array.null failed) do logDebug [ toDoc "Encountered some globs that are not in cwd, proceeding anyways:", indent $ toDoc failed ] pure (succeeded <> failed) diff --git a/test-fixtures/sources-output.win.txt b/test-fixtures/sources-output.win.txt new file mode 100644 index 000000000..a000589f1 --- /dev/null +++ b/test-fixtures/sources-output.win.txt @@ -0,0 +1,5 @@ +src\**\*.purs +test\**\*.purs +.spago\packages\console-6.0.0\src\**\*.purs +.spago\packages\effect-4.0.0\src\**\*.purs +.spago\packages\prelude-6.0.1\src\**\*.purs diff --git a/test-fixtures/sources-subproject-output.win.txt b/test-fixtures/sources-subproject-output.win.txt new file mode 100644 index 000000000..3c9528ba5 --- /dev/null +++ b/test-fixtures/sources-subproject-output.win.txt @@ -0,0 +1,5 @@ +.spago\packages\console-6.0.0\src\**\*.purs +.spago\packages\effect-4.0.0\src\**\*.purs +.spago\packages\prelude-6.0.1\src\**\*.purs +subpackage\src\**\*.purs +subpackage\test\**\*.purs diff --git a/test/Prelude.purs b/test/Prelude.purs index 96b14845b..e6e59ea1a 100644 --- a/test/Prelude.purs +++ b/test/Prelude.purs @@ -38,15 +38,15 @@ withTempDir = Aff.bracket createTempDir cleanupTempDir liftEffect $ Process.chdir temp log $ "Running test in " <> temp let - fixturesPath = oldCwd <> "/test-fixtures" + fixturesPath = oldCwd <> Path.sep <> "test-fixtures" fixture path = Path.concat [ fixturesPath, path ] spago' :: StdinConfig -> Array String -> Aff (Either ExecError ExecResult) spago' stdin args = Cmd.exec - (Path.concat [ oldCwd, "bin", "index.dev.js" ]) - args + "node" + ([ Path.concat [ oldCwd, "bin", "index.dev.js" ] ] <> args) $ Cmd.defaultExecOptions { pipeStdout = false, pipeStderr = false, pipeStdin = stdin } spago = spago' StdinNewPipe diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index 0bb864cd2..3d984543a 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -2,6 +2,8 @@ module Test.Spago.Build where import Test.Prelude +import Effect.Class.Console as Console +import Node.Path as Path import Registry.Version as Version import Spago.Command.Init as Init import Spago.Core.Config as Config @@ -48,11 +50,11 @@ spec = Spec.around withTempDir do Spec.it "there's only one output folder in a monorepo" \{ spago } -> do spago [ "init" ] >>= shouldBeSuccess - FS.mkdirp "subpackage/src" - FS.mkdirp "subpackage/test" - FS.writeTextFile "subpackage/src/Main.purs" (Init.srcMainTemplate "Subpackage.Main") - FS.writeTextFile "subpackage/test/Main.purs" (Init.testMainTemplate "Subpackage.Test.Main") - FS.writeYamlFile Config.configCodec "subpackage/spago.yaml" + FS.mkdirp (Path.concat [ "subpackage", "src" ]) + FS.mkdirp (Path.concat [ "subpackage", "test" ]) + FS.writeTextFile (Path.concat [ "subpackage", "src", "Main.purs" ]) (Init.srcMainTemplate "Subpackage.Main") + FS.writeTextFile (Path.concat [ "subpackage", "test", "Main.purs" ]) (Init.testMainTemplate "Subpackage.Test.Main") + FS.writeYamlFile Config.configCodec (Path.concat [ "subpackage", "spago.yaml" ]) ( Init.defaultConfig (mkPackageName "subpackage") Nothing @@ -61,18 +63,18 @@ spec = Spec.around withTempDir do spago [ "build" ] >>= shouldBeSuccess spago [ "build", "-p", "subpackage" ] >>= shouldBeSuccess FS.exists "output" `Assert.shouldReturn` true - FS.exists "subpackage/output" `Assert.shouldReturn` false + FS.exists (Path.concat [ "subpackage", "output" ]) `Assert.shouldReturn` false Spec.it "fails when there are imports from transitive dependencies and --pedantic-packages is passed" \{ spago, fixture } -> do spago [ "init", "--name", "7368613235362d34312f4e59746b7869335477336d33414d72" ] >>= shouldBeSuccess spago [ "install", "maybe" ] >>= shouldBeSuccess - FS.writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nimport Data.Maybe\nimport Control.Alt\nmain = unit" + FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) "module Main where\nimport Prelude\nimport Data.Maybe\nimport Control.Alt\nmain = unit" spago [ "build" ] >>= shouldBeSuccess spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-direct-import-transitive-dependency.txt") Spec.it "--pedantic-packages also warns about unused dependencies" \{ spago, fixture } -> do spago [ "init", "--name", "7368613235362d2f444a2b4f56375435646a59726b53586548" ] >>= shouldBeSuccess - FS.writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain = unit" + FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) "module Main where\nimport Prelude\nmain = unit" spago [ "build" ] >>= shouldBeSuccess spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-unused-dependency.txt") diff --git a/test/Spago/Init.purs b/test/Spago/Init.purs index 226344341..abe9b1d42 100644 --- a/test/Spago/Init.purs +++ b/test/Spago/Init.purs @@ -2,6 +2,7 @@ module Test.Spago.Init where import Test.Prelude +import Node.Path as Path import Spago.FS as FS import Test.Spec (Spec) import Test.Spec as Spec @@ -16,9 +17,9 @@ spec = Spec.around withTempDir do Spec.it "does not overwrite files when initing a project" \{ spago } -> do FS.mkdirp "src" - FS.writeTextFile "src/Main.purs" "Something" + FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) "Something" spago [ "init" ] >>= shouldBeSuccess - fileContent <- FS.readTextFile "src/Main.purs" + fileContent <- FS.readTextFile (Path.concat [ "src", "Main.purs" ]) fileContent `Assert.shouldEqual` "Something" Spec.it "always succeeds when doing init with force" \{ spago } -> do diff --git a/test/Spago/Sources.purs b/test/Spago/Sources.purs index fabca00a6..1d1fa5110 100644 --- a/test/Spago/Sources.purs +++ b/test/Spago/Sources.purs @@ -2,7 +2,8 @@ module Test.Spago.Sources where import Test.Prelude -import Registry.PackageName as PackageName +import Node.Platform as Platform +import Node.Process as Process import Spago.Command.Init as Init import Spago.Core.Config as Config import Spago.FS as FS @@ -15,7 +16,9 @@ spec = Spec.around withTempDir do Spec.it "contains both dependencies and project sources" \{ spago, fixture } -> do spago [ "init" ] >>= shouldBeSuccess - spago [ "sources" ] >>= shouldBeSuccessOutput (fixture "sources-output.txt") + spago [ "sources" ] >>= shouldBeSuccessOutput case Process.platform of + Just Platform.Win32 -> fixture "sources-output.win.txt" + _ -> fixture "sources-output.txt" Spec.it "contains subproject sources when selecting a subproject" \{ spago, fixture } -> do spago [ "init" ] >>= shouldBeSuccess @@ -29,4 +32,6 @@ spec = Spec.around withTempDir do Nothing "Subpackage.Test.Main" ) - spago [ "sources", "-p", "subpackage" ] >>= shouldBeSuccessOutput (fixture "sources-subproject-output.txt") + spago [ "sources", "-p", "subpackage" ] >>= shouldBeSuccessOutput case Process.platform of + Just Platform.Win32 -> fixture "sources-subproject-output.win.txt" + _ -> fixture "sources-subproject-output.txt"