-
-
Notifications
You must be signed in to change notification settings - Fork 113
feat(repl): add CLI option to specify custom zenstack load path #1823
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
📝 WalkthroughWalkthroughThe changes in this pull request enhance the REPL command in the CLI by introducing a new optional parameter Changes
Assessment against linked issues
Possibly related PRs
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 (
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (4)
packages/schema/src/cli/index.ts (1)
136-137
: LGTM! Consider enhancing the help text.The new CLI options effectively address issue #1768 by allowing users to specify custom paths for ZenStack modules and Prisma client. The implementation is clean and follows CLI conventions.
Consider enhancing the help text with examples:
-.option('--load-path <path>', 'path to load modules generated by ZenStack') -.option('--prisma-client <path>', 'path to Prisma client module') +.option('--load-path <path>', 'path to load modules generated by ZenStack (e.g., "./generated")') +.option('--prisma-client <path>', 'path to Prisma client module (e.g., "./generated/client")')packages/schema/src/cli/actions/repl.ts (3)
12-14
: Add path validation for loadPath option.While the path handling is implemented correctly, consider adding validation for the
loadPath
option to ensure it exists and is accessible before attempting to require the module. This would provide better error messages to users.const { enhance } = options.loadPath - ? require(path.join(path.resolve(options.loadPath), 'enhance')) + ? (() => { + const resolvedPath = path.resolve(options.loadPath!); + if (!fs.existsSync(resolvedPath)) { + throw new Error(`Load path ${options.loadPath} does not exist`); + } + return require(path.join(resolvedPath, 'enhance')); + })() : require('@zenstackhq/runtime');Also applies to: 55-57
151-162
: Enhance error handling in auth command.The auth command implementation is good, but the error handling could be more specific to help users understand what went wrong.
- } catch (err: any) { - console.error('Unable to set auth user:', err.message); + } catch (err: any) { + if (err instanceof SyntaxError) { + console.error('Invalid user object syntax. Example: .auth { id: "123" }'); + } else if (err instanceof TypeError) { + console.error('Invalid user object structure. Must be a valid object with required fields.'); + } else { + console.error('Unable to set auth user:', err.message); + }
12-15
: Add JSDoc documentation for the new loadPath option.The new
loadPath
option is a significant feature addition that deserves proper documentation./** * CLI action for starting a REPL session + * @param projectPath - Path to the project root + * @param options - Configuration options + * @param options.loadPath - Optional path to load ZenStack generated modules from + * @param options.prismaClient - Optional path to Prisma client module + * @param options.debug - Enable debug mode + * @param options.table - Enable table output format */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
packages/schema/src/cli/actions/repl.ts
(4 hunks)packages/schema/src/cli/index.ts
(1 hunks)
🧰 Additional context used
🪛 Biome
packages/schema/src/cli/actions/repl.ts
[error] 75-75: eval() exposes to security risks and performance issues.
See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().
(lint/security/noGlobalEval)
🔇 Additional comments (1)
packages/schema/src/cli/index.ts (1)
136-137
: Verify integration with repl action implementation.
Let's ensure the new options are properly handled in the repl action implementation.
✅ Verification successful
Both new options are properly integrated in the REPL implementation
The verification shows that both loadPath
and prismaClient
options are correctly handled in the REPL implementation:
loadPath
is used to load the enhancement module (lines 56-58)prismaClient
is used to load the Prisma client module (lines 35-47)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that the repl action properly handles the new options
# Test: Check if repl action implementation accepts these options
ast-grep --pattern 'export const repl = async ($params) => {
$$$
}'
# Test: Look for option usage in the repl implementation
rg -l "loadPath|prisma-client" --type typescript
Length of output: 157
Script:
#!/bin/bash
# Let's try different approaches to find the repl implementation and option usage
# Find files containing 'repl' function or command
rg -l "repl" --type ts
# Look for option usage with different patterns
rg -l "load-path|prismaClient|loadPath" --type ts
# Try to find the repl implementation using ast-grep with a more specific pattern
ast-grep --pattern 'export const repl = async (options: $_) => {
$$$
}'
# Also search for command registration pattern
ast-grep --pattern 'program
.command("repl")
$$$'
Length of output: 2846
Script:
#!/bin/bash
# Let's examine the repl action implementation in packages/schema/src/cli/actions/repl.ts
# Show the repl implementation to check option handling
cat packages/schema/src/cli/actions/repl.ts
# Also check the types/interfaces for the options
ast-grep --pattern 'interface $_ {
$$$
loadPath?: $_
$$$
}'
ast-grep --pattern 'interface $_ {
$$$
prismaClient?: $_
$$$
}'
Length of output: 9495
fixes #1768