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

refactor: re-organize code #143

Merged
merged 221 commits into from
Oct 26, 2023
Merged

refactor: re-organize code #143

merged 221 commits into from
Oct 26, 2023

Conversation

KSXGitHub
Copy link
Contributor

@KSXGitHub KSXGitHub commented Oct 6, 2023

Summary

  • Move code that handles package managing to its own crate named pacquet_package_manager.
    • Convert functions with multiple arguments into structs.
  • Make pacquet add reuses the algorithm from pacquet install.
    • Achieved by having pacquet add creates an in-memory package.json and pass it to the Install subroutine.
  • Convert the error-prone tests in crates/cli into proper integration tests that invoke the pacquet binary.
    • Tests become shorter and more readable.
    • Solve race condition issues with cargo test.
  • All code with set_current_dir have been replaced by either integration tests or dependency injection.
    • Solve race condition issues with cargo test.
  • thiserror has been completely removed. derive_more is used in its stead.
    • thiserror cannot handle generic trait bound.
    • derive_more is already used to generate custom string types in the lockfile.
    • one less macro crate leads to slightly faster compile time.
  • pacquet_package_json::PackageJson has been renamed to pacquet_package_manifest::PackageManifest.
  • Other minor changes.

@KSXGitHub KSXGitHub requested review from zkochan and anonrig October 6, 2023 16:14
@anonrig
Copy link
Member

anonrig commented Oct 6, 2023

Can you share the goal of this pull request before any reviews?

@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Attention: 291 lines in your changes are missing coverage. Please review.

Comparison is base (46604f5) 86.73% compared to head (47b3fa0) 86.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #143      +/-   ##
==========================================
- Coverage   86.73%   86.30%   -0.43%     
==========================================
  Files          39       53      +14     
  Lines        2540     2666     +126     
==========================================
+ Hits         2203     2301      +98     
- Misses        337      365      +28     
Files Coverage Δ
crates/cli/src/bin/main.rs 100.00% <100.00%> (+100.00%) ⬆️
crates/cli/src/lib.rs 100.00% <100.00%> (+58.66%) ⬆️
crates/fs/src/lib.rs 100.00% <100.00%> (ø)
crates/lockfile/src/comver.rs 84.00% <ø> (ø)
crates/lockfile/src/dependency_path.rs 100.00% <ø> (ø)
crates/lockfile/src/lib.rs 0.00% <ø> (ø)
crates/lockfile/src/load_lockfile.rs 0.00% <ø> (ø)
crates/lockfile/src/lockfile_version.rs 100.00% <ø> (ø)
crates/lockfile/src/pkg_name.rs 96.87% <ø> (ø)
crates/lockfile/src/pkg_name_suffix.rs 96.87% <ø> (ø)
... and 32 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

crates/package_manager/src/virtual_dir.rs Outdated Show resolved Hide resolved
crates/package_manager/src/virtual_dir.rs Outdated Show resolved Hide resolved
crates/package_manager/src/virtual_dir.rs Outdated Show resolved Hide resolved
@github-actions

This comment was marked as outdated.

@KSXGitHub
Copy link
Contributor Author

Can you share the goal of this pull request before any reviews?

The functions in pacquet_cli were named arbitrarily and placed to arbitrary modules, which make it difficult to navigate (I experienced it when I was doing the last frozen-lockfile PR). Furthermore, I see that pacquet_cli is loaded with responsibilities that aren't part of the CLI (such as fetching packages or modeling the node_modules folder structure). I want to move these code out to appropriate crates, with correct and descriptive names.

@anonrig
Copy link
Member

anonrig commented Oct 16, 2023

It's impossible for me to review this pull request. It's 215 commits with 2000 lines. I recommend splitting the pull request into multiple pull requests.

