Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/windows-app-config-reload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Fix `app dev` on Windows not reloading the app when `shopify.app.toml` changes
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,51 @@ describe('file-watcher events', () => {
},
)

test('a change to the app config reloads it when chokidar reports the path with backslashes, as on Windows', async () => {
await inTemporaryDirectory(async (dir) => {
// Given
const configPath = joinPath(dir, 'shopify.app.toml')
const app = testAppLinked({
allExtensions: [],
directory: dir,
configPath,
configuration: {
...DEFAULT_CONFIG,
extension_directories: ['extensions'],
} as any,
})

let eventHandler: any
const mockWatcher = {
on: vi.fn((event: string, listener: any) => {
if (event === 'all') {
eventHandler = listener
}
return mockWatcher
}),
close: vi.fn(() => Promise.resolve()),
}
vi.spyOn(chokidar, 'watch').mockReturnValue(mockWatcher as any)

const fileWatcher = new FileWatcher(app, outputOptions, 50)
const emitted = new Promise<WatcherEvent[]>((resolve) => {
fileWatcher.onChange((events) => {
if (events.length > 0) resolve(events)
})
})
await fileWatcher.start()
await flushPromises()

// When
await eventHandler('change', configPath.replace(/\//g, '\\'), undefined)

// Then
await expect(emitted).resolves.toEqual([
expect.objectContaining({type: 'extensions_config_updated', extensionPath: dir}),
])
})
})

test.each(multiEventTestCases)(
'The event $name returns the expected WatcherEvent',
async ({name, fileSystemEvents, expectedEvent}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class FileWatcher {
private readonly handleFileEvent = (event: string, path: string) => {
const startTime = startHRTime()
const normalizedPath = normalizePath(path)
const isConfigAppPath = path === this.app.configPath
const isConfigAppPath = normalizedPath === normalizePath(this.app.configPath)
const isExtensionToml = path.endsWith('.extension.toml')

outputDebug(`🌀: ${event} ${path.replace(this.app.directory, '')}\n`)
Expand Down Expand Up @@ -370,7 +370,7 @@ export class FileWatcher {
extensionHandle?: string,
) {
const isExtensionToml = path.endsWith('.extension.toml')
const isConfigAppPath = path === this.app.configPath
const isConfigAppPath = normalizePath(path) === normalizePath(this.app.configPath)

switch (event) {
case 'change':
Expand Down
Loading