Skip to content

fix(scaffolding): remove partially created project directory on failure#95

Merged
IT-WIBRC merged 1 commit intodevelopfrom
feat/project-scaffolding-cleanup
Oct 4, 2025
Merged

fix(scaffolding): remove partially created project directory on failure#95
IT-WIBRC merged 1 commit intodevelopfrom
feat/project-scaffolding-cleanup

Conversation

@IT-WIBRC
Copy link
Owner

@IT-WIBRC IT-WIBRC commented Oct 4, 2025

Description

This PR addresses a critical issue where a failed dk new command would leave a partially created project directory behind, cluttering the user's workspace with corrupted files.

The fix introduces robust cleanup logic to ensure the project directory is removed if any step in the scaffolding process fails after the directory has been created.

🛠️ Changes Implemented

  1. Cleanup Logic: A try...catch block in scaffoldProject now checks the projectDirCreated flag. If a failure occurs and the directory was internally created (i.e., not by an external CLI like npm create-...), the entire directory is removed using fs.remove().
  2. Logic Separation: The core file acquisition logic was moved from javascript.ts to a new helper function, scaffold-template.ts. This improves modularity and clarifies which parts of the process are responsible for directory creation.
  3. Unit Test Verification: A unit test was added to javascript.test.ts that reliably mocks a dependency installation failure and asserts that the cleanup function (mockFsRemove) is called, proving the safety net works.

🎯 Key Benefit

Users will no longer have to manually clean up directories after a failed attempt to create a project due to network issues, dependency conflicts, or template errors. The CLI now ensures a clean slate on failure.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing feature support current supported languages
  • Any dependent changes have been merged and published in downstream modules

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2025

Coverage Report for ./packages/devkit

Status Category Percentage Covered / Total
🟢 Lines 97.51% (🎯 85%) 3294 / 3378
🟢 Statements 97.51% (🎯 85%) 3294 / 3378
🟢 Functions 96.17% (🎯 90%) 151 / 157
🟢 Branches 93.61% (🎯 85%) 718 / 767
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/devkit/src/core/template/update-project-name.ts 93.75% 80% 100% 93.75% 31-32
packages/devkit/src/scaffolding/javascript.ts 97.56% 91.66% 100% 97.56% 99-100
packages/devkit/src/scaffolding/scaffold-template.ts 100% 100% 100% 100%
packages/devkit/src/utils/logger.ts 95.91% 94.87% 92.85% 95.91% 94-95, 102-103
Generated in workflow #280 for commit d0adef5 by the Vitest Coverage Report Action

@IT-WIBRC IT-WIBRC force-pushed the feat/project-scaffolding-cleanup branch from b5904c7 to d0adef5 Compare October 4, 2025 13:36
@IT-WIBRC IT-WIBRC merged commit f63786d into develop Oct 4, 2025
2 checks passed
@github-actions github-actions bot deleted the feat/project-scaffolding-cleanup branch October 4, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant