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

[Upgrade Tool] V2 #18990

Closed
wants to merge 195 commits into from
Closed

[Upgrade Tool] V2 #18990

wants to merge 195 commits into from

Conversation

Convly
Copy link
Member

@Convly Convly commented Dec 6, 2023

What does it do?

  • Modified the CLI usage to match new criterias
    • upgrade Don't do anything and display the help
    • upgrade major Will try upgrading to the next available major (only if the project is already on the latest minor.patch version for the current major), if none is found, it'll abort
    • upgrade minor todo in another PR
    • upgrade patch todo in another PR
  • Refactored the overall structure of the upgrade package
    • src/cli/index.ts contains the overall definition of the CLI usage
    • src/cli/commands contains actual commands' definitions, including the one for the upgrade
    • The upgrade task is defined in the src/tasks directory and is directly called by the upgrade command
    • Every domain-related piece of logic has been split as individual modules available at src/modules/*
      • Each module has a consistent folder structure that can contain:
        • types.ts exports types related to the module
        • constants.ts exports constants related to the module
        • xyz.ts contains domain logic related to the module (usually it exports a factory to create related domain objects. e.g: xyzFactory())
        • index.ts is considered the public module API and only exports what can be used by anyone outside the module
        • A __tests__/ directory which contains domain-related tests
  • Added unit tests
  • Fixed lint & build issues
  • Bumped fs-extra from 10.0.0 to 10.1.0 to fix compatibility issues with memfs which is used for mocking fs during tests (see fs-extra's changelog and related issue / fix PR)

Why is it needed?

After discussing at length the scope of the upgrade tool internally, we've decided to modify it a bit (mainly related to available commands, options, and how they should behave)

This PR aims to refactor the tool to incorporate those changes while cleaning up the overall architecture.

How to test it?

  • Make sure your monorepository is up-to-date (install, setup, etc...)
  • From the examples/getstarted directory, use ../../packages/utils/upgrade/bin/upgrade.js <command> [...options] to test the upgrade CLI

Convly and others added 30 commits October 25, 2023 13:45
@Convly Convly force-pushed the features/upgrade-tool branch 2 times, most recently from e85a23d to 24dabd2 Compare December 6, 2023 16:38
Copy link
Contributor

@innerdvations innerdvations left a comment

Choose a reason for hiding this comment

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

I think some of these comments are already outdated from the time I started the review.

Anyway, looks great, just a few comments!

const versionDirectory = path.join(this.cwd, literalVersion);

// Ignore obsolete versions
if (!fse.existsSync(versionDirectory)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to avoid sync methods, I've actually started removing them for v5 where possible and will eventually be adding a linting rule for them. But considering this is a CLI and every step is in series, it's not necessarily bad, so I can live with it (and it could ignore the future lint rule)

Copy link
Member Author

@Convly Convly Dec 6, 2023

Choose a reason for hiding this comment

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

I don't mind using the async ones, I don't why I believed the performance hint was on async ones 🤔

(<> thought the io blocking was on the async)

});
};

addReleaseUpgradeCommand(
Copy link
Contributor

Choose a reason for hiding this comment

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

This way, each type (major, minor, patch) has its own options and help command and has to import the upgrade.js for each. Are we really going to be having different options for major/minor/patch or could we just have one command with an argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally, we won't have different options between each command, but since the specs indicate 3 different paths, I prefer having them separated in 3 commands to handle possible divergences in the future + it doesn't cost us anything right now

@@ -0,0 +1,17 @@
export class UnexpectedError extends Error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we expect to have other kinds of errors to be added here? I'm not sure why we need this

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly it was just something I've bootstrapped now, but I plan on replacing every error with throw with custom ones so that it's easier to catch specific errors & understand where they're originating from

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like that we've built our own timer, but it's pretty small I guess. We should eventually move it to @strapi/utils later and use it for other cli timers (like in pack-up, which has its own timer too)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the idea, but honestly I didn't want this PR to become overcomplicated, we can handle refactoring of common utils in another PR

Copy link
Contributor

@innerdvations innerdvations left a comment

Choose a reason for hiding this comment

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

I think some of these comments are already outdated from the time I started the review.

Anyway, looks great, just a few comments!

@innerdvations innerdvations self-requested a review December 6, 2023 16:38
@Convly Convly mentioned this pull request Dec 6, 2023
@Convly
Copy link
Member Author

Convly commented Dec 6, 2023

Closing in favor of #18995

@innerdvations could you transpose your comment there? Otherwise I can just answer them here and act on the other PR

@Convly Convly closed this Dec 6, 2023
@Convly Convly deleted the upgrade-tool/refactor branch December 8, 2023 08:24
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.

None yet

6 participants