git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1961 from faineance/publish_error_on_missing_license

Error on missing LICENSE file or missing license field in bower.json

commite2864866692ba0837bbc6df8c8ebd3e627a38f0a authorPhil Freeman <paf31@cantab.net> dateSat 26 Mar 2016, 12:11 (11 years ago) parent406695a2162c48
6 files changed+35−8
CONTRIBUTORS.md+1 examples/docs/LICENSE+1 examples/docs/bower.json+2−1 purescript.cabal+1 src/Language/PureScript/Publish.hs+15−7 src/Language/PureScript/Publish/ErrorsWarnings.hs+15
CONTRIBUTORS.md+1
@@ -24,6 +24,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
2424- [@epost](https://github.com/epost) (Erik Post) - My existing contributions and all future contributions until further notice are Copyright Erik Post, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license
2525- [@erdeszt](https://github.com/erdeszt) (Tibor Erdesz) My existing contributions and all future contributions until further notice are Copyright Tibor Erdesz, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2626- [@etrepum](https://github.com/etrepum) (Bob Ippolito) My existing contributions and all future contributions until further notice are Copyright Bob Ippolito, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
27+- [@faineance](https://github.com/faineance) My existing contributions and all future contributions until further notice are Copyright faineance, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2728- [@garyb](https://github.com/garyb) (Gary Burgess) My existing contributions and all future contributions until further notice are Copyright Gary Burgess, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2829- [@hdgarrood](https://github.com/hdgarrood) (Harry Garrood) My existing contributions and all future contributions until further notice are Copyright Harry Garrood, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2930- [@izgzhen](https://github.com/izgzhen) (Zhen Zhang) My existing contributions and all future contributions until further notice are Copyright Zhen Zhang, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
examples/docs/LICENSEnew file+1
@@ -0,0 +1 @@
1+This isn't a real license, it's just here for the sake of the tests.
examples/docs/bower.json+2−1
@@ -15,5 +15,6 @@
1515 "output"
1616 ],
1717 "dependencies": {
18− }
18+ },
19+ "license": "replaceme"
1920}
purescript.cabal+1
@@ -23,6 +23,7 @@ extra-source-files: examples/passing/*.purs
2323 , examples/failing/*.purs
2424 , examples/docs/bower_components/purescript-prelude/src/*.purs
2525 , examples/docs/bower.json
26+ , examples/docs/LICENSE
2627 , examples/docs/src/*.purs
2728 , tests/support/setup.js
2829 , tests/support/package.json
src/Language/PureScript/Publish.hs+15−7
@@ -18,7 +18,7 @@ module Language.PureScript.Publish
1818 , getGitWorkingTreeStatus
1919 , checkCleanWorkingTree
2020 , getVersionFromGitTag
21− , getBowerInfo
21+ , getBowerRepositoryInfo
2222 , getModulesAndBookmarks
2323 , getResolvedDependencies
2424 ) where
@@ -127,19 +127,24 @@ otherError = throwError . OtherError
127127catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
128128catchLeft a f = either f pure a
129129
130+unlessM :: Monad m => m Bool -> m () -> m ()
131+unlessM cond act = cond >>= flip unless act
132+
130133preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
131134preparePackage' opts = do
132− exists <- liftIO (doesFileExist "bower.json")
133− unless exists (userError BowerJSONNotFound)
134−
135+ unlessM (liftIO (doesFileExist "bower.json")) (userError BowerJSONNotFound)
135136 checkCleanWorkingTree opts
136137
137138 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
138139 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
140+ unlessM (liftIO (doesFileExist "LICENSE")) (userError LicenseNotFound)
141+
139142 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
140− pkgGithub <- getBowerInfo pkgMeta
143+ pkgGithub <- getBowerRepositoryInfo pkgMeta
141144 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
142145
146+ unless (bowerLicenseExists pkgMeta) (userError NoLicenseSpecified)
147+
143148 let declaredDeps = map fst (bowerDependencies pkgMeta ++
144149 bowerDevDependencies pkgMeta)
145150 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
@@ -199,8 +204,8 @@ getVersionFromGitTag = do
199204 dropPrefix prefix str =
200205 fromMaybe str (stripPrefix prefix str)
201206
202−getBowerInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
203−getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
207+getBowerRepositoryInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
208+getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExtract
204209 where
205210 tryExtract pkgMeta =
206211 case bowerRepository pkgMeta of
@@ -210,6 +215,9 @@ getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
210215 (Left (BadRepositoryType repositoryType))
211216 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
212217
218+bowerLicenseExists :: PackageMeta -> Bool
219+bowerLicenseExists = any (not . null) . bowerLicense
220+
213221extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
214222extractGithub = stripGitHubPrefixes
215223 >>> fmap (splitOn "/")
src/Language/PureScript/Publish/ErrorsWarnings.hs+15
@@ -55,11 +55,13 @@ data PackageWarning
5555-- | An error that should be fixed by the user.
5656data UserError
5757 = BowerJSONNotFound
58+ | LicenseNotFound
5859 | BowerExecutableNotFound [String] -- list of executable names tried
5960 | CouldntDecodeBowerJSON (ParseError BowerError)
6061 | TagMustBeCheckedOut
6162 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
6263 | BadRepositoryField RepositoryFieldError
64+ | NoLicenseSpecified
6365 | MissingDependencies (NonEmpty PackageName)
6466 | CompileError P.MultipleErrors
6567 | DirtyWorkingTree
@@ -71,6 +73,7 @@ data RepositoryFieldError
7173 | NotOnGithub
7274 deriving (Show)
7375
76+
7477-- | An error that probably indicates a bug in this module.
7578data InternalError
7679 = JSONError JSONSource (ParseError BowerError)
@@ -126,6 +129,12 @@ displayUserError e = case e of
126129 "The bower.json file was not found. Please create one, or run " ++
127130 "`pulp init`."
128131 )
132+ LicenseNotFound ->
133+ para (concat
134+ ["No LICENSE file was found. Please create one. ",
135+ "Distributing code without a license means that nobody ",
136+ "will be able to (legally) use it."
137+ ])
129138 BowerExecutableNotFound names ->
130139 para (concat
131140 [ "The Bower executable was not found (tried: ", format names, "). Please"
@@ -172,6 +181,12 @@ displayUserError e = case e of
172181 ] ++ bulletedList showVersion vs
173182 BadRepositoryField err ->
174183 displayRepositoryError err
184+ 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+ ])
175190 MissingDependencies pkgs ->
176191 let singular = NonEmpty.length pkgs == 1
177192 pl a b = if singular then b else a