git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Error on missing LICENSE file or if bower.json has no license
2162c48faineance
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
@@ -17,7 +17,7 @@ module Language.PureScript.Publish
17 , getGitWorkingTreeStatus
17 , getGitWorkingTreeStatus
18 , checkCleanWorkingTree
18 , checkCleanWorkingTree
19 , getVersionFromGitTag
19 , getVersionFromGitTag
20− , getBowerInfo
20+ , getBowerRepositoryInfo
21 , getModulesAndBookmarks
21 , getModulesAndBookmarks
22 , getResolvedDependencies
22 , getResolvedDependencies
23 ) where
23 ) where
@@ -121,19 +121,24 @@ otherError = throwError . OtherError
121catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
121catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
122catchLeft a f = either f pure a
122catchLeft a f = either f pure a
123
123
124+unlessM :: Monad m => m Bool -> m () -> m ()
125+unlessM cond act = cond >>= flip unless act
126+
124preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
127preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
125preparePackage' opts = do
128preparePackage' opts = do
126− exists <- liftIO (doesFileExist "bower.json")
129+ unlessM (liftIO (doesFileExist "bower.json")) (userError BowerJSONNotFound)
127− unless exists (userError BowerJSONNotFound)
128−
129 checkCleanWorkingTree opts
130 checkCleanWorkingTree opts
130
131
131 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
132 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
132 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
133 >>= flip catchLeft (userError . CouldntDecodeBowerJSON)
134+ unlessM (liftIO (doesFileExist "LICENSE")) (userError LicenseNotFound)
135+
133 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
136 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
134− pkgGithub <- getBowerInfo pkgMeta
137+ pkgGithub <- getBowerRepositoryInfo pkgMeta
135 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
138 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
136
139
140+ unless (bowerLicenseExists pkgMeta) (userError NoLicenseSpecified)
141+
137 let declaredDeps = map fst (bowerDependencies pkgMeta ++
142 let declaredDeps = map fst (bowerDependencies pkgMeta ++
138 bowerDevDependencies pkgMeta)
143 bowerDevDependencies pkgMeta)
139 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
144 pkgResolvedDependencies <- getResolvedDependencies declaredDeps
@@ -193,8 +198,8 @@ getVersionFromGitTag = do
193 dropPrefix prefix str =
198 dropPrefix prefix str =
194 fromMaybe str (stripPrefix prefix str)
199 fromMaybe str (stripPrefix prefix str)
195
200
196−getBowerInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
201+getBowerRepositoryInfo :: PackageMeta -> PrepareM (D.GithubUser, D.GithubRepo)
197−getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
202+getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExtract
198 where
203 where
199 tryExtract pkgMeta =
204 tryExtract pkgMeta =
200 case bowerRepository pkgMeta of
205 case bowerRepository pkgMeta of
@@ -204,6 +209,9 @@ getBowerInfo = either (userError . BadRepositoryField) return . tryExtract
204 (Left (BadRepositoryType repositoryType))
209 (Left (BadRepositoryType repositoryType))
205 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
210 maybe (Left NotOnGithub) Right (extractGithub repositoryUrl)
206
211
212+bowerLicenseExists :: PackageMeta -> Bool
213+bowerLicenseExists = any (not . null) . bowerLicense
214+
207extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
215extractGithub :: String -> Maybe (D.GithubUser, D.GithubRepo)
208extractGithub = stripGitHubPrefixes
216extractGithub = stripGitHubPrefixes
209 >>> fmap (splitOn "/")
217 >>> fmap (splitOn "/")
src/Language/PureScript/Publish/ErrorsWarnings.hs+15
@@ -54,11 +54,13 @@ data PackageWarning
54-- | An error that should be fixed by the user.
54-- | An error that should be fixed by the user.
55data UserError
55data UserError
56 = BowerJSONNotFound
56 = BowerJSONNotFound
57+ | LicenseNotFound
57 | BowerExecutableNotFound [String] -- list of executable names tried
58 | BowerExecutableNotFound [String] -- list of executable names tried
58 | CouldntDecodeBowerJSON (ParseError BowerError)
59 | CouldntDecodeBowerJSON (ParseError BowerError)
59 | TagMustBeCheckedOut
60 | TagMustBeCheckedOut
60 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
61 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
61 | BadRepositoryField RepositoryFieldError
62 | BadRepositoryField RepositoryFieldError
63+ | NoLicenseSpecified
62 | MissingDependencies (NonEmpty PackageName)
64 | MissingDependencies (NonEmpty PackageName)
63 | CompileError P.MultipleErrors
65 | CompileError P.MultipleErrors
64 | DirtyWorkingTree
66 | DirtyWorkingTree
@@ -70,6 +72,7 @@ data RepositoryFieldError
70 | NotOnGithub
72 | NotOnGithub
71 deriving (Show)
73 deriving (Show)
72
74
75+
73-- | An error that probably indicates a bug in this module.
76-- | An error that probably indicates a bug in this module.
74data InternalError
77data InternalError
75 = JSONError JSONSource (ParseError BowerError)
78 = JSONError JSONSource (ParseError BowerError)
@@ -122,6 +125,12 @@ displayUserError e = case e of
122 "The bower.json file was not found. Please create one, or run " ++
125 "The bower.json file was not found. Please create one, or run " ++
123 "`pulp init`."
126 "`pulp init`."
124 )
127 )
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+ ])
125 BowerExecutableNotFound names ->
134 BowerExecutableNotFound names ->
126 para (concat
135 para (concat
127 [ "The Bower executable was not found (tried: ", format names, "). Please"
136 [ "The Bower executable was not found (tried: ", format names, "). Please"
@@ -168,6 +177,12 @@ displayUserError e = case e of
168 ] ++ bulletedList showVersion vs
177 ] ++ bulletedList showVersion vs
169 BadRepositoryField err ->
178 BadRepositoryField err ->
170 displayRepositoryError err
179 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+ ])
171 MissingDependencies pkgs ->
186 MissingDependencies pkgs ->
172 let singular = NonEmpty.length pkgs == 1
187 let singular = NonEmpty.length pkgs == 1
173 pl a b = if singular then b else a
188 pl a b = if singular then b else a