let command = if let Some(script) = manifest.script("start", true)? {
script
} else {
"node server.js"
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. We need to check for server.js. Here's the error code from pnpm

 ERR_PNPM_NO_SCRIPT_OR_SERVER  Missing script start or file server.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I didn't write this code and it's not related to the goal of refactoring, I have created an issue ticket: #154

@KSXGitHub
Copy link
Contributor Author

@anonrig

It's impossible for me to review this pull request. It's 215 commits with 2000 lines. I recommend splitting the pull request into multiple pull requests.

The PR is about restructuring the codebase. Not sure how splitting them is going to work.

You can read the summary at the top to get an idea of what it does. These bullet points closely depend on each other.

@zkochan
Copy link
Member

zkochan commented Oct 16, 2023

I think it is too late now to split this PR. In the future try to avoid such big PRs. If a PR's goal is to reorganize code then ideally it should only contain changes to file locations and/or parts of code moved between files. With no other changes.

pub manifest: &'a mut PackageManifest,
pub lockfile: Option<&'a Lockfile>,
pub list_dependency_groups: ListDependencyGroups, // must be a function because it is called multiple times
pub package_name: &'a str, // TODO: 1. support version range, 2. multiple arguments, 3. name this `packages`
Copy link
Member

@zkochan zkochan Oct 16, 2023

Choose a reason for hiding this comment

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

it is not a package name because it may have a version or a tag specified too. Like express@1.

in pnpm will call it package_specifier or package_spec. I think npm calls it a package spec.

and I think Yarn calls it package_descriptor.

I would recommend using pnpm's naming conventions. If we decide to change some conventions, then we should change in both repositories.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, it is package_name. The name would change once we add version range to pacquet add, but right now, it only functions as a package name.

@zkochan
Copy link
Member

zkochan commented Oct 16, 2023

I will not post more comments as I don't know what code was just moved and what code is new. I am fine with merging it but in the future let's try to avoid mixing code changes and reorganization in a single PR. And let's try to make smaller PRs.

@zkochan
Copy link
Member

zkochan commented Oct 17, 2023

@anonrig how do you feel about merging this?

@anonrig
Copy link
Member

anonrig commented Oct 17, 2023

@anonrig how do you feel about merging this?

It includes refactoring and new changes that I'm not comfortable with merging. We should split refactoring and new features into separate pull requests.

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

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

It's impossible to review this pull request due to the size and commit count. Please open separate pull request for refactoring and different pull request for each feature.

@KSXGitHub
Copy link
Contributor Author

It's impossible to review this pull request due to the size and commit count. Please open separate pull request for refactoring and different pull request for each feature.

I object. The "features" are interdependent. Separating them will cause merge conflict.

@anonrig
Copy link
Member

anonrig commented Oct 17, 2023

@KSXGitHub The pull request title and description does not mention this new features. How can a reviewer look through 200 commits and properly review them?

@KSXGitHub
Copy link
Contributor Author

KSXGitHub commented Oct 17, 2023

@anonrig #158 is the state of this PR right before @zkochan wrote this comment.

BTW, I have notified you guys in the Discord channel at the very moment this PR was drafted, and I've been pushing commits continuously since. I believe that GitHub should notifies you guys on each commit?

@zkochan
Copy link
Member

zkochan commented Oct 18, 2023

@anonrig I think there is a misunderstanding here. This PR does not contain any changes to the CLI behaviour. All the changes that were done are in the PR description.

Maybe there was a way to do these changes in multiple PRs but now it is too late. There's no easy way to split them and I don't think we want @KSXGitHub to spend time on reapplying the changes from scratch.

I want to assure you that @KSXGitHub is a dedicated contributor that works on pnpm full time, so if we miss something in this PR, Khải will be there to work on the fixes.

@zkochan zkochan requested a review from anonrig October 26, 2023 09:26
@zkochan zkochan merged commit cbdff94 into main Oct 26, 2023
10 of 12 checks passed
@zkochan zkochan deleted the big-refactor branch October 26, 2023 19:34
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.

4 participants