Skip to content

Commit 8e6d25a

Browse files
committed
Remove dead shouldIgnoreEvent filter from file watcher
shouldIgnoreEvent always returned false for any event that reached it: - extension_folder_* events short-circuited at the first line. - The literal-list check (watchPaths.some(matchGlob)) was always true, because pushEvent was only ever called for paths that came from extensionWatchedFiles, which is itself built from watchedFiles(). - The else-if gitignore branch was unreachable: watchedFiles() always returns a (possibly empty) array, so watchPaths is always truthy. Filtering for unknown paths happens earlier in handleFileEvent's 'not watched by any extension' early return; shouldIgnoreEvent was never doing real work. Deletes the method, the `ignored` field and createIgnoreInstance helper, the extension_folder_created branch in pushEvent (its only job was to populate `ignored`), the updateApp ignore-population, and the dynamic-map short-circuit added in the parent PR (now redundant).
1 parent 2ef08a3 commit 8e6d25a

2 files changed

Lines changed: 8 additions & 61 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/app': patch
3+
---
4+
5+
Remove dead `shouldIgnoreEvent` filter from file watcher

packages/app/src/cli/services/dev/app-events/file-watcher.ts

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import {FSWatcher} from 'chokidar'
77
import {outputDebug} from '@shopify/cli-kit/node/output'
88
import {AbortSignal} from '@shopify/cli-kit/node/abort'
99
import {startHRTime, StartTime} from '@shopify/cli-kit/node/hrtime'
10-
import {fileExistsSync, matchGlob, mkdir, readFileSync} from '@shopify/cli-kit/node/fs'
10+
import {fileExistsSync, matchGlob, mkdir} from '@shopify/cli-kit/node/fs'
1111
import {debounce} from '@shopify/cli-kit/common/function'
12-
import ignore from 'ignore'
1312
import {Writable} from 'stream'
1413

1514
const DEFAULT_DEBOUNCE_TIME_IN_MS = 200
@@ -59,7 +58,6 @@ export class FileWatcher {
5958
private onChangeCallback?: (events: WatcherEvent[]) => void
6059
private watcher?: FSWatcher
6160
private readonly debouncedEmit: () => void
62-
private readonly ignored: {[key: string]: ignore.Ignore | undefined} = {}
6361
// Map of file paths to the extension handles that watch them
6462
private readonly extensionWatchedFiles = new Map<string, Set<string>>()
6563

@@ -135,9 +133,6 @@ export class FileWatcher {
135133
this.extensionPaths = this.app.nonConfigExtensions
136134
.map((ext) => normalizePath(ext.directory))
137135
.filter((dir) => dir !== this.app.directory)
138-
this.extensionPaths.forEach((path) => {
139-
this.ignored[path] ??= this.createIgnoreInstance(path)
140-
})
141136
}
142137

143138
private addAbortListener() {
@@ -191,15 +186,8 @@ export class FileWatcher {
191186
* @param event - The event to be added
192187
*/
193188
private pushEvent(event: WatcherEvent) {
194-
if (this.shouldIgnoreEvent(event)) return
195-
196-
// If the event is for a new extension folder, create a new ignore instance
197-
if (event.type === 'extension_folder_created') {
198-
this.ignored[event.path] = this.createIgnoreInstance(event.path)
199-
}
200-
201-
// If the event is already in the list, don't push it again
202-
// Check path, type, AND extensionHandle to properly handle shared files
189+
// If the event is already in the list, don't push it again.
190+
// Check path, type, AND extensionHandle to properly handle shared files.
203191
if (
204192
this.currentEvents.some(
205193
(extEvent) =>
@@ -213,40 +201,6 @@ export class FileWatcher {
213201
this.currentEvents.push(event)
214202
}
215203

216-
/**
217-
* Whether an event should be ignored or not based on the extension's watch paths and gitignore file.
218-
* Never ignores extension create/delete events.
219-
*
220-
* If the affected extension defines custom watch paths, ignore the event if the path is not in the list
221-
* ELSE, if the extension has a custom gitignore file, ignore the event if the path matches the patterns
222-
* Explicit watch paths have priority over custom gitignore files
223-
*/
224-
private shouldIgnoreEvent(event: WatcherEvent) {
225-
if (event.type === 'extension_folder_deleted' || event.type === 'extension_folder_created') return false
226-
227-
// If this path is already tracked for this handle (either pre-registered or
228-
// discovered at runtime), accept without re-checking against the static list.
229-
if (event.extensionHandle && this.extensionWatchedFiles.get(event.path)?.has(event.extensionHandle)) {
230-
return false
231-
}
232-
233-
const extension = event.extensionHandle
234-
? this.app.realExtensions.find((ext) => ext.handle === event.extensionHandle)
235-
: undefined
236-
const watchPaths = extension?.watchedFiles()
237-
const ignoreInstance = this.ignored[event.extensionPath]
238-
239-
if (watchPaths) {
240-
const isAValidWatchedPath = watchPaths.some((pattern) => matchGlob(event.path, pattern))
241-
return !isAValidWatchedPath
242-
} else if (ignoreInstance) {
243-
const relative = relativePath(event.extensionPath, event.path)
244-
return ignoreInstance.ignores(relative)
245-
}
246-
247-
return false
248-
}
249-
250204
private readonly handleFileEvent = (event: string, path: string) => {
251205
const startTime = startHRTime()
252206
const normalizedPath = normalizePath(path)
@@ -408,16 +362,4 @@ export class FileWatcher {
408362
.then(() => outputDebug(`File watching closed`, this.options.stdout))
409363
.catch((error: Error) => outputDebug(`File watching failed to close: ${error.message}`, this.options.stderr))
410364
}
411-
412-
// Creates an "Ignore" instance for the given path if a .gitignore file exists, otherwise undefined
413-
private createIgnoreInstance(path: string): ignore.Ignore | undefined {
414-
const gitIgnorePath = joinPath(path, '.gitignore')
415-
if (!fileExistsSync(gitIgnorePath)) return undefined
416-
const gitIgnoreContent = readFileSync(gitIgnorePath)
417-
.toString()
418-
.split('\n')
419-
.map((pattern) => pattern.trim())
420-
.filter((pattern) => pattern !== '' && !pattern.startsWith('#'))
421-
return ignore.default().add(gitIgnoreContent)
422-
}
423365
}

0 commit comments

Comments
 (0)