Add glob pattern support for --environment flag#7173
Draft
graygilmore wants to merge 1 commit intomainfrom
Draft
Add glob pattern support for --environment flag#7173graygilmore wants to merge 1 commit intomainfrom
graygilmore wants to merge 1 commit intomainfrom
Conversation
a337335 to
abfa4e6
Compare
Contributor
Author
|
/snapit |
abfa4e6 to
3fdf83b
Compare
Contributor
|
🫰✨ 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-20260402231202Caution After installing, validate the version by running |
3fdf83b to
ab42fa4
Compare
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>
ab42fa4 to
bb545b8
Compare
Contributor
Differences in type declarationsWe 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:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--environment "*-production") so users can target multiple environments at once instead of specifying each individuallybase-command.tsbefore single/multi environment routing, keeping downstream consumers (like theme-command) unchangedminimatch(already a dependency) for pattern matching with support for*,?,[abc], and{a,b}syntaxCloses #6481
Supersedes #6493 with a cleaner single-expansion-point architecture.
🎩 Tophatting
Setup
Create a
shopify.theme.tomlwith multiple environments:Test cases
shopify theme pull -e "*-production"— should list bothus-productionandeu-productionas matched environmentsshopify theme pull -e "staging"— should apply the staging environment flags directlyshopify theme pull -e "*-sandbox"— should warn that no environments matched*must be wrapped in quotes to prevent shell expansionTest plan
environments.test.ts— 19 tests coveringgetEnvironmentNamesandexpandEnvironmentPatternsbase-command.test.ts— 34 tests including 4 new glob expansion teststheme-command.test.ts— 24 tests (regression, no changes needed)🤖 Generated with Claude Code