git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
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 #1985.

commit414372eab2399cdb63ecd09b63b8dcd416bdf6b3 authorHarry Garrood <harry@garrood.me> dateSun 17 Apr 2016, 18:21 (11 years ago) parent8bab509
5 files changed+37−14
examples/docs/LICENSE−1 examples/docs/bower.json+1−1 purescript.cabal+2−1 src/Language/PureScript/Publish.hs+13−6 src/Language/PureScript/Publish/ErrorsWarnings.hs+21−5
examples/docs/LICENSEdeleted−1
@@ -1 +0,0 @@
1−This isn't a real license, it's just here for the sake of the tests.
examples/docs/bower.json+1−1
@@ -16,5 +16,5 @@
1616 ],
1717 "dependencies": {
1818 },
19− "license": "replaceme"
19+ "license": "MIT"
2020}
purescript.cabal+2−1
@@ -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+13−6
@@ -39,6 +39,7 @@ import Data.Aeson.BetterErrors
3939import qualified Data.Text as T
4040import qualified Data.Text.Lazy as TL
4141import qualified Data.Text.Lazy.Encoding as TL
42+import qualified Data.SPDX as SPDX
4243
4344import Control.Category ((>>>))
4445import Control.Arrow ((***))
@@ -128,7 +129,7 @@ catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
128129catchLeft a f = either f pure a
129130
130131unlessM :: Monad m => m Bool -> m () -> m ()
131−unlessM cond act = cond >>= flip unless act
132+unlessM cond act = cond >>= flip unless act
132133
133134preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
134135preparePackage' 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
221228extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
222229extractGithub = stripGitHubPrefixes
src/Language/PureScript/Publish/ErrorsWarnings.hs+21−5
@@ -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