Skip to content

Commit f920c94

Browse files
authored
Merge pull request #6519 from Shopify/10-16-don_t_stop_dev_until_the_analytics_event_is_sent
Don't stop dev until the analytics event is sent
2 parents 51b6c89 + 97c0b48 commit f920c94

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"**/node_modules": true
2222
},
2323
"editor.formatOnSave": false,
24-
"eslint.validate": ["javascript", "javascriptreact", "typescript"],
24+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
2525
"[javascript]": {
2626
"editor.formatOnSave": true,
2727
"editor.defaultFormatter": "esbenp.prettier-vscode"

packages/app/src/cli/services/dev/ui/components/DevSessionUI.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {openURL} from '@shopify/cli-kit/node/system'
1818
import figures from '@shopify/cli-kit/node/figures'
1919
import {isUnitTest} from '@shopify/cli-kit/node/context/local'
2020
import {treeKill} from '@shopify/cli-kit/node/tree-kill'
21+
import {postRunHookHasCompleted} from '@shopify/cli-kit/node/hooks/postrun'
2122
import {Writable} from 'stream'
2223

2324
interface DevSesionUIProps {
@@ -61,9 +62,17 @@ const DevSessionUI: FunctionComponent<DevSesionUIProps> = ({
6162
await onAbort()
6263
}
6364
if (isUnitTest()) return
64-
treeKill(process.pid, 'SIGINT', false, () => {
65-
process.exit(0)
66-
})
65+
66+
// Wait for the post run hook to complete or timeout after 5 seconds.
67+
let totalTime = 0
68+
setInterval(() => {
69+
if (postRunHookHasCompleted() || totalTime > 5000) {
70+
treeKill(process.pid, 'SIGINT', false, () => {
71+
process.exit(0)
72+
})
73+
}
74+
totalTime += 100
75+
}, 100)
6776
})
6877

6978
const errorHandledProcesses = useMemo(() => {

packages/cli-kit/src/public/node/hooks/postrun.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import BaseCommand from '../base-command.js'
55
import * as metadata from '../../../public/node/metadata.js'
66
import {Command, Hook} from '@oclif/core'
77

8+
let postRunHookCompleted = false
9+
10+
/**
11+
* Check if post run hook has completed.
12+
*
13+
* @returns Whether post run hook has completed.
14+
*/
15+
export function postRunHookHasCompleted(): boolean {
16+
return postRunHookCompleted
17+
}
18+
819
// This hook is called after each successful command run. More info: https://oclif.io/docs/hooks
920
export const hook: Hook.Postrun = async ({config, Command}) => {
1021
await detectStopCommand(Command as unknown as typeof Command)
@@ -13,6 +24,7 @@ export const hook: Hook.Postrun = async ({config, Command}) => {
1324

1425
const command = Command.id.replace(/:/g, ' ')
1526
outputDebug(`Completed command ${command}`)
27+
postRunHookCompleted = true
1628
}
1729

1830
/**

0 commit comments

Comments
 (0)