Skip to content

Conversation

@Harjun751
Copy link
Contributor

@Harjun751 Harjun751 commented Jan 30, 2026

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

This is a re-PR over #2810.
Wanted to try out cherry-picking, and that PR had a lot of visual noise from my repeated poking of Copilot.

Resolves #2767

Overview of changes:
Update CLI clean functionality to use rmdir instead of a force delete. This preserves the folder structure in the situation where files already exist in them. Added test cases to account for this case.

Anything you'd like to highlight/discuss:
There is one instance in the cliUtil where I use console.warn to print out a warning message. It should only occur when the system fails to delete an empty directory for an unexpected reason (e.g. permissions). I specifically use console because it felt odd to me to import and create a new instance of logger (which we're cleaning up after in that context...).

Relevant snippet:

try {
    fs.rmdirSync(pathName);
  } catch (error) {
    // If directory is not empty, fail silently
    if (error.code !== DIR_NOT_EMPTY_ERROR_CODE) {
      // Warn for other unexpected errors
      // Use `console` instead of logger as we don't want to create a new logger instance
      // that might pollute the working directory again.
      // eslint-disable-next-line no-console
      console.warn(`WARNING: Failed to delete directory ${pathName}: ${error.message}`);
    }
  }

Testing instructions:

Proposed commit message: (wrap lines at 72 characters)

Update CLI clean function to preserve existing files


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Reviewer checklist:

Indicate the SEMVER impact of the PR:

  • Major (when you make incompatible API changes)
  • Minor (when you add functionality in a backward compatible manner)
  • Patch (when you make backward compatible bug fixes)

At the end of the review, please label the PR with the appropriate label: r.Major, r.Minor, r.Patch.

Breaking change release note preparation (if applicable):

  • To be included in the release note for any feature that is made obsolete/breaking

Give a brief explanation note about:

  • what was the old feature that was made obsolete
  • any replacement feature (if any), and
  • how the author should modify his website to migrate from the old feature to the replacement feature (if possible).

cliUtil tests use nested JSON structure to
pass intended mocked structure to memfs'
fromJSON method.

This method does not parse nested JSON
properly and carries on silently, resulting
in misleading test results.

Update test suite to not use nested JSON
where possible, and where necessary
use .fromNestedJSON instead.
@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.85%. Comparing base (6da5bc9) to head (b2705a9).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
packages/cli/src/util/cliUtil.js 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2811      +/-   ##
==========================================
+ Coverage   71.83%   71.85%   +0.02%     
==========================================
  Files         134      134              
  Lines        7331     7340       +9     
  Branches     1622     1503     -119     
==========================================
+ Hits         5266     5274       +8     
- Misses       1937     2020      +83     
+ Partials      128       46      -82     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a 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 fixes a bug where MarkBind CLI creates a _markbind/logs directory during markbind serve that doesn't get cleaned up when the command fails on an invalid folder. The fix changes the cleanup strategy from force-deleting directories to using rmdir, which only removes empty directories, thereby preserving any existing user files.

Changes:

  • Replaced fs.rmSync() with fs.rmdirSync() in a new tryDeleteFolder() helper function that silently skips non-empty directories
  • Added comprehensive test cases covering empty directories, non-empty directories, and partial cleanup scenarios
  • Included unrelated package-lock.json updates (peer dependency flags and optional encoding package)

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/cli/src/util/cliUtil.js Introduced tryDeleteFolder() function using rmdirSync() to delete only empty directories, with error handling for non-empty directories
packages/cli/test/unit/cliUtil.test.js Updated and added test cases to verify the new behavior of preserving non-empty directories during cleanup
package-lock.json Contains numerous peer dependency flag changes and adds an optional encoding package (appears unrelated to the main fix)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@gerteck gerteck left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @Harjun751

@gerteck gerteck merged commit b956547 into MarkBind:master Jan 30, 2026
16 checks passed
@github-actions
Copy link

@gerteck Each PR must have a SEMVER impact label, please remember to label the PR properly.

@gerteck gerteck added the r.Patch Version resolver: increment by 0.0.1 label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r.Patch Version resolver: increment by 0.0.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up created logs on failed markbind serve

2 participants