Skip to content

Commit a34012f

Browse files
EvilGenius13dejmedus
authored andcommitted
Create concurrency-friendly theme uploaders
`themeUploader` displays theme sync progress with an Ink animation. When multiple are ran at the same time, like in multi environment commands, it can behave unexpectedly. This commit creates alternative uploaders to prevent this
1 parent 42d0650 commit a34012f

File tree

3 files changed

+346
-35
lines changed

3 files changed

+346
-35
lines changed

packages/theme/src/cli/commands/theme/push.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import {globFlags, themeFlags} from '../../flags.js'
22
import ThemeCommand from '../../utilities/theme-command.js'
3-
import {push, PushFlags} from '../../services/push.js'
3+
import {push} from '../../services/push.js'
44
import {Flags} from '@oclif/core'
55
import {globalFlags, jsonFlag} from '@shopify/cli-kit/node/cli'
6+
67
import {recordTiming} from '@shopify/cli-kit/node/analytics'
8+
import {OutputFlags} from '@oclif/core/interfaces'
9+
import {AdminSession} from '@shopify/cli-kit/node/session'
10+
11+
type PushFlags = OutputFlags<typeof Push.flags>
712

813
export default class Push extends ThemeCommand {
914
static summary = 'Uploads your local theme files to the connected store, overwriting the remote version if specified.'
@@ -91,33 +96,14 @@ export default class Push extends ThemeCommand {
9196
description: 'Require theme check to pass without errors before pushing. Warnings are allowed.',
9297
env: 'SHOPIFY_FLAG_STRICT_PUSH',
9398
}),
99+
environment: themeFlags.environment,
94100
}
95101

96-
async run(): Promise<void> {
97-
const {flags} = await this.parse(Push)
98-
99-
const pushFlags: PushFlags = {
100-
path: flags.path,
101-
password: flags.password,
102-
store: flags.store,
103-
theme: flags.theme,
104-
development: flags.development,
105-
live: flags.live,
106-
unpublished: flags.unpublished,
107-
nodelete: flags.nodelete,
108-
only: flags.only,
109-
ignore: flags.ignore,
110-
json: flags.json,
111-
allowLive: flags['allow-live'],
112-
publish: flags.publish,
113-
force: flags.force,
114-
noColor: flags['no-color'],
115-
verbose: flags.verbose,
116-
strict: flags.strict,
117-
}
102+
static multiEnvironmentsFlags = ['store', 'password', 'theme']
118103

104+
async command(flags: PushFlags, adminSession: AdminSession): Promise<void> {
119105
recordTiming('theme-command:push')
120-
await push(pushFlags)
106+
await push(flags, adminSession)
121107
recordTiming('theme-command:push')
122108
}
123109
}

packages/theme/src/cli/services/push.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/* eslint-disable tsdoc/syntax */
22
import {hasRequiredThemeDirectories, mountThemeFileSystem} from '../utilities/theme-fs.js'
3-
import {uploadTheme} from '../utilities/theme-uploader.js'
43
import {ensureDirectoryConfirmed, themeComponent} from '../utilities/theme-ui.js'
5-
import {ensureThemeStore} from '../utilities/theme-store.js'
64
import {DevelopmentThemeManager} from '../utilities/development-theme-manager.js'
75
import {findOrSelectTheme} from '../utilities/theme-selector.js'
86
import {Role} from '../utilities/theme-selector/fetch.js'
97
import {configureCLIEnvironment} from '../utilities/cli-config.js'
108
import {runThemeCheck} from '../commands/theme/check.js'
11-
import {AdminSession, ensureAuthenticatedThemes} from '@shopify/cli-kit/node/session'
9+
import {uploadTheme4} from '../utilities/theme-uploader.js'
10+
import {AdminSession} from '@shopify/cli-kit/node/session'
1211
import {themeCreate, fetchChecksums, themePublish} from '@shopify/cli-kit/node/themes/api'
1312
import {Result, Theme} from '@shopify/cli-kit/node/themes/types'
1413
import {outputResult} from '@shopify/cli-kit/node/output'
@@ -33,6 +32,7 @@ interface PushOptions {
3332
publish?: boolean
3433
ignore?: string[]
3534
only?: string[]
35+
environment?: string
3636
}
3737

3838
interface JsonOutput {
@@ -99,14 +99,17 @@ export interface PushFlags {
9999

100100
/** Require theme check to pass without errors before pushing. Warnings are allowed. */
101101
strict?: boolean
102+
103+
/** The environment to push the theme to. */
104+
environment?: string
102105
}
103106

104107
/**
105108
* Initiates the push process based on provided flags.
106109
*
107110
* @param flags - The flags for the push operation.
108111
*/
109-
export async function push(flags: PushFlags): Promise<void> {
112+
export async function push(flags: PushFlags, adminSession?: AdminSession) {
110113
if (flags.strict) {
111114
const outputType = flags.json ? 'json' : 'text'
112115
const {offenses} = await runThemeCheck(flags.path ?? cwd(), outputType)
@@ -127,22 +130,20 @@ export async function push(flags: PushFlags): Promise<void> {
127130
})
128131

129132
const force = flags.force ?? false
130-
const store = ensureThemeStore({store: flags.store})
131-
const adminSession = await ensureAuthenticatedThemes(store, flags.password)
132133

133134
const workingDirectory = path ? resolvePath(path) : cwd()
134135
if (!(await hasRequiredThemeDirectories(workingDirectory)) && !(await ensureDirectoryConfirmed(force))) {
135136
return
136137
}
137138

138-
const selectedTheme: Theme | undefined = await createOrSelectTheme(adminSession, flags)
139+
const selectedTheme: Theme | undefined = await createOrSelectTheme(adminSession as unknown as AdminSession, flags)
139140
if (!selectedTheme) {
140141
return
141142
}
142143

143144
recordTiming('theme-service:push:setup')
144145

145-
await executePush(selectedTheme, adminSession, {
146+
await executePush(selectedTheme, adminSession as unknown as AdminSession, {
146147
path: workingDirectory,
147148
nodelete: flags.nodelete ?? false,
148149
publish: flags.publish ?? false,
@@ -166,7 +167,7 @@ async function executePush(theme: Theme, session: AdminSession, options: PushOpt
166167
const themeFileSystem = mountThemeFileSystem(options.path, {filters: options})
167168
recordTiming('theme-service:push:file-system')
168169

169-
const {uploadResults, renderThemeSyncProgress} = await uploadTheme(
170+
const {uploadResults, renderThemeSyncProgress} = await uploadTheme4(
170171
theme,
171172
session,
172173
themeChecksums,

0 commit comments

Comments
 (0)