-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
chore: Remove shelljs
from appsmithctl
#37401
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces significant modifications to the Changes
Possibly related PRs
Suggested reviewers
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
Documentation and Community
|
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: 2
🧹 Outside diff range and nitpick comments (4)
deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js (1)
7-10
: Consider adding edge cases for the echo command test.While the basic test is good, consider adding cases for empty input and special characters.
+ test("Output of echo with empty input", async () => { + const result = await utils.execCommandReturningOutput(["echo", ""]); + expect(result).toBe(""); + }); + + test("Output of echo with special characters", async () => { + const result = await utils.execCommandReturningOutput(["echo", "hello$world\n"]); + expect(result).toBe("hello$world\\n"); + });deploy/docker/fs/opt/appsmith/utils/bin/index.js (1)
Line range hint
14-18
: Consider consolidating duplicate environment variable handling logicThe APPSMITH_DB_URL fallback logic is duplicated before and after loading the .env file. While this might be intentional, consider consolidating this into a single function for better maintainability.
+function ensureDbUrl() { + if (!process.env.APPSMITH_DB_URL) { + process.env.APPSMITH_DB_URL = process.env.APPSMITH_MONGODB_URI; + delete process.env.APPSMITH_MONGODB_URI; + } +} -// Check if APPSMITH_DB_URL is set, if not set, fall back to APPSMITH_MONGODB_URI -if (!process.env.APPSMITH_DB_URL) { - process.env.APPSMITH_DB_URL = process.env.APPSMITH_MONGODB_URI; - delete process.env.APPSMITH_MONGODB_URI; -} +ensureDbUrl(); // Loading latest application configuration require("dotenv").config({ path: APPLICATION_CONFIG_PATH }); -// AGAIN: Check if APPSMITH_DB_URL is set, if not set, fall back to APPSMITH_MONGODB_URI -if (!process.env.APPSMITH_DB_URL) { - process.env.APPSMITH_DB_URL = process.env.APPSMITH_MONGODB_URI; - delete process.env.APPSMITH_MONGODB_URI; -} +ensureDbUrl();Also applies to: 21-25
🧰 Tools
🪛 Biome
[error] 43-43: Illegal return statement outside of a function
(parse)
deploy/docker/fs/opt/appsmith/utils/bin/utils.js (1)
94-121
: LGTM! Well-structured command execution implementation.The implementation properly handles command execution, output collection, and error cases. A few suggestions to make it more robust:
Consider these improvements:
function execCommandReturningOutput(cmd, options) { return new Promise((resolve, reject) => { const p = childProcess.spawn(cmd[0], cmd.slice(1), options); - - p.stdin.end() + // Handle spawn errors + p.on("error", (err) => { + reject(`Failed to start command: ${err.message}`); + }); + + if (p.stdin) { + p.stdin.end(); + } const outChunks = [], errChunks = [];deploy/docker/fs/opt/appsmith/utils/bin/import_db.js (1)
6-14
: Standardize logging messagesConsider updating the log statements for consistency and clarity.
Apply this diff:
- console.log('import_database ....') + console.log('Starting database import...') ... - console.log('import_database done') + console.log('Database import completed.')
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
deploy/docker/fs/opt/appsmith/utils/package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (5)
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js
(2 hunks)deploy/docker/fs/opt/appsmith/utils/bin/index.js
(1 hunks)deploy/docker/fs/opt/appsmith/utils/bin/utils.js
(2 hunks)deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js
(1 hunks)deploy/docker/fs/opt/appsmith/utils/package.json
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- deploy/docker/fs/opt/appsmith/utils/package.json
🔇 Additional comments (8)
deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js (4)
5-6
: LGTM! Clear test suite structure.
12-15
: LGTM! Clear stdout verification.
17-20
: LGTM! Clear stderr verification.
22-30
: Verify output ordering assumptions across environments.
The tests assume stdout always appears before stderr in the output string, regardless of the actual order of operations. This might not be consistent across different Node.js versions or operating systems.
deploy/docker/fs/opt/appsmith/utils/bin/index.js (1)
41-41
: LGTM! Method rename looks good.
The change from runImportDatabase
to run
aligns with the PR objective and maintains consistent parameter passing.
deploy/docker/fs/opt/appsmith/utils/bin/utils.js (2)
228-228
: LGTM! Export added correctly.
The new function is properly exported in the module exports.
94-121
: Verify complete removal of shelljs dependency.
Since this function is part of the shelljs removal effort, let's verify there are no remaining shelljs usages.
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js (1)
62-62
: 🛠️ Refactor suggestion
Avoid using process.exit()
in asynchronous code
Calling process.exit()
can interrupt pending asynchronous operations. Consider allowing the process to exit naturally or handle termination more gracefully.
Apply this diff:
- process.exit(errorCode)
Likely invalid or redundant comment.
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 (2)
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js (2)
27-38
: Improve robustness of command output parsingWhile error handling is good, the command output parsing could be more robust.
- const shellCmdResult = await utils.execCommandReturningOutput([ + const { stdout } = await utils.execCommandReturningOutput([ "mongo", process.env.APPSMITH_DB_URL, "--quiet", "--eval", "db.getCollectionNames().length", ]); } catch (error) { console.error("Failed to execute mongo command:", error); throw error; } - const collectionsLen = parseInt(shellCmdResult.stdout.toString().trimEnd()) + const output = stdout.toString().trimEnd(); + const collectionsLen = Number.isInteger(parseInt(output)) ? parseInt(output) : 0;
Line range hint
42-58
: Reduce code duplication in import logicThe importDatabase call is repeated in multiple places. Consider consolidating the logic.
+ async function performImport() { + await importDatabase(); + return; + } + if (collectionsLen > 0) { if (forceOption) { - await importDatabase() + await performImport(); return } console.log() console.log('**************************** WARNING ****************************') console.log(`Your target database is not empty, it has data in ${collectionsLen} collections.`) const input = readlineSync.question('Importing this DB will erase this data. Are you sure you want to proceed?[Yes/No] ') const answer = input && input.toLocaleUpperCase() if (answer === 'Y' || answer === 'YES') { - await importDatabase() + await performImport(); return } else if (answer === 'N' || answer === 'NO') { return } console.log(`Your input is invalid. Please try to run import command again.`) } else { - await importDatabase() + await performImport(); }🧰 Tools
🪛 Biome
[error] 49-49: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js
(2 hunks)deploy/docker/fs/opt/appsmith/utils/bin/index.js
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- deploy/docker/fs/opt/appsmith/utils/bin/index.js
🔇 Additional comments (2)
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js (2)
19-22
: LGTM! Good initialization with supervisor check
The supervisor check before proceeding with operations is a good practice.
60-71
: LGTM! Good error handling and cleanup
The cleanup in the finally block ensures services are restarted regardless of import success or failure.
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 (2)
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js (2)
Line range hint
29-64
: Simplify nested conditionals and error handlingThe current implementation has deep nesting which affects readability. Consider extracting the database check into a separate function.
+async function checkDatabaseCollections() { + try { + const shellCmdResult = await utils.execCommandReturningOutput([ + "mongo", + process.env.APPSMITH_DB_URL, + "--quiet", + "--eval", + "db.getCollectionNames().length", + ]); + return parseInt(shellCmdResult.stdout.toString().trimEnd()); + } catch (error) { + console.error("Failed to execute mongo command:", error); + throw error; + } +} async function run(forceOption) { // ... supervisor check ... try { await utils.stop(["backend", "rts"]); - try { - const shellCmdResult = // ... current implementation - } catch (error) { - console.error("Failed to execute mongo command:", error); - throw error; - } - const collectionsLen = parseInt(shellCmdResult.stdout.toString().trimEnd()) + const collectionsLen = await checkDatabaseCollections(); if (collectionsLen > 0 && !forceOption) { // ... rest of the code ... }
65-72
: Enhance error logging for better debuggingConsider adding more context to error logs to help with troubleshooting.
} catch (err) { - console.log(err) + console.error('Database import failed with error:', err.message); + console.error('Stack trace:', err.stack); errorCode = 1 }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js
(2 hunks)
🔇 Additional comments (2)
deploy/docker/fs/opt/appsmith/utils/bin/import_db.js (2)
6-20
: LGTM! Clean async implementation with proper error handling.
74-77
: LGTM! Clean exports following the function rename.
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Remove
shelljs
dependency fromappsmithctl
, instead using our own much smaller utility functions to run external commands.Now
esbuild
should be able to buildappsmithctl
project nicely! For a future PR.Automation
/test sanity
🔍 Cypress test results
Warning
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11857542672
Commit: a2d5a61
Cypress dashboard.
Tags: @tag.Sanity
Spec:
It seems like no tests ran 😔. We are not able to recognize it, please check workflow here.
Fri, 15 Nov 2024 13:58:27 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores