Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
555cd27
Change template spago.dhall to multi-target format
JordanMartinez Aug 14, 2021
f89ee67
Define types: Target and TargetName
JordanMartinez Aug 14, 2021
50c6037
Define common target names
JordanMartinez Aug 14, 2021
f1e6147
Make Config have targets, update Dhall parsing
JordanMartinez Aug 15, 2021
07c2db9
Add targetName arg to CLI commands
JordanMartinez Aug 15, 2021
aa58bee
Define `HasTarget` alias
JordanMartinez Aug 14, 2021
08463cb
Update spago repl to support targets
JordanMartinez Aug 15, 2021
531d6d6
Update spago sources to use targets
JordanMartinez Aug 14, 2021
54a377d
Updat sources to support targets
JordanMartinez Aug 14, 2021
c04b21b
Update spago ls to support targets
JordanMartinez Aug 15, 2021
8790f52
Refactor process for getting target
JordanMartinez Aug 15, 2021
c83e213
Refactor LsEnv to InstallEnv2
JordanMartinez Aug 15, 2021
a2d2557
Update install to support targets
JordanMartinez Aug 15, 2021
f869dd5
Support targets for build, run, test, bundle-*
JordanMartinez Aug 17, 2021
4c829ca
Support targets for search
JordanMartinez Aug 17, 2021
ff1f12e
Support targets for docs
JordanMartinez Aug 17, 2021
4a60828
Drop '2' suffix on replacement Env; drop old Env
JordanMartinez Aug 17, 2021
09ae7d1
Reduce diff: swap order of args
JordanMartinez Aug 17, 2021
d33989a
Remove unneeded whitespace
JordanMartinez Aug 17, 2021
cb896ec
Implement addRawDeps for targets
JordanMartinez Aug 19, 2021
6226017
Migrate psc-package: use target-based add deps
JordanMartinez Aug 19, 2021
fc98b77
Migrate bower: add target deps
JordanMartinez Aug 19, 2021
e07400b
Use one traversal to handle let bindings
JordanMartinez Aug 19, 2021
d81287d
Make install handle more Dhall expressions
JordanMartinez Aug 20, 2021
d8245fb
Migrate v1 and v2 configs to v3 Dhall expr
JordanMartinez Aug 20, 2021
72c4711
Normalize dhall expression before parsing
JordanMartinez Aug 20, 2021
834d034
Make bumpVersion require a target
JordanMartinez Aug 20, 2021
efd44fd
Make bumpVersion use target's dependencies
JordanMartinez Aug 20, 2021
5105bd9
Remove configSourcePaths from Config
JordanMartinez Aug 20, 2021
cd108f2
Remove dependencies from Config type
JordanMartinez Aug 20, 2021
8d79077
Drop 'o' shorthand for target
JordanMartinez Aug 20, 2021
0c0f912
Add new deps to first ListLit found or create one
JordanMartinez Aug 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions app/Spago.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ main = withUtf8 $ do
-> CLI.echo spagoVersion
Path whichPath buildOptions
-> Path.showPaths buildOptions whichPath
Repl replPackageNames paths pursArgs depsOnly
-> Spago.Build.repl replPackageNames paths pursArgs depsOnly
BundleApp modName tPath shouldBuild buildOptions
-> Spago.Build.bundleApp WithMain modName tPath shouldBuild buildOptions globalUsePsa
BundleModule modName tPath shouldBuild buildOptions
-> Spago.Build.bundleModule modName tPath shouldBuild buildOptions globalUsePsa
Repl targetName replPackageNames paths pursArgs depsOnly
-> Spago.Build.repl targetName replPackageNames paths pursArgs depsOnly
BundleApp targetName modName tPath shouldBuild buildOptions
-> Spago.Build.bundleApp targetName WithMain modName tPath shouldBuild buildOptions globalUsePsa
BundleModule targetName modName tPath shouldBuild buildOptions
-> Spago.Build.bundleModule targetName modName tPath shouldBuild buildOptions globalUsePsa
Script modulePath tag dependencies scriptBuildOptions
-> Spago.Build.script modulePath tag dependencies scriptBuildOptions

