Repository navigation
fix(desktop): restore treePathExcludePatterns filtering in the sidebar tree - #5461
Merged
Merged
Conversation
|
Website preview ready: https://pr-5461-marktext-website.ransixi.workers.dev Built from |
…r tree (#5159) Any non-empty `treePathExcludePatterns` emptied the sidebar project tree. `common/filesystem/paths.ts` imports `{ minimatch } from 'minimatch'`, but minimatch was never declared as a dependency. With `shamefully-hoist=true` it resolved to whichever transitive copy landed in the root node_modules — minimatch@3, whose CommonJS export is the function itself and carries no named `minimatch` export. So the imported binding was `undefined`. `src/types/shims.d.ts` hand-declared `export function minimatch(...)` for the module, which is why typecheck and lint stayed green over a binding that could never exist at runtime. `checkPathExcludePattern` only reaches the call inside the pattern loop, so an empty array worked and any non-empty one threw `TypeError: minimatch is not a function`. The watcher calls it from chokidar's `ignored` predicate, where the throw aborts the initial traversal: chokidar emits `error` instead of the `addDir`/`add` events the renderer builds the tree from, leaving the sidebar empty. Declare minimatch as a real dependency and drop the shim so the module's own types apply. Path exclusion now works as documented — it had been inert since #4001 introduced the import. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Jocs
force-pushed
the
fix/5159-tree-exclude-patterns-minimatch
branch
from
September 19, 2026 14:39
5385ed4 to
39fd11c
Compare
|
Build artifacts for PR #5461: Run: https://github.com/marktext/marktext/actions/runs/35449427513
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5159.
Reproduced
On
develop, with a temp project holdingalpha.md,beta.mdandnested/gamma.md, driving the realEditorWindow.openFolderpath (watcher IPC +mt::open-directory) in a Playwright-attached build:treePathExcludePatterns[]alpha.md,beta.md,nestedalpha.md,beta.md,nested["*.no-such-ext"](matches nothing)alpha.md,beta.md,nested["beta.md"]alpha.md,nested(beta.mdhidden)The main process logs, once per traversal step:
Same result against the
electron-builderpackaged.app.Root cause
packages/desktop/src/common/filesystem/paths.tsimports{ minimatch } from 'minimatch', but minimatch was never a declared dependency — it has been a phantom dependency since #4001 introduced the import. Withshamefully-hoist=trueit resolved to whichever transitive copy won the rootnode_moduleshoist, here minimatch@3, whose CommonJS export is the function itself:so the named import was
undefined.packages/desktop/src/types/shims.d.tshand-declared the module:which is why
typecheckandlintstayed green over a binding that could never exist at runtime.checkPathExcludePatternonly reaches the call inside its pattern loop, so an empty array short-circuits and works, while any non-empty value throwsTypeError: minimatch is not a function. The sidebar watcher calls it from chokidar'signoredpredicate, where the throw aborts the initial traversal — chokidar emitserrorinstead of theaddDir/addevents the renderer's project store builds the tree from, so the sidebar stays empty.This matches the report's note that isolating the release-bundled chokidar did not reproduce it: chokidar is fine, and so is minimatch — the break is the module boundary between them.
Fix
Declare
minimatchas a real dependency ofpackages/desktopand drop the shim so the package's own types apply.minimatch@9ships dual CJS/ESM with a real named export, andrequire("minimatch").minimatchis what the bundled main process now calls. (Pinned to 9 rather than 10: minimatch 10 relicensed to BlueOak-1.0.0, whichvalidate-licensesrejects. 9.0.9 is still ISC.)Side effect worth noting:
treePathExcludePatternsfilters for the first time since #4001 — previously it either did nothing (empty) or emptied the tree (non-empty).Verification
path-exclude-pattern.spec.ts— fails ondevelopwithTypeError: minimatch is not a functionon every non-empty pattern case.pnpm test:unit— 826 passed / 61 files.pnpm typecheck,pnpm lint— clean (0 errors).electron-builder --dir: minimatch present underapp.asar/node_modules/minimatch, and the packaged app filters correctly.pnpm validate-licenses— clean.🤖 Generated with Claude Code