Skip to content

Add glob pattern support for --environment flag#7173

Draft
graygilmore wants to merge 1 commit intomainfrom
gg-glob-envs
Draft

Add glob pattern support for --environment flag#7173
graygilmore wants to merge 1 commit intomainfrom
gg-glob-envs

Conversation

@graygilmore
Copy link
Copy Markdown
Contributor

Summary

  • Adds glob pattern support (e.g. --environment "*-production") so users can target multiple environments at once instead of specifying each individually
  • Expands patterns at a single point in base-command.ts before single/multi environment routing, keeping downstream consumers (like theme-command) unchanged
  • Uses minimatch (already a dependency) for pattern matching with support for *, ?, [abc], and {a,b} syntax

Closes #6481

Supersedes #6493 with a cleaner single-expansion-point architecture.

🎩 Tophatting

Setup

Create a shopify.theme.toml with multiple environments:

[environments.us-production]
store = "us-store.myshopify.com"

[environments.eu-production]
store = "eu-store.myshopify.com"

[environments.staging]
store = "staging-store.myshopify.com"

Test cases

  1. Glob matching multiple envs: shopify theme pull -e "*-production" — should list both us-production and eu-production as matched environments
  2. Single glob match: shopify theme pull -e "staging" — should apply the staging environment flags directly
  3. No match warning: shopify theme pull -e "*-sandbox" — should warn that no environments matched
  4. Quote requirement: Patterns with * must be wrapped in quotes to prevent shell expansion

Test plan

  • environments.test.ts — 19 tests covering getEnvironmentNames and expandEnvironmentPatterns
  • base-command.test.ts — 34 tests including 4 new glob expansion tests
  • theme-command.test.ts — 24 tests (regression, no changes needed)

🤖 Generated with Claude Code

@graygilmore graygilmore force-pushed the gg-glob-envs branch 5 times, most recently from a337335 to abfa4e6 Compare April 2, 2026 22:56
@graygilmore
Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🫰✨ Thanks @graygilmore! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260402231202

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Theme users with many similarly-named environments (e.g. us-production, eu-production, int-production) currently must specify each one individually with -e. This adds glob pattern support so they can use patterns like --environment "*-production" to target multiple environments at once.

The implementation expands glob patterns at a single point in base-command's resultWithEnvironment(), before the single/multi environment routing logic. This avoids needing downstream consumers like theme-command to handle expansion themselves.

Key design decisions:

- Uses minimatch (already a dependency) for pattern matching

- Extracts shared TOML parsing into private decodeEnvironments() to avoid duplication between loadEnvironment() and the new getEnvironmentNames()

- Expansion happens early so originalResult.flags.environment gets real names, not glob patterns

- Deduplicates across multiple patterns via Set

- Warns per-pattern when no environments match

Closes #6481

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/environments.d.ts
@@ -4,11 +4,16 @@ interface LoadEnvironmentOptions {
     from?: string;
     silent?: boolean;
 }
+export declare function loadEnvironment(environmentName: string, fileName: string, options?: LoadEnvironmentOptions): Promise<JsonMap | undefined>;
 /**
- * Loads environments from a file.
- * @param dir - The file path to load environments from.
- * @returns The loaded environments.
+ * Returns all environment names defined in the TOML file.
  */
-export declare function loadEnvironment(environmentName: string, fileName: string, options?: LoadEnvironmentOptions): Promise<JsonMap | undefined>;
+export declare function getEnvironmentNames(fileName: string, options?: LoadEnvironmentOptions): Promise<string[]>;
+/**
+ * Expands glob patterns against all available environment names.
+ * Literal (non-glob) names pass through unchanged via minimatch identity matching.
+ * Warns for each pattern that matches nothing.
+ */
+export declare function expandEnvironmentPatterns(patterns: string[], fileName: string, options?: LoadEnvironmentOptions): Promise<string[]>;
 export declare function environmentFilePath(fileName: string, options?: LoadEnvironmentOptions): Promise<string | undefined>;
 export {};
\ No newline at end of file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Support glob patterns in theme environment flags

1 participant