-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat: [#576] add package manager functionality #920
base: master
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #920 +/- ##
==========================================
+ Coverage 69.14% 69.34% +0.19%
==========================================
Files 158 168 +10
Lines 10607 11377 +770
==========================================
+ Hits 7334 7889 +555
- Misses 2942 3135 +193
- Partials 331 353 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50
.
Benchmark suite | Current: 72f4028 | Previous: ab139f2 | Ratio |
---|---|---|---|
BenchmarkFile_ReadWrite |
332358 ns/op 2073 B/op 28 allocs/op |
212688 ns/op 2072 B/op 28 allocs/op |
1.56 |
BenchmarkFile_ReadWrite - ns/op |
332358 ns/op |
212688 ns/op |
1.56 |
This comment was automatically generated by workflow using github-action-benchmark.
0b08b3f
to
2946b9b
Compare
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.
Pull Request Overview
This PR introduces package manager functionality to support installation and uninstallation of packages, along with updates to console commands and helper functions for managing Go source modifications. Key changes include:
- New console commands for package:install and package:uninstall.
- Enhancements to package helper logic (modifiers, matchers, and tests) used in configuration and provider registration.
- Updates to the package make command to support a new “manager” flag that generates the package manager files.
Reviewed Changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
foundation/console/package_uninstall_command.go | Implements package uninstallation logic using Go commands. |
foundation/console/package_install_command.go | Implements package installation logic with version handling and tidying. |
packages/* | Introduces new helper, modifier, matcher functions and test cases. |
foundation/console/package_make_command*.go | Adds support for the “manager” flag and updates file generation logic. |
foundation/application.go | Registers new package management commands during application boot. |
Files not reviewed (1)
- go.mod: Language not supported
Comments suppressed due to low confidence (2)
foundation/console/package_make_command_test.go:45
- [nitpick] The test error message for flag type assertions can be made more descriptive by clearly indicating whether the failure is for the manager flag or the root flag. This will help in debugging flag configuration issues.
managerFlag, ok := got.Flags[0].(*command.BoolFlag)
foundation/console/package_make_command.go:34
- [nitpick] Consider enhancing the usage description for the 'manager' flag to more explicitly state its effect (for example, that it creates a manager folder with the necessary files) so that users immediately understand its functionality.
&command.BoolFlag{ Name: "manager", Aliases: []string{"m"}, Usage: "Create a package manager", DisableDefaultText: true, }
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.
Amazing PR 👍
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.
Can we add some test cases for this file? Although It may be a bit complex.
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 will add test case in new PR after merged this one.
info, ok := debug.ReadBuildInfo() | ||
if !ok || !strings.HasSuffix(info.Path, "setup") { | ||
color.Errorln("Package module name is empty, please run command with module name.") | ||
return | ||
} | ||
} | ||
module := filepath.Dir(info.Path) | ||
force := len(os.Args) == 3 && (os.Args[2] == "--force" || os.Args[2] == "-f") |
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.
Can these lines be moved to a common function of goravel/framework? There should only be a setup configuration in this file, reduce other code as much as possible. To avoid the problem of the code being changed in the future.
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 is to get the current package’s module name, i.e., import path. I’m not quite sure how to move it to the framework.
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 make an example.
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 have some thoughts on this. Let me try making some changes.
if len(os.Args) > 1 { | ||
execute(pkg, os.Args[1]) | ||
} | ||
} | ||
if len(os.Args) > 1 && os.Args[1] == "install" { | ||
err := pkg.Install(dir) | ||
if err != nil { | ||
color.Errorln(err) | ||
return | ||
} | ||
color.Successf("Package %s installed successfully\n", module) | ||
func execute(pkg pkgcontracts.Setup, command string) { | ||
var err error | ||
switch command { | ||
case "install": | ||
err = pkg.Install() | ||
case "uninstall": | ||
err = pkg.Uninstall() | ||
default: | ||
return | ||
} | ||
if len(os.Args) > 1 && os.Args[1] == "uninstall" { | ||
err := pkg.Uninstall(dir) | ||
if err != nil { | ||
color.Errorln(err) | ||
return | ||
} | ||
color.Successf("Package %s uninstalled successfully\n", module) | ||
if err != nil { | ||
color.Errorln(err) | ||
os.Exit(1) | ||
} | ||
} | ||
color.Successf("Package %sed successfully\n", command) | ||
} |
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.
Ditto
66aabcc
to
446e763
Compare
📑 Description
This feature introduces a package manager to handle the installation and uninstallation of packages within the framework. A
setup
folder is created in the package repository’s root directory, containing thesetup.go
file. Thesetup.go
file handles key package management operations such as registering providers, adding configuration settings, and modifying Go files in the project.The part of the package manager responsible for registering providers is automatically handled when creating a new package using the
artisan make:package
command. This ensures that the necessary providers are registered in the configuration files when installing a new package. For example, when installing the Redis package (github.com/goravel/redis), the ServiceProvider for Redis is added to config/app.go.For example, using the Redis package (github.com/goravel/redis) as a case study, the package manager performs the following tasks:
config/app.go
file to register the Redis service provider, ensuring that Redis is available for use throughout the application.config/cache.go
andconfig/queue.go
to include necessary imports, configuration options, and Redis drivers, enabling caching and queue functionalities powered by Redis.app.go
,cache.go
, andqueue.go
.The installation and uninstallation processes are executed via command line, providing a simple and efficient way to manage packages. To install a package, run:
To uninstall the package, run:
Additionally, the package manager supports a
--force (-f)
flag, which allows the installation process to proceed even if errors are encountered.The
setup.go
file in the manager folder is responsible for managing the core functionality of the package manager. Below is the complete example code for themanager.go
file:This feature also supports local package installation. For example, a local package can be created using:
Then, the package can be installed using the package manager:
Closes goravel/goravel#576?
@coderabbitai summary
✅ Checks