git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Handle 'bower link' properly in psc-publish

Previously, if you added a bower dependency using 'bower link', psc-publish would fail with an internal error about a missing key "_resolution" while trying to ascertain the DependencyStatus for a package. Now, that case is handled gracefully. Any such packages are listed in the existing warning for packages which have been specified by something other than a version tag (eg, a branch or commit). The warning message wording and relevant data constructors have been amended slightly to account for this.

commit92cda397c2038adc3d6ae418618c222a6bd954a2 authorHarry Garrood <harry@garrood.me> dateTue 7 Jul 2015, 00:48 (11 years ago) parent190b129
2 files changed+19−12
psc-publish/ErrorsWarnings.hs+8−8 psc-publish/Main.hs+11−4
psc-publish/ErrorsWarnings.hs+8−8
@@ -33,7 +33,7 @@ data PackageError
3333 deriving (Show)
3434
3535data PackageWarning
36− = ResolutionNotVersion PackageName
36+ = NoResolvedVersion PackageName
3737 | UndeclaredDependency PackageName
3838 | UnacceptableVersion (PackageName, String)
3939 deriving (Show)
@@ -253,7 +253,7 @@ displayOtherError e = case e of
253253 [ "An IO exception occurred:", show exc ]
254254
255255data CollectedWarnings = CollectedWarnings
256− { resolutionNotVersions :: [PackageName]
256+ { noResolvedVersions :: [PackageName]
257257 , undeclaredDependencies :: [PackageName]
258258 , unacceptableVersions :: [(PackageName, String)]
259259 }
@@ -268,7 +268,7 @@ collectWarnings :: [PackageWarning] -> CollectedWarnings
268268collectWarnings = foldMap singular
269269 where
270270 singular w = case w of
271− ResolutionNotVersion pn -> CollectedWarnings [pn] [] []
271+ NoResolvedVersion pn -> CollectedWarnings [pn] [] []
272272 UndeclaredDependency pn -> CollectedWarnings [] [pn] []
273273 UnacceptableVersion t -> CollectedWarnings [] [] [t]
274274
@@ -276,7 +276,7 @@ renderWarnings :: [PackageWarning] -> Box
276276renderWarnings warns =
277277 let CollectedWarnings{..} = collectWarnings warns
278278 go toBox warns' = toBox <$> NonEmpty.nonEmpty warns'
279− mboxes = [ go warnResolutionNotVersions resolutionNotVersions
279+ mboxes = [ go warnNoResolvedVersions noResolvedVersions
280280 , go warnUndeclaredDependencies undeclaredDependencies
281281 , go warnUnacceptableVersions unacceptableVersions
282282 ]
@@ -286,18 +286,18 @@ renderWarnings warns =
286286 , indented (vcat (intersperse spacer boxes))
287287 ]
288288
289−warnResolutionNotVersions :: NonEmpty PackageName -> Box
290−warnResolutionNotVersions pkgNames =
289+warnNoResolvedVersions :: NonEmpty PackageName -> Box
290+warnNoResolvedVersions pkgNames =
291291 let singular = NonEmpty.length pkgNames == 1
292292 pl a b = if singular then b else a
293293
294294 packages = pl "packages" "package"
295− were = pl "were" "was"
296295 anyOfThese = pl "any of these" "this"
297296 these = pl "these" "this"
298297 in vcat $
299298 [ para (concat
300− ["The following ", packages, " ", were, " not resolved to a version:"])
299+ ["The following ", packages, " did not appear to have a resolved "
300+ , "version:"])
301301 ] ++
302302 bulletedList runPackageName (NonEmpty.toList pkgNames)
303303 ++
psc-publish/Main.hs+11−4
@@ -171,6 +171,12 @@ readProcess' prog args stdin = do
171171
172172data DependencyStatus
173173 = Missing
174+ -- ^ Listed in bower.json, but not installed.
175+ | NoResolution
176+ -- ^ In the output of `bower list --json --offline`, there was no
177+ -- _resolution key. This can be caused by adding the dependency using
178+ -- `bower link`, or simply copying it into bower_components instead of
179+ -- installing it normally.
174180 | ResolvedOther String
175181 -- ^ Resolved, but to something other than a version. The String argument
176182 -- is the resolution type. The values it can take that I'm aware of are
@@ -235,7 +241,7 @@ asDependencyStatus = do
235241 return Missing
236242 else
237243 key "pkgMeta" $
238− key "_resolution" $ do
244+ keyOrDefault "_resolution" NoResolution $ do
239245 type_ <- key "type" asString
240246 case type_ of
241247 "version" -> ResolvedVersion <$> key "tag" asString
@@ -248,12 +254,12 @@ warnUndeclared declared actual =
248254handleDeps ::
249255 [(PackageName, DependencyStatus)] -> PrepareM [(PackageName, Version)]
250256handleDeps deps = do
251− let (missing, notVersion, installed) = partitionDeps deps
257+ let (missing, noVersion, installed) = partitionDeps deps
252258 case missing of
253259 (x:xs) ->
254260 userError (MissingDependencies (x :| xs))
255261 [] -> do
256− mapM_ (warn . ResolutionNotVersion . fst) notVersion
262+ mapM_ (warn . NoResolvedVersion) noVersion
257263 withVersions <- catMaybes <$> mapM tryExtractVersion' installed
258264 filterM (liftIO . isPureScript . bowerDir . fst) withVersions
259265
@@ -262,7 +268,8 @@ handleDeps deps = do
262268 go (pkgName, d) (ms, os, is) =
263269 case d of
264270 Missing -> (pkgName : ms, os, is)
265− ResolvedOther o -> (ms, (pkgName, o) : os, is)
271+ NoResolution -> (ms, pkgName : os, is)
272+ ResolvedOther _ -> (ms, pkgName : os, is)
266273 ResolvedVersion v -> (ms, os, (pkgName, v) : is)
267274
268275 bowerDir pkgName = "bower_components/" ++ runPackageName pkgName