Skip to content

removeStaleFiles - also remove stale directories - #408

Merged
luisfpg merged 1 commit into
cyclosproject:masterfrom
StavNoyAkur8:fix/stale-fn-files
Sep 23, 2026
Merged

luisfpg merged 1 commit into
cyclosproject:masterfrom
StavNoyAkur8:fix/stale-fn-files

Conversation

@StavNoyAkur8

@StavNoyAkur8 StavNoyAkur8 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Why

With the removeStaleFiles option set to true (the default), extra files in the output directory are removed.
But there might also be stale directories. A directory that disappears from the generated tree (e.g. fn/<tag>/ after the last operation for that tag is removed, or a namespaced models/<namespace>/) is left behind forever, along with everything inside it.

Fixes #399.

What

  • In syncDirs (lib/gen-utils.ts), next to the existing code for removing stale files, add a branch to remove stale directories via the existing deleteDirRecursive helper.
  • Widened the removeStaleFiles description in lib/options.ts and ng-openapi-gen-schema.json to mention directories.
  • Added test/removeStaleFiles.spec.ts (+ fixtures) covering both the default behavior (stale directory removed) and the removeStaleFiles: false opt-out (directory preserved).

Verified with npm run build (lint + compile + full test suite, all green) and a manual end-to-end run of the exact repro from the issue.

syncDirs only unlinked stale files, so a directory that disappeared
from the generated tree (e.g. fn/<tag> after removing the last
operation for that tag) was never cleaned up, along with everything
inside it.

Fixes #399
Comment thread lib/gen-utils.ts
Comment on lines +446 to +449
if (stat.isDirectory()) {
deleteDirRecursive(destFile);
logger.debug('Removed stale directory ' + destFile);
} else if (stat.isFile()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: I'm using the in-house deleteDirRecursive() here for consistency.
It would probably be simpler and more performant to use fs-extra's removeSync(), (or just plain fs.rmSymc({ recursive: true, force: true })), without needing lstat anymore

@StavNoyAkur8 StavNoyAkur8 changed the title Recurse into stale directories so they get deleted, not just skipped removeStaleFiles - Include stale directories Aug 5, 2026
@StavNoyAkur8 StavNoyAkur8 changed the title removeStaleFiles - Include stale directories removeStaleFiles - also remove stale directories Aug 5, 2026
@luisfpg
luisfpg merged commit 7007dda into cyclosproject:master Sep 23, 2026
@StavNoyAkur8
StavNoyAkur8 deleted the fix/stale-fn-files branch September 23, 2026 09:08
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.

Stale files within fn/ do not get deleted

2 participants