Skip to content

Conversation

@Harjun751
Copy link
Contributor

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:

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:

Testing instructions:

Proposed commit message: (wrap lines at 72 characters)

Make cleaning in CLI respect 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).

@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 (ef59958).

Files with missing lines Patch % Lines
packages/cli/src/util/cliUtil.js 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2810      +/-   ##
==========================================
+ Coverage   71.83%   71.85%   +0.02%     
==========================================
  Files         134      134              
  Lines        7331     7340       +9     
  Branches     1622     1539      -83     
==========================================
+ 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 changes how the CLI cleans up the _markbind directory after a failed build/serve so that it uses non-recursive directory removal and preserves directory structure when files already exist, and extends unit tests to cover these scenarios.

Changes:

  • Updated cleanupFailedMarkbindBuild to delete _markbind/logs and _markbind using fs.rmdirSync, ignoring errors and only removing empty directories.
  • Added tests to verify that _markbind/logs and _markbind are preserved when they contain files, and that an empty logs directory is removed while a non-empty _markbind is kept.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/cli/src/util/cliUtil.js Adjusts cleanupFailedMarkbindBuild to attempt non-recursive deletion of _markbind/logs and then _markbind, thereby only removing them when empty.
packages/cli/test/unit/cliUtil.test.js Extends unit tests to cover preservation of _markbind and logs when they contain files, and removal of an empty logs directory while keeping a non-empty _markbind.

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

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

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


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

Comment on lines 27 to +51
cleanupFailedMarkbindBuild: () => {
const markbindDir = path.join(process.cwd(), '_markbind');
if (fs.pathExistsSync(markbindDir)) {
// delete _markbind/ folder and contents
fs.rmSync(markbindDir, { recursive: true, force: true });
}
const logsDir = path.join(markbindDir, 'logs');

tryDeleteFolder(logsDir);
tryDeleteFolder(markbindDir);
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

With the new non-recursive tryDeleteFolder implementation, cleanupFailedMarkbindBuild will never successfully delete a non-empty _markbind directory: fs.rmdirSync(markbindDir) will always throw ENOTEMPTY when _markbind contains any files or subdirectories, and that error is intentionally swallowed. This means that in common failure scenarios where _markbind already has contents (not just logs), no cleanup actually happens, which contradicts the intent of this helper and the existing tests. Consider either retaining recursive deletion when you know _markbind was created by this failed run, or otherwise tightening the heuristic (for example, only attempting to clean when the directory tree is known/verified to contain only MarkBind-created artifacts) so that we still remove transient build artifacts while preserving pre-existing user content.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is intended behavior. I don't think there's quite a mechanism for us to find out whether the folder was just-created in this run? If there is LMK. But I think for now this is OK?

@Harjun751 Harjun751 marked this pull request as draft January 30, 2026 02:24
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.
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

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


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

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.

Clean up created logs on failed markbind serve

1 participant