Skip to content

Commit 2bed51b

Browse files
committed
Merge remote-tracking branch 'upstream/master' into 1316-censortestwarnings
2 parents 9a8de77 + 8c735d5 commit 2bed51b

File tree

17 files changed

+307
-237
lines changed

17 files changed

+307
-237
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Other improvements:
4747
their specified dependency ranges.
4848
- `spago publish` no longer tries to validate all workspace dependencies, but
4949
only the (transitive) dependencies of the project being published.
50+
- Restored broken search-directed search in generated docs.
5051

5152
## [0.21.0] - 2023-05-04
5253

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# spago
22

3-
[![npm](https://img.shields.io/npm/v/spago.svg)][spago-npm]
4-
[![Latest release](https://img.shields.io/github/v/release/purescript/spago.svg)](https://github.com/purescript/spago/releases)
3+
![NPM Version (with dist tag)](https://img.shields.io/npm/v/spago/next)
4+
![Latest release](https://img.shields.io/badge/dynamic/yaml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpurescript%2Fspago%2Frefs%2Fheads%2Fmaster%2Fspago.yaml&query=package.publish.version&prefix=v&label=release)
55
[![build](https://github.com/purescript/spago/actions/workflows/build.yml/badge.svg)](https://github.com/purescript/spago/actions/workflows/build.yml)
66
[![nix-flake](https://github.com/purescript/spago/actions/workflows/nix-flake.yml/badge.svg)](https://github.com/purescript/spago/actions/workflows/nix-flake.yml)
77
[![Maintainer: f-f](https://img.shields.io/badge/maintainer-f%2d-f-teal.svg)](http://github.com/f-f)

Diff for: bin/spago.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package:
22
name: spago-bin
33
publish:
4-
version: 0.93.42
4+
version: 0.93.43
55
license: BSD-3-Clause
66
build:
77
strict: true

Diff for: core/src/Log.purs

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ data LogVerbosity
7777
| LogNormal
7878
| LogVerbose
7979

80+
derive instance Eq LogVerbosity
81+
8082
-- | LogVeryVerbose -- TODO:we'll need to add timestamps, and locations, see https://stackoverflow.com/questions/45395369/
8183

8284
data LogLevel

Diff for: docs-search/common/src/Docs/Search/TypeIndex.purs

+22-12
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ module Docs.Search.TypeIndex
77

88
import Prelude
99

10+
import Codec.JSON.DecodeError as DecodeError
1011
import Control.Promise (Promise, toAffE)
1112
import Data.Array as Array
13+
import Data.Bifunctor (lmap)
1214
import Data.Codec.JSON as CJ
13-
import Data.Either (hush)
15+
import Data.Either (Either(..))
1416
import Data.Foldable (fold, foldr)
1517
import Data.Map (Map)
1618
import Data.Map as Map
17-
import Data.Maybe (Maybe(..), fromMaybe')
19+
import Data.Maybe (Maybe(..))
1820
import Data.Newtype (class Newtype, over)
1921
import Data.Set (Set)
2022
import Docs.Search.Config as Config
@@ -27,6 +29,8 @@ import Docs.Search.TypeQuery (TypeQuery)
2729
import Docs.Search.TypeShape (shapeOfType, shapeOfTypeQuery, stringifyShape)
2830
import Effect (Effect)
2931
import Effect.Aff (Aff, try)
32+
import Effect.Aff as Error
33+
import Effect.Class.Console as Console
3034
import JSON (JSON)
3135
import Language.PureScript.Docs.Types (DocModule(..))
3236
import Registry.PackageName (PackageName)
@@ -80,15 +84,22 @@ lookup
8084
-> Aff { index :: TypeIndex, results :: Array SearchResult }
8185
lookup key index@(TypeIndex map) =
8286
case Map.lookup key map of
83-
Just results -> pure { index, results: fold results }
87+
Just results ->
88+
pure { index, results: fold results }
8489
Nothing -> do
85-
eiJson <- try (toAffE (lookup_ key $ Config.mkShapeScriptPath key))
86-
pure $ fromMaybe'
87-
(\_ -> { index: insert key Nothing index, results: [] })
88-
do
89-
json <- hush eiJson
90-
results <- hush (CJ.decode (CJ.array SearchResult.searchResultCodec) json)
90+
eitherJson <- try $ toAffE $ lookup_ key (Config.mkShapeScriptPath key)
91+
92+
let
93+
eitherResults = do
94+
json <- eitherJson # lmap Error.message
95+
CJ.decode (CJ.array SearchResult.searchResultCodec) json # lmap DecodeError.print
96+
97+
case eitherResults of
98+
Right results ->
9199
pure { index: insert key (Just results) index, results }
100+
Left err -> do
101+
Console.error $ "Error reading type index: " <> err
102+
pure { index: insert key Nothing index, results: [] }
92103

93104
where
94105
insert
@@ -102,9 +113,8 @@ query
102113
:: TypeIndex
103114
-> TypeQuery
104115
-> Aff { index :: TypeIndex, results :: Array SearchResult }
105-
query typeIndex typeQuery = do
106-
res <- lookup (stringifyShape $ shapeOfTypeQuery typeQuery) typeIndex
107-
pure $ res { results = res.results }
116+
query typeIndex typeQuery =
117+
lookup (stringifyShape $ shapeOfTypeQuery typeQuery) typeIndex
108118

109119
foreign import lookup_
110120
:: String

Diff for: docs-search/index/src/Docs/Search/IndexBuilder.purs

+61-80
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,13 @@ import Docs.Search.Types (PartId)
5151
import Effect (Effect)
5252
import Effect.Aff (Aff, parallel, sequential)
5353
import Effect.Class (liftEffect)
54-
import Effect.Console (log)
5554
import JSON (JSON)
5655
import JSON as JSON
5756
import Node.Encoding (Encoding(UTF8))
5857
import Node.FS.Aff (mkdir, readFile, readTextFile, readdir, stat, writeFile, writeTextFile)
5958
import Node.FS.Stats (isDirectory, isFile)
6059
import Node.FS.Sync (exists)
6160
import Node.Path as Path
62-
import Node.Process as Process
6361
import Registry.Manifest (Manifest(..))
6462
import Registry.Manifest as Manifest
6563
import Registry.PackageName (PackageName)
@@ -72,15 +70,16 @@ type Config =
7270
, generatedDocs :: String
7371
, workspacePackages :: Set PackageName
7472
, moduleGraph :: Graph.ModuleGraphWithPackage
73+
, log :: String -> Aff Unit
74+
, die :: String -> Aff Unit
7575
}
7676

7777
run :: Config -> Aff Unit
78-
run cfg = do
78+
run cfg@{ log } = do
7979

8080
checkDirectories cfg
8181

82-
liftEffect do
83-
log "Building the search index..."
82+
log "Building the search index..."
8483

8584
docsJsons /\ packageMetas <- sequential $
8685
Tuple
@@ -91,13 +90,12 @@ run cfg = do
9190
countOfPackages = Array.length packageMetas
9291
countOfModules = Array.length docsJsons
9392

94-
liftEffect do
95-
log $
96-
"Indexing "
97-
<> show countOfModules
98-
<> " modules from "
99-
<> show countOfPackages
100-
<> " packages..."
93+
log $
94+
"Indexing "
95+
<> show countOfModules
96+
<> " modules from "
97+
<> show countOfPackages
98+
<> " packages..."
10199

102100
let
103101
scores = mkScores packageMetas
@@ -108,32 +106,28 @@ run cfg = do
108106

109107
createDirectories cfg
110108

111-
void $ sequential do
112-
ignore <$> parallel (writeIndex cfg index)
113-
<*> parallel (writeTypeIndex typeIndex)
114-
<*> parallel (writePackageInfo packageInfo)
115-
<*> parallel (writeModuleIndex moduleIndex)
116-
<*> parallel (patchDocs cfg)
117-
<*> parallel (copyAppFile cfg)
109+
sequential $
110+
parallel (writeIndex cfg index)
111+
*> parallel (writeTypeIndex typeIndex)
112+
*> parallel (writePackageInfo packageInfo)
113+
*> parallel (writeModuleIndex moduleIndex)
114+
*> parallel (patchDocs cfg)
115+
*> parallel (copyAppFile cfg)
118116

119117
let
120118
countOfDefinitions = Trie.size $ unwrap index
121119
countOfTypeDefinitions =
122120
sum $ fromMaybe 0 <$> map Array.length <$> Map.values (unwrap typeIndex)
123121

124-
liftEffect do
125-
log $
126-
"Added "
127-
<> show countOfDefinitions
128-
<> " definitions and "
129-
<> show countOfTypeDefinitions
130-
<> " type definitions from "
131-
<> show countOfPackages
132-
<>
133-
" packages to the search index."
134-
135-
where
136-
ignore _ _ _ _ _ _ _ = unit
122+
log $
123+
"Added "
124+
<> show countOfDefinitions
125+
<> " definitions and "
126+
<> show countOfTypeDefinitions
127+
<> " type definitions from "
128+
<> show countOfPackages
129+
<>
130+
" packages to the search index."
137131

138132
-- | Exit early if something is missing.
139133
checkDirectories :: Config -> Aff Unit
@@ -147,23 +141,20 @@ checkDirectories cfg = do
147141

148142
for_ dirs \dir -> do
149143
whenM (not <$> directoryExists dir) $
150-
liftEffect do
151-
logAndExit "Build the documentation first!"
144+
cfg.die "Build the documentation first!"
152145

153146
-- | Read and decode given `docs.json` files.
154147
decodeDocsJsons
155-
:: forall rest
156-
. { docsFiles :: Array String | rest }
148+
:: rest
149+
. { docsFiles :: Array String, log :: String -> Aff Unit, die :: String -> Aff Unit | rest }
157150
-> Aff (Array DocModule)
158-
decodeDocsJsons cfg@{ docsFiles } = do
151+
decodeDocsJsons cfg@{ docsFiles, log } = do
159152

160153
paths <- getPathsByGlobs docsFiles
161154

162155
when (Array.null paths) do
163-
liftEffect do
164-
logAndExit $
165-
"The following globs do not match any files: " <> showGlobs cfg.docsFiles <>
166-
".\nBuild the documentation first!"
156+
cfg.die $
157+
"The following globs do not match any files: " <> showGlobs cfg.docsFiles <> ".\nBuild the documentation first!"
167158

168159
docsJsons <- Array.catMaybes <$> for paths \jsonFile -> do
169160
doesExist <- fileExists jsonFile
@@ -179,38 +170,36 @@ decodeDocsJsons cfg@{ docsFiles } = do
179170

180171
case eiResult of
181172
Left error -> do
182-
liftEffect $ log $
183-
"\"docs.json\" decoding failed failed for " <> jsonFile <> ": " <> error
173+
log $ "\"docs.json\" decoding failed failed for " <> jsonFile <> ": " <> error
184174
pure Nothing
185175
Right result -> pure $ Just result
186176

187177
else do
188-
liftEffect $ do
189-
log $
190-
"File does not exist: " <> jsonFile
178+
log $ "File does not exist: " <> jsonFile
191179
pure Nothing
192180

193181
when (Array.null docsJsons) do
194-
liftEffect $ logAndExit $
182+
cfg.die $
195183
"Couldn't decode any of the files matched by the following globs: " <> showGlobs cfg.docsFiles
196184

197185
pure docsJsons
198186

199-
decodePursJsons :: forall rest. { pursJsonFiles :: Array String | rest } -> Aff (Array Manifest)
200-
decodePursJsons { pursJsonFiles } = do
187+
decodePursJsons
188+
:: rest
189+
. { pursJsonFiles :: Array String, log :: String -> Aff Unit, die :: String -> Aff Unit | rest }
190+
-> Aff (Array Manifest)
191+
decodePursJsons cfg@{ pursJsonFiles } = do
201192
paths <- getPathsByGlobs pursJsonFiles
202193

203194
when (Array.null paths) do
204-
liftEffect do
205-
logAndExit $
206-
"The following globs do not match any files: " <> showGlobs pursJsonFiles <>
207-
".\nAre you in a project directory?"
208-
195+
cfg.die $
196+
"The following globs do not match any files: " <> showGlobs pursJsonFiles <>
197+
".\nAre you in a project directory?"
209198
Array.nubBy compareNames
210199
<$> Array.catMaybes
211200
<$>
212201
for paths \jsonFileName ->
213-
join <$> withExisting jsonFileName
202+
join <$> withExisting cfg jsonFileName
214203
\contents ->
215204
either (logError jsonFileName) (pure <<< Just)
216205
( JSON.parse contents >>=
@@ -224,24 +213,23 @@ decodePursJsons { pursJsonFiles } = do
224213
(Manifest { name: name2 }) = compare name1 name2
225214

226215
logError fileName error = do
227-
liftEffect $ log $
228-
"\"purs.json\" decoding failed for " <> fileName <> ": " <> error
216+
cfg.log $ "\"purs.json\" decoding failed for " <> fileName <> ": " <> error
229217
pure Nothing
230218

231219
-- | Write type index parts to files.
232220
writeTypeIndex :: TypeIndex -> Aff Unit
233221
writeTypeIndex typeIndex =
234222
for_ entries \(Tuple typeShape results) -> do
235223
writeTextFile UTF8 (unwrap Config.typeIndexDirectory <> "/" <> typeShape <> ".js")
236-
(mkHeader typeShape <> JSON.print (CJ.encode codec results))
224+
(mkHeader typeShape <> JSON.print (CJ.encode codec $ fromMaybe [] results))
237225
where
238226
mkHeader typeShape =
239227
"// This file was generated by docs-search\n"
240228
<> "window.DocsSearchTypeIndex[\""
241229
<> typeShape
242230
<> "\"] = "
243231

244-
codec = CJ.Common.maybe $ CJ.array SearchResult.searchResultCodec
232+
codec = CJ.array SearchResult.searchResultCodec
245233

246234
entries :: Array _
247235
entries = Map.toUnfoldableUnordered (unwrap typeIndex)
@@ -350,18 +338,18 @@ patchDocs cfg = do
350338
-- | Create directories for two indices, or fail with a message
351339
-- | in case the docs were not generated.
352340
createDirectories :: Config -> Aff Unit
353-
createDirectories { generatedDocs } = do
341+
createDirectories { generatedDocs, die } = do
354342
let
355343
htmlDocs = Path.concat [ generatedDocs, "html" ]
356344
indexDir = Path.concat [ generatedDocs, "html", "index" ]
357345
declIndexDir = Path.concat [ generatedDocs, "html", "index", "declarations" ]
358346
typeIndexDir = Path.concat [ generatedDocs, "html", "index", "types" ]
359347

360-
whenM (not <$> directoryExists generatedDocs) $ liftEffect do
361-
logAndExit "Generate the documentation first!"
348+
whenM (not <$> directoryExists generatedDocs) $
349+
die "Generate the documentation first!"
362350

363-
whenM (not <$> directoryExists htmlDocs) $ liftEffect do
364-
logAndExit "Generate the documentation first!"
351+
whenM (not <$> directoryExists htmlDocs) $
352+
die "Generate the documentation first!"
365353

366354
whenM (not <$> directoryExists indexDir) do
367355
mkdir indexDir
@@ -375,13 +363,13 @@ createDirectories { generatedDocs } = do
375363
-- | Copy the client-side application, responsible for handling user input and rendering
376364
-- | the results, to the destination path.
377365
copyAppFile :: Config -> Aff Unit
378-
copyAppFile { generatedDocs } = do
366+
copyAppFile { generatedDocs, die } = do
379367
appFile <- liftEffect getDocsSearchAppPath
380-
whenM (not <$> fileExists appFile) do
381-
liftEffect do
382-
logAndExit $
383-
"Client-side app was not found at " <> appFile <> ".\n" <>
384-
"Check your installation."
368+
unlessM (fileExists appFile)
369+
$ die
370+
$
371+
"Client-side app was not found at " <> appFile <> ".\n" <>
372+
"Check your installation."
385373
buffer <- readFile appFile
386374
writeFile (Path.concat [ generatedDocs, "html", "docs-search-app.js" ]) buffer
387375

@@ -399,25 +387,18 @@ fileExists path = do
399387
false -> pure false
400388
true -> isFile <$> stat path
401389

402-
withExisting :: forall a. String -> (String -> Aff a) -> Aff (Maybe a)
403-
withExisting file f = do
390+
withExisting :: a r. { log :: String -> Aff Unit | r } -> String -> (String -> Aff a) -> Aff (Maybe a)
391+
withExisting cfg file f = do
404392
doesExist <- fileExists file
405393

406394
if doesExist then do
407395
contents <- readTextFile UTF8 file
408396
res <- f contents
409397
pure $ Just res
410398
else do
411-
liftEffect $ do
412-
log $
413-
"File does not exist: " <> file
399+
cfg.log $ "File does not exist: " <> file
414400
pure Nothing
415401

416-
logAndExit :: forall a. String -> Effect a
417-
logAndExit message = do
418-
log message
419-
Process.exit' 1
420-
421402
showGlobs :: Array String -> String
422403
showGlobs = Array.intercalate ", "
423404

0 commit comments

Comments
 (0)