git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1961 from faineance/publish_error_on_missing_license
e286486Phil Freeman
CONTRIBUTORS.md+1
@@ -24,6 +24,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
24- [@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
24- [@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
25- [@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).
25- [@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).
26- [@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).
26- [@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).
27- [@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).
28- [@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).
28- [@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).
29- [@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).
29- [@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).
30- [@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 @@
15 "output"
15 "output"
16 ],
16 ],
17 "dependencies": {
17 "dependencies": {
18− }
18+ },
19+ "license": "replaceme"
19}
20}
purescript.cabal+1
@@ -23,6 +23,7 @@ extra-source-files: examples/passing/*.purs
23 , examples/failing/*.purs
23 , examples/failing/*.purs
24 , examples/docs/bower_components/purescript-prelude/src/*.purs
24 , examples/docs/bower_components/purescript-prelude/src/*.purs
25 , examples/docs/bower.json
25 , examples/docs/bower.json
26+ , examples/docs/LICENSE
26 , examples/docs/src/*.purs
27 , examples/docs/src/*.purs
27 , tests/support/setup.js
28 , tests/support/setup.js
28 , tests/support/package.json
29 , tests/support/package.json
src/Language/PureScript/Publish.hs+15−7
@@ -18,7 +18,7 @@ module Language.PureScript.Publish
18 , getGitWorkingTreeStatus
18 , getGitWorkingTreeStatus
19 , checkCleanWorkingTree
19 , checkCleanWorkingTree
20 , getVersionFromGitTag
20 , getVersionFromGitTag
21− , getBowerInfo
21+ , getBowerRepositoryInfo
22 , getModulesAndBookmarks
22 , getModulesAndBookmarks
23 , getResolvedDependencies
23 , getResolvedDependencies
24 ) where
24 ) where
@@ -127,19 +127,24 @@ otherError = throwError . OtherError
127catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
127catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
128catchLeft a f = either f pure a
128catchLeft a f = either f pure a
129
129
130+unlessM :: Monad m => m Bool -> m () -> m ()
131+unlessM cond act = cond >>= flip unless act
132+
130preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
133preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
131preparePackage' opts = do
134preparePackage' opts = do
132− exists <- liftIO (doesFileExist "bower.json")
135+ unlessM (liftIO (doesFileExist "bower.json")) (userError BowerJSONNotFound)
133− unless exists (userError BowerJSONNotFound)
134−
135 checkCleanWorkingTree opts
136 checkCleanWorkingTree opts
136
137
137 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
138 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
138 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
139 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
140+ unlessM (liftIO (doesFileExist "LICENSE")) (userError LicenseNotFound)
141+
139 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
142 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
140− pkgGithub <- getBowerInfo pkgMeta
143+ pkgGithub <- getBowerRepositoryInfo pkgMeta
141 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
144 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
142
145
146+ unless (bowerLicenseExists pkgMeta) (userError NoLicenseSpecified)
147+
143 let declaredDeps = map fst (bowerDependencies pkgMeta ++
148 let declaredDeps = map fst (bowerDependencies pkgMeta ++
144 bowerDevDependencies pkgMeta)
149 bowerDevDependencies pkgMeta)
145 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
150 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
@@ -199,8 +204,8 @@ getVersionFromGitTag = do
199 dropPrefix prefix str =
204 dropPrefix prefix str =
200 fromMaybe str (stripPrefix prefix str)
205 fromMaybe str (stripPrefix prefix str)
201
206
202−getBowerInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
207+getBowerRepositoryInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
203−getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
208+getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExtract
204 where
209 where
205 tryExtract pkgMeta =
210 tryExtract pkgMeta =
206 case bowerRepository pkgMeta of
211 case bowerRepository pkgMeta of
@@ -210,6 +215,9 @@ getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
210 (Left (BadRepositoryType repositoryType))
215 (Left (BadRepositoryType repositoryType))
211 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
216 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
212
217
218+bowerLicenseExists :: PackageMeta -> Bool
219+bowerLicenseExists = any (not . null) . bowerLicense
220+
213extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
221extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
214extractGithub = stripGitHubPrefixes
222extractGithub = stripGitHubPrefixes
215 >>> fmap (splitOn "/")
223 >>> fmap (splitOn "/")
src/Language/PureScript/Publish/ErrorsWarnings.hs+15
@@ -55,11 +55,13 @@ data PackageWarning
55-- | An error that should be fixed by the user.
55-- | An error that should be fixed by the user.
56data UserError
56data UserError
57 = BowerJSONNotFound
57 = BowerJSONNotFound
58+ | LicenseNotFound
58 | BowerExecutableNotFound [String] -- list of executable names tried
59 | BowerExecutableNotFound [String] -- list of executable names tried
59 | CouldntDecodeBowerJSON (ParseError BowerError)
60 | CouldntDecodeBowerJSON (ParseError BowerError)
60 | TagMustBeCheckedOut
61 | TagMustBeCheckedOut
61 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
62 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
62 | BadRepositoryField RepositoryFieldError
63 | BadRepositoryField RepositoryFieldError
64+ | NoLicenseSpecified
63 | MissingDependencies (NonEmpty PackageName)
65 | MissingDependencies (NonEmpty PackageName)
64 | CompileError P.MultipleErrors
66 | CompileError P.MultipleErrors
65 | DirtyWorkingTree
67 | DirtyWorkingTree
@@ -71,6 +73,7 @@ data RepositoryFieldError
71 | NotOnGithub
73 | NotOnGithub
72 deriving (Show)
74 deriving (Show)
73
75
76+
74-- | An error that probably indicates a bug in this module.
77-- | An error that probably indicates a bug in this module.
75data InternalError
78data InternalError
76 = JSONError JSONSource (ParseError BowerError)
79 = JSONError JSONSource (ParseError BowerError)
@@ -126,6 +129,12 @@ displayUserError e = case e of
126 "The bower.json file was not found. Please create one, or run " ++
129 "The bower.json file was not found. Please create one, or run " ++
127 "`pulp init`."
130 "`pulp init`."
128 )
131 )
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+ ])
129 BowerExecutableNotFound names ->
138 BowerExecutableNotFound names ->
130 para (concat
139 para (concat
131 [ "The Bower executable was not found (tried: ", format names, "). Please"
140 [ "The Bower executable was not found (tried: ", format names, "). Please"
@@ -172,6 +181,12 @@ displayUserError e = case e of
172 ] ++ bulletedList showVersion vs
181 ] ++ bulletedList showVersion vs
173 BadRepositoryField err ->
182 BadRepositoryField err ->
174 displayRepositoryError err
183 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+ ])
175 MissingDependencies pkgs ->
190 MissingDependencies pkgs ->
176 let singular = NonEmpty.length pkgs == 1
191 let singular = NonEmpty.length pkgs == 1
177 pl a b = if singular then b else a
192 pl a b = if singular then b else a