diff --git a/.changeset/chatty-pandas-sort.md b/.changeset/chatty-pandas-sort.md new file mode 100644 index 0000000000..fcb7d3bde5 --- /dev/null +++ b/.changeset/chatty-pandas-sort.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli': minor +--- + +Add multi-environment infrastructure and allow multiple environment usage in theme list command diff --git a/packages/cli-kit/src/public/node/base-command.test.ts b/packages/cli-kit/src/public/node/base-command.test.ts index 6ba92f74b0..a5fdf47d61 100644 --- a/packages/cli-kit/src/public/node/base-command.test.ts +++ b/packages/cli-kit/src/public/node/base-command.test.ts @@ -158,6 +158,19 @@ describe('applying environments', async () => { expect(outputMock.info()).toEqual('') }) + runTestInTmpDir('does not apply flags when multiple environments are specified', async (tmpDir: string) => { + // Given + const outputMock = mockAndCaptureOutput() + outputMock.clear() + + // When + await MockCommand.run(['--path', tmpDir, '--environment', 'validEnvironment', '--environment', 'validEnvironment']) + + // Then + expect(testResult).toEqual({}) + expect(outputMock.info()).toEqual('') + }) + runTestInTmpDir('applies a environment when one is specified', async (tmpDir: string) => { // Given const outputMock = mockAndCaptureOutput() diff --git a/packages/cli-kit/src/public/node/base-command.ts b/packages/cli-kit/src/public/node/base-command.ts index 9adb73b888..8905894e6e 100644 --- a/packages/cli-kit/src/public/node/base-command.ts +++ b/packages/cli-kit/src/public/node/base-command.ts @@ -16,7 +16,7 @@ import {Command, Errors} from '@oclif/core' import {FlagOutput, Input, ParserOutput, FlagInput, ArgOutput} from '@oclif/core/lib/interfaces/parser.js' interface EnvironmentFlags { - environment?: string + environment?: string | string[] path?: string } @@ -47,7 +47,7 @@ abstract class BaseCommand extends Command { // eslint-disable-next-line @typescript-eslint/no-explicit-any protected async init(): Promise { this.exitWithTimestampWhenEnvVariablePresent() - setCurrentCommandId(this.id || '') + setCurrentCommandId(this.id ?? '') if (!isDevelopment()) { // This function runs just prior to `run` await registerCleanBugsnagErrorsFromWithinPlugins(this.config) @@ -139,6 +139,9 @@ This flag is required in non-interactive terminal environments, such as a CI env const environmentsFileName = this.environmentsFilename() if (!flags.environment || !environmentsFileName) return originalResult + // If users pass multiple environments, do not load them and let each command handle it + if (Array.isArray(flags.environment)) return originalResult + // If the specified environment isn't found, don't modify the results const environment = await loadEnvironment(flags.environment, environmentsFileName, {from: flags.path}) if (!environment) return originalResult @@ -152,7 +155,7 @@ This flag is required in non-interactive terminal environments, such as a CI env // Replace the original result with this one. const result = await super.parse(options, [ // Need to specify argv default because we're merging with argsFromEnvironment. - ...(argv || this.argv), + ...(argv ?? this.argv), ...argsFromEnvironment(environment, options, noDefaultsResult), ]) diff --git a/packages/cli/README.md b/packages/cli/README.md index 97edb70e2b..858f9a56b0 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -1706,23 +1706,23 @@ USAGE [--init] [--list] [--no-color] [-o text|json] [--path ] [--print] [--verbose] [-v] FLAGS - -C, --config= Use the config provided, overriding .theme-check.yml if present - Supports all theme-check: config values, e.g., theme-check:theme-app-extension, - theme-check:recommended, theme-check:all - For backwards compatibility, :theme_app_extension is also supported - -a, --auto-correct Automatically fix offenses - -e, --environment= The environment to apply to the current command. - -o, --output=