@@ -39,6 +39,7 @@ import Data.Aeson.BetterErrors
39import qualified Data.Text as T
39import qualified Data.Text as T
40import qualified Data.Text.Lazy as TL
40import qualified Data.Text.Lazy as TL
41import qualified Data.Text.Lazy.Encoding as TL
41import qualified Data.Text.Lazy.Encoding as TL
42+import qualified Data.SPDX as SPDX
43import Control.Category ((>>>))
44import Control.Category ((>>>))
44import Control.Arrow ((***))
45import Control.Arrow ((***))
@@ -128,7 +129,7 @@ catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
128catchLeft a f = either f pure a
129catchLeft a f = either f pure a
130unlessM :: Monad m => m Bool -> m () -> m ()
131unlessM :: Monad m => m Bool -> m () -> m ()
131−unlessM cond act = cond >>= flip unless act
132+unlessM cond act = cond >>= flip unless act
133preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
134preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
134preparePackage' opts = do
135preparePackage' opts = do
@@ -137,14 +138,12 @@ preparePackage' opts = do
138 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
139 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
139 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
140 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
140− unlessM (liftIO (doesFileExist "LICENSE")) (userError LicenseNotFound)
141+ checkLicense pkgMeta
142 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
143 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
143 pkgGithub <- getBowerRepositoryInfo pkgMeta
144 pkgGithub <- getBowerRepositoryInfo pkgMeta
144 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
145 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
146− unless (bowerLicenseExists pkgMeta) (userError NoLicenseSpecified)
148 let declaredDeps = map fst (bowerDependencies pkgMeta ++
147 let declaredDeps = map fst (bowerDependencies pkgMeta ++
149 bowerDevDependencies pkgMeta)
148 bowerDevDependencies pkgMeta)
150 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
149 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
@@ -215,8 +214,16 @@ getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExt
215 (Left (BadRepositoryType repositoryType))
214 (Left (BadRepositoryType repositoryType))
216 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
215 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
218−bowerLicenseExists :: PackageMeta -> Bool
217+checkLicense :: PackageMeta -> PrepareM ()
219−bowerLicenseExists = any (not . null) . bowerLicense
218+checkLicense pkgMeta =
219+ unless (any isValidSPDX (bowerLicense pkgMeta))
220+ (userError NoLicenseSpecified)
223+-- Check if a string is a valid SPDX license expression.
225+isValidSPDX :: String -> Bool
226+isValidSPDX = (== 1) . length . SPDX.parseExpression
221extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
228extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
222extractGithub = stripGitHubPrefixes
229extractGithub = stripGitHubPrefixes