Skip to content
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

Merged
merged 1 commit into from Sep 29, 2020
Merged

Conversation

Martinsos
Copy link
Member

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!

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
Copy link
Member Author

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.

Copy link
Contributor

@matijaSos matijaSos left a 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Member Author

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: "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
++ " 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

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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!.

Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
= let depses = [d | (WaspElementNpmDependencies d) <- waspElements wasp]
= let deps = [d | (WaspElementNpmDependencies d) <- waspElements wasp]

deps is already a plural, right?

Copy link
Member Author

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.

getNpmDependencies :: Wasp -> NpmDependencies
getNpmDependencies wasp
= let depses = [d | (WaspElementNpmDependencies d) <- waspElements wasp]
in case length depses of
Copy link
Contributor

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.

Copy link
Member Author

@Martinsos Martinsos Sep 29, 2020

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)
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member Author

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")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice tests

@Martinsos Martinsos merged commit ca03930 into master Sep 29, 2020
@Martinsos Martinsos deleted the npm-dependencies branch September 29, 2020 11:47
Huntemall pushed a commit to Huntemall/wasp-dev that referenced this pull request Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants