Skip to content

Conversation

graygilmore
Copy link
Contributor

@graygilmore graygilmore commented Oct 7, 2025

WHY are these changes introduced?

Some theme commands accept multiple environments to be specified but it can be annoying to write them all out if you have many environments that follow a certain pattern.

This PR allows you to specify environment names using glob patterns:

shopify theme push -e "*-production"

The above example will try to match all environments defined in your shopify.theme.toml file that end with -production. We're support all pattern matching from minimatch including these common patterns:

  • *: Matches zero or more characters
  • ?: Matches exactly one character
  • []: Matches any single character within the brackets
  • {}: Matches any of the comma-separated patterns

How to test your changes?

Install the snapped version:

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

Try running commands with glob patterns:

shopify theme info -e "test*"

With a shopify.theme.toml that looks like this:

[environments.test1]
store = "test1"
password = "asdf"

[environments.test2]
store = "test2"
password = "asdf"

[environments.test3]
store = "test3"
password = "asdf"

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Oct 7, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
79.05% (+0.07% 🔼)
13381/16928
🟡 Branches
72.75% (+0.09% 🔼)
6536/8984
🟡 Functions
79.24% (+0.05% 🔼)
3455/4360
🟡 Lines
79.41% (+0.07% 🔼)
12639/15917
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / fs.ts
87.83% (-0.41% 🔻)
92.31% (-2.69% 🔻)
85.42% (+0.63% 🔼)
88.29% (+0.29% 🔼)

Test suite run success

3265 tests passing in 1347 suites.

Report generated by 🧪jest coverage report action from e4bb2d9

@graygilmore graygilmore force-pushed the gg-glob-envs branch 2 times, most recently from 49f89d1 to 322d2ef Compare October 7, 2025 19:24
@graygilmore graygilmore marked this pull request as ready for review October 8, 2025 14:22
@graygilmore graygilmore requested review from a team as code owners October 8, 2025 14:22
const matchedEnvironments = new Set<string>()

for (const pattern of patterns) {
const isGlob = ENVIRONMENT_ALLOWED_GLOB_PATTERN.test(pattern)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of matching against this we could always parse with minimatch but this would result in us ignoring the flag if it doesn't find any matches.

While this is open for review I'm going to play around with the consequences of that approach.

@graygilmore
Copy link
Contributor Author

/snapit

@Shopify Shopify deleted a comment from github-actions bot Oct 8, 2025
Copy link
Contributor

github-actions bot commented Oct 8, 2025

🫰✨ 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-20251008192534

Caution

After installing, validate the version by running just shopify 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.

Without the quotes we're unable to use globbing patterns like `--only
"templates/*"` because the pattern will get expanded as arguments
instead of passing `"templates/*"` to the command which may have
specific logic to handle those cases.
We'll be adding another function that will need to do this same behavior
so let's separate it out now to make the next diff easier to parse.
@graygilmore
Copy link
Contributor Author

/snapit

Copy link
Contributor

github-actions bot commented Oct 9, 2025

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
@@ -8,9 +8,26 @@ interface LoadEnvironmentOptions {
 }
 /**
  * Loads environments from a file.
- * @param dir - The file path to load environments from.
- * @returns The loaded environments.
+ * @param environmentName - The name of the environment.
+ * @param fileName - The file name to load environments from.
+ * @param options - Optional configuration for loading.
+ * @returns The loaded environment.
  */
 export declare function loadEnvironment(environmentName: string, fileName: string, options?: LoadEnvironmentOptions): Promise<JsonMap | undefined>;
 export declare function environmentFilePath(fileName: string, options?: LoadEnvironmentOptions): Promise<string | undefined>;
+/**
+ * Gets all available environment names from a file.
+ * @param fileName - The file name to load environments from.
+ * @param options - Optional configuration for loading.
+ * @returns Array of environment names, or empty array if none found.
+ */
+export declare function getEnvironmentNames(fileName: string, options?: LoadEnvironmentOptions): Promise<string[]>;
+/**
+ * Expands environment patterns (including globs) to actual environment names.
+ * @param patterns - Array of environment names or glob patterns.
+ * @param fileName - The file name to load environments from.
+ * @param options - Optional configuration for loading.
+ * @returns Array of matched environment names.
+ */
+export declare function expandEnvironmentPatterns(patterns: string[], fileName: string, options?: LoadEnvironmentOptions): Promise<string[]>;
 export {};
\ No newline at end of file

Copy link
Contributor

github-actions bot commented Oct 9, 2025

🫰✨ 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-20251009161632

Caution

After installing, validate the version by running just shopify 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.

@graygilmore graygilmore marked this pull request as draft October 10, 2025 23:54
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

2 participants