-
Notifications
You must be signed in to change notification settings - Fork 79
Find packages that will be dropped from the package set #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
maxdeviant
wants to merge
8
commits into
purescript:master
from
deviant-forks:find-packages-that-will-be-dropped
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c43f2f
Parse the constituent files
maxdeviant 54d40d6
Log the packages that will be dropped
maxdeviant 621f045
Improve output
maxdeviant 18118d1
Improve error output
maxdeviant 8f4db2e
Clean up output
maxdeviant 0c82c33
Add doc comments
maxdeviant 8e2a7b6
Update path to package set file
maxdeviant d47cec5
Add instructions
maxdeviant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| , "spec" | ||
| , "string-parsers" | ||
| , "strings" | ||
| , "stringutils" | ||
| , "sunde" | ||
| , "transformers" | ||
| , "tuples" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| module Registry.Scripts.FindDroppedPackages where | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| import Registry.Prelude | ||
|
|
||
| import Data.Argonaut as Json | ||
| import Data.Array as Array | ||
| import Data.Foldable (intercalate) | ||
| import Data.Interpolate (i) | ||
| import Data.List as List | ||
| import Data.Map as Map | ||
| import Data.Array.NonEmpty as NEA | ||
| import Data.String.Utils (lines) | ||
| import Effect.Aff as Aff | ||
| import Registry.PackageName as PackageName | ||
| import Registry.Scripts.LegacyImport.Error | ||
| ( ImportError(..) | ||
| , ManifestError(..) | ||
| , PackageFailures(..) | ||
| , RawPackageName(..) | ||
| , RawVersion(..) | ||
| ) | ||
|
|
||
| -- | A PureScript package set. | ||
| newtype PackageSet = PackageSet (Map RawPackageName PackageSetPackage) | ||
|
|
||
| derive instance Newtype PackageSet _ | ||
|
|
||
| instance Json.DecodeJson PackageSet where | ||
| decodeJson json = do | ||
| packagesObject :: Object PackageSetPackage <- Json.decodeJson json | ||
| pure | ||
| $ PackageSet | ||
| $ objectToMap (Just <<< RawPackageName) packagesObject | ||
|
|
||
| -- | A package in the package set. | ||
| type PackageSetPackage = | ||
| { version :: RawVersion | ||
| } | ||
|
|
||
| -- | A package that will be dropped from the package set. | ||
| type DroppedPackage = | ||
| { name :: RawPackageName | ||
| , version :: RawVersion | ||
| , reason :: ImportError | ||
| } | ||
|
|
||
| type ExcludedPackages = Map RawPackageName (Either ImportError (Map RawVersion ImportError)) | ||
|
|
||
| main :: Effect Unit | ||
| main = Aff.launchAff_ do | ||
| bowerExclusionsFile <- readJsonFile "bower-exclusions.json" | ||
| case bowerExclusionsFile of | ||
| Left err -> do | ||
| let decodeError = "Decoding bower-exclusions.json failed with error:\n\n" <> Json.printJsonDecodeError err | ||
| throwError $ Aff.error decodeError | ||
| Right bowerExclusions -> do | ||
| packageSetPackagesFile <- readJsonFile "package-set-packages.json" | ||
| case packageSetPackagesFile of | ||
| Left err -> do | ||
| let decodeError = "Decoding packages.json failed with error:\n\n" <> Json.printJsonDecodeError err | ||
| throwError $ Aff.error decodeError | ||
| Right packages -> | ||
| let | ||
| packagesThatWillBeDropped = findPackagesThatWillBeDropped packages $ dropImportErrorKeys bowerExclusions | ||
| in | ||
| liftEffect $ packagesThatWillBeDropped | ||
| # map printMessage | ||
| # intercalate "\n\n" | ||
| # log | ||
|
|
||
| printMessage :: DroppedPackage -> String | ||
| printMessage droppedPackage = message | ||
| where | ||
| name = un RawPackageName droppedPackage.name | ||
| version = un RawVersion droppedPackage.version | ||
| reason = printDroppedReason droppedPackage.reason | ||
| packageIdentifier = name <> " " <> version | ||
| message = i packageIdentifier " will be dropped from the package set due to:\n\t" <> reason | ||
|
|
||
| printDroppedReason :: ImportError -> String | ||
| printDroppedReason = case _ of | ||
| InvalidGitHubRepo _ -> "invalid GitHub repo" | ||
| ResourceError _ -> "resource error" | ||
| MalformedPackageName _ -> "malformed package name" | ||
| NoDependencyFiles -> "no dependency files" | ||
| NonRegistryDependencies _ -> "non-registry dependencies" | ||
| NoManifests -> "no manifests" | ||
| ManifestError manifestErrors -> | ||
| manifestErrors | ||
| # map printManifestError | ||
| # intercalate ", " | ||
|
|
||
| printManifestError :: ManifestError -> String | ||
| printManifestError = case _ of | ||
| MissingName -> "missing name" | ||
| MissingLicense -> "missing license" | ||
| BadLicense licenses -> | ||
| "bad license:\n" <> | ||
| ( intercalate "\n" $ map ("\t\t" <> _) | ||
| $ Array.concatMap lines licenses | ||
| ) | ||
| BadVersion version -> "bad version: " <> version | ||
| InvalidDependencyNames dependencyNames -> | ||
| "invalid dependency names:\n" <> intercalate "\n\t\t" dependencyNames | ||
| BadDependencyVersions badVersions -> | ||
| "bad dependency versions:\n" <> | ||
| ( intercalate "\n" $ map ("\t\t" <> _) | ||
| $ Array.concatMap lines | ||
| $ map printBadDependencyVersion | ||
| $ NEA.toArray badVersions | ||
| ) | ||
|
|
||
| where | ||
| printBadDependencyVersion { dependency, failedBounds } = | ||
| i "Dependency: " (PackageName.print dependency) "\nFailed bounds: " failedBounds | ||
|
|
||
| -- | Drops the import keys from the `PackageFailures` collection, as we don't | ||
| -- | need the groupings. | ||
| dropImportErrorKeys :: PackageFailures -> ExcludedPackages | ||
| dropImportErrorKeys = | ||
| un PackageFailures | ||
| >>> Map.values | ||
| >>> List.foldl Map.union Map.empty | ||
|
|
||
| -- | Returns an array of all packages that will be dropped from the package set | ||
| -- | based on the packages currently excluded from the registry. | ||
| findPackagesThatWillBeDropped :: PackageSet -> ExcludedPackages -> Array DroppedPackage | ||
| findPackagesThatWillBeDropped packageSet bowerExclusions = | ||
| packageSet | ||
| # un PackageSet | ||
| # Map.toUnfoldable | ||
| # Array.mapMaybe \(Tuple name { version }) -> willBeDropped name version | ||
| where | ||
| willBeDropped name version = | ||
| case Map.lookup name bowerExclusions of | ||
| Just (Left reason) -> Just { name, version, reason } | ||
| Just (Right excludedVersions) -> | ||
| case Map.lookup version excludedVersions of | ||
| Just reason -> Just { name, version, reason } | ||
| Nothing -> Nothing | ||
| Nothing -> Nothing | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed simpler to make downloading this a manual step than making it part of the script. I can move it into the script itself, if desired.