git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Relax rules on license files in psc-publish
414372eHarry Garrood
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 @@
16 ],
16 ],
17 "dependencies": {
17 "dependencies": {
18 },
18 },
19− "license": "replaceme"
19+ "license": "MIT"
20}
20}
purescript.cabal+2−1
@@ -92,7 +92,8 @@ library
92 monad-logger >= 0.3 && < 0.4,
92 monad-logger >= 0.3 && < 0.4,
93 pipes >= 4.0.0 && < 4.2.0 ,
93 pipes >= 4.0.0 && < 4.2.0 ,
94 pipes-http -any,
94 pipes-http -any,
95− http-types -any
95+ http-types -any,
96+ spdx == 0.2.*
96
97
97 exposed-modules: Language.PureScript
98 exposed-modules: Language.PureScript
98 Language.PureScript.AST
99 Language.PureScript.AST
src/Language/PureScript/Publish.hs+13−6
@@ -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
42
43
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
129
130
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
132
133
133preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
134preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
134preparePackage' opts = do
135preparePackage' opts = do
@@ -137,14 +138,12 @@ preparePackage' opts = do
137
138
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
141
142
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
145
146
146− unless (bowerLicenseExists pkgMeta) (userError NoLicenseSpecified)
147−
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)
217
216
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)
221+
222+-- |
223+-- Check if a string is a valid SPDX license expression.
224+--
225+isValidSPDX :: String -> Bool
226+isValidSPDX = (== 1) . length . SPDX.parseExpression
220
227
221extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
228extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
222extractGithub = stripGitHubPrefixes
229extractGithub = stripGitHubPrefixes
src/Language/PureScript/Publish/ErrorsWarnings.hs+21−5
@@ -182,11 +182,27 @@ displayUserError e = case e of
182 BadRepositoryField err ->
182 BadRepositoryField err ->
183 displayRepositoryError err
183 displayRepositoryError err
184 NoLicenseSpecified ->
184 NoLicenseSpecified ->
185+ vcat $
185− para (concat
186+ [ para (concat
186− ["No license specified in bower.json. Please add one. ",
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
187− "Distributing code without a license means that nobody ",
202+ [ "Note that distributing code without a license means that nobody "
188− "will be able to (legally) use it."
203+ , "will (legally) be able to use it."
189− ])
204+ ])
205+ ]
190 MissingDependencies pkgs ->
206 MissingDependencies pkgs ->
191 let singular = NonEmpty.length pkgs == 1
207 let singular = NonEmpty.length pkgs == 1
192 pl a b = if singular then b else a
208 pl a b = if singular then b else a