Skip to content

Commit 1361708

Browse files
unhappychoiceclaude
andcommitted
chore(deps): bump chokidar from 4.0.3 to 6.0.0
chokidar 5 is ESM-only and chokidar 6 requires Node.js 22.22+. - Switch tsconfig module to node20 so the CommonJS build can require() the ESM-only package - Use the named watch export, since require(esm) does not provide the esModuleInterop default - Declare engines.node >=22.22 to match chokidar's requirement Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b4e6341 commit 1361708

6 files changed

Lines changed: 44 additions & 224 deletions

File tree

‎package-lock.json‎

Lines changed: 13 additions & 192 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"description": "A markdown preview server.",
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
8+
"engines": {
9+
"node": ">=22.22"
10+
},
811
"bin": {
912
"mdts": "./bin/mdts"
1013
},
@@ -69,7 +72,7 @@
6972
},
7073
"dependencies": {
7174
"chalk": "^6.0.0",
72-
"chokidar": "^4.0.3",
75+
"chokidar": "^6.0.0",
7376
"commander": "^15.0.0",
7477
"express": "^5.1.0",
7578
"github-slugger": "^2.0.0",

‎src/server/watcher.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chokidar, { FSWatcher } from 'chokidar';
1+
import { FSWatcher, watch } from 'chokidar';
22
import * as fs from 'fs';
33
import * as http from 'http';
44
import path from 'path';
@@ -86,7 +86,7 @@ const describeWatchTarget = (error: unknown, directory: string): string => {
8686

8787
const setupDirectoryWatcher = (directory: string, wss: WebSocketServer): FSWatcher | null => {
8888
try {
89-
const watcher = chokidar.watch(directory, {
89+
const watcher = watch(directory, {
9090
ignored: (watchedFilePath: string, stats?: fs.Stats) => {
9191
if (EXCLUDED_DIRECTORIES.some(p => watchedFilePath.includes(`/${p}`))) {
9292
return true;
@@ -133,7 +133,7 @@ const setupFilePatternWatcher = (context: ServerContext, wss: WebSocketServer):
133133

134134
try {
135135
const absolutePaths = filePatterns.map(f => path.join(directory, f));
136-
const watcher = chokidar.watch(absolutePaths, { ignoreInitial: true });
136+
const watcher = watch(absolutePaths, { ignoreInitial: true });
137137

138138
attachTreeReloadHandlers(watcher, wss);
139139

@@ -161,7 +161,7 @@ const setupContentWatcher = (ws: WebSocket, directory: string, filePath: string)
161161

162162
contentWatcher?.close(); // Close existing content watcher if any
163163

164-
contentWatcher = chokidar.watch(path.join(directory, currentWatchedFile), { ignoreInitial: true });
164+
contentWatcher = watch(path.join(directory, currentWatchedFile), { ignoreInitial: true });
165165
contentWatcher.on('change', (changedFilePath) => {
166166
logger.log('Livereload', `🔃 File changed: ${changedFilePath.replace(`${directory}/`, '')}, reloading content...`);
167167
ws.send(JSON.stringify({ type: 'reload-content' }));

‎test/__mocks__/chokidar.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { EventEmitter } from 'events';
22

3-
class FSWatcher extends EventEmitter {
4-
add() { return this; }
5-
on() { return this; }
6-
close() { }
3+
export class FSWatcher extends EventEmitter {
4+
add(): this { return this; }
5+
on(): this { return this; }
6+
close(): void { }
77
}
88

9-
const chokidar = {
10-
watch: jest.fn(() => new FSWatcher()),
11-
};
12-
13-
export default chokidar;
9+
export const watch = jest.fn(() => new FSWatcher());

0 commit comments

Comments
 (0)