Skip to content

Commit 5585d11

Browse files
Merge branch 'main' into upgrade-graphql
2 parents ff67b7b + f9be711 commit 5585d11

File tree

14 files changed

+850
-521
lines changed

14 files changed

+850
-521
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"devDependencies": {
4141
"@bugsnag/source-maps": "^2.3.1",
42-
"@changesets/cli": "2.26.2",
42+
"@changesets/cli": "2.27.12",
4343
"@graphql-codegen/cli": "5.0.4",
4444
"@graphql-codegen/near-operation-file-preset": "3.0.0",
4545
"@nx/eslint-plugin": "19.8.14",
@@ -103,7 +103,8 @@
103103
"supports-hyperlinks": "3.1.0",
104104
"@graphql-tools/utils": "10.7.2",
105105
"@shopify/cli-hydrogen>@shopify/cli-kit": "link:./packages/cli-kit",
106-
"@shopify/cli-hydrogen>@shopify/plugin-cloudflare": "link:./packages/plugin-cloudflare"
106+
"@shopify/cli-hydrogen>@shopify/plugin-cloudflare": "link:./packages/plugin-cloudflare",
107+
"nanoid": "3.3.8"
107108
},
108109
"knip": {
109110
"$schema": "https://unpkg.com/knip@5/schema.json",

packages/app/src/cli/services/dev.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {getCachedAppInfo, setCachedAppInfo} from './local-storage.js'
2525
import {canEnablePreviewMode} from './extensions/common.js'
2626
import {fetchAppRemoteConfiguration} from './app/select-app.js'
2727
import {patchAppConfigurationFile} from './app/patch-app-configuration-file.js'
28+
import {DevSessionStatusManager} from './dev/processes/dev-session-status-manager.js'
2829
import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js'
2930
import {Web, isCurrentAppSchema, getAppScopesArray, AppLinkedInterface} from '../models/app/app.js'
3031
import {Organization, OrganizationApp, OrganizationStore} from '../models/organization.js'
@@ -71,9 +72,9 @@ export interface DevOptions {
7172
export async function dev(commandOptions: DevOptions) {
7273
const config = await prepareForDev(commandOptions)
7374
await actionsBeforeSettingUpDevProcesses(config)
74-
const {processes, graphiqlUrl, previewUrl} = await setupDevProcesses(config)
75+
const {processes, graphiqlUrl, previewUrl, devSessionStatusManager} = await setupDevProcesses(config)
7576
await actionsBeforeLaunchingDevProcesses(config)
76-
await launchDevProcesses({processes, previewUrl, graphiqlUrl, config})
77+
await launchDevProcesses({processes, previewUrl, graphiqlUrl, config, devSessionStatusManager})
7778
}
7879

7980
async function prepareForDev(commandOptions: DevOptions): Promise<DevConfig> {
@@ -117,10 +118,10 @@ async function prepareForDev(commandOptions: DevOptions): Promise<DevConfig> {
117118
await installAppDependencies(app)
118119
}
119120

120-
const graphiqlPort = commandOptions.graphiqlPort || (await getAvailableTCPPort(ports.graphiql))
121+
const graphiqlPort = commandOptions.graphiqlPort ?? (await getAvailableTCPPort(ports.graphiql))
121122
const {graphiqlKey} = commandOptions
122123

123-
if (graphiqlPort !== (commandOptions.graphiqlPort || ports.graphiql)) {
124+
if (graphiqlPort !== (commandOptions.graphiqlPort ?? ports.graphiql)) {
124125
renderWarning({
125126
headline: [
126127
'A random port will be used for GraphiQL because',
@@ -224,7 +225,7 @@ export async function warnIfScopesDifferBeforeDev({
224225
scopesMessage(getAppScopesArray(localApp.configuration)),
225226
'\n',
226227
'Scopes in Partner Dashboard:',
227-
scopesMessage(remoteAccess?.scopes?.split(',') || []),
228+
scopesMessage(remoteAccess?.scopes?.split(',') ?? []),
228229
],
229230
nextSteps,
230231
})
@@ -301,7 +302,7 @@ async function setupNetworkingOptions(
301302
...frontEndOptions,
302303
tunnelClient,
303304
}),
304-
getBackendPort() || backendConfig?.configuration.port || getAvailableTCPPort(),
305+
getBackendPort() ?? backendConfig?.configuration.port ?? getAvailableTCPPort(),
305306
getURLs(remoteAppConfig),
306307
])
307308
const proxyUrl = usingLocalhost ? `${frontendUrl}:${proxyPort}` : frontendUrl
@@ -330,11 +331,13 @@ async function launchDevProcesses({
330331
previewUrl,
331332
graphiqlUrl,
332333
config,
334+
devSessionStatusManager,
333335
}: {
334336
processes: DevProcesses
335337
previewUrl: string
336338
graphiqlUrl: string | undefined
337339
config: DevConfig
340+
devSessionStatusManager: DevSessionStatusManager
338341
}) {
339342
const abortController = new AbortController()
340343
const processesForTaskRunner: OutputProcess[] = processes.map((process) => {
@@ -375,6 +378,7 @@ async function launchDevProcesses({
375378
abortController,
376379
developerPreview: developerPreviewController(apiKey, developerPlatformClient),
377380
shopFqdn: config.storeFqdn,
381+
devSessionStatusManager,
378382
})
379383
}
380384

packages/app/src/cli/services/dev/processes/dev-session-status-manager.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import {devSessionStatusManager, DevSessionStatus} from './dev-session-status-manager.js'
1+
import {DevSessionStatus, DevSessionStatusManager} from './dev-session-status-manager.js'
22
import {describe, test, expect, beforeEach, vi} from 'vitest'
33

44
describe('DevSessionStatusManager', () => {
5+
const devSessionStatusManager = new DevSessionStatusManager()
6+
57
beforeEach(() => {
68
devSessionStatusManager.removeAllListeners()
79
devSessionStatusManager.reset()

packages/app/src/cli/services/dev/processes/dev-session-status-manager.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import {EventEmitter} from 'events'
44
export interface DevSessionStatus {
55
isReady: boolean
66
previewURL?: string
7+
graphiqlURL?: string
78
}
89

9-
class DevSessionStatusManager extends EventEmitter {
10+
export class DevSessionStatusManager extends EventEmitter {
1011
private currentStatus: DevSessionStatus = {
1112
isReady: false,
1213
previewURL: undefined,
14+
graphiqlURL: undefined,
15+
}
16+
17+
constructor(defaultStatus?: DevSessionStatus) {
18+
super()
19+
if (defaultStatus) this.currentStatus = defaultStatus
1320
}
1421

1522
updateStatus(status: Partial<DevSessionStatus>) {
@@ -29,8 +36,7 @@ class DevSessionStatusManager extends EventEmitter {
2936
this.currentStatus = {
3037
isReady: false,
3138
previewURL: undefined,
39+
graphiqlURL: undefined,
3240
}
3341
}
3442
}
35-
36-
export const devSessionStatusManager = new DevSessionStatusManager()

packages/app/src/cli/services/dev/processes/dev-session.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {setupDevSessionProcess, pushUpdatesForDevSession} from './dev-session.js'
2-
import {devSessionStatusManager} from './dev-session-status-manager.js'
2+
import {DevSessionStatusManager} from './dev-session-status-manager.js'
33
import {DeveloperPlatformClient} from '../../../utilities/developer-platform-client.js'
44
import {AppLinkedInterface} from '../../../models/app/app.js'
55
import {AppEventWatcher} from '../app-events/app-event-watcher.js'
@@ -39,6 +39,7 @@ describe('setupDevSessionProcess', () => {
3939
appWatcher: {} as AppEventWatcher,
4040
appPreviewURL: 'https://test.preview.url',
4141
appLocalProxyURL: 'https://test.local.url',
42+
devSessionStatusManager: new DevSessionStatusManager(),
4243
}
4344

4445
// When
@@ -60,6 +61,7 @@ describe('setupDevSessionProcess', () => {
6061
appWatcher: options.appWatcher,
6162
appPreviewURL: options.appPreviewURL,
6263
appLocalProxyURL: options.appLocalProxyURL,
64+
devSessionStatusManager: options.devSessionStatusManager,
6365
},
6466
})
6567
})
@@ -73,6 +75,7 @@ describe('pushUpdatesForDevSession', () => {
7375
let appWatcher: AppEventWatcher
7476
let app: AppLinkedInterface
7577
let abortController: AbortController
78+
let devSessionStatusManager: DevSessionStatusManager
7679

7780
beforeEach(() => {
7881
vi.mocked(formData).mockReturnValue({append: vi.fn(), getHeaders: vi.fn()} as any)
@@ -83,7 +86,7 @@ describe('pushUpdatesForDevSession', () => {
8386
app = testAppLinked()
8487
appWatcher = new AppEventWatcher(app)
8588
abortController = new AbortController()
86-
devSessionStatusManager.reset()
89+
devSessionStatusManager = new DevSessionStatusManager()
8790
options = {
8891
developerPlatformClient,
8992
appWatcher,
@@ -92,6 +95,7 @@ describe('pushUpdatesForDevSession', () => {
9295
organizationId: 'org123',
9396
appPreviewURL: 'https://test.preview.url',
9497
appLocalProxyURL: 'https://test.local.url',
98+
devSessionStatusManager,
9599
}
96100
})
97101

packages/app/src/cli/services/dev/processes/dev-session.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {BaseProcess, DevProcessFunction} from './types.js'
2-
import {devSessionStatusManager} from './dev-session-status-manager.js'
2+
import {DevSessionStatusManager} from './dev-session-status-manager.js'
33
import {DeveloperPlatformClient} from '../../../utilities/developer-platform-client.js'
44
import {AppLinkedInterface} from '../../../models/app/app.js'
55
import {getExtensionUploadURL} from '../../deploy/upload.js'
@@ -31,6 +31,7 @@ interface DevSessionOptions {
3131
appWatcher: AppEventWatcher
3232
appPreviewURL: string
3333
appLocalProxyURL: string
34+
devSessionStatusManager: DevSessionStatusManager
3435
}
3536

3637
interface DevSessionProcessOptions extends DevSessionOptions {
@@ -88,7 +89,7 @@ export const pushUpdatesForDevSession: DevProcessFunction<DevSessionOptions> = a
8889
{stderr, stdout, abortSignal: signal},
8990
options,
9091
) => {
91-
const {appWatcher} = options
92+
const {appWatcher, devSessionStatusManager} = options
9293

9394
const processOptions = {...options, stderr, stdout, signal, bundlePath: appWatcher.buildOutputPath}
9495

@@ -164,7 +165,7 @@ async function handleDevSessionResult(
164165
await printSuccess(`✅ Updated`, processOptions.stdout)
165166
await printActionRequiredMessages(processOptions, event)
166167
} else if (result.status === 'created') {
167-
devSessionStatusManager.updateStatus({isReady: true})
168+
processOptions.devSessionStatusManager.updateStatus({isReady: true})
168169
await printSuccess(`✅ Ready, watching for changes in your app `, processOptions.stdout)
169170
} else if (result.status === 'aborted') {
170171
outputDebug('❌ Session update aborted (new change detected or error in Session Update)', processOptions.stdout)
@@ -174,7 +175,7 @@ async function handleDevSessionResult(
174175

175176
// If we failed to create a session, exit the process. Don't throw an error in tests as it can't be caught due to the
176177
// async nature of the process.
177-
if (!devSessionStatusManager.status.isReady && !isUnitTest()) {
178+
if (!processOptions.devSessionStatusManager.status.isReady && !isUnitTest()) {
178179
throw new AbortError('Failed to start dev session.')
179180
}
180181
}
@@ -253,7 +254,7 @@ async function bundleExtensionsAndUpload(options: DevSessionProcessOptions): Pro
253254
// Create or update the dev session
254255
if (currentBundleController.signal.aborted) return {status: 'aborted'}
255256
try {
256-
if (devSessionStatusManager.status.isReady) {
257+
if (options.devSessionStatusManager.status.isReady) {
257258
const result = await devSessionUpdateWithRetry(payload, options.developerPlatformClient)
258259
const errors = result.devSessionUpdate?.userErrors ?? []
259260
if (errors.length) return {status: 'remote-error', error: errors}
@@ -363,5 +364,5 @@ async function printLogMessage(message: string, stdout: Writable, prefix?: strin
363364
async function updatePreviewURL(options: DevSessionProcessOptions, event: AppEvent) {
364365
const hasPreview = event.app.allExtensions.filter((ext) => ext.isPreviewable).length > 0
365366
const newPreviewURL = hasPreview ? options.appLocalProxyURL : options.appPreviewURL
366-
devSessionStatusManager.updateStatus({previewURL: newPreviewURL})
367+
options.devSessionStatusManager.updateStatus({previewURL: newPreviewURL})
367368
}

packages/app/src/cli/services/dev/processes/setup-dev-processes.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {WebProcess, setupWebProcesses} from './web.js'
88
import {DevSessionProcess, setupDevSessionProcess} from './dev-session.js'
99
import {AppLogsSubscribeProcess, setupAppLogsPollingProcess} from './app-logs-polling.js'
1010
import {AppWatcherProcess, setupAppWatcherProcess} from './app-watcher-process.js'
11+
import {DevSessionStatusManager} from './dev-session-status-manager.js'
1112
import {environmentVariableNames} from '../../../constants.js'
1213
import {AppLinkedInterface, getAppScopes, WebType} from '../../../models/app/app.js'
1314

@@ -78,6 +79,7 @@ export async function setupDevProcesses({
7879
processes: DevProcesses
7980
previewUrl: string
8081
graphiqlUrl: string | undefined
82+
devSessionStatusManager: DevSessionStatusManager
8183
}> {
8284
const apiKey = remoteApp.apiKey
8385
const apiSecret = remoteApp.apiSecretKeys[0]?.secret ?? ''
@@ -93,7 +95,13 @@ export async function setupDevProcesses({
9395
// Decide on the appropriate preview URL for a session with these processes
9496
const anyPreviewableExtensions = reloadedApp.allExtensions.some((ext) => ext.isPreviewable)
9597
const devConsoleURL = `${network.proxyUrl}/extensions/dev-console`
96-
const previewUrl = anyPreviewableExtensions ? devConsoleURL : appPreviewUrl
98+
const previewURL = anyPreviewableExtensions ? devConsoleURL : appPreviewUrl
99+
100+
const graphiqlURL = shouldRenderGraphiQL
101+
? `http://localhost:${graphiqlPort}/graphiql${graphiqlKey ? `?key=${graphiqlKey}` : ''}`
102+
: undefined
103+
104+
const devSessionStatusManager = new DevSessionStatusManager({isReady: false, previewURL, graphiqlURL})
97105

98106
const processes = [
99107
...(await setupWebProcesses({
@@ -143,6 +151,7 @@ export async function setupDevProcesses({
143151
appWatcher,
144152
appPreviewURL: appPreviewUrl,
145153
appLocalProxyURL: devConsoleURL,
154+
devSessionStatusManager,
146155
})
147156
: await setupDraftableExtensionsProcess({
148157
localApp: reloadedApp,
@@ -189,10 +198,9 @@ export async function setupDevProcesses({
189198

190199
return {
191200
processes: processesWithProxy,
192-
previewUrl,
193-
graphiqlUrl: shouldRenderGraphiQL
194-
? `http://localhost:${graphiqlPort}/graphiql${graphiqlKey ? `?key=${graphiqlKey}` : ''}`
195-
: undefined,
201+
previewUrl: previewURL,
202+
graphiqlUrl: graphiqlURL,
203+
devSessionStatusManager,
196204
}
197205
}
198206

0 commit comments

Comments
 (0)