Skip to content

Commit 4381814

Browse files
authored
When resolving modules in graph, glob their paths relative to their own roots (#1334)
1 parent de2e98c commit 4381814

File tree

23 files changed

+192
-20
lines changed

23 files changed

+192
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ Other improvements:
4949
their specified dependency ranges.
5050
- `spago publish` no longer tries to validate all workspace dependencies, but
5151
only the (transitive) dependencies of the project being published.
52-
- Restored broken search-directed search in generated docs.
52+
- Restored broken type-directed search in generated docs.
53+
- `spago graph modules` now correctly reports extra-packages located outside the
54+
workspace root.
5355

5456
## [0.21.0] - 2023-05-04
5557

src/Spago/Purs/Graph.purs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Registry.PackageName as PackageName
2929
import Spago.Command.Fetch as Fetch
3030
import Spago.Config (Package(..), WithTestGlobs(..), WorkspacePackage)
3131
import Spago.Config as Config
32+
import Spago.FS as FS
3233
import Spago.Glob as Glob
3334
import Spago.Log as Log
3435
import Spago.Path as Path
@@ -96,10 +97,26 @@ getModuleGraphWithPackage (ModuleGraph graph) = do
9697
$ for (Map.toUnfoldable allPackages)
9798
\(Tuple name package) -> do
9899
-- Basically partition the modules of the current package by in src and test packages
99-
let withTestGlobs = if (Set.member name (Map.keys testPackages)) then OnlyTestGlobs else NoTestGlobs
100+
let withTestGlobs = if (Map.member name testPackages) then OnlyTestGlobs else NoTestGlobs
100101
logDebug $ "Getting globs for package " <> PackageName.print name
101-
globMatches :: Array LocalPath <- map Array.fold $ traverse compileGlob (Config.sourceGlob rootPath withTestGlobs name package)
102-
pure $ map (\p -> Tuple p name) globMatches
102+
103+
-- We have to glob this package's sources relative to its own root,
104+
-- not to our workspace root, because the package may be located
105+
-- outside of the workspace root - e.g. if it's a local-file-system
106+
-- package, - in which case the `gitignoringGlob` function won't match
107+
-- any files there. That's just how it works: it walks down the tree
108+
-- from the given root.
109+
packageRoot <- Path.mkRoot $ Config.getLocalPackageLocation rootPath name package
110+
packageExists <- FS.exists packageRoot
111+
112+
if packageExists then
113+
Config.sourceGlob rootPath withTestGlobs name package
114+
<#> (_ `Path.relativeTo` packageRoot)
115+
# traverse (compileGlob packageRoot)
116+
<#> Array.fold
117+
<#> map \p -> (p `Path.relativeTo` rootPath) /\ name
118+
else
119+
pure []
103120

104121
logDebug "Got the pathToPackage map, calling packageGraph"
105122
let
@@ -118,10 +135,9 @@ getModuleGraphWithPackage (ModuleGraph graph) = do
118135

119136
pure packageGraph
120137

121-
compileGlob :: a. LocalPath -> Spago { rootPath :: RootPath | a } (Array LocalPath)
122-
compileGlob sourcePath = do
123-
{ rootPath } <- ask
124-
liftAff $ Glob.gitignoringGlob
138+
compileGlob :: a. RootPath -> LocalPath -> Spago { rootPath :: RootPath | a } (Array LocalPath)
139+
compileGlob rootPath sourcePath = liftAff $
140+
Glob.gitignoringGlob
125141
{ root: rootPath
126142
, includePatterns: [ Path.localPart $ withForwardSlashes sourcePath ]
127143
, ignorePatterns: []
@@ -233,7 +249,7 @@ checkImports graph = do
233249
{ rootPath } <- ask
234250
projectFiles :: Set String <-
235251
Config.sourceGlob rootPath testGlobOption packageName (WorkspacePackage selected)
236-
# traverse compileGlob
252+
# traverse (compileGlob rootPath)
237253
<#> Array.fold
238254
<#> map (Path.localPart <<< withForwardSlashes)
239255
<#> Set.fromFoldable
@@ -324,7 +340,7 @@ unusedError isTest selected unused = do
324340
{ errorMessage: toDoc
325341
[ toDoc $ (if isTest then "Tests for package '" else "Sources for package '")
326342
<> PackageName.print selected.package.name
327-
<> "' declares unused dependencies - please remove them from the project config:"
343+
<> "' declare unused dependencies - please remove them from the project config:"
328344
, indent $ toDoc $ map (append "- ") unusedPkgs
329345
]
330346
, correction: toDoc
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package:
2+
name: consumer
3+
dependencies:
4+
- extra-package
5+
6+
workspace:
7+
packageSet:
8+
registry: 41.5.0
9+
extraPackages:
10+
extra-package:
11+
path: ../extra-package
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Consumer where
2+
3+
import ExtraPackage (x)
4+
5+
y :: Int
6+
y = x
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Consumer:
2+
depends:
3+
- ExtraPackage
4+
package: consumer
5+
path: src/Main.purs
6+
ExtraPackage:
7+
depends: []
8+
package: extra-package
9+
path: ../extra-package/src/Main.purs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package:
2+
name: extra-package
3+
dependencies: []
4+
5+
workspace:
6+
packageSet:
7+
registry: 41.5.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ExtraPackage where
2+
3+
x :: Int
4+
x = 42
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Reading Spago workspace configuration...
2+
3+
✓ Selecting package to build: packagec
4+
5+
Downloading dependencies...
6+
Building...
7+
Src Lib All
8+
Warnings 0 0 0
9+
Errors 0 0 0
10+
11+
✓ Build succeeded.
12+
13+
Looking for unused and undeclared transitive dependencies...
14+
15+
✘ Found unused and/or undeclared transitive dependencies:
16+
17+
Sources for package 'packagec' declare unused dependencies - please remove them from the project config:
18+
- packageb
19+
20+
These errors can be fixed by running the below command(s):
21+
spago uninstall -p packagec packageb
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Reading Spago workspace configuration...
2+
3+
✓ Selecting package to build: packagea
4+
5+
Downloading dependencies...
6+
Building...
7+
Src Lib All
8+
Warnings 0 0 0
9+
Errors 0 0 0
10+
11+
✓ Build succeeded.
12+
13+
Looking for unused and undeclared transitive dependencies...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package:
2+
name: packagea
3+
dependencies:
4+
- maybe
5+
- packageb
6+
workspace:
7+
packageSet:
8+
registry: 58.0.1
9+
extraPackages:
10+
packageb:
11+
path: ../packageb

0 commit comments

Comments
 (0)