Repository navigation
fix(deps): bump chokidar to 4.0.3 to resolve braces advisory (#11308) - #11336
Conversation
- Bump chokidar to ^4.0.3 in package.json and update npm-shrinkwrap.json - Add @angular-devkit/core chokidar override to resolve optional peer dependency - Remove vulnerable braces dependency from production graph (GHSA-vfj7-8cjw-p6xm) - Use minimatch for glob matching in Functions emulator ignore filter for chokidar 4 compatibility - Add unit tests for functions emulator ignore filter
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function createIgnoredFilter to centralize and standardize the logic for ignoring files in the functions emulator, improving maintainability and testability. The changes include updating the chokidar dependency to version 4.0.3, adding the necessary minimatch dependency, and refactoring the file watcher configuration. Unit tests have been added to verify the ignore logic. I have included a review comment suggesting the pre-compilation of minimatch patterns to enhance performance during file-watching operations.
| const patterns = ignore.map((pattern) => | ||
| pattern.startsWith("**/") ? pattern : `**/${pattern}`, | ||
| ); | ||
| ignored.push((filePath: string) => { | ||
| const normalized = filePath.replace(/\\/g, "/"); | ||
| return patterns.some((p) => minimatch(normalized, p, { dot: true })); | ||
| }); |
There was a problem hiding this comment.
Pre-compiling the minimatch patterns into Minimatch instances outside of the file-matching callback avoids recompiling the glob patterns or performing repetitive cache lookups for every single file and directory during the file-watching process. This significantly improves the efficiency of the file watcher, especially in larger projects with many files.
const minimatchInstances = ignore.map((pattern) => {
const p = pattern.startsWith("**/") ? pattern : `**/${pattern}`;
return new minimatch.Minimatch(p, { dot: true });
});
ignored.push((filePath: string) => {
const normalized = filePath.replace(/\\/g, "/");
return minimatchInstances.some((m) => m.match(normalized));
});There was a problem hiding this comment.
Fixed in commit dba5f87 by pre-compiling the ignore patterns into minimatch.Minimatch instances outside the matcher callback.
Description
Fixes #11308.
chokidarfrom^3.6.0to^4.0.3inpackage.jsonand updatesnpm-shrinkwrap.json.braces(GHSA-vfj7-8cjw-p6xm), removingbracesfrom the production dependency graph aschokidar@4only depends onreaddirp@^4.0.1.@angular-devkit/core's optional peer dependency onchokidar("@angular-devkit/core": { "chokidar": "$chokidar" }).src/emulator/functionsEmulator.ts) to useminimatchforbackend.ignorepattern matching, preserving glob ignore functionality underchokidar@4(which dropped native glob matching in favor of matcher functions and regexes).src/emulator/functionsEmulatorUtils.spec.tsfor the Functions emulator ignore filter.Scenarios Tested
npm audit --omit=dev --jsonverified thatbracesis completely removed from the production dependency graph.require()against all built emulator modules (databaseEmulator.js,firestoreEmulator.js,functionsEmulator.js,storage/rules/manager.js).npm run buildpassed (TypeScript and Vite compilation).npm run lint:quietpassed (ESLint and Prettier across all files).src/emulator/functionsEmulatorUtils.spec.ts(30 passing)src/emulator/databaseEmulator.spec.ts(4 passing)src/emulator/storage/rules/config.spec.tsandsrc/emulator/storage/rules/runtime.spec.ts(13 passing)npm run sanitize:lockfileand reproducible lockfile generation.Sample Commands
N/A