Expand All @@ -71,15 +71,15 @@ main = withUtf8 $ do
$ Ls.listPackageSet jsonFlag

-- ### Commands that need an "install environment": global options and a Config
Install packageNames -> Run.withInstallEnv
Install targetName packageNames -> Run.withInstallEnv targetName
$ Spago.Packages.install packageNames
ListDeps jsonFlag transitiveFlag -> Run.withInstallEnv
ListDeps targetName jsonFlag transitiveFlag -> Run.withInstallEnv targetName
$ Ls.listPackages transitiveFlag jsonFlag
Sources -> Run.withInstallEnv
Sources targetName -> Run.withInstallEnv targetName
$ Spago.Packages.sources

-- ### Commands that need a "publish env": install env + git and bower
BumpVersion dryRun spec -> Run.withPublishEnv
BumpVersion targetName dryRun spec -> Run.withPublishEnv targetName
$ Spago.Version.bumpVersion dryRun spec

-- ### Commands that need a "verification env": a Package Set + purs
Expand All @@ -89,18 +89,18 @@ main = withUtf8 $ do
$ Verify.verify checkUniqueModules Nothing

-- ### Commands that need a build environment: a config, build options and access to purs
Build buildOptions -> Run.withBuildEnv globalUsePsa buildOptions
Build targetName buildOptions -> Run.withBuildEnv targetName globalUsePsa buildOptions
$ Spago.Build.build Nothing
Search -> Run.withBuildEnv globalUsePsa defaultBuildOptions
Search targetName -> Run.withBuildEnv targetName globalUsePsa defaultBuildOptions
$ Spago.Build.search
Docs format sourcePaths depsOnly noSearch openDocs ->
Docs targetName format sourcePaths depsOnly noSearch openDocs ->
let
opts = defaultBuildOptions { depsOnly = depsOnly, sourcePaths = sourcePaths }
in Run.withBuildEnv globalUsePsa opts
in Run.withBuildEnv targetName globalUsePsa opts
$ Spago.Build.docs format noSearch openDocs
Test modName buildOptions nodeArgs -> Run.withBuildEnv globalUsePsa buildOptions
Test targetName modName buildOptions nodeArgs -> Run.withBuildEnv targetName globalUsePsa buildOptions
$ Spago.Build.test modName nodeArgs
Run modName buildOptions nodeArgs -> Run.withBuildEnv globalUsePsa buildOptions
Run targetName modName buildOptions nodeArgs -> Run.withBuildEnv targetName globalUsePsa buildOptions
$ Spago.Build.run modName nodeArgs

-- ### Legacy commands, here for smoother migration path to new ones
Expand Down
1 change: 1 addition & 0 deletions spago.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ library
Spago.PscPackage
Spago.Purs
Spago.RunEnv
Spago.Targets
Spago.Templates
Spago.TH
Spago.Types
Expand Down
2 changes: 1 addition & 1 deletion src/Spago/Bower.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mkBowerVersion packageName version (Repo repo) = do
mkDependencies
:: forall env. HasPublishEnv env => RIO env [(Bower.PackageName, Bower.VersionRange)]
mkDependencies = do
deps <- Packages.getDirectDeps
deps <- Packages.getTransitiveTargetDeps

Jobs jobs <- getJobs

Expand Down
61 changes: 37 additions & 24 deletions src/Spago/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import qualified Spago.FetchPackage as Fetch
import qualified Spago.Messages as Messages
import qualified Spago.Packages as Packages
import qualified Spago.Purs as Purs
import qualified Spago.Targets as Targets
import qualified Spago.Templates as Templates
import qualified Spago.Watch as Watch

