Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/chokidar-v5-update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@swc/cli": major
---

Update chokidar to v5

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.
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"homepage": "https://github.com/swc-project/pkgs",
"engines": {
"node": ">= 16.14.0"
"node": ">= 20.19.0"
Copy link
Member

Choose a reason for hiding this comment

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

@kwonoj Thoughts?

},
"bin": {
"swc": "./bin/swc.js",
Expand All @@ -63,15 +63,15 @@
"@types/jest": "^29.5.0",
"@types/node": "^20.11.5",
"@types/semver": "^7.3.13",
"chokidar": "^4.0.1",
"chokidar": "^5.0.0",
"deepmerge": "^4.2.2",
"jest": "^29.5.0",
"ts-jest": "^29.0.5",
"typescript": "~5.8.3"
},
"peerDependencies": {
"@swc/core": "^1.2.66",
"chokidar": "^4.0.1"
"chokidar": "^5.0.0"
},
"peerDependenciesMeta": {
"chokidar": {
Expand Down
65 changes: 65 additions & 0 deletions packages/cli/src/swc/chokidar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Local type declarations for chokidar v5.
*
* Chokidar v5's FSWatcher extends EventEmitter<T> which requires Node.js 22+ types.
* Since we support Node.js 20.19+, we provide a simplified type interface here
* that describes the subset of the API we actually use.
*/
declare module "chokidar" {
import { Stats } from "fs";

export type AWF = {
stabilityThreshold: number;
pollInterval: number;
};

export type MatchFunction = (val: string, stats?: Stats) => boolean;

export interface MatcherObject {
path: string;
recursive?: boolean;
}

export type Matcher = string | RegExp | MatchFunction | MatcherObject;

export type ChokidarOptions = {
persistent?: boolean;
ignoreInitial?: boolean;
followSymlinks?: boolean;
cwd?: string;
usePolling?: boolean;
interval?: number;
binaryInterval?: number;
alwaysStat?: boolean;
depth?: number;
ignorePermissionErrors?: boolean;
atomic?: boolean | number;
ignored?: Matcher | Matcher[];
awaitWriteFinish?: boolean | Partial<AWF>;
};

export type EmitArgs = [string, Stats?];

export interface FSWatcher {
on(event: "ready", listener: () => void): this;
on(event: "add" | "change" | "unlink", listener: (path: string, stats?: Stats) => void): this;
on(event: "addDir" | "unlinkDir", listener: (path: string, stats?: Stats) => void): this;
on(event: "error", listener: (error: Error) => void): this;
on(event: "all", listener: (eventName: string, path: string, stats?: Stats) => void): this;
on(event: "raw", listener: (eventName: string, path: string, details: any) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
add(paths: string | string[]): this;
unwatch(paths: string | string[]): this;
close(): Promise<void>;
getWatched(): Record<string, string[]>;
}

export function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;

const _default: {
watch: typeof watch;
FSWatcher: new (options?: ChokidarOptions) => FSWatcher;
};

export default _default;
}
4 changes: 3 additions & 1 deletion packages/cli/src/swc/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { stat } from "fs";
import { join, basename, extname } from "path";
import { minimatch } from "minimatch";

import type { FSWatcher } from "chokidar";

/**
* Find all input files based on source globs
*/
Expand Down Expand Up @@ -112,7 +114,7 @@ export async function watchSources(
includeDotfiles = false,
only: string[] = [],
ignore: string[] = []
) {
): Promise<FSWatcher> {
const chokidar = await requireChokidar();
return chokidar.watch(sources, {
ignored: (filename: string) => {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "es2019",
"module": "commonjs",
"strict": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
Expand Down
42 changes: 21 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.