Polls
Problem
-
DuplicateModule
error is possible when I add two libs and they define the same module (Data.Percent
for example) -
I have to write
module Foo.Bar where
all the time. Why should I write it when it can be perfectly derived from file path src/Foo/Bar.purs
- When I import module
import Data.String.Extra
I don’t actually know the name of the module. Is it purescript-strings
OR purescript-strings-extra
? Or maybe it’s even purescript-string
?
Proposal
- Make all imports qualified by package name, i.e. it should be not possible to write non-package-name-qualified
import
- Make module name derivable from path
- enforce domain - reason in this issue
- allow relative imports within the same package
spago.dhall
before
{ name = "my-app"
, dependencies = [ "strings", "strings-extra", "other-strings" ]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
spago.dhall
after
-- this is a name of a package that is published to package-sets / pursuit
-- it's fixed to "publishedSource" dir below, this dir won't be ignored
{ name = "my-app"
, domain = "me" -- enforce domain / namespace
, dependencies = [ "@core/strings", "@contrib/strings-extra", "@noname/other-strings" ]
, packages = ./packages.dhall
, publishedSource = "src" -- this is what end up in a package in pursuit
, localPackages =
-- these dirs are not publised to pursuit, they are ignored to preserve space (if we need to)
-- type in haskell - `type LocalPackages = Map String String`
[ { packageName = "my-app-test", directory = "test" } -- imported as `import "@me/my-app-test/..."`
, { packageName = "my-app-bench", directory = "bench" } -- imported as `import "@me/my-app-bench/..."`
, { packageName = "my-app-demo", directory = "demo" } -- imported as `import "@me/my-app-demo/..."`
]
}
before
purs compile --output output \
.spago/strings/v9.9.9/src/**/*.purs \
.spago/strings-extra/v9.9.9/src/**/*.purs \
.spago/other-strings/v9.9.9/src/**/*.purs \
src/**/*.purs \
test/**/*.purs
after
purs compile --output output \
--package @core/strings:.spago/@core/strings/v9.9.9/src \
--package @contrib/strings-extra:.spago/@contrib/strings-extra/v9.9.9/src \
--package @noname/other-strings:.spago/@noname/other-strings/v9.9.9/src \
--package @me/my-app:src \
--package @me/my-app-test:test \
--package @me/my-app-bench:bench
## no, it's not possible to specify the same package name two times,
## because it will make DuplicateModule possible and we end up where we stopped
# --package @noname/other-strings:.spago/@noname/other-strings/v9.9.9/other-src
## no, you cannot define aliases, i.e. import already imported dir
## (well, we could allow aliases, but how the ./output dir will be generated?)
# --package @me/my-utils:src/utils
having
| .spago/
| @core/strings/v9.9.9/src/
| index.purs
| bar.purs -- this file will be imported on `import "strings/bar"`
| bar/
| index.purs -- only imported on `import "strings/bar/index"`
| baz.purs
| @contrib/strings-extra/v9.9.9/src/
| index.purs
| @noname/other-strings/v9.9.9/src/
| index.purs
| src/
| test/
| bench/
the output dir will be the following
| output/
| @core/strings/...
| @contrib/strings-extra/...
| @noname/other-strings/...
| @me/my-app/...
| @me/my-app-test/...
| @me/my-app-bench/...
-- `module ... where` is replaced with `export` (or maybe just `where`?)
-- because module name is calculated automatically from path
-- `export` is optional (by default exports everything)
export
( Foo(..)
, bar
)
import "@core/prelude"
-- will import from ".spago/@core/strings/v9.9.9/src/index.purs"
import "@core/strings"
-- will import from ".spago/@contrib/strings-extra/v9.9.9/src/index.purs"
import "@contrib/strings-extra" as StringsExtra
( Foo(Bar)
)
-- will import
-- from ".spago/@noname/other-strings/v9.9.9/src/String.purs"
-- or
-- from ".spago/@noname/other-strings/v9.9.9/src/String/index.purs"
import "@noname/other-strings/String" as OtherString
-- relative imports are possible only within the same package
import "./foo/bar"
-- will import the same file as the relative import above
import "@me/my-app/foo/bar"