git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Error on missing LICENSE file or if bower.json has no license
commit2162c48f6eb5b6c6eacbdccb653529a4e73ba9ba authorfaineance <faineance@users.noreply.github.com> dateWed 16 Mar 2016, 21:45 (11 years ago) parent7d69a33
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
@@ -17,7 +17,7 @@ module Language.PureScript.Publish
1717 , getGitWorkingTreeStatus
1818 , checkCleanWorkingTree
1919 , getVersionFromGitTag
20− , getBowerInfo
20+ , getBowerRepositoryInfo
2121 , getModulesAndBookmarks
2222 , getResolvedDependencies
2323 ) where
@@ -121,19 +121,24 @@ otherError = throwError . OtherError
121121catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
122122catchLeft a f = either f pure a
123123
124+unlessM :: Monad m => m Bool -> m () -> m ()
125+unlessM cond act = cond >>= flip unless act
126+
124127preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
125128preparePackage' opts = do
126− exists <- liftIO (doesFileExist "bower.json")
127− unless exists (userError BowerJSONNotFound)
128−
129+ unlessM (liftIO (doesFileExist "bower.json")) (userError BowerJSONNotFound)
129130 checkCleanWorkingTree opts
130131
131132 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
132133 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
134+ unlessM (liftIO (doesFileExist "LICENSE")) (userError LicenseNotFound)
135+
133136 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
134− pkgGithub <- getBowerInfo pkgMeta
137+ pkgGithub <- getBowerRepositoryInfo pkgMeta
135138 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
136139
140+ unless (bowerLicenseExists pkgMeta) (userError NoLicenseSpecified)
141+
137142 let declaredDeps = map fst (bowerDependencies pkgMeta ++
138143 bowerDevDependencies pkgMeta)
139144 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
@@ -193,8 +198,8 @@ getVersionFromGitTag = do
193198 dropPrefix prefix str =
194199 fromMaybe str (stripPrefix prefix str)
195200
196−getBowerInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
197−getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
201+getBowerRepositoryInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
202+getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExtract
198203 where
199204 tryExtract pkgMeta =
200205 case bowerRepository pkgMeta of
@@ -204,6 +209,9 @@ getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
204209 (Left (BadRepositoryType repositoryType))
205210 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
206211
212+bowerLicenseExists :: PackageMeta -> Bool
213+bowerLicenseExists = any (not . null) . bowerLicense
214+
207215extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
208216extractGithub = stripGitHubPrefixes
209217 >>> fmap (splitOn "/")
src/Language/PureScript/Publish/ErrorsWarnings.hs+15
@@ -54,11 +54,13 @@ data PackageWarning
5454-- | An error that should be fixed by the user.
5555data UserError
5656 = BowerJSONNotFound
57+ | LicenseNotFound
5758 | BowerExecutableNotFound [String] -- list of executable names tried
5859 | CouldntDecodeBowerJSON (ParseError BowerError)
5960 | TagMustBeCheckedOut
6061 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
6162 | BadRepositoryField RepositoryFieldError
63+ | NoLicenseSpecified
6264 | MissingDependencies (NonEmpty PackageName)
6365 | CompileError P.MultipleErrors
6466 | DirtyWorkingTree
@@ -70,6 +72,7 @@ data RepositoryFieldError
7072 | NotOnGithub
7173 deriving (Show)
7274
75+
7376-- | An error that probably indicates a bug in this module.
7477data InternalError
7578 = JSONError JSONSource (ParseError BowerError)
@@ -122,6 +125,12 @@ displayUserError e = case e of
122125 "The bower.json file was not found. Please create one, or run " ++
123126 "`pulp init`."
124127 )
128+ LicenseNotFound ->
129+ para (concat
130+ ["No LICENSE file was found. Please create one. ",
131+ "Distributing code without a license means that nobody ",
132+ "will be able to (legally) use it."
133+ ])
125134 BowerExecutableNotFound names ->
126135 para (concat
127136 [ "The Bower executable was not found (tried: ", format names, "). Please"
@@ -168,6 +177,12 @@ displayUserError e = case e of
168177 ] ++ bulletedList showVersion vs
169178 BadRepositoryField err ->
170179 displayRepositoryError err
180+ NoLicenseSpecified ->
181+ para (concat
182+ ["No license specified in bower.json. Please add one. ",
183+ "Distributing code without a license means that nobody ",
184+ "will be able to (legally) use it."
185+ ])
171186 MissingDependencies pkgs ->
172187 let singular = NonEmpty.length pkgs == 1
173188 pl a b = if singular then b else a