-
Notifications
You must be signed in to change notification settings - Fork 60
Fix open compiled command for monorepos #592
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
Fix open compiled command for monorepos #592
Conversation
@zth Would be nice to get this in soon. |
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.
- Can we get rid of the
any
here? Dunno if it's introduced in this PR or if you're just explicitly stating something that was implicit before, but it would be nice to see if we can get rid off them. - Has this been thoroughly tested both on monorepo setups and non-monorepo setups?
45d042f
to
323b70f
Compare
Ad 1.: Added build-schema types (converted from the compilers original JSON schema) |
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.
All good from me! Ok with you as well @cristianoc ?
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.
Left some comments about consolidating the search logic more.
I guess there's more analogous logic for the binary, and putting both in the same place could be useful to keep them in sync.
server/src/utils.ts
Outdated
// If the file is not found, lookup a possible root bsconfig that may contain | ||
// info about the possible location of the file. | ||
if (!fs.existsSync(result)) { | ||
let rootBsConfigPath = findFilePathFromProjectRoot( |
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.
This logic is a little strange, but I guess monorepos are unspecified at the moment, so looking blindly at the parent dir is one way of doing it.
Of course, this might not be a monorepo, or it could be that the file simply is not compiled, and we start searching in random places.
I guess these are all current limitations.
This logic, and any such logic, should probably live together in a dedicated file, so it's easier to update in the future when things become less unspecified.
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.
What exactly should be moved into a separate file? The recursive functions findProjectRootOfFile
and findFilePathFromProjectRoot
or the new logic I introduced with this PR (what is inside the !fs.existsSync
if-block)?
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 would say just the logic.
I.e. go looking in the parent, find the root from there, take the info from the root bsconfig.
I guess the logic for the binary is similar and if they go to the same place it's easy to keep them in sync.
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.
This will introduce circular dependencies. I know this will work in TypeScript, but I think it is not good regardless.
Except I move the aforementioned lookup methods to the new file as well.
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.
Why would move some code to a brand new file introduce circular dependencies?
Unless this refers to something else.z
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.
And this is definitely not a generic util.
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.
Assuming I keep the getCompiledFilePath
in utils.ts
, but move the new parts into another file. In that file I would have to access utils.findFilePathFromProjectRoot
among others --> circular dep
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.
It could be a lookup file, with a section for monorepo.
Or a lookup file and a monorepo file.
It does not really matter much as long as relevant coupled code is all in one place.
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.
Gave it a try in 6830b29
hope this is how you meant it
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.
Looks great. Ready to merge I think.
For my understanding, could we draw some boundaries around how things can possibly be structured? I thing the most general multi-project scenario would look like this:
And I'm intentionally keeping it unreasonably vague in hope one can narrow down some of these boundaries. |
Added a small fix (this got lost when refactoring) and tested it again agains some of our repos (including non-monorepos), all good. |
When you for instance set the suffix in your root bsconfig in a monorepo, but omit it in the nearest bsconfig to your ReScript file, the
open compiled
command won't work. This PR addresses that. I tried to fix it gracefully, i.e. only when no file is found with the current approach, it tries to go one directory up and find the root bsconfig from there. Then the already existing bsconfig-processing logic is applied on the root bsconfig to find the correct suffix/module system.