1- {-# LANGUAGE OverloadedRecordDot #-}
21
32module Strategy.Node.Pnpm.Types (
43 -- * Lockfile types
@@ -41,7 +40,6 @@ import Control.Applicative ((<|>))
4140import Data.Aeson (FromJSON (.. ), withObject )
4241import Data.Aeson.Extra (TextLike (.. ))
4342import Data.Aeson.KeyMap (toHashMapText )
44- import DepTypes (DepEnvironment )
4543import Data.HashMap.Strict qualified as HashMap
4644import Data.Map (Map )
4745import Data.Map qualified as Map
@@ -52,6 +50,7 @@ import Data.Text (Text)
5250import Data.Text qualified as Text
5351import Data.Yaml (Object , Parser , (.!=) , (.:) , (.:?) )
5452import Data.Yaml qualified as Yaml
53+ import DepTypes (DepEnvironment )
5554
5655-- | Pnpm Lockfile
5756--
@@ -146,7 +145,7 @@ import Data.Yaml qualified as Yaml
146145-- | Shared fields present in all lockfile versions.
147146data PnpmLockfileBase = PnpmLockfileBase
148147 { lockfileImporters :: Map Text ProjectMap
149- , lockfilePackages :: Map Text PackageData
148+ , lockfilePackages :: Map Text PackageData
150149 , lockfileRawVersion :: Text
151150 -- ^ Raw lockfileVersion string, used for warning about unsupported versions.
152151 }
@@ -162,9 +161,9 @@ newtype PnpmLockfileV678 = PnpmLockfileV678 PnpmLockfileBase
162161
163162-- | Version-specific extension for v9+ lockfiles.
164163data PnpmLockfileV9 = PnpmLockfileV9
165- { lockfileBase :: PnpmLockfileBase
164+ { lockfileBase :: PnpmLockfileBase
166165 , lockfileSnapshots :: PnpmLockFileSnapshots
167- , lockfileCatalogs :: PnpmCatalogs
166+ , lockfileCatalogs :: PnpmCatalogs
168167 }
169168 deriving (Show , Eq , Ord )
170169
@@ -174,8 +173,8 @@ data PnpmLockfileV9 = PnpmLockfileV9
174173-- carries only the data relevant to its format.
175174data PnpmLockfile
176175 = LockfileV4Or5 PnpmLockfileV4Or5
177- | LockfileV678 PnpmLockfileV678
178- | LockfileV9 PnpmLockfileV9
176+ | LockfileV678 PnpmLockfileV678
177+ | LockfileV9 PnpmLockfileV9
179178 deriving (Show , Eq , Ord )
180179
181180--
@@ -341,9 +340,9 @@ classifyVersion (TextLike ver) = case listToMaybe (toString ver) of
341340 Just ' 3' -> pure VersionV4Or5
342341 Just ' 4' -> pure VersionV4Or5
343342 Just ' 5' -> pure VersionV4Or5
344- Just x | x `elem` [' 6' , ' 7' , ' 8' ] -> pure VersionV678
343+ Just x | x `elem` [' 6' , ' 7' , ' 8' ] -> pure VersionV678
345344 Just ' 9' -> pure VersionV9
346- _ -> fail $ " expected numeric lockfileVersion, got: " <> show ver
345+ _ -> fail $ " expected numeric lockfileVersion, got: " <> show ver
347346
348347-- | Parse the shared base fields (importers + packages) common to all versions.
349348parseBaseLockfile :: TextLike -> Object -> Parser PnpmLockfileBase
@@ -357,38 +356,41 @@ parseBaseLockfile (TextLike rawVer) obj = do
357356 -- A project without a workspace is the same as having a single workspace at
358357 -- the path of \".\".
359358 importers <- obj .:? " importers" .!= mempty
360- packages <- obj .:? " packages" .!= mempty
361- dependencies <- obj .:? " dependencies" .!= mempty
362- devDependencies <- obj .:? " devDependencies" .!= mempty
359+ packages <- obj .:? " packages" .!= mempty
360+ dependencies <- obj .:? " dependencies" .!= mempty
361+ devDependencies <- obj .:? " devDependencies" .!= mempty
363362 let virtualRootWs = ProjectMap dependencies devDependencies
364363 let refinedImporters =
365364 if Map. null importers
366365 then Map. insert " ." virtualRootWs importers
367366 else importers
368- pure $ PnpmLockfileBase
369- { lockfileImporters = refinedImporters
370- , lockfilePackages = packages
371- , lockfileRawVersion = rawVer
372- }
367+ pure $
368+ PnpmLockfileBase
369+ { lockfileImporters = refinedImporters
370+ , lockfilePackages = packages
371+ , lockfileRawVersion = rawVer
372+ }
373373
374374-- | FromJSON for the sum type — reads 'lockfileVersion' and dispatches.
375375instance FromJSON PnpmLockfile where
376376 parseJSON = Yaml. withObject " pnpm-lock content" $ \ obj -> do
377377 rawVer <- obj .:? " lockfileVersion" .!= (TextLike mempty )
378- base <- parseBaseLockfile rawVer obj
378+ base <- parseBaseLockfile rawVer obj
379379
380380 versionClass <- classifyVersion rawVer
381381 case versionClass of
382382 VersionV4Or5 -> pure $ LockfileV4Or5 $ PnpmLockfileV4Or5 base
383- VersionV678 -> pure $ LockfileV678 $ PnpmLockfileV678 base
384- VersionV9 -> do
383+ VersionV678 -> pure $ LockfileV678 $ PnpmLockfileV678 base
384+ VersionV9 -> do
385385 snapshots <- obj .:? " snapshots" .!= mempty
386- catalogs <- obj .:? " catalogs" .!= mempty
387- pure $ LockfileV9 $ PnpmLockfileV9
388- { lockfileBase = base
389- , lockfileSnapshots = snapshots
390- , lockfileCatalogs = catalogs
391- }
386+ catalogs <- obj .:? " catalogs" .!= mempty
387+ pure $
388+ LockfileV9 $
389+ PnpmLockfileV9
390+ { lockfileBase = base
391+ , lockfileSnapshots = snapshots
392+ , lockfileCatalogs = catalogs
393+ }
392394
393395--
394396-- Graph configuration
@@ -414,17 +416,17 @@ data LabelingMode = LabelingOff | LabelingOn
414416-- - 'bgcCatalogs': catalog name -> (package name -> resolved version) mappings
415417data BuildGraphConfig = BuildGraphConfig
416418 { bgcGetPkgNameVersion :: Text -> Maybe (Text , Text )
417- -- ^ Parse (name, version) from a package key
419+ -- ^ Parse (name, version) from a package key
418420 , bgcMkPkgKey :: Text -> Text -> Text
419- -- ^ Build a registry package key from (name, version)
421+ -- ^ Build a registry package key from (name, version)
420422 , bgcToEnv :: Bool -> Set. Set DepEnvironment
421- -- ^ Derive environment from @dev@ field (or ignore for v9)
423+ -- ^ Derive environment from @dev@ field (or ignore for v9)
422424 , bgcLabelingMode :: LabelingMode
423- -- ^ Whether to label direct deps for hydrateDepEnvs propagation
425+ -- ^ Whether to label direct deps for hydrateDepEnvs propagation
424426 , bgcSnapshotEdges :: [(SnapshotDepName , [(SnapshotDepName , SnapShotDepRev )])]
425- -- ^ Additional edges from v9 snapshots
427+ -- ^ Additional edges from v9 snapshots
426428 , bgcCatalogs :: PnpmCatalogs
427- -- ^ Catalog name -> (package name -> resolved version) mappings
429+ -- ^ Catalog name -> (package name -> resolved version) mappings
428430 }
429431
430432--
0 commit comments