-
Notifications
You must be signed in to change notification settings - Fork 471
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
Conversation
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.
Let me know if something doesn't make any sense.
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
commit: |
I think it might make sense to rethink the format command as well. Would it not be more consistent if we format either:
The |
Agreed, defaulting to all / keeping args similar to build/clean definitely makes sense! |
There still is more work to do here.
Running
I also think that if there is no link with package and repository rescript, For the time being if there is a workspace rescript.json, that "suffix" is primary. 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 |
@@ -1,4 +1,4 @@ | |||
{ | |||
"name": "rescript", | |||
"dependencies": ["@tests/gentype-react-example"] | |||
"dependencies": ["@tests/gentype-react-example", "playground"] |
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.
"playground"
is part of the workspace, so I need to be listed here for rewatch to pick up the correct node_modules
folder.
The package.json
has rescript clean
in the commands.
This will now accurately only clean the playground package.
But it needs that link to the parent rescript json.
bold "Rescript version" | ||
(cd ../testrepo && ./node_modules/.bin/rescript -v) | ||
(cd ../testrepo && ./node_modules/.bin/rescript --version) |
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.
-v
is verbosity and this was trying to compile the testrepo with an older installed version of rescript.
I'm not sure how this wasn't leading to bigger problems.
rewatch/src/project_context.rs
Outdated
// I don't think this linting rule matters very much as we only create a single instance of this enum. | ||
// See https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum ProjectContext { |
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 streamlines the many workspace: Option<string>
checks that were being done.
It improves the readability and debugability of rewatch.
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 maybe do:
pub enum MonoRepoContext {
Root {local_dependencies, local_dev_dependencies}
Package {parent_config: Config, parent_path: RescriptJsonPath}
}
pub struct ProjectContext {
config: Config,
path: RescriptJsonPath,
mono_repo_context: Option<MonoRepoContext>
}
I would like to be mindful about memory consumption - even if minor - you never know how much these will grow in the future - and I think we should try and keep a small footprint (smaller than we do now). I think the enum
will otherwise always take the biggest size when allocating, even in smaller contexts.
For those overwhelmed by these changes: in short, this resolves the expectations described in #7707 comment. This PR makes Rewatch more aware of its context:
In the last case, Rewatch will run I removed the I will add a changelog entry if there is consensus to move forward. Please ask any questions you may have. |
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.
Really nice work! Left some comments on the Rust bits and pieces 👌 / some optimisations.
@@ -709,7 +699,7 @@ fn compile_file( | |||
} | |||
|
|||
// copy js file | |||
root_package.config.get_package_specs().iter().for_each(|spec| { | |||
root_config.get_package_specs().iter().for_each(|spec| { |
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.
More of a note to myself for some future refactor - I think we can do better with memory management - the package specs / root_config and those things are essentially constant after reading. We should be able - for the most part - to just always return references rather than cloning - I think we can further smallen the footprint / make things quite a bit faster that way
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 function also get's called a lot. I think we might benefit from some more abstraction, having an internal representation for a package / packagespec, rather than the parseTree we need for Serde
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.
5 usages indeed, worth revisiting. Will consider this outside the scope of this PR, as it is already so large.
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.
we pass references right? Where are we doing cloning?
rewatch/src/project_context.rs
Outdated
// I don't think this linting rule matters very much as we only create a single instance of this enum. | ||
// See https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum ProjectContext { |
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 maybe do:
pub enum MonoRepoContext {
Root {local_dependencies, local_dev_dependencies}
Package {parent_config: Config, parent_path: RescriptJsonPath}
}
pub struct ProjectContext {
config: Config,
path: RescriptJsonPath,
mono_repo_context: Option<MonoRepoContext>
}
I would like to be mindful about memory consumption - even if minor - you never know how much these will grow in the future - and I think we should try and keep a small footprint (smaller than we do now). I think the enum
will otherwise always take the biggest size when allocating, even in smaller contexts.
context | ||
} | ||
|
||
pub fn get_root_config(&self) -> &Config { |
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.
Breaking up the enum
into a struct
for the shared fields would remove the need for these too, which is nice imo :)
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's not exactly the same, because we want to get different things (in a mono repo package, get the root config, otherwise get the config of the current package). So I think it's pretty nice like this - and with an implementation, it's easy to get the configuration.
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.
Yeah, check you're right actually. Misread - these would still be there :) - still think having the overlapping fields in a struct would model the real world better though
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.
@rolandpeelen I've refactored based on the feedback,
now I have
#[allow(clippy::large_enum_variant)]
pub enum ProjectContext {
/// Single project - no workspace relationship
SingleProject { config: Config },
/// Monorepo root - contains local dependencies (symlinked in node_modules)
MonorepoRoot {
config: Config,
local_dependencies: AHashSet<String>, // names of local deps
local_dev_dependencies: AHashSet<String>,
},
/// Package within a monorepo - has a parent workspace
MonorepoPackage { config: Config, parent_config: Config },
}
How would change that? They all share their own Config
. How to continue?
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 personally still break it out to a struct
+ enum
, all have the same config
object at the root, and only when you have a monorepo, there are additional fields.
So a project always has a config, but it may have a parent config (in the case of a package within a monorepo), or may have local dependencies (in case it's the root package) - but have no strong opinion.
The functions could still be there, because the 'root' would change in the case of a monorepo-package, but you'd for instance won't need the get_current_rescript_config
- it would just be x.config
, which makes a lot more sense to me than having an abstraction over a field that exists for all cases.
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.
Come to think of it - I think we can leave it like this - the one property you lose doing this is an easy (and very clear) distinction you can use everywhere, and perhaps that's worth more than this is.
rewatch/src/project_context.rs
Outdated
// See https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum ProjectContext { | ||
/// Single project - no workspace relationship |
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.
Super nice, I like this a lot!
Okay, I'm going to merge this. I want to get it over it. I didn't hear any strong objections to the CLI changes. I think this is fine, but if you're reading this after the merge and still want to discuss, please speak up. |
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.