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

TS config cleanup - Part 2 #2407

Open
wants to merge 7 commits into
base: filip-ts-config-cleanup
Choose a base branch
from

Conversation

sodic
Copy link
Contributor

@sodic sodic commented Dec 10, 2024

Fixes the technical dept left over by #2276

@sodic sodic mentioned this pull request Dec 10, 2024
@sodic sodic changed the base branch from main to filip-ts-config-cleanup December 10, 2024 11:24
waspc/src/Wasp/Job.hs Outdated Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These functions were extracted into a module with virtually no changes (the only change is one usage of the orElse function).

I wanted to move WaspFilePath, WaspLangFile, and others from Project.Common, but that created a circular dependency, so I kept them there.

I've only exported the symbols required by other modules:

  • findWaspFile and analyzeWaspFile must be exported as two distinct functions because our analyze function first looks for the file, does some other stuff (e.g., parses schema.prisma), and only then comes back to the wasp file to analyze it.
  • analyzeWaspFileContent is a lower-level function used by AI (because there's no file on disk).

Copy link
Contributor

Choose a reason for hiding this comment

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

This file feels little busy to me, it feels like two different files.

I'd maybe go for Wasp.Project.WaspFile.DSL and Wasp.Project.WaspFile.Ts modules (names could be better). This way both files would be smaller and easier to follow IMHO.

Copy link
Member

Choose a reason for hiding this comment

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

+1 to what @infomiho said, that also makes sense to me.

As for cyclic deps -> I guess we would have to figure out what is the best way to organize stuff. I am guessing the problem is that in other places of code we have stuff organized by "Analyze" and here you put all WaspFile stuff into one file including analysis and types and so on, so there are some cycles. Or it is something else. Anyway, maybe for example you could do it so that operations like analyze and compile and are under Project.WaspFile.Analyze. Or Project.Analyze.WaspFile if there is such file. I am making up stuff here, but there must be a way to arrange stuff so it all makes sense. But we don'th ave to do it now if you think that is too much, of course, it can stay like this if you think this is fine for now.

Copy link
Contributor Author

@sodic sodic Dec 20, 2024

Choose a reason for hiding this comment

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

I specifically didn't want to do this (I prefer a single file). We discussed it in the original PR too.

But since you both prefer two files, I'll change it.

As for the cyclic deps, it was much simpler and caused by the stuff in common (e.g., this file uses WaspProjectDir from Common, and Common would be using WaspLangFile from here) .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I split it in the end.

@sodic sodic marked this pull request as ready for review December 10, 2024 13:14
Copy link
Contributor

@infomiho infomiho left a comment

Choose a reason for hiding this comment

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

Good refactors. Suggested extracting bits from WaspFile module.

@@ -88,7 +88,6 @@ dotWaspInfoFileInGeneratedCodeDir = [relfile|.waspinfo|]
packageJsonInWaspProjectDir :: Path' (Rel WaspProjectDir) (File PackageJsonFile)
packageJsonInWaspProjectDir = [relfile|package.json|]

-- TODO: The entire tsconfig story is very fragile
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we cover this with some sort of an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and no.

I wrote the comment back when the code looked differently and left it by accident. Still, there are things we could improve. And those are covered by other issues, such as:

I created the second one now, so thanks for pointing this out :)

Path' Abs (File WaspTsFile) ->
IO (Either [CompileError] [AS.Decl])
analyzeWaspTsFile waspProjectDir prismaSchemaAst waspFilePath = runExceptT $ do
-- TODO: I'm not yet sure where tsconfig.node.json location should come from
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
-- TODO: I'm not yet sure where tsconfig.node.json location should come from
-- TODO: I'm not yet sure where tsconfig.wasp.json location should come from

Copy link
Contributor

Choose a reason for hiding this comment

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

This file feels little busy to me, it feels like two different files.

I'd maybe go for Wasp.Project.WaspFile.DSL and Wasp.Project.WaspFile.Ts modules (names could be better). This way both files would be smaller and easier to follow IMHO.

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

Approved, as there is nothing major!

THere are some smaller things though, so please check those before merging.

waspc/src/Wasp/Analyzer.hs Outdated Show resolved Hide resolved
@@ -250,6 +251,9 @@ eitherToMaybe :: Either e a -> Maybe a
eitherToMaybe (Right x) = Just x
eitherToMaybe (Left _) = Nothing

orElse :: Maybe a -> a -> a
Copy link
Member

Choose a reason for hiding this comment

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

Cool!

import Wasp.Util (indent, insertAt, leftPad)
import qualified Wasp.Util.Terminal as T

-- | Transforms compiler error (error with parse context) into an informative, pretty String that
-- can be printed directly into the terminal. It uses terminal features like escape codes
-- (colors, styling, ...).
showCompilerErrorForTerminal :: (Path' Abs (File f), String) -> (String, Ctx) -> String
showCompilerErrorForTerminal :: (Path' Abs (File WaspLangFile), String) -> (String, Ctx) -> String
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

waspc/src/Wasp/Job.hs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

+1 to what @infomiho said, that also makes sense to me.

As for cyclic deps -> I guess we would have to figure out what is the best way to organize stuff. I am guessing the problem is that in other places of code we have stuff organized by "Analyze" and here you put all WaspFile stuff into one file including analysis and types and so on, so there are some cycles. Or it is something else. Anyway, maybe for example you could do it so that operations like analyze and compile and are under Project.WaspFile.Analyze. Or Project.Analyze.WaspFile if there is such file. I am making up stuff here, but there must be a way to arrange stuff so it all makes sense. But we don'th ave to do it now if you think that is too much, of course, it can stay like this if you think this is fine for now.

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.

3 participants