Skip to content

Commit 414372e

Browse files
committed
Relax rules on license files in psc-publish
Instead of requiring a LICENSE file to exist, instead, just check that there is a valid SPDX license expression in bower.json. Fixes purescript#1985.
1 parent 8bab509 commit 414372e

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

examples/docs/LICENSE

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/docs/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
],
1717
"dependencies": {
1818
},
19-
"license": "replaceme"
19+
"license": "MIT"
2020
}

purescript.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ library
9292
monad-logger >= 0.3 && < 0.4,
9393
pipes >= 4.0.0 && < 4.2.0 ,
9494
pipes-http -any,
95-
http-types -any
95+
http-types -any,
96+
spdx == 0.2.*
9697

9798
exposed-modules: Language.PureScript
9899
Language.PureScript.AST

src/Language/PureScript/Publish.hs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import Data.Aeson.BetterErrors
3939
import qualified Data.Text as T
4040
import qualified Data.Text.Lazy as TL
4141
import qualified Data.Text.Lazy.Encoding as TL
42+
import qualified Data.SPDX as SPDX
4243

4344
import Control.Category ((>>>))
4445
import Control.Arrow ((***))
@@ -128,7 +129,7 @@ catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
128129
catchLeft a f = either f pure a
129130

130131
unlessM :: Monad m => m Bool -> m () -> m ()
131-
unlessM cond act = cond >>= flip unless act
132+
unlessM cond act = cond >>= flip unless act
132133

133134
preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
134135
preparePackage' opts = do
@@ -137,14 +138,12 @@ preparePackage' opts = do
137138

138139
pkgMeta <- liftIO (Bower.decodeFile "bower.json")
139140
>>= flip catchLeft (userError . CouldntDecodeBowerJSON)
140-
unlessM (liftIO (doesFileExist "LICENSE")) (userError LicenseNotFound)
141+
checkLicense pkgMeta
141142

142143
(pkgVersionTag, pkgVersion) <- publishGetVersion opts
143144
pkgGithub <- getBowerRepositoryInfo pkgMeta
144145
(pkgBookmarks, pkgModules) <- getModulesAndBookmarks
145146

146-
unless (bowerLicenseExists pkgMeta) (userError NoLicenseSpecified)
147-
148147
let declaredDeps = map fst (bowerDependencies pkgMeta ++
149148
bowerDevDependencies pkgMeta)
150149
pkgResolvedDependencies <- getResolvedDependencies declaredDeps
@@ -215,8 +214,16 @@ getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExt
215214
(Left (BadRepositoryType repositoryType))
216215
maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
217216

218-
bowerLicenseExists :: PackageMeta -> Bool
219-
bowerLicenseExists = any (not . null) . bowerLicense
217+
checkLicense :: PackageMeta -> PrepareM ()
218+
checkLicense pkgMeta =
219+
unless (any isValidSPDX (bowerLicense pkgMeta))
220+
(userError NoLicenseSpecified)
221+
222+
-- |
223+
-- Check if a string is a valid SPDX license expression.
224+
--
225+
isValidSPDX :: String -> Bool
226+
isValidSPDX = (== 1) . length . SPDX.parseExpression
220227

221228
extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
222229
extractGithub = stripGitHubPrefixes

src/Language/PureScript/Publish/ErrorsWarnings.hs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,27 @@ displayUserError e = case e of
182182
BadRepositoryField err ->
183183
displayRepositoryError err
184184
NoLicenseSpecified ->
185-
para (concat
186-
["No license specified in bower.json. Please add one. ",
187-
"Distributing code without a license means that nobody ",
188-
"will be able to (legally) use it."
189-
])
185+
vcat $
186+
[ para (concat
187+
[ "No license is specified in bower.json. Please add one, using the "
188+
, "SPDX license expression format. For example, any of the "
189+
, "following would be acceptable:"
190+
])
191+
, spacer
192+
] ++
193+
map (indented . para)
194+
[ "* \"MIT\""
195+
, "* \"BSD-2-Clause\""
196+
, "* \"GPL-2.0+\""
197+
, "* \"(GPL-3.0 OR MIT)\""
198+
]
199+
++
200+
[ spacer
201+
, para (concat
202+
[ "Note that distributing code without a license means that nobody "
203+
, "will (legally) be able to use it."
204+
])
205+
]
190206
MissingDependencies pkgs ->
191207
let singular = NonEmpty.length pkgs == 1
192208
pl a b = if singular then b else a

0 commit comments

Comments
 (0)