New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wasper can now specify npm dependencies. #58
Conversation
L.reserved L.reservedNameDependencies | ||
closureContent <- P.waspNamedClosure "json" | ||
let jsonBytestring = BLU.fromString $ "{ " ++ closureContent ++ " }" | ||
npmDeps <- case Aeson.eitherDecode' jsonBytestring :: Either String (M.HashMap String String) of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here return type (which I specified explicitely) decides how string will be decoded by Aeson -> meaning it is polymorphic in return type, pretty cool! This is also how Haskell Regex libraries work normally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, nice job, you did everything, including tests.
else Left conflictingUserDeps | ||
where | ||
conflictingUserDeps :: [(ND.NpmDependency, NpmDependenciesConflictError)] | ||
conflictingUserDeps = map (\(d, e) -> (d, fromJust e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conflictingUserDeps = map (\(d, e) -> (d, fromJust e)) | |
conflictingUserDeps = map (\(d, err) -> (d, fromJust err)) |
Maybe at least this, so it is clearer what is err
:D. Let's not save letters, I know it's not cool but still :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But Haskell loves single character variables :P. Kidding, ok I made them more descriptive you are right!
(\d -> "Error: Dependency conflict for user npm dependency (" | ||
++ ND._name d ++ ", " ++ ND._version d ++ "): " | ||
++ "Version must be set to the exactly the same version as" | ||
++ " wasp dependency is using: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ " wasp dependency is using: " | |
++ " the one wasp is using: " |
Previous sentence didn't make sense, "same version as wasp dependency is using"? If I got it wrong nvm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right this is better!
++ " wasp dependency is using: " | ||
++ ND._version d | ||
) | ||
<$> find (areTwoDepsInConflict userDep) waspDeps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, fmap on Maybe. Didn't know about find, cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes first I wrote case of
but when I saw what I was doing in it I thought aha, fmap!
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually rewrote it now a little bit by naming the function and then using it via let in
, I think it is better that way.
&& ND._version d1 /= ND._version d2 | ||
|
||
userDepsNotInWaspDeps :: [ND.NpmDependency] | ||
userDepsNotInWaspDeps = filter (not . isDepWithNameInWaspDeps . ND._name) userDeps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
(resolvedWaspDeps, resolvedUserDeps) = | ||
case resolveNpmDeps waspDeps userDeps of | ||
Right deps -> deps | ||
Left depsAndErrors -> error $ intercalate " ; " $ map snd depsAndErrors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha here we just crash everything, ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for now, until we implement some nicer way to handle errors.
@@ -37,6 +38,7 @@ waspElement | |||
<|> waspElementEntity | |||
<|> waspElementEntityForm | |||
<|> waspElementEntityList | |||
<|> waspElementNpmDependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm since here it is a part of AST, maybe you should move the file above in Wasp/ dir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But file above is NpmDependency, while this here is NpmDependencies (plural).
|
||
getNpmDependencies :: Wasp -> NpmDependencies | ||
getNpmDependencies wasp | ||
= let depses = [d | (WaspElementNpmDependencies d) <- waspElements wasp] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= let depses = [d | (WaspElementNpmDependencies d) <- waspElements wasp] | |
= let deps = [d | (WaspElementNpmDependencies d) <- waspElements wasp] |
deps
is already a plural, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but here I needed plural of plural :D.
waspc/src/Wasp.hs
Outdated
getNpmDependencies :: Wasp -> NpmDependencies | ||
getNpmDependencies wasp | ||
= let depses = [d | (WaspElementNpmDependencies d) <- waspElements wasp] | ||
in case length depses of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also match the list directly to []
or [_]
I think? That sounds more common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey yes, that is much nicer! Cool, did it.
|
||
setNpmDependencies :: Wasp -> NpmDependencies -> Wasp | ||
setNpmDependencies wasp deps = wasp | ||
{ waspElements = WaspElementNpmDependencies deps : filter (not . isNpmDependenciesElem) (waspElements wasp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha, this is "redux" style, we have to deconstruct stuff and put it back together. We are now changing the order in waspElements array but I guess it is not important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although some tests rely on the order being preserved (e.g. the main one for parser, valid.wasp) -> I compare directly two lists, element for element. But I think that won't be affected by this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm that is because tests are too fragile. Let's leave it as it is and let's see what happens?
, ("foo", "bar") | ||
] | ||
let Left conflicts = resolveNpmDeps (ND.fromList waspDeps) (ND.fromList userDeps) | ||
(map fst conflicts) `shouldBe` ND.fromList [("axios", "^1.20.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice tests
2a4b556
to
3b4ffe8
Compare
Implements #11 .
Right now, if user specifies npm package that user is already using, they will get a message explaining that they have to use the very same version as wasp is using, and they will be informed about that version, and everything will crash.
I also need to add documentation for this but that happens in another repo!