Skip to content
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

Refactor FileWatcher into a Class #4916

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

isaacroldan
Copy link
Contributor

@isaacroldan isaacroldan commented Nov 25, 2024

WHY are these changes introduced?

Refactors the file watcher implementation into a class-based structure to improve maintainability and testability of the file watching system used during app development.

WHAT is this pull request doing?

NO NEW FEATURES, mainly a refactor:

  • Converts the file watcher from a function-based to a class-based implementation: the new FileWatcher class
  • Adds proper dependency injection for testing
  • Introduces constants for configuration values
  • Updates tests to use the new class-based structure
  • Remove micromatch, it's not used anymore.

How to test your changes?

  1. Run dev command on an app with multiple extensions
  2. Verify that file changes are properly detected and handled
  3. Create new extensions and verify they are detected
  4. Delete extensions and verify proper cleanup

Measuring impact

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor Author

isaacroldan commented Nov 25, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from cca2ed9 to 4ccf516 Compare November 25, 2024 12:42
Comment on lines +237 to +243
private readonly close = () => {
outputDebug(`Closing file watcher`, this.options.stdout)
this.watcher
?.close()
.then(() => outputDebug(`File watching closed`, this.options.stdout))
.catch((error: Error) => outputDebug(`File watching failed to close: ${error.message}`, this.options.stderr))
}
Copy link

Choose a reason for hiding this comment

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

The close method should remove the event listener that was added to options.signal in the start method. Not removing it could cause memory leaks if the FileWatcher instance is reused, as the old listener would remain attached to the signal.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from 4ccf516 to 7306041 Compare November 25, 2024 12:44
Copy link
Contributor

github-actions bot commented Nov 25, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
75.26% (-0.01% 🔻)
8660/11507
🟡 Branches
70.62% (-0.02% 🔻)
4225/5983
🟡 Functions
74.84% (-0.01% 🔻)
2269/3032
🟡 Lines
75.83% (+0% 🔼)
8191/10802
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / multi-cli-warning.ts
100% 88.89% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / loader.ts
91.88% (-1.39% 🔻)
83.16% (-1.62% 🔻)
96.19% (-0.92% 🔻)
92.62% (-1.53% 🔻)
🟢
... / import-extensions.ts
100%
83.33% (-16.67% 🔻)
100% 100%
🟡
... / identifiers-extensions.ts
75.4% (-1.22% 🔻)
68.66% 100%
76.99% (-1.39% 🔻)
🟢
... / app-event-watcher.ts
93.67% (-1.07% 🔻)
88.57% (-2.34% 🔻)
90.48%
98.59% (+0.06% 🔼)
🟢
... / file-watcher.ts
81.44% (+0.12% 🔼)
70.45% (-1.64% 🔻)
80% (+0.83% 🔼)
85.88% (+0.88% 🔼)
🔴
... / draftable-extension.ts
25.93% (-3.7% 🔻)
25% (-25% 🔻)
9.09%
28% (-4% 🔻)

Test suite run success

1958 tests passing in 888 suites.

Report generated by 🧪jest coverage report action from ff1bc64

@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from 7306041 to d975467 Compare November 25, 2024 14:03
@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch 2 times, most recently from 77a4f78 to 1b4002b Compare November 25, 2024 16:10
@isaacroldan isaacroldan marked this pull request as ready for review November 25, 2024 16:27
@isaacroldan isaacroldan requested a review from a team as a code owner November 25, 2024 16:27
Copy link
Contributor

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch 2 times, most recently from 0899271 to 4536258 Compare November 27, 2024 12:18
@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from 4536258 to ff1bc64 Compare November 27, 2024 14:36
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.

1 participant