Skip to content

Commit 65238cd

Browse files
committed
reduce reproduction code
1 parent 2ad7898 commit 65238cd

2 files changed

Lines changed: 5 additions & 34 deletions

File tree

packages/codegen/src/runner.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ describe('runCMKInWatchMode', () => {
2828
// To avoid test flakiness, wait for a short time before starting the watcher.
2929
await sleep(100);
3030

31-
const loggerSpy = createLoggerSpy();
32-
await runCMKInWatchMode(fakeParsedArgs({ project: iff.rootDir }), loggerSpy);
31+
await runCMKInWatchMode(iff.rootDir);
3332

3433
// Workaround for https://github.com/paulmillr/chokidar/issues/1443
3534
if (platform === 'darwin') {

packages/codegen/src/runner.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import type { Stats } from 'node:fs';
21
import chokidar, { type FSWatcher } from 'chokidar';
3-
import type { Logger } from './logger/logger.js';
4-
import { createProject, type Project } from './project.js';
5-
6-
interface RunnerArgs {
7-
project: string;
8-
clean: boolean;
9-
}
2+
import { type Project } from './project.js';
103

114
export interface Watcher {
125
/** Exported for testing purposes */
@@ -27,36 +20,17 @@ export interface Watcher {
2720
* @throws {WriteDtsFileError}
2821
* @throws {WatchInitializationError}
2922
*/
30-
export async function runCMKInWatchMode(args: RunnerArgs, logger: Logger): Promise<Watcher> {
23+
export async function runCMKInWatchMode(rootDir: string): Promise<void> {
3124
const fsWatchers: FSWatcher[] = [];
32-
const project = createProject(args);
3325

3426
// Watch project files and report diagnostics on changes
3527
const readyPromises: Promise<void>[] = [];
36-
for (const wildcardDirectory of project.config.wildcardDirectories) {
28+
for (const wildcardDirectory of [{ fileName: rootDir }]) {
3729
const { promise, resolve } = promiseWithResolvers<void>();
3830
readyPromises.push(promise);
3931
fsWatchers.push(
4032
chokidar
41-
.watch(wildcardDirectory.fileName, {
42-
ignored: (fileName: string, stats?: Stats) => {
43-
// The ignored function is called twice for the same path. The first time with stats undefined,
44-
// and the second time with stats provided.
45-
// In the first call, we can't determine if the path is a directory or file.
46-
// So we include it in the watch target considering it might be a directory.
47-
if (!stats) return false;
48-
49-
// In the second call, we include directories or files that match wildcards in the watch target.
50-
// However, `dtsOutDir` is excluded from the watch target.
51-
if (stats.isDirectory()) {
52-
return fileName === project.config.dtsOutDir;
53-
} else {
54-
return !project.isWildcardMatchedFile(fileName);
55-
}
56-
},
57-
ignoreInitial: true,
58-
...(wildcardDirectory.recursive ? {} : { depth: 0 }),
59-
})
33+
.watch(wildcardDirectory.fileName, { ignoreInitial: true })
6034
.on('change', (fileName) => {
6135
console.log('change event: ', fileName);
6236
if (fileName.endsWith('a.module.css')) {
@@ -70,8 +44,6 @@ export async function runCMKInWatchMode(args: RunnerArgs, logger: Logger): Promi
7044
);
7145
}
7246
await Promise.all(readyPromises);
73-
74-
return { project };
7547
}
7648

7749
function promiseWithResolvers<T>() {

0 commit comments

Comments
 (0)