Skip to content

Be more aware of the workspace during clean #7752

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

nojaf
Copy link
Member

@nojaf nojaf commented Aug 2, 2025

This is an attempt to drive the conversation at #7707

In case of clean, we already do an upward traversal to find a root rescript json.
I'm adding some logic to check if the parent rescript json contains the current rescript json in "dependencies" (or "dev-dependencies").

If we did find a link, we would only remove the files from the current project and not everything.

Consider https://github.com/nojaf/rescript-kaplay/blob/main/packages/rescript-kaplay/rescript.json

We already find https://github.com/nojaf/rescript-kaplay/blob/d38649fcd409c174c39b31488f790e036f3b0a20/rescript.json#L8

If that name matches root_package (in the code, a bit confusing name) is "@nojaf/rescript-kaplay", so we only need to remove those files.

Files from https://github.com/nojaf/rescript-kaplay/blob/main/packages/samples/rescript.json are unaffected.

If we were to clean from the repo root, root_config would be the well the root package and everything gets cleaned.

Copy link
Member Author

@nojaf nojaf left a comment

Choose a reason for hiding this comment

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

Let me know if something doesn't make any sense.

Copy link

pkg-pr-new bot commented Aug 2, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7752

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7752

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7752

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7752

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7752

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7752

commit: 5b2e427

@nojaf
Copy link
Member Author

nojaf commented Aug 4, 2025

I think it might make sense to rethink the format command as well.

Would it not be more consistent if we format either:

  • a specific file argument like format Foo.res
  • Format all projects in case of a monorepo when invoked at the root.
  • Format a specific project only when it is part of a workspace, but invoked at the project level and not the root.

The --all flag seems a bit off compared to clean.

@cknitt
Copy link
Member

cknitt commented Aug 7, 2025

Agreed, defaulting to all / keeping args similar to build/clean definitely makes sense!

@nojaf
Copy link
Member Author

nojaf commented Aug 7, 2025

There still is more work to do here.
In general the concept of current_package and workspace_package and their relation should be cemented more in all code paths.

my-monorepo/
  packages/
    a/
      rescript.json
    b/
      rescript.json
rescript.json

Running clean, build, format and compiler-args inside a or my-monorepo need to clearly defined.

repository (my-monorepo) package (a) expectation repository expectation project
compiler-args packages/a/src/File.res src/Files.res Get compiler args. Extension from repo is used Exact same result, extension from repo is used
format All files of all packages are formatted Files of current package are formatted
build All packages are built Only this package is built
clean All packages are cleaned Only this packaged is cleaned

I also think that if there is no link with package and repository rescript, workspace_path should be None.

For the time being if there is a workspace rescript.json, that "suffix" is primary.
Nested rescript.json files cannot define it again. Maybe we add a warning for that.

Post v12 we can explore the option to override suffix in child packages, but it is my understanding that it doesn't work that way today.

I'm also in favour of renaming root_package of current_package in code.

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