Skip to content

Commit 12e5b06

Browse files
Coly010kdy1
andauthored
feat(cli): Update chokidar to v5 (#122)
This update resolves peer dependency conflicts in repositories that use both @swc/cli and Angular, as Angular now uses chokidar v5. BREAKING CHANGE: Minimum Node.js version bumped from 16.14.0 to 20.19.0 to match chokidar v5's requirements. Changes: - Update chokidar from ^4.0.1 to ^5.0.0 in devDependencies and peerDependencies - Add local type declarations for chokidar to support Node.js 20.19+ (chokidar v5 types use Node.js 22+ generic EventEmitter) - Add skipLibCheck to tsconfig.json for type compatibility - Add explicit FSWatcher return type to watchSources function --------- Co-authored-by: Donny/강동윤 <kdy.1997.dev@gmail.com>
1 parent 298c68b commit 12e5b06

File tree

7 files changed

+103
-25
lines changed

7 files changed

+103
-25
lines changed

.changeset/stupid-lobsters-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@swc/cli": minor
3+
---
4+
5+
feat(cli): Update chokidar to v5

.changeset/wise-otters-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@swc/cli": patch
3+
---
4+
5+
feat(cli): Update chokidar to v5

packages/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"homepage": "https://github.com/swc-project/pkgs",
3939
"engines": {
40-
"node": ">= 16.14.0"
40+
"node": ">= 20.19.0"
4141
},
4242
"bin": {
4343
"swc": "./bin/swc.js",
@@ -63,15 +63,15 @@
6363
"@types/jest": "^29.5.0",
6464
"@types/node": "^20.11.5",
6565
"@types/semver": "^7.3.13",
66-
"chokidar": "^4.0.1",
66+
"chokidar": "^5.0.0",
6767
"deepmerge": "^4.2.2",
6868
"jest": "^29.5.0",
6969
"ts-jest": "^29.0.5",
7070
"typescript": "~5.8.3"
7171
},
7272
"peerDependencies": {
7373
"@swc/core": "^1.2.66",
74-
"chokidar": "^4.0.1"
74+
"chokidar": "^5.0.0"
7575
},
7676
"peerDependenciesMeta": {
7777
"chokidar": {

packages/cli/src/swc/chokidar.d.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Local type declarations for chokidar v5.
3+
*
4+
* Chokidar v5's FSWatcher extends EventEmitter<T> which requires Node.js 22+ types.
5+
* Since we support Node.js 20.19+, we provide a simplified type interface here
6+
* that describes the subset of the API we actually use.
7+
*/
8+
declare module "chokidar" {
9+
import { Stats } from "fs";
10+
11+
export type AWF = {
12+
stabilityThreshold: number;
13+
pollInterval: number;
14+
};
15+
16+
export type MatchFunction = (val: string, stats?: Stats) => boolean;
17+
18+
export interface MatcherObject {
19+
path: string;
20+
recursive?: boolean;
21+
}
22+
23+
export type Matcher = string | RegExp | MatchFunction | MatcherObject;
24+
25+
export type ChokidarOptions = {
26+
persistent?: boolean;
27+
ignoreInitial?: boolean;
28+
followSymlinks?: boolean;
29+
cwd?: string;
30+
usePolling?: boolean;
31+
interval?: number;
32+
binaryInterval?: number;
33+
alwaysStat?: boolean;
34+
depth?: number;
35+
ignorePermissionErrors?: boolean;
36+
atomic?: boolean | number;
37+
ignored?: Matcher | Matcher[];
38+
awaitWriteFinish?: boolean | Partial<AWF>;
39+
};
40+
41+
export type EmitArgs = [string, Stats?];
42+
43+
export interface FSWatcher {
44+
on(event: "ready", listener: () => void): this;
45+
on(event: "add" | "change" | "unlink", listener: (path: string, stats?: Stats) => void): this;
46+
on(event: "addDir" | "unlinkDir", listener: (path: string, stats?: Stats) => void): this;
47+
on(event: "error", listener: (error: Error) => void): this;
48+
on(event: "all", listener: (eventName: string, path: string, stats?: Stats) => void): this;
49+
on(event: "raw", listener: (eventName: string, path: string, details: any) => void): this;
50+
on(event: string, listener: (...args: any[]) => void): this;
51+
add(paths: string | string[]): this;
52+
unwatch(paths: string | string[]): this;
53+
close(): Promise<void>;
54+
getWatched(): Record<string, string[]>;
55+
}
56+
57+
export function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
58+
59+
const _default: {
60+
watch: typeof watch;
61+
FSWatcher: new (options?: ChokidarOptions) => FSWatcher;
62+
};
63+
64+
export default _default;
65+
}

packages/cli/src/swc/sources.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { stat } from "fs";
44
import { join, basename, extname } from "path";
55
import { minimatch } from "minimatch";
66

7+
import type { FSWatcher } from "chokidar";
8+
79
/**
810
* Find all input files based on source globs
911
*/
@@ -112,7 +114,7 @@ export async function watchSources(
112114
includeDotfiles = false,
113115
only: string[] = [],
114116
ignore: string[] = []
115-
) {
117+
): Promise<FSWatcher> {
116118
const chokidar = await requireChokidar();
117119
return chokidar.watch(sources, {
118120
ignored: (filename: string) => {

packages/cli/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"target": "es2019",
44
"module": "commonjs",
55
"strict": true,
6+
"skipLibCheck": true,
67
"noUnusedLocals": true,
78
"noUnusedParameters": true,
89
"noImplicitReturns": true,

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)