Expand All @@ -54,10 +55,11 @@ build maybePostBuild = do
logDebug "Running `spago build`"
BuildOptions{..} <- view (the @BuildOptions)
Config{..} <- view (the @Config)
deps <- Packages.getProjectDeps
let partitionedGlobs@(Packages.Globs{..}) = Packages.getGlobs deps depsOnly configSourcePaths
Target{..} <- view (the @Target)
deps <- Packages.getTransitiveTargetDeps
let partitionedGlobs@(Packages.Globs{..}) = Packages.getGlobs deps depsOnly targetSourcePaths
allPsGlobs = Packages.getGlobsSourcePaths partitionedGlobs <> sourcePaths
allJsGlobs = Packages.getJsGlobs deps depsOnly configSourcePaths <> sourcePaths
allJsGlobs = Packages.getJsGlobs deps depsOnly targetSourcePaths <> sourcePaths

checkImports = do
maybeGraph <- view (the @Graph)
Expand Down Expand Up @@ -103,7 +105,7 @@ build maybePostBuild = do
$ Set.toList importedPackageModules

dependencyPackages :: Set PackageName
dependencyPackages = Set.fromList dependencies
dependencyPackages = Set.fromList targetDependencies

let
unusedPackages =
Expand Down Expand Up @@ -197,16 +199,19 @@ build maybePostBuild = do
-- | Start a repl
repl
:: (HasEnv env)
=> [PackageName]
=> TargetName
-> [PackageName]
-> [SourcePath]
-> [PursArg]
-> Packages.DepsOnly
-> RIO env ()
repl newPackages sourcePaths pursArgs depsOnly = do
repl tgtName newPackages sourcePaths pursArgs depsOnly = do
logDebug "Running `spago repl`"
purs <- Run.getPurs NoPsa
Config.ensureConfig >>= \case
Right config -> Run.withInstallEnv' (Just config) (replAction purs)
Right config -> do
target <- Run.getTarget tgtName (targets config)
Run.withReplEnv config target (replAction purs)
Left err -> do
logDebug err
GlobalCache cacheDir _ <- view (the @GlobalCache)
Expand All @@ -215,16 +220,20 @@ repl newPackages sourcePaths pursArgs depsOnly = do

writeTextFile ".purs-repl" Templates.pursRepl

let dependencies = [ PackageName "effect", PackageName "console", PackageName "psci-support" ] <> newPackages
let
dependencies = [ PackageName "effect", PackageName "console", PackageName "psci-support" ] <> newPackages
srcPaths = []
target = Target { targetDependencies = dependencies, targetSourcePaths = srcPaths }

config <- Run.withPursEnv NoPsa $ do
Config.makeTempConfig dependencies Nothing [] Nothing
Config.makeTempConfig dependencies Nothing srcPaths Nothing

Run.withInstallEnv' (Just config) (replAction purs)
Run.withReplEnv config target (replAction purs)
where
replAction :: PursCmd -> RIO ReplEnv ()
replAction purs = do
Config{..} <- view (the @Config)
deps <- Packages.getProjectDeps
Target{ targetSourcePaths } <- view (the @Target)
deps <- Packages.getTransitiveTargetDeps
-- we check that psci-support is in the deps, see #550
unless (Set.member (PackageName "psci-support") (Set.fromList (map fst deps))) $ do
die
Expand All @@ -233,7 +242,7 @@ repl newPackages sourcePaths pursArgs depsOnly = do
]
let
globs =
Packages.getGlobsSourcePaths $ Packages.getGlobs deps depsOnly (configSourcePaths <> sourcePaths)
Packages.getGlobsSourcePaths $ Packages.getGlobs deps depsOnly (targetSourcePaths <> sourcePaths)
Fetch.fetchPackages deps
runRIO purs $ Purs.repl globs pursArgs

Expand Down Expand Up @@ -304,7 +313,7 @@ script modulePath tag packageDeps opts = do
let runDirs :: RunDirectories
runDirs = RunDirectories scriptDirPath currentDir

