Watch asset directories for changes during dev#7470
Conversation
5f3d9d6 to
92ac699
Compare
dev
92ac699 to
4034f2f
Compare
4034f2f to
3feb8ae
Compare
3feb8ae to
8e21010
Compare
| // For deleted files, skip the live watchPaths check — the file is already gone from disk | ||
| // so globSync won't find it. The file was already validated as belonging to the extension | ||
| // via the cached extensionWatchedFiles map earlier in the flow. | ||
| if (event.type === 'file_deleted') return false |
There was a problem hiding this comment.
Added this to enable deleting an asset will emit a websocket update event.
Without it, since the shouldIgnoreEvent() calls extension.watchedFiles() which runs globSync live against the filesystem. For delete events, by the time this check runs, the file is already gone from disk — so globSync never returns it, isAValidWatchedPath is false, and the event gets silently dropped.
|
/snapit |
|
🫰✨ Thanks @melissaluu! Your snapshot has been published to npm. Test the snapshot by installing your package globally: Caution After installing, validate the version by running |

WHY are these changes introduced?
Closes https://github.com/shop/issues-admin-extensibility/issues/2461
When developers add new files to the watched
assetsdirectories during adevsesstion, they were not being picked up by the file watcher and meant that adding an asset image would not trigger a rebuild or hot-reload.WHAT is this pull request doing?
Introduces a mechanism for
ExtensionInstanceto track additional watched paths beyond its source imports, and wires it into the file watcher and build pipeline:addWatchedPath,getWatchedPaths, andclearWatchedPathsmethods toExtensionInstance. Paths are stored in a deduplicatedSetand are included in the output ofwatchedFiles().executeIncludeAssetsStep, directory-type asset sources are registered as watched paths on the extension after being copied, so the watcher knows to monitor them.FileWatcher, theextensionWatchedFilesmap now tracks both files and directories. A newgetExtensionHandlesForFilePathmethod resolves the owning extension for any file path by checking both exact matches and prefix matches against watched directories. Directories themselves are excluded from the paths passed to chokidar (since chokidar already watches the extension directory), but files inside them are still attributed to the correct extension.AppEventWatcher, after building extensions, the set of watched paths is compared before and after the build. If new paths were registered (e.g., a new asset directory was discovered), the file watcher is restarted to pick them up.How to test your changes?
Video
app-homeextension that usesinclude_assetswith aassetconfig key pointing to a directory.shopify app dev.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset addgeeck