@@ -16,6 +16,8 @@ import {
16
16
import { AbortController } from '@shopify/cli-kit/node/abort'
17
17
import { recordEvent , compileData } from '@shopify/cli-kit/node/analytics'
18
18
import { addPublicMetadata , addSensitiveMetadata } from '@shopify/cli-kit/node/metadata'
19
+ import { cwd , joinPath } from '@shopify/cli-kit/node/path'
20
+ import { fileExistsSync } from '@shopify/cli-kit/node/fs'
19
21
import type { Writable } from 'stream'
20
22
21
23
export interface FlagValues {
@@ -103,7 +105,13 @@ export default abstract class ThemeCommand extends Command {
103
105
return
104
106
}
105
107
106
- const environmentsMap = await this . loadEnvironments ( environments , flags , klass )
108
+ const { flags : flagsWithoutDefaults } = await this . parse ( noDefaultsOptions ( klass ) , this . argv )
109
+ if ( 'path' in flagsWithoutDefaults ) {
110
+ this . errorOnGlobalPath ( )
111
+ return
112
+ }
113
+
114
+ const environmentsMap = await this . loadEnvironments ( environments , flags , flagsWithoutDefaults )
107
115
const validationResults = await this . validateEnvironments ( environmentsMap , requiredFlags )
108
116
109
117
const commandAllowsForceFlag = 'force' in klass . flags
@@ -120,16 +128,14 @@ export default abstract class ThemeCommand extends Command {
120
128
* Create a map of environments from the shopify.theme.toml file
121
129
* @param environments - Names of environments to load
122
130
* @param flags - Flags provided via the CLI or by default
123
- * @param klass - The command class
131
+ * @param flagsWithoutDefaults - Flags provided via the CLI
124
132
* @returns The map of environments
125
133
*/
126
134
private async loadEnvironments (
127
135
environments : EnvironmentName [ ] ,
128
136
flags : FlagValues ,
129
- klass : Input < FlagOutput , FlagOutput , ArgOutput > ,
137
+ flagsWithoutDefaults : FlagValues ,
130
138
) : Promise < Map < EnvironmentName , FlagValues > > {
131
- const { flags : flagsWithoutDefaults } = await this . parse ( noDefaultsOptions ( klass ) )
132
-
133
139
const environmentMap = new Map < EnvironmentName , FlagValues > ( )
134
140
135
141
for ( const environmentName of environments ) {
@@ -328,6 +334,27 @@ export default abstract class ThemeCommand extends Command {
328
334
return true
329
335
}
330
336
337
+ /**
338
+ * Error if the --path flag is provided via CLI when running a multi environment command
339
+ * Commands that act on local files require each environment to specify its own path in the shopify.theme.toml
340
+ */
341
+ private errorOnGlobalPath ( ) {
342
+ const tomlPath = joinPath ( cwd ( ) , 'shopify.theme.toml' )
343
+ const tomlInCwd = fileExistsSync ( tomlPath )
344
+
345
+ renderError ( {
346
+ body : [
347
+ "Can't use `--path` flag with multiple environments." ,
348
+ ...( tomlInCwd
349
+ ? [ "Configure each environment's theme path in your shopify.theme.toml file instead." ]
350
+ : [
351
+ 'Run this command from the directory containing shopify.theme.toml.' ,
352
+ 'No shopify.theme.toml found in current directory.' ,
353
+ ] ) ,
354
+ ] ,
355
+ } )
356
+ }
357
+
331
358
private async logAnalyticsData ( session : AdminSession ) : Promise < void > {
332
359
const data = compileData ( )
333
360
0 commit comments