Run.withBuildEnv' (Just config) NoPsa buildOpts (runAction runDirs)
Run.withBuildEnv' (Just config) Targets.mainTarget NoPsa buildOpts (runAction runDirs)
where
buildOpts = fromScriptOptions defaultBuildOptions opts
runAction dirs = runBackend Nothing dirs (ModuleName "Main") Nothing "Script failed to run; " []
Expand Down Expand Up @@ -366,30 +375,32 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe
-- | Bundle the project to a js file
bundleApp
:: HasEnv env
=> WithMain
=> TargetName
-> WithMain
-> Maybe ModuleName
-> Maybe TargetPath
-> NoBuild
-> BuildOptions
-> UsePsa
-> RIO env ()
bundleApp withMain maybeModuleName maybeTargetPath noBuild buildOpts usePsa =
bundleApp tgtName withMain maybeModuleName maybeTargetPath noBuild buildOpts usePsa =
let (moduleName, targetPath) = prepareBundleDefaults maybeModuleName maybeTargetPath
bundleAction = Purs.bundle withMain (withSourceMap buildOpts) moduleName targetPath
in case noBuild of
DoBuild -> Run.withBuildEnv usePsa buildOpts $ build (Just bundleAction)
DoBuild -> Run.withBuildEnv tgtName usePsa buildOpts $ build (Just bundleAction)
NoBuild -> Run.getEnv >>= (flip runRIO) bundleAction

-- | Bundle into a CommonJS module
bundleModule
:: HasEnv env
=> Maybe ModuleName
=> TargetName
-> Maybe ModuleName
-> Maybe TargetPath
-> NoBuild
-> BuildOptions
-> UsePsa
-> RIO env ()
bundleModule maybeModuleName maybeTargetPath noBuild buildOpts usePsa = do
bundleModule tgtName maybeModuleName maybeTargetPath noBuild buildOpts usePsa = do
logDebug "Running `bundleModule`"
let (moduleName, targetPath) = prepareBundleDefaults maybeModuleName maybeTargetPath
jsExport = Text.unpack $ "\nmodule.exports = PS[\""<> unModuleName moduleName <> "\"];"
Expand All @@ -404,7 +415,7 @@ bundleModule maybeModuleName maybeTargetPath noBuild buildOpts usePsa = do
Right _ -> logInfo $ display $ "Make module succeeded and output file to " <> unTargetPath targetPath
Left (n :: SomeException) -> die [ "Make module failed: " <> repr n ]
case noBuild of
DoBuild -> Run.withBuildEnv usePsa buildOpts $ build (Just bundleAction)
DoBuild -> Run.withBuildEnv tgtName usePsa buildOpts $ build (Just bundleAction)
NoBuild -> Run.getEnv >>= (flip runRIO) bundleAction

docsSearchTemplate :: (HasType LogFunc env, HasType PursCmd env) => RIO env Text
Expand All @@ -428,9 +439,10 @@ docs format noSearch open = do
logDebug "Running `spago docs`"
BuildOptions { sourcePaths, depsOnly } <- view (the @BuildOptions)
Config{..} <- view (the @Config)
deps <- Packages.getProjectDeps
Target{..} <- view (the @Target)
deps <- Packages.getTransitiveTargetDeps
logInfo "Generating documentation for the project. This might take a while..."
Purs.docs docsFormat $ Packages.getGlobsSourcePaths (Packages.getGlobs deps depsOnly configSourcePaths) <> sourcePaths
Purs.docs docsFormat $ Packages.getGlobsSourcePaths (Packages.getGlobs deps depsOnly targetSourcePaths) <> sourcePaths

when isHTMLFormat $ do
when (noSearch == AddSearch) $ do
Expand Down Expand Up @@ -465,11 +477,12 @@ docs format noSearch open = do
search :: HasBuildEnv env => RIO env ()
search = do
Config{..} <- view (the @Config)
deps <- Packages.getProjectDeps
Target{..} <- view (the @Target)
deps <- Packages.getTransitiveTargetDeps

logInfo "Building module metadata..."

Purs.compile (Packages.getGlobsSourcePaths (Packages.getGlobs deps Packages.AllSources configSourcePaths))
Purs.compile (Packages.getGlobsSourcePaths (Packages.getGlobs deps Packages.AllSources targetSourcePaths))
[ PursArg "--codegen"
, PursArg "docs"
]
Expand Down
Loading