Skip to content

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

Merged

Conversation

fhammerschmidt
Copy link
Member

@fhammerschmidt fhammerschmidt commented Sep 26, 2022

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.

@fhammerschmidt
Copy link
Member Author

@zth Would be nice to get this in soon.

Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

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

  1. 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.
  2. Has this been thoroughly tested both on monorepo setups and non-monorepo setups?

@fhammerschmidt fhammerschmidt force-pushed the fix-open-compiled-monorepo branch from 45d042f to 323b70f Compare October 10, 2022 13:13
@fhammerschmidt
Copy link
Member Author

Ad 1.: Added build-schema types (converted from the compilers original JSON schema)
Ad 2.: Used it for the last two weeks on my projects, @cknitt tested it as well. I also worked on a real-world non-monorepo and the command still worked.

Copy link
Collaborator

@zth zth left a 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 ?

Copy link
Collaborator

@cristianoc cristianoc left a 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.

// 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(
Copy link
Collaborator

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.

Copy link
Member Author

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)?

Copy link
Collaborator

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.

Copy link
Member Author

@fhammerschmidt fhammerschmidt Oct 11, 2022

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.

Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Member Author

@fhammerschmidt fhammerschmidt Oct 11, 2022

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

Copy link
Collaborator

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.

Copy link
Member Author

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

Copy link
Collaborator

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.

@cristianoc
Copy link
Collaborator

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:

  • There are multiple projects (corresponding to multiple `bsconfig.json files in different dirs)
  • There are multiple node_modules dirs (perhaps of different number and perhaps on completely different dirs than those where bsconfig.json files go)
  • There are multiple compilation artifacts dirs (perhaps of different number and perhaps on completely different dirs than those where bsconfig.json files go).

And I'm intentionally keeping it unreasonably vague in hope one can narrow down some of these boundaries.

@fhammerschmidt
Copy link
Member Author

Added a small fix (this got lost when refactoring) and tested it again agains some of our repos (including non-monorepos), all good.

@cristianoc cristianoc merged commit 15be47c into rescript-lang:master Oct 11, 2022
@fhammerschmidt fhammerschmidt deleted the fix-open-compiled-monorepo branch October 11, 2022 16:38
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