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
6 changes: 0 additions & 6 deletions .changeset/sunny-aliens-mate.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {AbortSignal, AbortController} from '@shopify/cli-kit/node/abort'
import {flushPromises} from '@shopify/cli-kit/node/promises'
import * as outputContext from '@shopify/cli-kit/node/ui/components'
import {readdir} from '@shopify/cli-kit/node/fs'
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'
import {firstPartyDev, skipLocalDevConsole} from '@shopify/cli-kit/node/context/local'

vi.mock('@shopify/cli-kit/node/fs')
vi.mock('@shopify/cli-kit/node/archiver')
Expand All @@ -33,6 +33,7 @@ vi.mock('@shopify/cli-kit/node/context/local', async (importOriginal) => {
return {
...original,
firstPartyDev: vi.fn().mockReturnValue(false),
skipLocalDevConsole: vi.fn().mockReturnValue(false),
}
})

Expand Down Expand Up @@ -218,9 +219,10 @@ describe('pushUpdatesForDevSession', () => {
contextSpy.mockRestore()
})

test('updates preview URL to appPreviewURL by default (local dev console only for 1P devs)', async () => {
// Given - dev console is NOT shown by default (only for 1P devs)
test('updates preview URL to appLocalProxyURL when extension is previewable (dev console shown by default)', async () => {
// Given - dev console is shown by default when skipLocalDevConsole is false
vi.mocked(firstPartyDev).mockReturnValue(false)
vi.mocked(skipLocalDevConsole).mockReturnValue(false)
const extension = await testUIExtension({type: 'ui_extension'})
const newApp = testAppLinked({allExtensions: [extension]})

Expand All @@ -232,12 +234,13 @@ describe('pushUpdatesForDevSession', () => {
await flushPromises()

// Then
expect(devSessionStatusManager.status.previewURL).toBe(options.appPreviewURL)
expect(devSessionStatusManager.status.previewURL).toBe(options.appLocalProxyURL)
})

test('updates preview URL to appLocalProxyURL when 1P dev has previewable extensions', async () => {
// Given - dev console is shown for 1P devs with previewable extensions
vi.mocked(firstPartyDev).mockReturnValue(true)
test('updates preview URL to appPreviewURL when both skip conditions are met', async () => {
// Given - dev console is skipped only when !firstPartyDev() AND skipLocalDevConsole()
vi.mocked(firstPartyDev).mockReturnValue(false)
vi.mocked(skipLocalDevConsole).mockReturnValue(true)
const extension = await testUIExtension({type: 'ui_extension'})
const newApp = testAppLinked({allExtensions: [extension]})

Expand All @@ -249,8 +252,8 @@ describe('pushUpdatesForDevSession', () => {
await flushPromises()

// Then
expect(devSessionStatusManager.status.previewURL).toBe(options.appLocalProxyURL)
vi.mocked(firstPartyDev).mockReturnValue(false)
expect(devSessionStatusManager.status.previewURL).toBe(options.appPreviewURL)
vi.mocked(skipLocalDevConsole).mockReturnValue(false)
})

test('updates preview URL to appPreviewURL when no previewable extensions', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {endHRTimeInMs, startHRTime} from '@shopify/cli-kit/node/hrtime'
import {ClientError} from 'graphql-request'
import {JsonMapType} from '@shopify/cli-kit/node/toml'
import {AbortError} from '@shopify/cli-kit/node/error'
import {firstPartyDev, isUnitTest} from '@shopify/cli-kit/node/context/local'
import {firstPartyDev, isUnitTest, skipLocalDevConsole} from '@shopify/cli-kit/node/context/local'
import {dirname, joinPath} from '@shopify/cli-kit/node/path'
import {readdir} from '@shopify/cli-kit/node/fs'
import {SerialBatchProcessor} from '@shopify/cli-kit/node/serial-batch-processor'
Expand Down Expand Up @@ -240,12 +240,13 @@ export class DevSession {
/**
* Update the preview URL, it only changes if we move between a non-previewable state and a previewable state.
* (i.e. if we go from a state with no extensions to a state with ui-extensions or vice versa)
* Use local dev console only for 1P developers (SHOPIFY_CLI_1P_DEV is enabled).
* Skip the dev console only when BOTH: SHOPIFY_CLI_1P_DEV is NOT enabled AND SHOPIFY_SKIP_LOCAL_DEV_CONSOLE is set.
* @param event - The app event
*/
private updatePreviewURL(event: AppEvent) {
const hasPreview = event.app.allExtensions.filter((ext) => ext.isPreviewable).length > 0
const useDevConsole = firstPartyDev() && hasPreview
const skipDevConsole = !firstPartyDev() && skipLocalDevConsole()
const useDevConsole = !skipDevConsole && hasPreview
const newPreviewURL = useDevConsole ? this.options.appLocalProxyURL : this.options.appPreviewURL
this.statusManager.updateStatus({previewURL: newPreviewURL})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {Config} from '@oclif/core'
import {getEnvironmentVariables} from '@shopify/cli-kit/node/environment'
import {isStorefrontPasswordProtected} from '@shopify/theme'
import {fetchTheme} from '@shopify/cli-kit/node/themes/api'
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'
import {firstPartyDev, skipLocalDevConsole} from '@shopify/cli-kit/node/context/local'

vi.mock('../../context/identifiers.js')
vi.mock('@shopify/cli-kit/node/session.js')
Expand Down Expand Up @@ -69,8 +69,10 @@ beforeEach(() => {
role: 'theme',
processing: false,
})
// By default, firstPartyDev is false (local dev console only shown for 1P devs)
// By default, firstPartyDev is false (dev console URL only used when enabled)
vi.mocked(firstPartyDev).mockReturnValue(false)
// By default, skipLocalDevConsole is false
vi.mocked(skipLocalDevConsole).mockReturnValue(false)
})

const appContextResult = {
Expand Down Expand Up @@ -166,8 +168,8 @@ describe('setup-dev-processes', () => {
graphiqlKey,
})

// Dev console is NOT shown by default (only shown for 1P devs)
expect(res.previewUrl).toBe('https://store.myshopify.io/admin/oauth/redirect_from_cli?client_id=api-key')
// Dev console is shown by default (only skipped when !firstPartyDev() AND skipLocalDevConsole())
expect(res.previewUrl).toBe('https://example.com/proxy/extensions/dev-console')
expect(res.processes[0]).toMatchObject({
type: 'web',
prefix: 'web-backend-frontend',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {AppEventWatcher} from '../app-events/app-event-watcher.js'
import {reloadApp} from '../../../models/app/loader.js'
import {getAvailableTCPPort} from '@shopify/cli-kit/node/tcp'
import {isTruthy} from '@shopify/cli-kit/node/context/utilities'
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'
import {firstPartyDev, skipLocalDevConsole} from '@shopify/cli-kit/node/context/local'
import {getEnvironmentVariables} from '@shopify/cli-kit/node/environment'
import {outputInfo} from '@shopify/cli-kit/node/output'

Expand Down Expand Up @@ -100,10 +100,11 @@ export async function setupDevProcesses({
const appWatcher = new AppEventWatcher(reloadedApp, network.proxyUrl)

// Decide on the appropriate preview URL for a session with these processes
// Use local dev console only for 1P developers (SHOPIFY_CLI_1P_DEV is enabled)
// Skip the dev console only when BOTH: SHOPIFY_CLI_1P_DEV is NOT enabled AND SHOPIFY_SKIP_LOCAL_DEV_CONSOLE is set
const anyPreviewableExtensions = reloadedApp.allExtensions.some((ext) => ext.isPreviewable)
const devConsoleURL = `${network.proxyUrl}/extensions/dev-console`
const useDevConsole = firstPartyDev() && anyPreviewableExtensions
const skipDevConsole = !firstPartyDev() && skipLocalDevConsole()
const useDevConsole = !skipDevConsole && anyPreviewableExtensions
const previewURL = useDevConsole ? devConsoleURL : appPreviewUrl

const graphiqlURL = shouldRenderGraphiQL
Expand Down
1 change: 1 addition & 0 deletions packages/cli-kit/src/private/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const environmentVariables = {
enableCliRedirect: 'SHOPIFY_CLI_ENABLE_CLI_REDIRECT',
env: 'SHOPIFY_CLI_ENV',
firstPartyDev: 'SHOPIFY_CLI_1P_DEV',
skipLocalDevConsole: 'SHOPIFY_SKIP_LOCAL_DEV_CONSOLE',
noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS',
partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN',
runAsUser: 'SHOPIFY_RUN_AS_USER',
Expand Down
10 changes: 10 additions & 0 deletions packages/cli-kit/src/public/node/context/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ export function firstPartyDev(env = process.env): boolean {
return isTruthy(env[environmentVariables.firstPartyDev])
}

/**
* Returns true if the local dev console should be skipped.
*
* @param env - The environment variables from the environment of the current process.
* @returns True if SHOPIFY_SKIP_LOCAL_DEV_CONSOLE is truthy.
*/
export function skipLocalDevConsole(env = process.env): boolean {
return isTruthy(env[environmentVariables.skipLocalDevConsole])
}

/**
* Return gitpodURL if we are running in gitpod.
* Https://www.gitpod.io/docs/environment-variables#default-environment-variables.
Expand Down