Skip to content

Conversation

@mizdra
Copy link
Owner

@mizdra mizdra commented Nov 3, 2025

close: #178

Design Notes:

  • Mimics the behavior of tsc --watch
  • Does not watch changes to tsconfig.json
    • This is for implementation simplicity
  • Uses chokidar for file watching
    • Considered using ts.sys.watchDirectory. However, it was unclear whether this API would be provided in ts-go, so it was not adopted.
  • File watching is handled by the runCMKInWatchMode function.
    • runCMKInWatchMode delegates most processing to Project.
    • Project is used by both the runCMK function for normal mode and the runCMKInWatchMode function for watch mode. It implements the common logic for both modes.
    • Through Project, CSS Module files are parsed and inspected, diagnostics are reported, and .d.ts files are emitted.
    • Project maintains internal caches for the parsing, checking, and emitting stages. When notified of file changes by runCMKInWatchMode, it discards the relevant caches.
    • See also Refactor the runner by introducing Project #276
  • Currently, it excessively discards the cache during the check stage when files are updated.
    • Plans to improve this in the future.

@mizdra mizdra added the Type: Add Add new features. label Nov 3, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2025

🦋 Changeset detected

Latest commit: 5a3b590

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@css-modules-kit/codegen Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mizdra mizdra force-pushed the implement-watch-mode branch 3 times, most recently from 869ea8e to 56f6254 Compare November 3, 2025 15:36
@mizdra mizdra force-pushed the implement-watch-mode branch from 56f6254 to 04e1b6e Compare November 3, 2025 15:47
@mizdra
Copy link
Owner Author

mizdra commented Nov 3, 2025

TODO: Add tests for runCMKInWatchMode and Project

emitAndReportDiagnosticsTimer = setTimeout(() => {
emitAndReportDiagnosticsTimer = undefined;
emitAndReportDiagnostics().catch(logger.logError.bind(logger));
}, 250);
Copy link
Owner Author

Choose a reason for hiding this comment

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

* @throws {WriteDtsFileError}
*/
async function emitAndReportDiagnostics() {
logger.clearScreen();
Copy link
Owner Author

Choose a reason for hiding this comment

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

Some users may not want the console cleared. We may need to add the --preserveWatchOutput option.

logger.logDiagnostics(diagnostics);
}
logger.logMessage(
`Found ${diagnostics.length} error${diagnostics.length === 1 ? '' : 's'}. Watching for file changes.`,
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is exactly the same format as tsc messages. Users may find it difficult to distinguish whether a message is from tsc or css-modules-kit...

@mizdra mizdra force-pushed the implement-watch-mode branch from bb76ec3 to 858661d Compare November 4, 2025 15:43
@mizdra mizdra force-pushed the implement-watch-mode branch from 352dd22 to 615dc2c Compare November 4, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Add Add new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support --watch mode

2 participants